@@ -113,6 +113,16 @@ static XREF_T metering_mode_map[] =
113113
114114static const int metering_mode_map_size = sizeof (metering_mode_map )/sizeof (metering_mode_map [0 ]);
115115
116+ static XREF_T drc_mode_map [] =
117+ {
118+ {"off" , MMAL_PARAMETER_DRC_STRENGTH_OFF },
119+ {"low" , MMAL_PARAMETER_DRC_STRENGTH_LOW },
120+ {"med" , MMAL_PARAMETER_DRC_STRENGTH_MEDIUM },
121+ {"high" , MMAL_PARAMETER_DRC_STRENGTH_HIGH }
122+ };
123+
124+ static const int drc_mode_map_size = sizeof (drc_mode_map )/sizeof (drc_mode_map [0 ]);
125+
116126
117127#define CommandSharpness 0
118128#define CommandContrast 1
@@ -132,6 +142,7 @@ static const int metering_mode_map_size = sizeof(metering_mode_map)/sizeof(meter
132142#define CommandROI 15
133143#define CommandShutterSpeed 16
134144#define CommandAwbGains 17
145+ #define CommandDRCLevel 18
135146
136147static COMMAND_LIST cmdline_commands [] =
137148{
@@ -152,7 +163,8 @@ static COMMAND_LIST cmdline_commands[] =
152163 {CommandVFlip , "-vflip" , "vf" , "Set vertical flip" , 0 },
153164 {CommandROI , "-roi" , "roi" ,"Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])" , 1 },
154165 {CommandShutterSpeed ,"-shutter" , "ss" , "Set shutter speed in microseconds" , 1 },
155- {CommandAwbGains , "-awbgains" , "awbg" , "Set AWB gains - AWB mode must be off" , 1 }
166+ {CommandAwbGains , "-awbgains" , "awbg" , "Set AWB gains - AWB mode must be off" , 1 },
167+ {CommandDRCLevel , "-drc" , "drc" , "Set DRC Level" , 1 }
156168};
157169
158170static int cmdline_commands_size = sizeof (cmdline_commands ) / sizeof (cmdline_commands [0 ]);
@@ -451,6 +463,22 @@ static MMAL_PARAM_EXPOSUREMETERINGMODE_T metering_mode_from_string(const char *s
451463 return MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE ;
452464}
453465
466+ /**
467+ * Convert string to the MMAL parameter for DRC level
468+ * @param str Incoming string to match
469+ * @return MMAL parameter matching the string, or the AUTO option if no match found
470+ */
471+ static MMAL_PARAMETER_DRC_STRENGTH_T drc_mode_from_string (const char * str )
472+ {
473+ int i = raspicli_map_xref (str , drc_mode_map , drc_mode_map_size );
474+
475+ if ( i != -1 )
476+ return (MMAL_PARAMETER_DRC_STRENGTH_T )i ;
477+
478+ vcos_log_error ("Unknown DRC level: %s" , str );
479+ return MMAL_PARAMETER_DRC_STRENGTH_OFF ;
480+ }
481+
454482/**
455483 * Parse a possible command pair - command and parameter
456484 * @param arg1 Command
@@ -601,6 +629,14 @@ int raspicamcontrol_parse_cmdline(RASPICAM_CAMERA_PARAMETERS *params, const char
601629 used = 2 ;
602630 break ;
603631 }
632+
633+ case CommandDRCLevel :
634+ {
635+ params -> drc_level = drc_mode_from_string (arg2 );
636+ used = 2 ;
637+ break ;
638+ }
639+
604640 }
605641
606642 return used ;
@@ -796,6 +832,7 @@ int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T *camera, const RASPICAM_
796832 result += raspicamcontrol_set_flips (camera , params -> hflip , params -> vflip );
797833 result += raspicamcontrol_set_ROI (camera , params -> roi );
798834 result += raspicamcontrol_set_shutter_speed (camera , params -> shutter_speed );
835+ result += raspicamcontrol_set_DRC (camera , params -> drc_level );
799836
800837 return result ;
801838}
@@ -1188,6 +1225,26 @@ int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T *camera, int speed)
11881225 return mmal_status_to_int (mmal_port_parameter_set_uint32 (camera -> control , MMAL_PARAMETER_SHUTTER_SPEED , speed ));
11891226}
11901227
1228+ /**
1229+ * Adjust the Dynamic range compression level
1230+ * @param camera Pointer to camera component
1231+ * @param strength Strength of DRC to apply
1232+ * MMAL_PARAMETER_DRC_STRENGTH_OFF
1233+ * MMAL_PARAMETER_DRC_STRENGTH_LOW
1234+ * MMAL_PARAMETER_DRC_STRENGTH_MEDIUM
1235+ * MMAL_PARAMETER_DRC_STRENGTH_HIGH
1236+ *
1237+ * @return 0 if successful, non-zero if any parameters out of range
1238+ */
1239+ int raspicamcontrol_set_DRC (MMAL_COMPONENT_T * camera , MMAL_PARAMETER_DRC_STRENGTH_T strength )
1240+ {
1241+ MMAL_PARAMETER_DRC_T drc = {{MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION , sizeof (MMAL_PARAMETER_DRC_T )}, strength };
1242+
1243+ if (!camera )
1244+ return 1 ;
1245+
1246+ return mmal_status_to_int (mmal_port_parameter_set (camera -> control , & drc .hdr ));
1247+ }
11911248
11921249
11931250/**
0 commit comments