[v2,3/3] apps: common: dng_writer: Support RAW10 and RAW12 format
diff mbox series

Message ID 20240628100227.2910842-4-stefan.klug@ideasonboard.com
State Accepted
Headers show
Series
  • * dng_writer: Add support for RAW10 and RAW 12
Related show

Commit Message

Stefan Klug June 28, 2024, 10:01 a.m. UTC
Add support for RAW10 and RAW12 to the dng_writer. This is needed on
imx8mp to produce tuning images.  Both formats were tested on a debix
som with a imx335.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/apps/common/dng_writer.cpp | 76 ++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

Comments

Kieran Bingham June 28, 2024, 10:48 a.m. UTC | #1
Quoting Stefan Klug (2024-06-28 11:01:45)
> Add support for RAW10 and RAW12 to the dng_writer. This is needed on
> imx8mp to produce tuning images.  Both formats were tested on a debix
> som with a imx335.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/apps/common/dng_writer.cpp | 76 ++++++++++++++++++++++++++++++++++
>  1 file changed, 76 insertions(+)
> 
> diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> index 474aa72beb92..f61930b68b2b 100644
> --- a/src/apps/common/dng_writer.cpp
> +++ b/src/apps/common/dng_writer.cpp
> @@ -136,6 +136,34 @@ void packScanlineRaw8(void *output, const void *input, unsigned int width)
>         std::copy(in, in + width, out);
>  }
>  
> +void packScanlineRaw10(void *output, const void *input, unsigned int width)
> +{
> +       const uint16_t *in = static_cast<const uint16_t *>(input);
> +       uint8_t *out = static_cast<uint8_t *>(output);
> +
> +       for (unsigned int i = 0; i < width; i += 4) {
> +               *out++ = (in[0] & 0x3fc) >> 2;
> +               *out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4;
> +               *out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6;
> +               *out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8;
> +               *out++ = (in[3] & 0x0ff);
> +               in += 4;
> +       }
> +}
> +
> +void packScanlineRaw12(void *output, const void *input, unsigned int width)
> +{
> +       const uint16_t *in = static_cast<const uint16_t *>(input);
> +       uint8_t *out = static_cast<uint8_t *>(output);
> +
> +       for (unsigned int i = 0; i < width; i += 2) {
> +               *out++ = (in[0] & 0xff0) >> 4;
> +               *out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8;
> +               *out++ = (in[1] & 0x0ff);
> +               in += 2;
> +       }
> +}
> +
>  void packScanlineRaw16(void *output, const void *input, unsigned int width)
>  {
>         const uint16_t *in = static_cast<const uint16_t *>(input);
> @@ -341,6 +369,54 @@ const std::map<PixelFormat, FormatInfo> formatInfo = {
>                 .packScanline = packScanlineRaw8,
>                 .thumbScanline = thumbScanlineRaw_CSI2P,
>         } },
> +       { formats::SBGGR10, {
> +               .bitsPerSample = 10,
> +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> +               .packScanline = packScanlineRaw10,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SGBRG10, {
> +               .bitsPerSample = 10,
> +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> +               .packScanline = packScanlineRaw10,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SGRBG10, {
> +               .bitsPerSample = 10,
> +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> +               .packScanline = packScanlineRaw10,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SRGGB10, {
> +               .bitsPerSample = 10,
> +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> +               .packScanline = packScanlineRaw10,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SBGGR12, {
> +               .bitsPerSample = 12,
> +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> +               .packScanline = packScanlineRaw12,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SGBRG12, {
> +               .bitsPerSample = 12,
> +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> +               .packScanline = packScanlineRaw12,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SGRBG12, {
> +               .bitsPerSample = 12,
> +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> +               .packScanline = packScanlineRaw12,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
> +       { formats::SRGGB12, {
> +               .bitsPerSample = 12,
> +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> +               .packScanline = packScanlineRaw12,
> +               .thumbScanline = thumbScanlineRaw,
> +       } },
>         { formats::SBGGR16, {
>                 .bitsPerSample = 16,
>                 .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> -- 
> 2.43.0
>
Dan Scally June 28, 2024, 3:19 p.m. UTC | #2
Hi Stefan, thanks for the patch

On 28/06/2024 11:01, Stefan Klug wrote:
> Add support for RAW10 and RAW12 to the dng_writer. This is needed on
> imx8mp to produce tuning images.  Both formats were tested on a debix
> som with a imx335.
>
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>   src/apps/common/dng_writer.cpp | 76 ++++++++++++++++++++++++++++++++++
>   1 file changed, 76 insertions(+)
>
> diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> index 474aa72beb92..f61930b68b2b 100644
> --- a/src/apps/common/dng_writer.cpp
> +++ b/src/apps/common/dng_writer.cpp
> @@ -136,6 +136,34 @@ void packScanlineRaw8(void *output, const void *input, unsigned int width)
>   	std::copy(in, in + width, out);
>   }
>   
> +void packScanlineRaw10(void *output, const void *input, unsigned int width)
> +{
> +	const uint16_t *in = static_cast<const uint16_t *>(input);
> +	uint8_t *out = static_cast<uint8_t *>(output);
> +
> +	for (unsigned int i = 0; i < width; i += 4) {
> +		*out++ = (in[0] & 0x3fc) >> 2;
> +		*out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4;
> +		*out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6;
> +		*out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8;
> +		*out++ = (in[3] & 0x0ff);
> +		in += 4;
> +	}
> +}
> +
> +void packScanlineRaw12(void *output, const void *input, unsigned int width)
> +{
> +	const uint16_t *in = static_cast<const uint16_t *>(input);
> +	uint8_t *out = static_cast<uint8_t *>(output);
> +
> +	for (unsigned int i = 0; i < width; i += 2) {
> +		*out++ = (in[0] & 0xff0) >> 4;
> +		*out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8;
> +		*out++ = (in[1] & 0x0ff);
> +		in += 2;
> +	}
> +}


These always take me an annoying amount of time to follow through:


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

> +
>   void packScanlineRaw16(void *output, const void *input, unsigned int width)
>   {
>   	const uint16_t *in = static_cast<const uint16_t *>(input);
> @@ -341,6 +369,54 @@ const std::map<PixelFormat, FormatInfo> formatInfo = {
>   		.packScanline = packScanlineRaw8,
>   		.thumbScanline = thumbScanlineRaw_CSI2P,
>   	} },
> +	{ formats::SBGGR10, {
> +		.bitsPerSample = 10,
> +		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> +		.packScanline = packScanlineRaw10,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SGBRG10, {
> +		.bitsPerSample = 10,
> +		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> +		.packScanline = packScanlineRaw10,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SGRBG10, {
> +		.bitsPerSample = 10,
> +		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> +		.packScanline = packScanlineRaw10,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SRGGB10, {
> +		.bitsPerSample = 10,
> +		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> +		.packScanline = packScanlineRaw10,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SBGGR12, {
> +		.bitsPerSample = 12,
> +		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> +		.packScanline = packScanlineRaw12,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SGBRG12, {
> +		.bitsPerSample = 12,
> +		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> +		.packScanline = packScanlineRaw12,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SGRBG12, {
> +		.bitsPerSample = 12,
> +		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> +		.packScanline = packScanlineRaw12,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
> +	{ formats::SRGGB12, {
> +		.bitsPerSample = 12,
> +		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> +		.packScanline = packScanlineRaw12,
> +		.thumbScanline = thumbScanlineRaw,
> +	} },
>   	{ formats::SBGGR16, {
>   		.bitsPerSample = 16,
>   		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
Laurent Pinchart June 28, 2024, 3:25 p.m. UTC | #3
On Fri, Jun 28, 2024 at 11:48:28AM +0100, Kieran Bingham wrote:
> Quoting Stefan Klug (2024-06-28 11:01:45)
> > Add support for RAW10 and RAW12 to the dng_writer. This is needed on
> > imx8mp to produce tuning images.  Both formats were tested on a debix
> > som with a imx335.
> > 
> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> > ---
> >  src/apps/common/dng_writer.cpp | 76 ++++++++++++++++++++++++++++++++++
> >  1 file changed, 76 insertions(+)
> > 
> > diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> > index 474aa72beb92..f61930b68b2b 100644
> > --- a/src/apps/common/dng_writer.cpp
> > +++ b/src/apps/common/dng_writer.cpp
> > @@ -136,6 +136,34 @@ void packScanlineRaw8(void *output, const void *input, unsigned int width)
> >         std::copy(in, in + width, out);
> >  }
> >  
> > +void packScanlineRaw10(void *output, const void *input, unsigned int width)
> > +{
> > +       const uint16_t *in = static_cast<const uint16_t *>(input);
> > +       uint8_t *out = static_cast<uint8_t *>(output);
> > +
> > +       for (unsigned int i = 0; i < width; i += 4) {
> > +               *out++ = (in[0] & 0x3fc) >> 2;
> > +               *out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4;
> > +               *out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6;
> > +               *out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8;
> > +               *out++ = (in[3] & 0x0ff);
> > +               in += 4;
> > +       }

This will only work on little-endian machines. The following would work
regardless of endianness.

       const uint8_t *in = static_cast<const uint8_t *>(input);
       uint8_t *out = static_cast<uint8_t *>(output);

       for (unsigned int i = 0; i < width; i += 4) {
               *out++ = in[1] << 6 | in[0] >> 2;
               *out++ = in[0] << 6 | (in[3] & 0x03) << 4 | in[2] >> 4;
               *out++ = in[2] << 4 | (in[5] & 0x03) << 2 | in[4] >> 6;
               *out++ = in[4] << 2 | (in[7] & 0x03) << 0;
               *out++ = in[6];
               in += 8;
       }

> > +}
> > +
> > +void packScanlineRaw12(void *output, const void *input, unsigned int width)
> > +{
> > +       const uint16_t *in = static_cast<const uint16_t *>(input);
> > +       uint8_t *out = static_cast<uint8_t *>(output);
> > +
> > +       for (unsigned int i = 0; i < width; i += 2) {
> > +               *out++ = (in[0] & 0xff0) >> 4;
> > +               *out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8;
> > +               *out++ = (in[1] & 0x0ff);
> > +               in += 2;
> > +       }

And here

	const uint8_t *in = static_cast<const uint8_t *>(input);
	uint8_t *out = static_cast<uint8_t *>(output);

	for (unsigned int i = 0; i < width; i += 2) {
		*out++ = in[1] << 4 | in[0] >> 4;
		*out++ = in[0] << 4 | (in[3] & 0x0f);
		*out++ = in[2];
		in += 4;
	}

With that (assuming it works),

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> > +}
> > +
> >  void packScanlineRaw16(void *output, const void *input, unsigned int width)
> >  {
> >         const uint16_t *in = static_cast<const uint16_t *>(input);
> > @@ -341,6 +369,54 @@ const std::map<PixelFormat, FormatInfo> formatInfo = {
> >                 .packScanline = packScanlineRaw8,
> >                 .thumbScanline = thumbScanlineRaw_CSI2P,
> >         } },
> > +       { formats::SBGGR10, {
> > +               .bitsPerSample = 10,
> > +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> > +               .packScanline = packScanlineRaw10,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SGBRG10, {
> > +               .bitsPerSample = 10,
> > +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> > +               .packScanline = packScanlineRaw10,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SGRBG10, {
> > +               .bitsPerSample = 10,
> > +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> > +               .packScanline = packScanlineRaw10,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SRGGB10, {
> > +               .bitsPerSample = 10,
> > +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> > +               .packScanline = packScanlineRaw10,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SBGGR12, {
> > +               .bitsPerSample = 12,
> > +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> > +               .packScanline = packScanlineRaw12,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SGBRG12, {
> > +               .bitsPerSample = 12,
> > +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> > +               .packScanline = packScanlineRaw12,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SGRBG12, {
> > +               .bitsPerSample = 12,
> > +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> > +               .packScanline = packScanlineRaw12,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> > +       { formats::SRGGB12, {
> > +               .bitsPerSample = 12,
> > +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> > +               .packScanline = packScanlineRaw12,
> > +               .thumbScanline = thumbScanlineRaw,
> > +       } },
> >         { formats::SBGGR16, {
> >                 .bitsPerSample = 16,
> >                 .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
Laurent Pinchart June 28, 2024, 8:13 p.m. UTC | #4
On Fri, Jun 28, 2024 at 06:25:45PM +0300, Laurent Pinchart wrote:
> On Fri, Jun 28, 2024 at 11:48:28AM +0100, Kieran Bingham wrote:
> > Quoting Stefan Klug (2024-06-28 11:01:45)
> > > Add support for RAW10 and RAW12 to the dng_writer. This is needed on
> > > imx8mp to produce tuning images.  Both formats were tested on a debix
> > > som with a imx335.
> > > 
> > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> > 
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > 
> > > ---
> > >  src/apps/common/dng_writer.cpp | 76 ++++++++++++++++++++++++++++++++++
> > >  1 file changed, 76 insertions(+)
> > > 
> > > diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
> > > index 474aa72beb92..f61930b68b2b 100644
> > > --- a/src/apps/common/dng_writer.cpp
> > > +++ b/src/apps/common/dng_writer.cpp
> > > @@ -136,6 +136,34 @@ void packScanlineRaw8(void *output, const void *input, unsigned int width)
> > >         std::copy(in, in + width, out);
> > >  }
> > >  
> > > +void packScanlineRaw10(void *output, const void *input, unsigned int width)
> > > +{
> > > +       const uint16_t *in = static_cast<const uint16_t *>(input);
> > > +       uint8_t *out = static_cast<uint8_t *>(output);
> > > +
> > > +       for (unsigned int i = 0; i < width; i += 4) {
> > > +               *out++ = (in[0] & 0x3fc) >> 2;
> > > +               *out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4;
> > > +               *out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6;
> > > +               *out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8;
> > > +               *out++ = (in[3] & 0x0ff);
> > > +               in += 4;
> > > +       }
> 
> This will only work on little-endian machines. The following would work
> regardless of endianness.
> 
>        const uint8_t *in = static_cast<const uint8_t *>(input);
>        uint8_t *out = static_cast<uint8_t *>(output);
> 
>        for (unsigned int i = 0; i < width; i += 4) {
>                *out++ = in[1] << 6 | in[0] >> 2;
>                *out++ = in[0] << 6 | (in[3] & 0x03) << 4 | in[2] >> 4;
>                *out++ = in[2] << 4 | (in[5] & 0x03) << 2 | in[4] >> 6;
>                *out++ = in[4] << 2 | (in[7] & 0x03) << 0;
>                *out++ = in[6];
>                in += 8;
>        }
> 
> > > +}
> > > +
> > > +void packScanlineRaw12(void *output, const void *input, unsigned int width)
> > > +{
> > > +       const uint16_t *in = static_cast<const uint16_t *>(input);
> > > +       uint8_t *out = static_cast<uint8_t *>(output);
> > > +
> > > +       for (unsigned int i = 0; i < width; i += 2) {
> > > +               *out++ = (in[0] & 0xff0) >> 4;
> > > +               *out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8;
> > > +               *out++ = (in[1] & 0x0ff);
> > > +               in += 2;
> > > +       }
> 
> And here
> 
> 	const uint8_t *in = static_cast<const uint8_t *>(input);
> 	uint8_t *out = static_cast<uint8_t *>(output);
> 
> 	for (unsigned int i = 0; i < width; i += 2) {
> 		*out++ = in[1] << 4 | in[0] >> 4;
> 		*out++ = in[0] << 4 | (in[3] & 0x0f);
> 		*out++ = in[2];
> 		in += 4;
> 	}
> 
> With that (assuming it works),

Let's fix this on top. I'll send a patch.

> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> > > +}
> > > +
> > >  void packScanlineRaw16(void *output, const void *input, unsigned int width)
> > >  {
> > >         const uint16_t *in = static_cast<const uint16_t *>(input);
> > > @@ -341,6 +369,54 @@ const std::map<PixelFormat, FormatInfo> formatInfo = {
> > >                 .packScanline = packScanlineRaw8,
> > >                 .thumbScanline = thumbScanlineRaw_CSI2P,
> > >         } },
> > > +       { formats::SBGGR10, {
> > > +               .bitsPerSample = 10,
> > > +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> > > +               .packScanline = packScanlineRaw10,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SGBRG10, {
> > > +               .bitsPerSample = 10,
> > > +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> > > +               .packScanline = packScanlineRaw10,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SGRBG10, {
> > > +               .bitsPerSample = 10,
> > > +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> > > +               .packScanline = packScanlineRaw10,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SRGGB10, {
> > > +               .bitsPerSample = 10,
> > > +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> > > +               .packScanline = packScanlineRaw10,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SBGGR12, {
> > > +               .bitsPerSample = 12,
> > > +               .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> > > +               .packScanline = packScanlineRaw12,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SGBRG12, {
> > > +               .bitsPerSample = 12,
> > > +               .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> > > +               .packScanline = packScanlineRaw12,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SGRBG12, {
> > > +               .bitsPerSample = 12,
> > > +               .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> > > +               .packScanline = packScanlineRaw12,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > > +       { formats::SRGGB12, {
> > > +               .bitsPerSample = 12,
> > > +               .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> > > +               .packScanline = packScanlineRaw12,
> > > +               .thumbScanline = thumbScanlineRaw,
> > > +       } },
> > >         { formats::SBGGR16, {
> > >                 .bitsPerSample = 16,
> > >                 .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },

Patch
diff mbox series

diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp
index 474aa72beb92..f61930b68b2b 100644
--- a/src/apps/common/dng_writer.cpp
+++ b/src/apps/common/dng_writer.cpp
@@ -136,6 +136,34 @@  void packScanlineRaw8(void *output, const void *input, unsigned int width)
 	std::copy(in, in + width, out);
 }
 
+void packScanlineRaw10(void *output, const void *input, unsigned int width)
+{
+	const uint16_t *in = static_cast<const uint16_t *>(input);
+	uint8_t *out = static_cast<uint8_t *>(output);
+
+	for (unsigned int i = 0; i < width; i += 4) {
+		*out++ = (in[0] & 0x3fc) >> 2;
+		*out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4;
+		*out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6;
+		*out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8;
+		*out++ = (in[3] & 0x0ff);
+		in += 4;
+	}
+}
+
+void packScanlineRaw12(void *output, const void *input, unsigned int width)
+{
+	const uint16_t *in = static_cast<const uint16_t *>(input);
+	uint8_t *out = static_cast<uint8_t *>(output);
+
+	for (unsigned int i = 0; i < width; i += 2) {
+		*out++ = (in[0] & 0xff0) >> 4;
+		*out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8;
+		*out++ = (in[1] & 0x0ff);
+		in += 2;
+	}
+}
+
 void packScanlineRaw16(void *output, const void *input, unsigned int width)
 {
 	const uint16_t *in = static_cast<const uint16_t *>(input);
@@ -341,6 +369,54 @@  const std::map<PixelFormat, FormatInfo> formatInfo = {
 		.packScanline = packScanlineRaw8,
 		.thumbScanline = thumbScanlineRaw_CSI2P,
 	} },
+	{ formats::SBGGR10, {
+		.bitsPerSample = 10,
+		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
+		.packScanline = packScanlineRaw10,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SGBRG10, {
+		.bitsPerSample = 10,
+		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
+		.packScanline = packScanlineRaw10,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SGRBG10, {
+		.bitsPerSample = 10,
+		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
+		.packScanline = packScanlineRaw10,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SRGGB10, {
+		.bitsPerSample = 10,
+		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
+		.packScanline = packScanlineRaw10,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SBGGR12, {
+		.bitsPerSample = 12,
+		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
+		.packScanline = packScanlineRaw12,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SGBRG12, {
+		.bitsPerSample = 12,
+		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
+		.packScanline = packScanlineRaw12,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SGRBG12, {
+		.bitsPerSample = 12,
+		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
+		.packScanline = packScanlineRaw12,
+		.thumbScanline = thumbScanlineRaw,
+	} },
+	{ formats::SRGGB12, {
+		.bitsPerSample = 12,
+		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
+		.packScanline = packScanlineRaw12,
+		.thumbScanline = thumbScanlineRaw,
+	} },
 	{ formats::SBGGR16, {
 		.bitsPerSample = 16,
 		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },