Set TIFFTAG_CFAPATTERN depending on pixel format

Add a function to get a CFA pattern string that matches a given
pixel format, and use it to set TIFFTAG_CFAPATTERN on capture.
This commit is contained in:
Yassine Oudjana 2022-01-21 13:36:13 +04:00
parent d8f34f7f89
commit 7b403f2e79
3 changed files with 34 additions and 2 deletions

View File

@ -176,6 +176,32 @@ mp_pixel_format_cfa(MPPixelFormat pixel_format)
}
}
const char *
mp_pixel_format_cfa_pattern(MPPixelFormat pixel_format)
{
g_return_val_if_fail(pixel_format < MP_PIXEL_FMT_MAX, 0);
switch (pixel_format) {
case MP_PIXEL_FMT_BGGR8:
case MP_PIXEL_FMT_BGGR10P:
return "\002\001\001\000";
break;
case MP_PIXEL_FMT_GBRG8:
case MP_PIXEL_FMT_GBRG10P:
return "\001\002\000\001";
break;
case MP_PIXEL_FMT_GRBG8:
case MP_PIXEL_FMT_GRBG10P:
return "\001\000\002\001";
break;
case MP_PIXEL_FMT_RGGB8:
case MP_PIXEL_FMT_RGGB10P:
return "\000\001\001\002";
break;
default:
return NULL;
}
}
uint32_t
mp_pixel_format_width_to_bytes(MPPixelFormat pixel_format, uint32_t width)
{

View File

@ -32,6 +32,7 @@ uint32_t mp_pixel_format_to_v4l_bus_code(MPPixelFormat pixel_format);
uint32_t mp_pixel_format_bits_per_pixel(MPPixelFormat pixel_format);
uint32_t mp_pixel_format_pixel_depth(MPPixelFormat pixel_format);
const char *mp_pixel_format_cfa(MPPixelFormat pixel_format);
const char *mp_pixel_format_cfa_pattern(MPPixelFormat pixel_format);
uint32_t mp_pixel_format_width_to_bytes(MPPixelFormat pixel_format, uint32_t width);
uint32_t mp_pixel_format_width_to_colors(MPPixelFormat pixel_format, uint32_t width);
uint32_t mp_pixel_format_height_to_colors(MPPixelFormat pixel_format,

View File

@ -488,9 +488,14 @@ process_image_for_capture(const uint8_t *image, int count)
static const short cfapatterndim[] = { 2, 2 };
TIFFSetField(tif, TIFFTAG_CFAREPEATPATTERNDIM, cfapatterndim);
#if (TIFFLIB_VERSION < 20201219) && !LIBTIFF_CFA_PATTERN
TIFFSetField(tif, TIFFTAG_CFAPATTERN, "\002\001\001\000"); // BGGR
TIFFSetField(tif,
TIFFTAG_CFAPATTERN,
mp_pixel_format_cfa_pattern(mode.pixel_format));
#else
TIFFSetField(tif, TIFFTAG_CFAPATTERN, 4, "\002\001\001\000"); // BGGR
TIFFSetField(tif,
TIFFTAG_CFAPATTERN,
4,
mp_pixel_format_cfa_pattern(mode.pixel_format));
#endif
printf("TIFF version %d\n", TIFFLIB_VERSION);
int whitelevel = camera->whitelevel;