aa4b003e5b390d517eda8944aac3c5791e679349
[openwrt/staging/pepe2k.git] /
1 From 5d6318f242cce5f9b5677baedde736a2b81061df Mon Sep 17 00:00:00 2001
2 From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
3 Date: Wed, 17 Jan 2024 11:21:50 +0200
4 Subject: [PATCH 1151/1215] media: uapi: Document PiSP Compressed RAW Bayer
5 formats
6
7 Document the Raspberry Pi compressed RAW Bayer formats.
8
9 The compression algorithm description is provided by Nick Hollinghurst
10 <nick.hollinghurst@raspberrypi.com> from Raspberry Pi.
11
12 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
13 Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
14 ---
15 .../userspace-api/media/v4l/pixfmt-bayer.rst | 1 +
16 .../media/v4l/pixfmt-srggb8-pisp-comp.rst | 74 +++++++++++++++++++
17 2 files changed, 75 insertions(+)
18 create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-srggb8-pisp-comp.rst
19
20 --- a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
21 +++ b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
22 @@ -20,6 +20,7 @@ orders. See also `the Wikipedia article
23 :maxdepth: 1
24
25 pixfmt-srggb8
26 + pixfmt-srggb8-pisp-comp
27 pixfmt-srggb10
28 pixfmt-srggb10p
29 pixfmt-srggb10alaw8
30 --- /dev/null
31 +++ b/Documentation/userspace-api/media/v4l/pixfmt-srggb8-pisp-comp.rst
32 @@ -0,0 +1,74 @@
33 +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
34 +
35 +.. _v4l2-pix-fmt-pisp-comp1-rggb:
36 +.. _v4l2-pix-fmt-pisp-comp1-grbg:
37 +.. _v4l2-pix-fmt-pisp-comp1-gbrg:
38 +.. _v4l2-pix-fmt-pisp-comp1-bggr:
39 +.. _v4l2-pix-fmt-pisp-comp1-mono:
40 +.. _v4l2-pix-fmt-pisp-comp2-rggb:
41 +.. _v4l2-pix-fmt-pisp-comp2-grbg:
42 +.. _v4l2-pix-fmt-pisp-comp2-gbrg:
43 +.. _v4l2-pix-fmt-pisp-comp2-bggr:
44 +.. _v4l2-pix-fmt-pisp-comp2-mono:
45 +
46 +**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
47 +V4L2_PIX_FMT_PISP_COMP1_RGGB ('PC1R'), V4L2_PIX_FMT_PISP_COMP1_GRBG ('PC1G'), V4L2_PIX_FMT_PISP_COMP1_GBRG ('PC1g'), V4L2_PIX_FMT_PISP_COMP1_BGGR ('PC1B), V4L2_PIX_FMT_PISP_COMP1_MONO ('PC1M'), V4L2_PIX_FMT_PISP_COMP2_RGGB ('PC2R'), V4L2_PIX_FMT_PISP_COMP2_GRBG ('PC2G'), V4L2_PIX_FMT_PISP_COMP2_GBRG ('PC2g'), V4L2_PIX_FMT_PISP_COMP2_BGGR ('PC2B), V4L2_PIX_FMT_PISP_COMP2_MONO ('PC2M')
48 +**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
49 +
50 +================================================
51 +Raspberry Pi PiSP compressed 8-bit Bayer formats
52 +================================================
53 +
54 +Description
55 +===========
56 +
57 +The Raspberry Pi ISP (PiSP) uses a family of three fixed-rate compressed Bayer
58 +formats. A black-level offset may be subtracted to improve compression
59 +efficiency; the nominal black level and amount of offset must be signalled out
60 +of band. Each scanline is padded to a multiple of 8 pixels wide, and each block
61 +of 8 horizontally-contiguous pixels is coded using 8 bytes.
62 +
63 +Mode 1 uses a quantization and delta-based coding scheme which preserves up to
64 +12 significant bits. Mode 2 is a simple sqrt-like companding scheme with 6 PWL
65 +chords, preserving up to 12 significant bits. Mode 3 combines both companding
66 +(with 4 chords) and the delta scheme, preserving up to 14 significant bits.
67 +
68 +The remainder of this description applies to Modes 1 and 3.
69 +
70 +Each block of 8 pixels is separated into even and odd phases of 4 pixels,
71 +coded independently by 32-bit words at successive locations in memory.
72 +The two LS bits of each 32-bit word give its "quantization mode".
73 +
74 +In quantization mode 0, the lowest 321 quantization levels are multiples of
75 +FSD/4096 and the remaining levels are successive multiples of FSD/2048.
76 +Quantization modes 1 and 2 use linear quantization with step sizes of
77 +FSD/1024 and FSD/512 respectively. Each of the four pixels is quantized
78 +independently, with rounding to the nearest level.
79 +In quantization mode 2 where the middle two samples have quantized values
80 +(q1,q2) both in the range [384..511], they are coded using 9 bits for q1
81 +followed by 7 bits for (q2 & 127). Otherwise, for quantization modes
82 +0, 1 and 2: a 9-bit field encodes MIN(q1,q2) which must be in the range
83 +[0..511] and a 7-bit field encodes (q2-q1+64) which must be in [0..127].
84 +
85 +Each of the outer samples (q0,q3) is encoded using a 7-bit field based
86 +on its inner neighbour q1 or q2. In quantization mode 2 where the inner
87 +sample has a quantized value in the range [448..511], the field value is
88 +(q0-384). Otherwise for quantization modes 0, 1 and 2: The outer sample
89 +is encoded as (q0-MAX(0,q1-64)). q3 is likewise coded based on q2.
90 +Each of these values must be in the range [0..127]. All these fields
91 +of 2, 9, 7, 7, 7 bits respectively are packed in little-endian order
92 +to give a 32-bit word with LE byte order.
93 +
94 +Quantization mode 3 has a "7.5-bit" escape, used when none of the above
95 +encodings will fit. Each pixel value is quantized to the nearest of 176
96 +levels, where the lowest 95 levels are multiples of FSD/256 and the
97 +remaining levels are multiples of FSD/128 (level 175 represents values
98 +very close to FSD and may require saturating arithmetic to decode).
99 +
100 +Each pair of quantized pixels (q0,q1) or (q2,q3) is jointly coded
101 +by a 15-bit field: 2816*(q0>>4) + 16*q1 + (q0&15).
102 +Three fields of 2, 15, 15 bits are packed in LE order {15,15,2}.
103 +
104 +An implementation of a software decoder of compressed formats is available
105 +in `Raspberry Pi camera applications code base
106 +<https://github.com/raspberrypi/rpicam-apps/blob/main/image/dng.cpp>`_.