Skip to content

Commit

Permalink
Raspicam: Update for justification and offset in annotation
Browse files Browse the repository at this point in the history
Camera annotation can now support left and right justification of
the text, and setting an x and y offset.
Update the raspicam apps to allow taking these via the command
line.
  • Loading branch information
6by9 authored and popcornmix committed Jul 26, 2018
1 parent 53469d9 commit f74ea7f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
29 changes: 21 additions & 8 deletions host_applications/linux/apps/raspicam/RaspiCamControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static COMMAND_LIST cmdline_commands[] =
{CommandStereoMode, "-stereo", "3d", "Select stereoscopic mode", 1},
{CommandStereoDecimate,"-decimate","dec", "Half width/height of stereo image"},
{CommandStereoSwap, "-3dswap", "3dswap", "Swap camera order for stereoscopic"},
{CommandAnnotateExtras,"-annotateex","ae", "Set extra annotation parameters (text size, text colour(hex YUV), bg colour(hex YUV))", 2},
{CommandAnnotateExtras,"-annotateex","ae", "Set extra annotation parameters (text size, text colour(hex YUV), bg colour(hex YUV), justify, x, y)", 2},
{CommandAnalogGain, "-analoggain", "ag", "Set the analog gain (floating point)", 1},
{CommandDigitalGain, "-digitalgain", "dg", "Set the digital gain (floating point)", 1},
};
Expand Down Expand Up @@ -772,9 +772,13 @@ int raspicamcontrol_parse_cmdline(RASPICAM_CAMERA_PARAMETERS *params, const char
case CommandAnnotateExtras:
{
// 3 parameters - text size (6-80), text colour (Hex VVUUYY) and background colour (Hex VVUUYY)
sscanf(arg2, "%u,%X,%X", &params->annotate_text_size,
sscanf(arg2, "%u,%X,%X,%u,%u,%u", &params->annotate_text_size,
&params->annotate_text_colour,
&params->annotate_bg_colour);
&params->annotate_bg_colour,
&params->annotate_justify,
&params->annotate_x,
&params->annotate_y
);
used=2;
break;
}
Expand Down Expand Up @@ -1065,7 +1069,11 @@ int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T *camera, const RASPICAM_
result += raspicamcontrol_set_annotate(camera, params->enable_annotate, params->annotate_string,
params->annotate_text_size,
params->annotate_text_colour,
params->annotate_bg_colour);
params->annotate_bg_colour,
params->annotate_justify,
params->annotate_x,
params->annotate_y
);
result += raspicamcontrol_set_gains(camera, params->analog_gain, params->digital_gain);

return result;
Expand Down Expand Up @@ -1594,16 +1602,17 @@ int raspicamcontrol_set_stats_pass(MMAL_COMPONENT_T *camera, int stats_pass)
* @return 0 if successful, non-zero if any parameters out of range
*/
int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int settings, const char *string,
const int text_size, const int text_colour, const int bg_colour)
const int text_size, const int text_colour, const int bg_colour,
const unsigned int justify, const unsigned int x, const unsigned int y)
{
MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T annotate =
{{MMAL_PARAMETER_ANNOTATE, sizeof(MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T)}};
MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T annotate =
{{MMAL_PARAMETER_ANNOTATE, sizeof(MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T)}};

if (settings)
{
time_t t = time(NULL);
struct tm tm = *localtime(&t);
char tmp[MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3];
char tmp[MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V4];
int process_datetime = 1;

annotate.enable = 1;
Expand Down Expand Up @@ -1682,6 +1691,10 @@ int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int settings, c
}
else
annotate.custom_background_colour = MMAL_FALSE;

annotate.justify = justify;
annotate.x_offset = x;
annotate.y_offset = y;
}
else
annotate.enable = 0;
Expand Down
7 changes: 6 additions & 1 deletion host_applications/linux/apps/raspicam/RaspiCamControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ typedef struct raspicam_camera_parameters_s
int annotate_text_size; // Text size for annotation
int annotate_text_colour; // Text colour for annotation
int annotate_bg_colour; // Background colour for annotation
unsigned int annotate_justify;
unsigned int annotate_x;
unsigned int annotate_y;

MMAL_PARAMETER_STEREOSCOPIC_MODE_T stereo_mode;
float analog_gain; // Analog gain
float digital_gain; // Digital gain
Expand Down Expand Up @@ -210,7 +214,8 @@ int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T *camera, int speed_ms);
int raspicamcontrol_set_DRC(MMAL_COMPONENT_T *camera, MMAL_PARAMETER_DRC_STRENGTH_T strength);
int raspicamcontrol_set_stats_pass(MMAL_COMPONENT_T *camera, int stats_pass);
int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int bitmask, const char *string,
const int text_size, const int text_colour, const int bg_colour);
const int text_size, const int text_colour, const int bg_colour,
const unsigned int justify, const unsigned int x, const unsigned int y);
int raspicamcontrol_set_stereo_mode(MMAL_PORT_T *port, MMAL_PARAMETER_STEREOSCOPIC_MODE_T *stereo_mode);
int raspicamcontrol_set_gains(MMAL_COMPONENT_T *camera, float analog, float digital);

Expand Down
12 changes: 10 additions & 2 deletions host_applications/linux/apps/raspicam/RaspiVid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,11 @@ static void update_annotation_data(RASPIVID_STATE *state)
raspicamcontrol_set_annotate(state->camera_component, state->camera_parameters.enable_annotate, text,
state->camera_parameters.annotate_text_size,
state->camera_parameters.annotate_text_colour,
state->camera_parameters.annotate_bg_colour);
state->camera_parameters.annotate_bg_colour,
state->camera_parameters.annotate_justify,
state->camera_parameters.annotate_x,
state->camera_parameters.annotate_y
);

free(text);
}
Expand All @@ -1267,7 +1271,11 @@ static void update_annotation_data(RASPIVID_STATE *state)
raspicamcontrol_set_annotate(state->camera_component, state->camera_parameters.enable_annotate, state->camera_parameters.annotate_string,
state->camera_parameters.annotate_text_size,
state->camera_parameters.annotate_text_colour,
state->camera_parameters.annotate_bg_colour);
state->camera_parameters.annotate_bg_colour,
state->camera_parameters.annotate_justify,
state->camera_parameters.annotate_x,
state->camera_parameters.annotate_y
);
}
}

Expand Down

0 comments on commit f74ea7f

Please sign in to comment.