Skip to content

Instantly share code, notes, and snippets.

@asendra
Created April 20, 2015 11:53
Show Gist options
  • Save asendra/bbc40478e0d78705294c to your computer and use it in GitHub Desktop.
Save asendra/bbc40478e0d78705294c to your computer and use it in GitHub Desktop.
Grayscale YUV rpi
//Try to some colors http://en.wikipedia.org/wiki/YUV
int chrominance_offset = userdata->width * userdata->height;
int v_offset = chrominance_offset / 4;
int chroma = 0;
if (output_buffer) {
mmal_buffer_header_mem_lock(buffer);
memcpy(output_buffer->data, buffer->data, buffer->length);
int grayOffset;
for (grayOffset = chrominance_offset; grayOffset < (chrominance_offset + v_offset + v_offset); ++grayOffset)
{
output_buffer->data[grayOffset] = 0x00;
}
/*
// dim
int x, y;
for (x = 0; x < 600; x++) {
for (y = 0; y < 100; y++) {
if (local_overlay_buffer[(y * 600 + x) * 4] > 0) {
//copy luma Y
output_buffer->data[y * userdata->width + x ] = 0xdf;
//pointer to chrominance U/V
chroma= y / 2 * userdata->width / 2 + x / 2 + chrominance_offset;
//just guessing colors
output_buffer->data[chroma] = 0x38 ;
output_buffer->data[chroma+v_offset] = 0xb8 ;
}
}
}
*/
output_buffer->length = buffer->length;
mmal_buffer_header_mem_unlock(buffer);
if (mmal_port_send_buffer(userdata->encoder_input_port, output_buffer) != MMAL_SUCCESS) {
fprintf(stderr, "ERROR: Unable to send buffer \n");
}
} else {
fprintf(stderr, "ERROR: mmal_queue_get (%d)\n", output_buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment