Browse Source

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.
Yassine Oudjana 3 years ago
parent
commit
7b403f2e79
3 changed files with 34 additions and 2 deletions
  1. 26 0
      src/camera.c
  2. 1 0
      src/camera.h
  3. 7 2
      src/process_pipeline.c

+ 26 - 0
src/camera.c

@@ -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)
 {

+ 1 - 0
src/camera.h

@@ -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,

+ 7 - 2
src/process_pipeline.c

@@ -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;