summaryrefslogtreecommitdiff
path: root/src/gen-image.c
AgeCommit message (Collapse)Author
2025-04-09gen-image: Add support for YUV to RGB conversionLaurent Pinchart
Support YUV to RGB conversion, to emulate the RPF and WPF CSC. As for RGB to YUV conversion, the coefficients have been reverse-engineered. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2025-04-09gen-image: Don't copy CSC conversion matrixLaurent Pinchart
Merge the csc_matrix() function into image_convert_rgb_to_yuv() to avoid unnecessary copies of the matrix. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2025-04-09gen-image: Centralize format conversion codeLaurent Pinchart
Create an image_convert() function that encapsulates all format conversion, and use it to replace direct calls to other converter functions. This prepares for extending the supported conversions. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2025-04-09gen-image: Split struct params into CSC and packing parametersLaurent Pinchart
To prepare for improvements to the format conversion code, split the struct params into CSC parameters and packing parameters. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2025-04-09gen-image: Update the RGB to YCbCr conversion to match VSP hardwareLaurent Pinchart
RGB to YCbCr conversion is only used at the moment to generate images for test cases that run fully YUV pipelines. The exact value of the RGB to YCbCr conversion matrices hasn't mattered much so far. However, this will change with introduction of tests that perform RGB to YCbCr conversion. To achieve pixel-perfect match between the reference and hardware frames, reference images need to be generated with the exact method used by the VSP. Replace the current coefficients by values obtained from reverse-engineering of the RGB to YCbCr conversion performed by the VSP1. Remove support for SMPTE240 and BT.2020, as the VSP hardware supports BT.601 and BT.709 only. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2025-04-05gen-image: Round sub-sampled chroma towards zeroLaurent Pinchart
Based on tests, the VSP1 hardware seems to round averaged chroma values towards 0 when subsampling YUV formats. Replicate the same calculation in gen-image. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-02-28gen-image: Crop input image before format conversion to YUVLaurent Pinchart
When converting the input image to a subsampled YUV format, chroma components are averaged horizontally to emulate the VSP internal conversion to YUV444. If the image is subsequently cropped to emulate the RPF cropping, the edge chroma values end up effectively taking into account pixels outside of the crop rectangle. This doesn't match the hardware mode of operation which crops the image when reading it through DMA, before performing any other operation. Fix this by cropping the image just after reading it, before format conversion. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
2020-07-14gen-image: Replace copyright text with SPDX tagsLaurent Pinchart
Standardize on the usage of SPDX tags. No change in copyright is included. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
2017-03-03gen-image: Add generation of HGT reference frameNiklas Söderlund
Add a new histogram type HGT to be able to compute HGT histogram frame from RGB data. This is needed to test the HGT module together with the HST module in the VSP pipeline to convert a image from RGB to HSV. This also includes a new command line option to be able to specify the user configuration of the HGT hue areas. This is needed to verify that the HGT driver can operate with different hue area configurations. Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2017-03-03gen-image: Add option to specify histogram typeNiklas Söderlund
The VSP hardware can compute both 1D (HGO) and 2D (HGT) histograms. The gen-image utility needs to know which histogram type it should generate a reference frame for. Add a command line option which allows the user to set the type. Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2017-02-12gen-image: Implement option to parse an input cropKieran Bingham
Allow the user to specify an input crop in the form (X,Y)/WxH Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-09-16gen-image: Add conversion from RGB to HSV supportLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-09-13gen-image: Subsample YUV chroma on inputLaurent Pinchart
When the input format is YUV, subsample the chroma during RGB to YUV conversion based on the YUV format parameters. This matches the RGB to YUV conversion performed to generate the test input frame fed to the RPF. A better fix would be to add support for unpacking all RGB and YUV formats instead of converting the .pnm reference frames. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-09-13gen-image: Add -C argument to disable chroma averaging on outputLaurent Pinchart
gen-image averages consecutive chroma values when subsampling chroma horizontally. This matches the hardware behaviour, but isn't desired to produce test input frames in subsampled formats as otherwise the hardware will average the values a second time in the RPF to interpolate missing chroma components. Add a -C argument to disable chroma averaging on output, to be used to generate test input frames. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-09-13gen-image: Add input format configurationLaurent Pinchart
Replace the -y argument with a more flexible -i argument that allows specifying the input format. This is useful to generate reference frames based on an RGB pipeline input format that uses less than 8 bits per pixel. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-06-19gen-image: Add horizontal and vertical flip supportLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-06-17gen-image: Add look up table supportLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-06-16Add gen-image toolLaurent Pinchart
The tool is used to generate test images in a variety of formats from a PNM input image. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
href='#n379'>379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
/* From Linux kernel: drm_edid.c */
/*
 * Copyright (c) 2006 Luc Verhaegen (quirks list)
 * Copyright (c) 2007-2008 Intel Corporation
 *   Jesse Barnes <jesse.barnes@intel.com>
 * Copyright 2010 Red Hat, Inc.
 *
 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
 * FB layer.
 *   Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "modedb.h"

#include <xf86drm.h>

namespace kms
{

#define DIV_ROUND(n, d) (((n) + (d) / 2) / (d))

#define DRM_MODE(nm, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
	.name = nm, .clock = (c), \
	.hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), .htotal = (ht), .hskew = (hsk), \
	.vdisplay = (vd), .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), .vscan = (vs), \
	.vrefresh = DIV_ROUND(c * 1000, ht * vt), .flags = (f), .type = 0

/*
 * Probably taken from CEA-861 spec.
 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
 */
const Videomode cea_modes[] = {
	/* 1 - 640x480@60Hz */
	{ DRM_MODE("640x480", 25175, 640, 656,
	  752, 800, 0, 480, 490, 492, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 2 - 720x480@60Hz */
	{ DRM_MODE("720x480", 27000, 720, 736,
	  798, 858, 0, 480, 489, 495, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 3 - 720x480@60Hz */
	{ DRM_MODE("720x480", 27000, 720, 736,
	  798, 858, 0, 480, 489, 495, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 4 - 1280x720@60Hz */
	{ DRM_MODE("1280x720", 74250, 1280, 1390,
	  1430, 1650, 0, 720, 725, 730, 750, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 5 - 1920x1080i@60Hz */
	{ DRM_MODE("1920x1080i", 74250, 1920, 2008,
	  2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 6 - 720(1440)x480i@60Hz */
	{ DRM_MODE("720x480i", 13500, 720, 739,
	  801, 858, 0, 480, 488, 494, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
	},
	/* 7 - 720(1440)x480i@60Hz */
	{ DRM_MODE("720x480i", 13500, 720, 739,
	  801, 858, 0, 480, 488, 494, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
	},
	/* 8 - 720(1440)x240@60Hz */
	{ DRM_MODE("720x240", 13500, 720, 739,
	  801, 858, 0, 240, 244, 247, 262, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_DBLCLK),
	},
	/* 9 - 720(1440)x240@60Hz */
	{ DRM_MODE("720x240", 13500, 720, 739,
	  801, 858, 0, 240, 244, 247, 262, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_DBLCLK),
	},
	/* 10 - 2880x480i@60Hz */
	{ DRM_MODE("2880x480i", 54000, 2880, 2956,
	  3204, 3432, 0, 480, 488, 494, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 11 - 2880x480i@60Hz */
	{ DRM_MODE("2880x480i", 54000, 2880, 2956,
	  3204, 3432, 0, 480, 488, 494, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 12 - 2880x240@60Hz */
	{ DRM_MODE("2880x240", 54000, 2880, 2956,
	  3204, 3432, 0, 240, 244, 247, 262, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 13 - 2880x240@60Hz */
	{ DRM_MODE("2880x240", 54000, 2880, 2956,
	  3204, 3432, 0, 240, 244, 247, 262, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 14 - 1440x480@60Hz */
	{ DRM_MODE("1440x480", 54000, 1440, 1472,
	  1596, 1716, 0, 480, 489, 495, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 15 - 1440x480@60Hz */
	{ DRM_MODE("1440x480", 54000, 1440, 1472,
	  1596, 1716, 0, 480, 489, 495, 525, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 16 - 1920x1080@60Hz */
	{ DRM_MODE("1920x1080", 148500, 1920, 2008,
	  2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 17 - 720x576@50Hz */
	{ DRM_MODE("720x576", 27000, 720, 732,
	  796, 864, 0, 576, 581, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 18 - 720x576@50Hz */
	{ DRM_MODE("720x576", 27000, 720, 732,
	  796, 864, 0, 576, 581, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 19 - 1280x720@50Hz */
	{ DRM_MODE("1280x720", 74250, 1280, 1720,
	  1760, 1980, 0, 720, 725, 730, 750, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 20 - 1920x1080i@50Hz */
	{ DRM_MODE("1920x1080i", 74250, 1920, 2448,
	  2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 21 - 720(1440)x576i@50Hz */
	{ DRM_MODE("720x576i", 13500, 720, 732,
	  795, 864, 0, 576, 580, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
	},
	/* 22 - 720(1440)x576i@50Hz */
	{ DRM_MODE("720x576i", 13500, 720, 732,
	  795, 864, 0, 576, 580, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
	},
	/* 23 - 720(1440)x288@50Hz */
	{ DRM_MODE("720x288", 13500, 720, 732,
	  795, 864, 0, 288, 290, 293, 312, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_DBLCLK),
	},
	/* 24 - 720(1440)x288@50Hz */
	{ DRM_MODE("720x288", 13500, 720, 732,
	  795, 864, 0, 288, 290, 293, 312, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_DBLCLK),
	},
	/* 25 - 2880x576i@50Hz */
	{ DRM_MODE("2880x576i", 54000, 2880, 2928,
	  3180, 3456, 0, 576, 580, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 26 - 2880x576i@50Hz */
	{ DRM_MODE("2880x576i", 54000, 2880, 2928,
	  3180, 3456, 0, 576, 580, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
	  DRM_MODE_FLAG_INTERLACE),
	},
	/* 27 - 2880x288@50Hz */
	{ DRM_MODE("2880x288", 54000, 2880, 2928,
	  3180, 3456, 0, 288, 290, 293, 312, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 28 - 2880x288@50Hz */
	{ DRM_MODE("2880x288", 54000, 2880, 2928,
	  3180, 3456, 0, 288, 290, 293, 312, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 29 - 1440x576@50Hz */
	{ DRM_MODE("1440x576", 54000, 1440, 1464,
	  1592, 1728, 0, 576, 581, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 30 - 1440x576@50Hz */
	{ DRM_MODE("1440x576", 54000, 1440, 1464,
	  1592, 1728, 0, 576, 581, 586, 625, 0,
	  DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
	},
	/* 31 - 1920x1080@50Hz */
	{ DRM_MODE("1920x1080", 148500, 1920, 2448,
	  2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 32 - 1920x1080@24Hz */
	{ DRM_MODE("1920x1080", 74250, 1920, 2558,
	  2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 33 - 1920x1080@25Hz */
	{ DRM_MODE("1920x1080", 74250, 1920, 2448,
	  2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
	  DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
	},
	/* 34 - 1920x1080@30Hz */