Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: uapi: Add PiSP Compressed RAW Bayer formats

Add Raspberry Pi compressed RAW Bayer formats.

The compression algorithm description is provided by Nick Hollinghurst
<nick.hollinghurst@raspberrypi.com> from Raspberry Pi.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Jacopo Mondi and committed by
Hans Verkuil
d260c122 8f6c2202

+97
+1
Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
··· 20 20 :maxdepth: 1 21 21 22 22 pixfmt-srggb8 23 + pixfmt-srggb8-pisp-comp 23 24 pixfmt-srggb10 24 25 pixfmt-srggb10p 25 26 pixfmt-srggb10alaw8
+74
Documentation/userspace-api/media/v4l/pixfmt-srggb8-pisp-comp.rst
··· 1 + .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2 + 3 + .. _v4l2-pix-fmt-pisp-comp1-rggb: 4 + .. _v4l2-pix-fmt-pisp-comp1-grbg: 5 + .. _v4l2-pix-fmt-pisp-comp1-gbrg: 6 + .. _v4l2-pix-fmt-pisp-comp1-bggr: 7 + .. _v4l2-pix-fmt-pisp-comp1-mono: 8 + .. _v4l2-pix-fmt-pisp-comp2-rggb: 9 + .. _v4l2-pix-fmt-pisp-comp2-grbg: 10 + .. _v4l2-pix-fmt-pisp-comp2-gbrg: 11 + .. _v4l2-pix-fmt-pisp-comp2-bggr: 12 + .. _v4l2-pix-fmt-pisp-comp2-mono: 13 + 14 + ************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** 15 + 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') 16 + ************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** 17 + 18 + ================================================ 19 + Raspberry Pi PiSP compressed 8-bit Bayer formats 20 + ================================================ 21 + 22 + Description 23 + =========== 24 + 25 + The Raspberry Pi ISP (PiSP) uses a family of three fixed-rate compressed Bayer 26 + formats. A black-level offset may be subtracted to improve compression 27 + efficiency; the nominal black level and amount of offset must be signalled out 28 + of band. Each scanline is padded to a multiple of 8 pixels wide, and each block 29 + of 8 horizontally-contiguous pixels is coded using 8 bytes. 30 + 31 + Mode 1 uses a quantization and delta-based coding scheme which preserves up to 32 + 12 significant bits. Mode 2 is a simple sqrt-like companding scheme with 6 PWL 33 + chords, preserving up to 12 significant bits. Mode 3 combines both companding 34 + (with 4 chords) and the delta scheme, preserving up to 14 significant bits. 35 + 36 + The remainder of this description applies to Modes 1 and 3. 37 + 38 + Each block of 8 pixels is separated into even and odd phases of 4 pixels, 39 + coded independently by 32-bit words at successive locations in memory. 40 + The two LS bits of each 32-bit word give its "quantization mode". 41 + 42 + In quantization mode 0, the lowest 321 quantization levels are multiples of 43 + FSD/4096 and the remaining levels are successive multiples of FSD/2048. 44 + Quantization modes 1 and 2 use linear quantization with step sizes of 45 + FSD/1024 and FSD/512 respectively. Each of the four pixels is quantized 46 + independently, with rounding to the nearest level. 47 + In quantization mode 2 where the middle two samples have quantized values 48 + (q1,q2) both in the range [384..511], they are coded using 9 bits for q1 49 + followed by 7 bits for (q2 & 127). Otherwise, for quantization modes 50 + 0, 1 and 2: a 9-bit field encodes MIN(q1,q2) which must be in the range 51 + [0..511] and a 7-bit field encodes (q2-q1+64) which must be in [0..127]. 52 + 53 + Each of the outer samples (q0,q3) is encoded using a 7-bit field based 54 + on its inner neighbour q1 or q2. In quantization mode 2 where the inner 55 + sample has a quantized value in the range [448..511], the field value is 56 + (q0-384). Otherwise for quantization modes 0, 1 and 2: The outer sample 57 + is encoded as (q0-MAX(0,q1-64)). q3 is likewise coded based on q2. 58 + Each of these values must be in the range [0..127]. All these fields 59 + of 2, 9, 7, 7, 7 bits respectively are packed in little-endian order 60 + to give a 32-bit word with LE byte order. 61 + 62 + Quantization mode 3 has a "7.5-bit" escape, used when none of the above 63 + encodings will fit. Each pixel value is quantized to the nearest of 176 64 + levels, where the lowest 95 levels are multiples of FSD/256 and the 65 + remaining levels are multiples of FSD/128 (level 175 represents values 66 + very close to FSD and may require saturating arithmetic to decode). 67 + 68 + Each pair of quantized pixels (q0,q1) or (q2,q3) is jointly coded 69 + by a 15-bit field: 2816*(q0>>4) + 16*q1 + (q0&15). 70 + Three fields of 2, 15, 15 bits are packed in LE order {15,15,2}. 71 + 72 + An implementation of a software decoder of compressed formats is available 73 + in `Raspberry Pi camera applications code base 74 + <https://github.com/raspberrypi/rpicam-apps/blob/main/image/dng.cpp>`_.
+10
drivers/media/v4l2-core/v4l2-ioctl.c
··· 1532 1532 case V4L2_PIX_FMT_MT2110T: descr = "Mediatek 10bit Tile Mode"; break; 1533 1533 case V4L2_PIX_FMT_MT2110R: descr = "Mediatek 10bit Raster Mode"; break; 1534 1534 case V4L2_PIX_FMT_HEXTILE: descr = "Hextile Compressed Format"; break; 1535 + case V4L2_PIX_FMT_PISP_COMP1_RGGB: descr = "PiSP 8b RGRG/GBGB mode1 compr"; break; 1536 + case V4L2_PIX_FMT_PISP_COMP1_GRBG: descr = "PiSP 8b GRGR/BGBG mode1 compr"; break; 1537 + case V4L2_PIX_FMT_PISP_COMP1_GBRG: descr = "PiSP 8b GBGB/RGRG mode1 compr"; break; 1538 + case V4L2_PIX_FMT_PISP_COMP1_BGGR: descr = "PiSP 8b BGBG/GRGR mode1 compr"; break; 1539 + case V4L2_PIX_FMT_PISP_COMP1_MONO: descr = "PiSP 8b monochrome mode1 compr"; break; 1540 + case V4L2_PIX_FMT_PISP_COMP2_RGGB: descr = "PiSP 8b RGRG/GBGB mode2 compr"; break; 1541 + case V4L2_PIX_FMT_PISP_COMP2_GRBG: descr = "PiSP 8b GRGR/BGBG mode2 compr"; break; 1542 + case V4L2_PIX_FMT_PISP_COMP2_GBRG: descr = "PiSP 8b GBGB/RGRG mode2 compr"; break; 1543 + case V4L2_PIX_FMT_PISP_COMP2_BGGR: descr = "PiSP 8b BGBG/GRGR mode2 compr"; break; 1544 + case V4L2_PIX_FMT_PISP_COMP2_MONO: descr = "PiSP 8b monochrome mode2 compr"; break; 1535 1545 default: 1536 1546 if (fmt->description[0]) 1537 1547 return;
+12
include/uapi/linux/videodev2.h
··· 816 816 #define V4L2_PIX_FMT_IPU3_SGRBG10 v4l2_fourcc('i', 'p', '3', 'G') /* IPU3 packed 10-bit GRBG bayer */ 817 817 #define V4L2_PIX_FMT_IPU3_SRGGB10 v4l2_fourcc('i', 'p', '3', 'r') /* IPU3 packed 10-bit RGGB bayer */ 818 818 819 + /* Raspberry Pi PiSP compressed formats. */ 820 + #define V4L2_PIX_FMT_PISP_COMP1_RGGB v4l2_fourcc('P', 'C', '1', 'R') /* PiSP 8-bit mode 1 compressed RGGB bayer */ 821 + #define V4L2_PIX_FMT_PISP_COMP1_GRBG v4l2_fourcc('P', 'C', '1', 'G') /* PiSP 8-bit mode 1 compressed GRBG bayer */ 822 + #define V4L2_PIX_FMT_PISP_COMP1_GBRG v4l2_fourcc('P', 'C', '1', 'g') /* PiSP 8-bit mode 1 compressed GBRG bayer */ 823 + #define V4L2_PIX_FMT_PISP_COMP1_BGGR v4l2_fourcc('P', 'C', '1', 'B') /* PiSP 8-bit mode 1 compressed BGGR bayer */ 824 + #define V4L2_PIX_FMT_PISP_COMP1_MONO v4l2_fourcc('P', 'C', '1', 'M') /* PiSP 8-bit mode 1 compressed monochrome */ 825 + #define V4L2_PIX_FMT_PISP_COMP2_RGGB v4l2_fourcc('P', 'C', '2', 'R') /* PiSP 8-bit mode 2 compressed RGGB bayer */ 826 + #define V4L2_PIX_FMT_PISP_COMP2_GRBG v4l2_fourcc('P', 'C', '2', 'G') /* PiSP 8-bit mode 2 compressed GRBG bayer */ 827 + #define V4L2_PIX_FMT_PISP_COMP2_GBRG v4l2_fourcc('P', 'C', '2', 'g') /* PiSP 8-bit mode 2 compressed GBRG bayer */ 828 + #define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B') /* PiSP 8-bit mode 2 compressed BGGR bayer */ 829 + #define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M') /* PiSP 8-bit mode 2 compressed monochrome */ 830 + 819 831 /* SDR formats - used only for Software Defined Radio devices */ 820 832 #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */ 821 833 #define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */