From 4513db58c0f5a4e94b61bebf633277d1a3efc4eb Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Fri, 28 Jun 2024 12:01:44 +0200 Subject: apps: common: dng_writer: Add thumbnail scanline function for Raw Add a thumbnail function for raw formats that are 16bit aligned. This is needed for the upcoming RAW10 and RAW12 implemntation. Use the new function for RAW16 as the thumbScanlineRaw_CSI2P produces incorrect results for that format (it averages over adjacent bytes, which works for the CSI formats). Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Laurent Pinchart --- src/apps/common/dng_writer.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/apps/common') diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp index 3b17dadc..96bbd26b 100644 --- a/src/apps/common/dng_writer.cpp +++ b/src/apps/common/dng_writer.cpp @@ -144,6 +144,29 @@ void packScanlineRaw16(void *output, const void *input, unsigned int width) std::copy(in, in + width, out); } +/* Thumbnail function for raw data with each pixel aligned to 16bit. */ +void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input, + unsigned int width, unsigned int stride) +{ + const uint16_t *in = static_cast(input); + const uint16_t *in2 = static_cast(input) + stride / 2; + uint8_t *out = static_cast(output); + + /* Shift down to 8. */ + unsigned int shift = info.bitsPerSample - 8; + + /* Simple averaging that produces greyscale RGB values. */ + for (unsigned int x = 0; x < width; x++) { + uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2; + value = value >> shift; + *out++ = value; + *out++ = value; + *out++ = value; + in += 16; + in2 += 16; + } +} + void packScanlineRaw10_CSI2P(void *output, const void *input, unsigned int width) { const uint8_t *in = static_cast(input); @@ -321,25 +344,25 @@ const std::map formatInfo = { .bitsPerSample = 16, .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, .packScanline = packScanlineRaw16, - .thumbScanline = thumbScanlineRaw_CSI2P, + .thumbScanline = thumbScanlineRaw, } }, { formats::SGBRG16, { .bitsPerSample = 16, .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, .packScanline = packScanlineRaw16, - .thumbScanline = thumbScanlineRaw_CSI2P, + .thumbScanline = thumbScanlineRaw, } }, { formats::SGRBG16, { .bitsPerSample = 16, .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, .packScanline = packScanlineRaw16, - .thumbScanline = thumbScanlineRaw_CSI2P, + .thumbScanline = thumbScanlineRaw, } }, { formats::SRGGB16, { .bitsPerSample = 16, .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineRaw16, - .thumbScanline = thumbScanlineRaw_CSI2P, + .thumbScanline = thumbScanlineRaw, } }, { formats::SBGGR10_CSI2P, { .bitsPerSample = 10, -- cgit v1.2.1