[libcamera-devel] [PATCH] qcam: dng_writer: Add support for IPU3 Bayer formats
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sun May 3 02:33:04 CEST 2020
Hi Niklas,
Thank you for the patch.
On Sun, May 03, 2020 at 02:27:55AM +0200, Niklas Söderlund wrote:
> Add support for the Bayer formats produced on the IPU3. The format uses
> a memory layout that is hard to repack and keep the 10-bit sample size,
> therefore scale the samples to 16-bit when creating the scanlines.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> ---
> src/qcam/dng_writer.cpp | 45 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
> index f0d6f5f473e3d680..7ad52592d4449929 100644
> --- a/src/qcam/dng_writer.cpp
> +++ b/src/qcam/dng_writer.cpp
> @@ -56,6 +56,31 @@ void packScanlineSBGGR12P(void *output, const void *input, unsigned int width)
> }
> }
>
> +void packScanlineIPU3(void *output, const void *input, unsigned int width)
> +{
> + const uint8_t *in = static_cast<const uint8_t *>(input);
> + uint16_t *out = static_cast<uint16_t *>(output);
> +
> + /*
> + * Upsacle the 10-bit format to 16-bit as it's none trivial to pack it
s/Upsacle/Upscale/
s/none /non-/
> + * it as 10-bits without gaps.
s/it as/as/
> + *
> + * \todo Improve packig to keep the 10-bit sample size.
s/packig/packing/
> + */
> + for (unsigned int x = 0; x < width; x += 25) {
> + for (unsigned int i = 0; i < 6; i++) {
> + *out++ = ((in[1] & 0x02) << 8 | in[0]) << 6;
> + *out++ = ((in[2] & 0x0f) << 6 | in[1] >> 2) << 6;
> + *out++ = ((in[3] & 0x3f) << 4 | in[2] >> 4) << 6;
> + *out++ = ((in[4] & 0xff) << 2 | in[3] >> 6) << 6;
> + in += 5;
> + }
> +
> + *out++ = ((in[1] & 0x02) << 8 | in[0]) << 6;
> + in += 2;
> + }
> +}
> +
> static const std::map<PixelFormat, FormatInfo> formatInfo = {
> { PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED), {
> .bitsPerSample = 10,
> @@ -97,6 +122,26 @@ static const std::map<PixelFormat, FormatInfo> formatInfo = {
> .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> .packScanline = packScanlineSBGGR12P,
> } },
> + { PixelFormat(DRM_FORMAT_SBGGR10, IPU3_FORMAT_MOD_PACKED), {
> + .bitsPerSample = 16,
> + .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> + .packScanline = packScanlineIPU3,
> + } },
> + { PixelFormat(DRM_FORMAT_SGBRG10, IPU3_FORMAT_MOD_PACKED), {
> + .bitsPerSample = 16,
> + .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> + .packScanline = packScanlineIPU3,
> + } },
> + { PixelFormat(DRM_FORMAT_SGRBG10, IPU3_FORMAT_MOD_PACKED), {
> + .bitsPerSample = 16,
> + .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> + .packScanline = packScanlineIPU3,
> + } },
> + { PixelFormat(DRM_FORMAT_SRGGB10, IPU3_FORMAT_MOD_PACKED), {
> + .bitsPerSample = 16,
> + .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> + .packScanline = packScanlineIPU3,
> + } },
Depending on which patch gets merged first, you need .thumbScanline here
too :-)
> };
>
> int DNGWriter::write(const char *filename, const Camera *camera,
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list