File Index
Files and directories
Sign in
FILE

vpu_color.c

File preview with syntax highlighting.

linux-6.19.14/drivers/media/platform/amphion/vpu_color.c C
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright 2020-2021 NXP
  4 */
  5
  6#include <linux/init.h>
  7#include <linux/device.h>
  8#include <linux/ioctl.h>
  9#include <linux/list.h>
 10#include <linux/module.h>
 11#include <linux/kernel.h>
 12#include <linux/slab.h>
 13#include <linux/delay.h>
 14#include <linux/types.h>
 15#include <media/v4l2-device.h>
 16#include "vpu.h"
 17#include "vpu_helpers.h"
 18
 19static const u8 colorprimaries[] = {
 20	V4L2_COLORSPACE_LAST,
 21	V4L2_COLORSPACE_REC709,         /*Rec. ITU-R BT.709-6*/
 22	0,
 23	0,
 24	V4L2_COLORSPACE_470_SYSTEM_M,   /*Rec. ITU-R BT.470-6 System M*/
 25	V4L2_COLORSPACE_470_SYSTEM_BG,  /*Rec. ITU-R BT.470-6 System B, G*/
 26	V4L2_COLORSPACE_SMPTE170M,      /*SMPTE170M*/
 27	V4L2_COLORSPACE_SMPTE240M,      /*SMPTE240M*/
 28	0,                              /*Generic film*/
 29	V4L2_COLORSPACE_BT2020,         /*Rec. ITU-R BT.2020-2*/
 30	0,                              /*SMPTE ST 428-1*/
 31};
 32
 33static const u8 colortransfers[] = {
 34	V4L2_XFER_FUNC_LAST,
 35	V4L2_XFER_FUNC_709,             /*Rec. ITU-R BT.709-6*/
 36	0,
 37	0,
 38	0,                              /*Rec. ITU-R BT.470-6 System M*/
 39	0,                              /*Rec. ITU-R BT.470-6 System B, G*/
 40	V4L2_XFER_FUNC_709,             /*SMPTE170M*/
 41	V4L2_XFER_FUNC_SMPTE240M,       /*SMPTE240M*/
 42	V4L2_XFER_FUNC_NONE,            /*Linear transfer characteristics*/
 43	0,
 44	0,
 45	0,                              /*IEC 61966-2-4*/
 46	0,                              /*Rec. ITU-R BT.1361-0 extended colour gamut*/
 47	V4L2_XFER_FUNC_SRGB,            /*IEC 61966-2-1 sRGB or sYCC*/
 48	V4L2_XFER_FUNC_709,             /*Rec. ITU-R BT.2020-2 (10 bit system)*/
 49	V4L2_XFER_FUNC_709,             /*Rec. ITU-R BT.2020-2 (12 bit system)*/
 50	V4L2_XFER_FUNC_SMPTE2084,       /*SMPTE ST 2084*/
 51	0,                              /*SMPTE ST 428-1*/
 52	0                               /*Rec. ITU-R BT.2100-0 hybrid log-gamma (HLG)*/
 53};
 54
 55static const u8 colormatrixcoefs[] = {
 56	V4L2_YCBCR_ENC_LAST,
 57	V4L2_YCBCR_ENC_709,              /*Rec. ITU-R BT.709-6*/
 58	0,
 59	0,
 60	0,                               /*Title 47 Code of Federal Regulations*/
 61	V4L2_YCBCR_ENC_601,              /*Rec. ITU-R BT.601-7 625*/
 62	V4L2_YCBCR_ENC_601,              /*Rec. ITU-R BT.601-7 525*/
 63	V4L2_YCBCR_ENC_SMPTE240M,        /*SMPTE240M*/
 64	0,
 65	V4L2_YCBCR_ENC_BT2020,           /*Rec. ITU-R BT.2020-2*/
 66	V4L2_YCBCR_ENC_BT2020_CONST_LUM  /*Rec. ITU-R BT.2020-2 constant*/
 67};
 68
 69u32 vpu_color_cvrt_primaries_v2i(u32 primaries)
 70{
 71	return vpu_helper_find_in_array_u8(colorprimaries, ARRAY_SIZE(colorprimaries), primaries);
 72}
 73
 74u32 vpu_color_cvrt_primaries_i2v(u32 primaries)
 75{
 76	return primaries < ARRAY_SIZE(colorprimaries) ? colorprimaries[primaries] : 0;
 77}
 78
 79u32 vpu_color_cvrt_transfers_v2i(u32 transfers)
 80{
 81	return vpu_helper_find_in_array_u8(colortransfers, ARRAY_SIZE(colortransfers), transfers);
 82}
 83
 84u32 vpu_color_cvrt_transfers_i2v(u32 transfers)
 85{
 86	return transfers < ARRAY_SIZE(colortransfers) ? colortransfers[transfers] : 0;
 87}
 88
 89u32 vpu_color_cvrt_matrix_v2i(u32 matrix)
 90{
 91	return vpu_helper_find_in_array_u8(colormatrixcoefs, ARRAY_SIZE(colormatrixcoefs), matrix);
 92}
 93
 94u32 vpu_color_cvrt_matrix_i2v(u32 matrix)
 95{
 96	return matrix < ARRAY_SIZE(colormatrixcoefs) ? colormatrixcoefs[matrix] : 0;
 97}
 98
 99u32 vpu_color_cvrt_full_range_v2i(u32 full_range)
100{
101	return (full_range == V4L2_QUANTIZATION_FULL_RANGE);
102}
103
104u32 vpu_color_cvrt_full_range_i2v(u32 full_range)
105{
106	if (full_range)
107		return V4L2_QUANTIZATION_FULL_RANGE;
108
109	return V4L2_QUANTIZATION_LIM_RANGE;
110}
~/ Read-only file preview.