drivers/media/common/v4l2-tpg/v4l2-tpg-colors.c

Source file repositories/reference/linux-study-clean/drivers/media/common/v4l2-tpg/v4l2-tpg-colors.c

File Facts

System
Linux kernel
Corpus path
drivers/media/common/v4l2-tpg/v4l2-tpg-colors.c
Extension
.c
Size
98392 bytes
Lines
1410
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * v4l2-tpg-colors.c - A table that converts colors to various colorspaces
 *
 * The test pattern generator uses the tpg_colors for its test patterns.
 * For testing colorspaces the first 8 colors of that table need to be
 * converted to their equivalent in the target colorspace.
 *
 * The tpg_csc_colors[] table is the result of that conversion and since
 * it is precalculated the colorspace conversion is just a simple table
 * lookup.
 *
 * This source also contains the code used to generate the tpg_csc_colors
 * table. Run the following command to compile it:
 *
 *	gcc v4l2-tpg-colors.c -DCOMPILE_APP -o gen-colors -lm
 *
 * and run the utility.
 *
 * Note that the converted colors are in the range 0x000-0xff0 (so times 16)
 * in order to preserve precision.
 *
 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
 */

#include <linux/videodev2.h>
#include <media/tpg/v4l2-tpg.h>

/* sRGB colors with range [0-255] */
const struct tpg_rbg_color8 tpg_colors[TPG_COLOR_MAX] = {
	/*
	 * Colors to test colorspace conversion: converting these colors
	 * to other colorspaces will never lead to out-of-gamut colors.
	 */
	{ 191, 191, 191 }, /* TPG_COLOR_CSC_WHITE */
	{ 191, 191,  50 }, /* TPG_COLOR_CSC_YELLOW */
	{  50, 191, 191 }, /* TPG_COLOR_CSC_CYAN */
	{  50, 191,  50 }, /* TPG_COLOR_CSC_GREEN */
	{ 191,  50, 191 }, /* TPG_COLOR_CSC_MAGENTA */
	{ 191,  50,  50 }, /* TPG_COLOR_CSC_RED */
	{  50,  50, 191 }, /* TPG_COLOR_CSC_BLUE */
	{  50,  50,  50 }, /* TPG_COLOR_CSC_BLACK */

	/* 75% colors */
	{ 191, 191,   0 }, /* TPG_COLOR_75_YELLOW */
	{   0, 191, 191 }, /* TPG_COLOR_75_CYAN */
	{   0, 191,   0 }, /* TPG_COLOR_75_GREEN */
	{ 191,   0, 191 }, /* TPG_COLOR_75_MAGENTA */
	{ 191,   0,   0 }, /* TPG_COLOR_75_RED */
	{   0,   0, 191 }, /* TPG_COLOR_75_BLUE */

	/* 100% colors */
	{ 255, 255, 255 }, /* TPG_COLOR_100_WHITE */
	{ 255, 255,   0 }, /* TPG_COLOR_100_YELLOW */
	{   0, 255, 255 }, /* TPG_COLOR_100_CYAN */
	{   0, 255,   0 }, /* TPG_COLOR_100_GREEN */
	{ 255,   0, 255 }, /* TPG_COLOR_100_MAGENTA */
	{ 255,   0,   0 }, /* TPG_COLOR_100_RED */
	{   0,   0, 255 }, /* TPG_COLOR_100_BLUE */
	{   0,   0,   0 }, /* TPG_COLOR_100_BLACK */

	{   0,   0,   0 }, /* TPG_COLOR_RANDOM placeholder */
};

#ifndef COMPILE_APP

/* Generated table */
const unsigned short tpg_rec709_to_linear[255 * 16 + 1] = {
	   0,    0,    0,    1,    1,    1,    1,    2,    2,    2,    2,    2,    3,    3,    3,    3,
	   4,    4,    4,    4,    4,    5,    5,    5,    5,    6,    6,    6,    6,    6,    7,    7,
	   7,    7,    8,    8,    8,    8,    8,    9,    9,    9,    9,   10,   10,   10,   10,   10,
	  11,   11,   11,   11,   12,   12,   12,   12,   12,   13,   13,   13,   13,   14,   14,   14,
	  14,   14,   15,   15,   15,   15,   16,   16,   16,   16,   16,   17,   17,   17,   17,   18,
	  18,   18,   18,   18,   19,   19,   19,   19,   20,   20,   20,   20,   20,   21,   21,   21,
	  21,   22,   22,   22,   22,   22,   23,   23,   23,   23,   24,   24,   24,   24,   24,   25,
	  25,   25,   25,   26,   26,   26,   26,   26,   27,   27,   27,   27,   28,   28,   28,   28,
	  28,   29,   29,   29,   29,   30,   30,   30,   30,   30,   31,   31,   31,   31,   32,   32,
	  32,   32,   32,   33,   33,   33,   33,   34,   34,   34,   34,   34,   35,   35,   35,   35,
	  36,   36,   36,   36,   36,   37,   37,   37,   37,   38,   38,   38,   38,   38,   39,   39,
	  39,   39,   40,   40,   40,   40,   40,   41,   41,   41,   41,   42,   42,   42,   42,   42,
	  43,   43,   43,   43,   44,   44,   44,   44,   44,   45,   45,   45,   45,   46,   46,   46,
	  46,   46,   47,   47,   47,   47,   48,   48,   48,   48,   48,   49,   49,   49,   49,   50,
	  50,   50,   50,   50,   51,   51,   51,   51,   52,   52,   52,   52,   52,   53,   53,   53,
	  53,   54,   54,   54,   54,   54,   55,   55,   55,   55,   56,   56,   56,   56,   56,   57,
	  57,   57,   57,   58,   58,   58,   58,   58,   59,   59,   59,   59,   60,   60,   60,   60,
	  60,   61,   61,   61,   61,   62,   62,   62,   62,   62,   63,   63,   63,   63,   64,   64,
	  64,   64,   64,   65,   65,   65,   65,   66,   66,   66,   66,   66,   67,   67,   67,   67,
	  68,   68,   68,   68,   68,   69,   69,   69,   69,   70,   70,   70,   70,   70,   71,   71,
	  71,   71,   72,   72,   72,   72,   72,   73,   73,   73,   73,   73,   74,   74,   74,   74,
	  74,   75,   75,   75,   75,   76,   76,   76,   76,   76,   77,   77,   77,   77,   78,   78,

Annotation

Implementation Notes