Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fd0157

Browse files
committed
Merge pull request raspberrypi#181 from JamesH65/drc
Add DRC (Dynamic range compression)
2 parents 02633df + ea90b82 commit 5fd0157

5 files changed

Lines changed: 64 additions & 4 deletions

File tree

host_applications/linux/apps/raspicam/RaspiCamControl.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ static XREF_T metering_mode_map[] =
113113

114114
static 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

136147
static 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

158170
static 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
/**

host_applications/linux/apps/raspicam/RaspiCamControl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ typedef struct
132132
int shutter_speed; /// 0 = auto, otherwise the shutter speed in ms
133133
float awb_gains_r; /// AWB red gain
134134
float awb_gains_b; /// AWB blue gain
135+
MMAL_PARAMETER_DRC_STRENGTH_T drc_level; // Strength of Dynamic Range compression to apply
135136
} RASPICAM_CAMERA_PARAMETERS;
136137

137138

@@ -167,6 +168,8 @@ int raspicamcontrol_set_rotation(MMAL_COMPONENT_T *camera, int rotation);
167168
int raspicamcontrol_set_flips(MMAL_COMPONENT_T *camera, int hflip, int vflip);
168169
int raspicamcontrol_set_ROI(MMAL_COMPONENT_T *camera, PARAM_FLOAT_RECT_T rect);
169170
int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T *camera, int speed_ms);
171+
int raspicamcontrol_set_DRC(MMAL_COMPONENT_T *camera, MMAL_PARAMETER_DRC_STRENGTH_T strength);
172+
170173

171174
//Individual getting functions
172175
int raspicamcontrol_get_saturation(MMAL_COMPONENT_T *camera);

host_applications/linux/apps/raspicam/RaspiStill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5757
#include <errno.h>
5858
#include <sysexits.h>
5959

60-
#define VERSION_STRING "v1.3.7"
60+
#define VERSION_STRING "v1.3.8"
6161

6262
#include "bcm_host.h"
6363
#include "interface/vcos/vcos.h"

host_applications/linux/apps/raspicam/RaspiStillYUV.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5555
#include <memory.h>
5656
#include <sysexits.h>
5757

58-
#define VERSION_STRING "v1.3.3"
58+
#define VERSION_STRING "v1.3.4"
5959

6060
#include "bcm_host.h"
6161
#include "interface/vcos/vcos.h"

host_applications/linux/apps/raspicam/RaspiVid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5656
#include <memory.h>
5757
#include <sysexits.h>
5858

59-
#define VERSION_STRING "v1.3.11"
59+
#define VERSION_STRING "v1.3.12"
6060

6161
#include "bcm_host.h"
6262
#include "interface/vcos/vcos.h"

0 commit comments

Comments
 (0)