From e0b7d30fd437292c88141fb08d60681870b86c6e Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 8 May 2026 17:22:58 +0300 Subject: Squashed 'subprojects/pixpat/' content from commit d444626 git-subtree-dir: subprojects/pixpat git-subtree-split: d444626e6ba988ec6d487800721e447f94b1eaf5 --- pixpat-native/src/formats/bayer.h | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 pixpat-native/src/formats/bayer.h (limited to 'pixpat-native/src/formats/bayer.h') diff --git a/pixpat-native/src/formats/bayer.h b/pixpat-native/src/formats/bayer.h new file mode 100644 index 0000000..057c342 --- /dev/null +++ b/pixpat-native/src/formats/bayer.h @@ -0,0 +1,97 @@ +#pragma once + +// Bayer raw layouts. Each pixel carries one of R/G/B selected by +// (x mod 2, y mod 2) and BayerOrder; the pattern is on the +// BayerSource/BayerSink template, not the layout itself. Storage shape +// is single-component (C::Y reused as the storage tag) so the same +// 8/10/12/16-bit shapes apply across all four phase patterns. +// +// Each format is a distinct struct (rather than a type alias of one +// another) so each format type can carry its own pattern-specific +// Source/Sink aliases. The shared bit layout lives in a base struct per +// (depth,packing) combination. +// +// ColorKind is RGB because the normalized pixel passed through ColorXfm +// is RGB16 — the sink picks one of r/g/b at write time, and the +// source nearest-neighbor demosaics into RGB16 at read time. + +#include "../layout.h" +#include "../io/bayer.h" + +namespace pixpat::formats +{ + +namespace bayer_detail +{ + +// Per-(depth,packing) base layouts. Every Bayer format derives from +// one of these and pins its own pattern-specific I/O templates. +using Bayer8 = Layout >; +using Bayer10 = Layout >; +using Bayer12 = Layout >; +using Bayer16 = Layout >; +// MIPI CSI-2 packed Bayer (10P: 4 pix in 5 bytes; 12P: 2 pix in 3 +// bytes). The Layout doesn't capture the packed bit layout — the +// BayerPackedSink hand-rolls the byte writes. uint8_t plane shape is +// a placeholder so the dispatch plumbing is uniform. +using Bayer10P = Layout >; +using Bayer12P = Layout >; + +} // namespace bayer_detail + +// Unpacked Bayer (4 patterns × 4 bit depths). +#define PIXPAT_BAYER(name, base, pat) \ + struct name : bayer_detail::base { \ + using Source = BayerSource_ ## pat; \ + using Sink = BayerSink_ ## pat; \ + } + +PIXPAT_BAYER(SRGGB8, Bayer8, RGGB); +PIXPAT_BAYER(SBGGR8, Bayer8, BGGR); +PIXPAT_BAYER(SGRBG8, Bayer8, GRBG); +PIXPAT_BAYER(SGBRG8, Bayer8, GBRG); + +PIXPAT_BAYER(SRGGB10, Bayer10, RGGB); +PIXPAT_BAYER(SBGGR10, Bayer10, BGGR); +PIXPAT_BAYER(SGRBG10, Bayer10, GRBG); +PIXPAT_BAYER(SGBRG10, Bayer10, GBRG); + +PIXPAT_BAYER(SRGGB12, Bayer12, RGGB); +PIXPAT_BAYER(SBGGR12, Bayer12, BGGR); +PIXPAT_BAYER(SGRBG12, Bayer12, GRBG); +PIXPAT_BAYER(SGBRG12, Bayer12, GBRG); + +PIXPAT_BAYER(SRGGB16, Bayer16, RGGB); +PIXPAT_BAYER(SBGGR16, Bayer16, BGGR); +PIXPAT_BAYER(SGRBG16, Bayer16, GRBG); +PIXPAT_BAYER(SGBRG16, Bayer16, GBRG); + +#undef PIXPAT_BAYER + +// MIPI-packed Bayer: pattern + bit depth both encoded in the I/O +// template name (BayerPackedSource_RGGB10, ...). +#define PIXPAT_BAYER_PACKED(name, base, pat_depth) \ + struct name : bayer_detail::base { \ + using Source = BayerPackedSource_ ## pat_depth; \ + using Sink = BayerPackedSink_ ## pat_depth; \ + } + +PIXPAT_BAYER_PACKED(SRGGB10P, Bayer10P, RGGB10); +PIXPAT_BAYER_PACKED(SBGGR10P, Bayer10P, BGGR10); +PIXPAT_BAYER_PACKED(SGRBG10P, Bayer10P, GRBG10); +PIXPAT_BAYER_PACKED(SGBRG10P, Bayer10P, GBRG10); + +PIXPAT_BAYER_PACKED(SRGGB12P, Bayer12P, RGGB12); +PIXPAT_BAYER_PACKED(SBGGR12P, Bayer12P, BGGR12); +PIXPAT_BAYER_PACKED(SGRBG12P, Bayer12P, GRBG12); +PIXPAT_BAYER_PACKED(SGBRG12P, Bayer12P, GBRG12); + +#undef PIXPAT_BAYER_PACKED + +} // namespace pixpat::formats -- cgit v1.2.3