1d722e3fbSopenharmony_ci/* 2d722e3fbSopenharmony_ci * Copyright 2008 Tungsten Graphics 3d722e3fbSopenharmony_ci * Jakob Bornecrantz <jakob@tungstengraphics.com> 4d722e3fbSopenharmony_ci * Copyright 2008 Intel Corporation 5d722e3fbSopenharmony_ci * Jesse Barnes <jesse.barnes@intel.com> 6d722e3fbSopenharmony_ci * 7d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"), 9d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation 10d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 12d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions: 13d722e3fbSopenharmony_ci * 14d722e3fbSopenharmony_ci * The above copyright notice and this permission notice shall be included in 15d722e3fbSopenharmony_ci * all copies or substantial portions of the Software. 16d722e3fbSopenharmony_ci * 17d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20d722e3fbSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22d722e3fbSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23d722e3fbSopenharmony_ci * IN THE SOFTWARE. 24d722e3fbSopenharmony_ci */ 25d722e3fbSopenharmony_ci 26d722e3fbSopenharmony_ci#include <stdint.h> 27d722e3fbSopenharmony_ci#include <stdio.h> 28d722e3fbSopenharmony_ci#include <stdlib.h> 29d722e3fbSopenharmony_ci#include <string.h> 30d722e3fbSopenharmony_ci 31d722e3fbSopenharmony_ci#include <drm_fourcc.h> 32d722e3fbSopenharmony_ci 33d722e3fbSopenharmony_ci#if HAVE_CAIRO 34d722e3fbSopenharmony_ci#include <cairo.h> 35d722e3fbSopenharmony_ci#include <math.h> 36d722e3fbSopenharmony_ci#endif 37d722e3fbSopenharmony_ci 38d722e3fbSopenharmony_ci#include "common.h" 39d722e3fbSopenharmony_ci#include "format.h" 40d722e3fbSopenharmony_ci#include "pattern.h" 41d722e3fbSopenharmony_ci 42d722e3fbSopenharmony_cistruct color_rgb24 { 43d722e3fbSopenharmony_ci unsigned int value:24; 44d722e3fbSopenharmony_ci} __attribute__((__packed__)); 45d722e3fbSopenharmony_ci 46d722e3fbSopenharmony_cistruct color_yuv { 47d722e3fbSopenharmony_ci unsigned char y; 48d722e3fbSopenharmony_ci unsigned char u; 49d722e3fbSopenharmony_ci unsigned char v; 50d722e3fbSopenharmony_ci}; 51d722e3fbSopenharmony_ci 52d722e3fbSopenharmony_ci#define MAKE_YUV_601_Y(r, g, b) \ 53d722e3fbSopenharmony_ci ((( 66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16) 54d722e3fbSopenharmony_ci#define MAKE_YUV_601_U(r, g, b) \ 55d722e3fbSopenharmony_ci (((-38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128) 56d722e3fbSopenharmony_ci#define MAKE_YUV_601_V(r, g, b) \ 57d722e3fbSopenharmony_ci (((112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128) 58d722e3fbSopenharmony_ci 59d722e3fbSopenharmony_ci#define MAKE_YUV_601(r, g, b) \ 60d722e3fbSopenharmony_ci { .y = MAKE_YUV_601_Y(r, g, b), \ 61d722e3fbSopenharmony_ci .u = MAKE_YUV_601_U(r, g, b), \ 62d722e3fbSopenharmony_ci .v = MAKE_YUV_601_V(r, g, b) } 63d722e3fbSopenharmony_ci 64d722e3fbSopenharmony_ci/* This function takes 8-bit color values */ 65d722e3fbSopenharmony_cistatic inline uint32_t shiftcolor8(const struct util_color_component *comp, 66d722e3fbSopenharmony_ci uint32_t value) 67d722e3fbSopenharmony_ci{ 68d722e3fbSopenharmony_ci value &= 0xff; 69d722e3fbSopenharmony_ci /* Fill the low bits with the high bits. */ 70d722e3fbSopenharmony_ci value = (value << 8) | value; 71d722e3fbSopenharmony_ci /* Shift down to remove unwanted low bits */ 72d722e3fbSopenharmony_ci value = value >> (16 - comp->length); 73d722e3fbSopenharmony_ci /* Shift back up to where the value should be */ 74d722e3fbSopenharmony_ci return value << comp->offset; 75d722e3fbSopenharmony_ci} 76d722e3fbSopenharmony_ci 77d722e3fbSopenharmony_ci/* This function takes 10-bit color values */ 78d722e3fbSopenharmony_cistatic inline uint32_t shiftcolor10(const struct util_color_component *comp, 79d722e3fbSopenharmony_ci uint32_t value) 80d722e3fbSopenharmony_ci{ 81d722e3fbSopenharmony_ci value &= 0x3ff; 82d722e3fbSopenharmony_ci /* Fill the low bits with the high bits. */ 83d722e3fbSopenharmony_ci value = (value << 6) | (value >> 4); 84d722e3fbSopenharmony_ci /* Shift down to remove unwanted low bits */ 85d722e3fbSopenharmony_ci value = value >> (16 - comp->length); 86d722e3fbSopenharmony_ci /* Shift back up to where the value should be */ 87d722e3fbSopenharmony_ci return value << comp->offset; 88d722e3fbSopenharmony_ci} 89d722e3fbSopenharmony_ci 90d722e3fbSopenharmony_ci/* This function takes 16-bit color values */ 91d722e3fbSopenharmony_cistatic inline uint64_t shiftcolor16(const struct util_color_component *comp, 92d722e3fbSopenharmony_ci uint64_t value) 93d722e3fbSopenharmony_ci{ 94d722e3fbSopenharmony_ci value &= 0xffff; 95d722e3fbSopenharmony_ci /* Shift down to remove unwanted low bits */ 96d722e3fbSopenharmony_ci value = value >> (16 - comp->length); 97d722e3fbSopenharmony_ci /* Shift back up to where the value should be */ 98d722e3fbSopenharmony_ci return value << comp->offset; 99d722e3fbSopenharmony_ci} 100d722e3fbSopenharmony_ci 101d722e3fbSopenharmony_ci#define MAKE_RGBA10(rgb, r, g, b, a) \ 102d722e3fbSopenharmony_ci (shiftcolor10(&(rgb)->red, (r)) | \ 103d722e3fbSopenharmony_ci shiftcolor10(&(rgb)->green, (g)) | \ 104d722e3fbSopenharmony_ci shiftcolor10(&(rgb)->blue, (b)) | \ 105d722e3fbSopenharmony_ci shiftcolor10(&(rgb)->alpha, (a))) 106d722e3fbSopenharmony_ci 107d722e3fbSopenharmony_ci#define MAKE_RGBA(rgb, r, g, b, a) \ 108d722e3fbSopenharmony_ci (shiftcolor8(&(rgb)->red, (r)) | \ 109d722e3fbSopenharmony_ci shiftcolor8(&(rgb)->green, (g)) | \ 110d722e3fbSopenharmony_ci shiftcolor8(&(rgb)->blue, (b)) | \ 111d722e3fbSopenharmony_ci shiftcolor8(&(rgb)->alpha, (a))) 112d722e3fbSopenharmony_ci 113d722e3fbSopenharmony_ci#define MAKE_RGB24(rgb, r, g, b) \ 114d722e3fbSopenharmony_ci { .value = MAKE_RGBA(rgb, r, g, b, 0) } 115d722e3fbSopenharmony_ci 116d722e3fbSopenharmony_ci 117d722e3fbSopenharmony_ci/** 118d722e3fbSopenharmony_ci * Takes a uint16_t, divides by 65536, converts the infinite-precision 119d722e3fbSopenharmony_ci * result to fp16 with round-to-zero. 120d722e3fbSopenharmony_ci * 121d722e3fbSopenharmony_ci * Copied from mesa:src/util/half_float.c 122d722e3fbSopenharmony_ci */ 123d722e3fbSopenharmony_cistatic uint16_t uint16_div_64k_to_half(uint16_t v) 124d722e3fbSopenharmony_ci{ 125d722e3fbSopenharmony_ci /* Zero or subnormal. Set the mantissa to (v << 8) and return. */ 126d722e3fbSopenharmony_ci if (v < 4) 127d722e3fbSopenharmony_ci return v << 8; 128d722e3fbSopenharmony_ci 129d722e3fbSopenharmony_ci /* Count the leading 0s in the uint16_t */ 130d722e3fbSopenharmony_ci int n = __builtin_clz(v) - 16; 131d722e3fbSopenharmony_ci 132d722e3fbSopenharmony_ci /* Shift the mantissa up so bit 16 is the hidden 1 bit, 133d722e3fbSopenharmony_ci * mask it off, then shift back down to 10 bits 134d722e3fbSopenharmony_ci */ 135d722e3fbSopenharmony_ci int m = ( ((uint32_t)v << (n + 1)) & 0xffff ) >> 6; 136d722e3fbSopenharmony_ci 137d722e3fbSopenharmony_ci /* (0{n} 1 X{15-n}) * 2^-16 138d722e3fbSopenharmony_ci * = 1.X * 2^(15-n-16) 139d722e3fbSopenharmony_ci * = 1.X * 2^(14-n - 15) 140d722e3fbSopenharmony_ci * which is the FP16 form with e = 14 - n 141d722e3fbSopenharmony_ci */ 142d722e3fbSopenharmony_ci int e = 14 - n; 143d722e3fbSopenharmony_ci 144d722e3fbSopenharmony_ci return (e << 10) | m; 145d722e3fbSopenharmony_ci} 146d722e3fbSopenharmony_ci 147d722e3fbSopenharmony_ci#define MAKE_RGBA8FP16(rgb, r, g, b, a) \ 148d722e3fbSopenharmony_ci (shiftcolor16(&(rgb)->red, uint16_div_64k_to_half((r) << 8)) | \ 149d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->green, uint16_div_64k_to_half((g) << 8)) | \ 150d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->blue, uint16_div_64k_to_half((b) << 8)) | \ 151d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->alpha, uint16_div_64k_to_half((a) << 8))) 152d722e3fbSopenharmony_ci 153d722e3fbSopenharmony_ci#define MAKE_RGBA10FP16(rgb, r, g, b, a) \ 154d722e3fbSopenharmony_ci (shiftcolor16(&(rgb)->red, uint16_div_64k_to_half((r) << 6)) | \ 155d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->green, uint16_div_64k_to_half((g) << 6)) | \ 156d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->blue, uint16_div_64k_to_half((b) << 6)) | \ 157d722e3fbSopenharmony_ci shiftcolor16(&(rgb)->alpha, uint16_div_64k_to_half((a) << 6))) 158d722e3fbSopenharmony_ci 159d722e3fbSopenharmony_cistatic void fill_smpte_yuv_planar(const struct util_yuv_info *yuv, 160d722e3fbSopenharmony_ci unsigned char *y_mem, unsigned char *u_mem, 161d722e3fbSopenharmony_ci unsigned char *v_mem, unsigned int width, 162d722e3fbSopenharmony_ci unsigned int height, unsigned int stride) 163d722e3fbSopenharmony_ci{ 164d722e3fbSopenharmony_ci const struct color_yuv colors_top[] = { 165d722e3fbSopenharmony_ci MAKE_YUV_601(191, 192, 192), /* grey */ 166d722e3fbSopenharmony_ci MAKE_YUV_601(192, 192, 0), /* yellow */ 167d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 192), /* cyan */ 168d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 0), /* green */ 169d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 192), /* magenta */ 170d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 0), /* red */ 171d722e3fbSopenharmony_ci MAKE_YUV_601(0, 0, 192), /* blue */ 172d722e3fbSopenharmony_ci }; 173d722e3fbSopenharmony_ci const struct color_yuv colors_middle[] = { 174d722e3fbSopenharmony_ci MAKE_YUV_601(0, 0, 192), /* blue */ 175d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 176d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 192), /* magenta */ 177d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 178d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 192), /* cyan */ 179d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 180d722e3fbSopenharmony_ci MAKE_YUV_601(192, 192, 192), /* grey */ 181d722e3fbSopenharmony_ci }; 182d722e3fbSopenharmony_ci const struct color_yuv colors_bottom[] = { 183d722e3fbSopenharmony_ci MAKE_YUV_601(0, 33, 76), /* in-phase */ 184d722e3fbSopenharmony_ci MAKE_YUV_601(255, 255, 255), /* super white */ 185d722e3fbSopenharmony_ci MAKE_YUV_601(50, 0, 106), /* quadrature */ 186d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 187d722e3fbSopenharmony_ci MAKE_YUV_601(9, 9, 9), /* 3.5% */ 188d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* 7.5% */ 189d722e3fbSopenharmony_ci MAKE_YUV_601(29, 29, 29), /* 11.5% */ 190d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 191d722e3fbSopenharmony_ci }; 192d722e3fbSopenharmony_ci unsigned int cs = yuv->chroma_stride; 193d722e3fbSopenharmony_ci unsigned int xsub = yuv->xsub; 194d722e3fbSopenharmony_ci unsigned int ysub = yuv->ysub; 195d722e3fbSopenharmony_ci unsigned int x; 196d722e3fbSopenharmony_ci unsigned int y; 197d722e3fbSopenharmony_ci 198d722e3fbSopenharmony_ci /* Luma */ 199d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 200d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 201d722e3fbSopenharmony_ci y_mem[x] = colors_top[x * 7 / width].y; 202d722e3fbSopenharmony_ci y_mem += stride; 203d722e3fbSopenharmony_ci } 204d722e3fbSopenharmony_ci 205d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 206d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 207d722e3fbSopenharmony_ci y_mem[x] = colors_middle[x * 7 / width].y; 208d722e3fbSopenharmony_ci y_mem += stride; 209d722e3fbSopenharmony_ci } 210d722e3fbSopenharmony_ci 211d722e3fbSopenharmony_ci for (; y < height; ++y) { 212d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 213d722e3fbSopenharmony_ci y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y; 214d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 215d722e3fbSopenharmony_ci y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3 216d722e3fbSopenharmony_ci / (width / 7) + 4].y; 217d722e3fbSopenharmony_ci for (; x < width; ++x) 218d722e3fbSopenharmony_ci y_mem[x] = colors_bottom[7].y; 219d722e3fbSopenharmony_ci y_mem += stride; 220d722e3fbSopenharmony_ci } 221d722e3fbSopenharmony_ci 222d722e3fbSopenharmony_ci /* Chroma */ 223d722e3fbSopenharmony_ci for (y = 0; y < height / ysub * 6 / 9; ++y) { 224d722e3fbSopenharmony_ci for (x = 0; x < width; x += xsub) { 225d722e3fbSopenharmony_ci u_mem[x*cs/xsub] = colors_top[x * 7 / width].u; 226d722e3fbSopenharmony_ci v_mem[x*cs/xsub] = colors_top[x * 7 / width].v; 227d722e3fbSopenharmony_ci } 228d722e3fbSopenharmony_ci u_mem += stride * cs / xsub; 229d722e3fbSopenharmony_ci v_mem += stride * cs / xsub; 230d722e3fbSopenharmony_ci } 231d722e3fbSopenharmony_ci 232d722e3fbSopenharmony_ci for (; y < height / ysub * 7 / 9; ++y) { 233d722e3fbSopenharmony_ci for (x = 0; x < width; x += xsub) { 234d722e3fbSopenharmony_ci u_mem[x*cs/xsub] = colors_middle[x * 7 / width].u; 235d722e3fbSopenharmony_ci v_mem[x*cs/xsub] = colors_middle[x * 7 / width].v; 236d722e3fbSopenharmony_ci } 237d722e3fbSopenharmony_ci u_mem += stride * cs / xsub; 238d722e3fbSopenharmony_ci v_mem += stride * cs / xsub; 239d722e3fbSopenharmony_ci } 240d722e3fbSopenharmony_ci 241d722e3fbSopenharmony_ci for (; y < height / ysub; ++y) { 242d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; x += xsub) { 243d722e3fbSopenharmony_ci u_mem[x*cs/xsub] = 244d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)].u; 245d722e3fbSopenharmony_ci v_mem[x*cs/xsub] = 246d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)].v; 247d722e3fbSopenharmony_ci } 248d722e3fbSopenharmony_ci for (; x < width * 6 / 7; x += xsub) { 249d722e3fbSopenharmony_ci u_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * 250d722e3fbSopenharmony_ci 3 / (width / 7) + 4].u; 251d722e3fbSopenharmony_ci v_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * 252d722e3fbSopenharmony_ci 3 / (width / 7) + 4].v; 253d722e3fbSopenharmony_ci } 254d722e3fbSopenharmony_ci for (; x < width; x += xsub) { 255d722e3fbSopenharmony_ci u_mem[x*cs/xsub] = colors_bottom[7].u; 256d722e3fbSopenharmony_ci v_mem[x*cs/xsub] = colors_bottom[7].v; 257d722e3fbSopenharmony_ci } 258d722e3fbSopenharmony_ci u_mem += stride * cs / xsub; 259d722e3fbSopenharmony_ci v_mem += stride * cs / xsub; 260d722e3fbSopenharmony_ci } 261d722e3fbSopenharmony_ci} 262d722e3fbSopenharmony_ci 263d722e3fbSopenharmony_cistatic void fill_smpte_yuv_packed(const struct util_yuv_info *yuv, void *mem, 264d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 265d722e3fbSopenharmony_ci unsigned int stride) 266d722e3fbSopenharmony_ci{ 267d722e3fbSopenharmony_ci const struct color_yuv colors_top[] = { 268d722e3fbSopenharmony_ci MAKE_YUV_601(191, 192, 192), /* grey */ 269d722e3fbSopenharmony_ci MAKE_YUV_601(192, 192, 0), /* yellow */ 270d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 192), /* cyan */ 271d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 0), /* green */ 272d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 192), /* magenta */ 273d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 0), /* red */ 274d722e3fbSopenharmony_ci MAKE_YUV_601(0, 0, 192), /* blue */ 275d722e3fbSopenharmony_ci }; 276d722e3fbSopenharmony_ci const struct color_yuv colors_middle[] = { 277d722e3fbSopenharmony_ci MAKE_YUV_601(0, 0, 192), /* blue */ 278d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 279d722e3fbSopenharmony_ci MAKE_YUV_601(192, 0, 192), /* magenta */ 280d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 281d722e3fbSopenharmony_ci MAKE_YUV_601(0, 192, 192), /* cyan */ 282d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 283d722e3fbSopenharmony_ci MAKE_YUV_601(192, 192, 192), /* grey */ 284d722e3fbSopenharmony_ci }; 285d722e3fbSopenharmony_ci const struct color_yuv colors_bottom[] = { 286d722e3fbSopenharmony_ci MAKE_YUV_601(0, 33, 76), /* in-phase */ 287d722e3fbSopenharmony_ci MAKE_YUV_601(255, 255, 255), /* super white */ 288d722e3fbSopenharmony_ci MAKE_YUV_601(50, 0, 106), /* quadrature */ 289d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 290d722e3fbSopenharmony_ci MAKE_YUV_601(9, 9, 9), /* 3.5% */ 291d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* 7.5% */ 292d722e3fbSopenharmony_ci MAKE_YUV_601(29, 29, 29), /* 11.5% */ 293d722e3fbSopenharmony_ci MAKE_YUV_601(19, 19, 19), /* black */ 294d722e3fbSopenharmony_ci }; 295d722e3fbSopenharmony_ci unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; 296d722e3fbSopenharmony_ci unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; 297d722e3fbSopenharmony_ci unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; 298d722e3fbSopenharmony_ci unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; 299d722e3fbSopenharmony_ci unsigned int x; 300d722e3fbSopenharmony_ci unsigned int y; 301d722e3fbSopenharmony_ci 302d722e3fbSopenharmony_ci /* Luma */ 303d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 304d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 305d722e3fbSopenharmony_ci y_mem[2*x] = colors_top[x * 7 / width].y; 306d722e3fbSopenharmony_ci y_mem += stride; 307d722e3fbSopenharmony_ci } 308d722e3fbSopenharmony_ci 309d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 310d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 311d722e3fbSopenharmony_ci y_mem[2*x] = colors_middle[x * 7 / width].y; 312d722e3fbSopenharmony_ci y_mem += stride; 313d722e3fbSopenharmony_ci } 314d722e3fbSopenharmony_ci 315d722e3fbSopenharmony_ci for (; y < height; ++y) { 316d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 317d722e3fbSopenharmony_ci y_mem[2*x] = colors_bottom[x * 4 / (width * 5 / 7)].y; 318d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 319d722e3fbSopenharmony_ci y_mem[2*x] = colors_bottom[(x - width * 5 / 7) * 3 320d722e3fbSopenharmony_ci / (width / 7) + 4].y; 321d722e3fbSopenharmony_ci for (; x < width; ++x) 322d722e3fbSopenharmony_ci y_mem[2*x] = colors_bottom[7].y; 323d722e3fbSopenharmony_ci y_mem += stride; 324d722e3fbSopenharmony_ci } 325d722e3fbSopenharmony_ci 326d722e3fbSopenharmony_ci /* Chroma */ 327d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 328d722e3fbSopenharmony_ci for (x = 0; x < width; x += 2) { 329d722e3fbSopenharmony_ci c_mem[2*x+u] = colors_top[x * 7 / width].u; 330d722e3fbSopenharmony_ci c_mem[2*x+v] = colors_top[x * 7 / width].v; 331d722e3fbSopenharmony_ci } 332d722e3fbSopenharmony_ci c_mem += stride; 333d722e3fbSopenharmony_ci } 334d722e3fbSopenharmony_ci 335d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 336d722e3fbSopenharmony_ci for (x = 0; x < width; x += 2) { 337d722e3fbSopenharmony_ci c_mem[2*x+u] = colors_middle[x * 7 / width].u; 338d722e3fbSopenharmony_ci c_mem[2*x+v] = colors_middle[x * 7 / width].v; 339d722e3fbSopenharmony_ci } 340d722e3fbSopenharmony_ci c_mem += stride; 341d722e3fbSopenharmony_ci } 342d722e3fbSopenharmony_ci 343d722e3fbSopenharmony_ci for (; y < height; ++y) { 344d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; x += 2) { 345d722e3fbSopenharmony_ci c_mem[2*x+u] = colors_bottom[x * 4 / (width * 5 / 7)].u; 346d722e3fbSopenharmony_ci c_mem[2*x+v] = colors_bottom[x * 4 / (width * 5 / 7)].v; 347d722e3fbSopenharmony_ci } 348d722e3fbSopenharmony_ci for (; x < width * 6 / 7; x += 2) { 349d722e3fbSopenharmony_ci c_mem[2*x+u] = colors_bottom[(x - width * 5 / 7) * 350d722e3fbSopenharmony_ci 3 / (width / 7) + 4].u; 351d722e3fbSopenharmony_ci c_mem[2*x+v] = colors_bottom[(x - width * 5 / 7) * 352d722e3fbSopenharmony_ci 3 / (width / 7) + 4].v; 353d722e3fbSopenharmony_ci } 354d722e3fbSopenharmony_ci for (; x < width; x += 2) { 355d722e3fbSopenharmony_ci c_mem[2*x+u] = colors_bottom[7].u; 356d722e3fbSopenharmony_ci c_mem[2*x+v] = colors_bottom[7].v; 357d722e3fbSopenharmony_ci } 358d722e3fbSopenharmony_ci c_mem += stride; 359d722e3fbSopenharmony_ci } 360d722e3fbSopenharmony_ci} 361d722e3fbSopenharmony_ci 362d722e3fbSopenharmony_cistatic void fill_smpte_rgb16(const struct util_rgb_info *rgb, void *mem, 363d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 364d722e3fbSopenharmony_ci unsigned int stride) 365d722e3fbSopenharmony_ci{ 366d722e3fbSopenharmony_ci const uint16_t colors_top[] = { 367d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ 368d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ 369d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ 370d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ 371d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ 372d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ 373d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ 374d722e3fbSopenharmony_ci }; 375d722e3fbSopenharmony_ci const uint16_t colors_middle[] = { 376d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ 377d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 378d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ 379d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 380d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ 381d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 382d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ 383d722e3fbSopenharmony_ci }; 384d722e3fbSopenharmony_ci const uint16_t colors_bottom[] = { 385d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ 386d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ 387d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ 388d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ 389d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ 390d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ 391d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ 392d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ 393d722e3fbSopenharmony_ci }; 394d722e3fbSopenharmony_ci unsigned int x; 395d722e3fbSopenharmony_ci unsigned int y; 396d722e3fbSopenharmony_ci 397d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 398d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 399d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = colors_top[x * 7 / width]; 400d722e3fbSopenharmony_ci mem += stride; 401d722e3fbSopenharmony_ci } 402d722e3fbSopenharmony_ci 403d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 404d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 405d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = colors_middle[x * 7 / width]; 406d722e3fbSopenharmony_ci mem += stride; 407d722e3fbSopenharmony_ci } 408d722e3fbSopenharmony_ci 409d722e3fbSopenharmony_ci for (; y < height; ++y) { 410d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 411d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = 412d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)]; 413d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 414d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = 415d722e3fbSopenharmony_ci colors_bottom[(x - width * 5 / 7) * 3 416d722e3fbSopenharmony_ci / (width / 7) + 4]; 417d722e3fbSopenharmony_ci for (; x < width; ++x) 418d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = colors_bottom[7]; 419d722e3fbSopenharmony_ci mem += stride; 420d722e3fbSopenharmony_ci } 421d722e3fbSopenharmony_ci} 422d722e3fbSopenharmony_ci 423d722e3fbSopenharmony_cistatic void fill_smpte_rgb24(const struct util_rgb_info *rgb, void *mem, 424d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 425d722e3fbSopenharmony_ci unsigned int stride) 426d722e3fbSopenharmony_ci{ 427d722e3fbSopenharmony_ci const struct color_rgb24 colors_top[] = { 428d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 192, 192), /* grey */ 429d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 192, 0), /* yellow */ 430d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ 431d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 192, 0), /* green */ 432d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ 433d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 0, 0), /* red */ 434d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 0, 192), /* blue */ 435d722e3fbSopenharmony_ci }; 436d722e3fbSopenharmony_ci const struct color_rgb24 colors_middle[] = { 437d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 0, 192), /* blue */ 438d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* black */ 439d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ 440d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* black */ 441d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ 442d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* black */ 443d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 192, 192, 192), /* grey */ 444d722e3fbSopenharmony_ci }; 445d722e3fbSopenharmony_ci const struct color_rgb24 colors_bottom[] = { 446d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 0, 33, 76), /* in-phase */ 447d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 255, 255, 255), /* super white */ 448d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 50, 0, 106), /* quadrature */ 449d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* black */ 450d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 9, 9, 9), /* 3.5% */ 451d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* 7.5% */ 452d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 29, 29, 29), /* 11.5% */ 453d722e3fbSopenharmony_ci MAKE_RGB24(rgb, 19, 19, 19), /* black */ 454d722e3fbSopenharmony_ci }; 455d722e3fbSopenharmony_ci unsigned int x; 456d722e3fbSopenharmony_ci unsigned int y; 457d722e3fbSopenharmony_ci 458d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 459d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 460d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = 461d722e3fbSopenharmony_ci colors_top[x * 7 / width]; 462d722e3fbSopenharmony_ci mem += stride; 463d722e3fbSopenharmony_ci } 464d722e3fbSopenharmony_ci 465d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 466d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 467d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = 468d722e3fbSopenharmony_ci colors_middle[x * 7 / width]; 469d722e3fbSopenharmony_ci mem += stride; 470d722e3fbSopenharmony_ci } 471d722e3fbSopenharmony_ci 472d722e3fbSopenharmony_ci for (; y < height; ++y) { 473d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 474d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = 475d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)]; 476d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 477d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = 478d722e3fbSopenharmony_ci colors_bottom[(x - width * 5 / 7) * 3 479d722e3fbSopenharmony_ci / (width / 7) + 4]; 480d722e3fbSopenharmony_ci for (; x < width; ++x) 481d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = colors_bottom[7]; 482d722e3fbSopenharmony_ci mem += stride; 483d722e3fbSopenharmony_ci } 484d722e3fbSopenharmony_ci} 485d722e3fbSopenharmony_ci 486d722e3fbSopenharmony_cistatic void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem, 487d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 488d722e3fbSopenharmony_ci unsigned int stride) 489d722e3fbSopenharmony_ci{ 490d722e3fbSopenharmony_ci const uint32_t colors_top[] = { 491d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ 492d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ 493d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ 494d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ 495d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ 496d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ 497d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ 498d722e3fbSopenharmony_ci }; 499d722e3fbSopenharmony_ci const uint32_t colors_middle[] = { 500d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ 501d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 502d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ 503d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 504d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ 505d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ 506d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ 507d722e3fbSopenharmony_ci }; 508d722e3fbSopenharmony_ci const uint32_t colors_bottom[] = { 509d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ 510d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ 511d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ 512d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ 513d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ 514d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ 515d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ 516d722e3fbSopenharmony_ci MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ 517d722e3fbSopenharmony_ci }; 518d722e3fbSopenharmony_ci unsigned int x; 519d722e3fbSopenharmony_ci unsigned int y; 520d722e3fbSopenharmony_ci 521d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 522d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 523d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = colors_top[x * 7 / width]; 524d722e3fbSopenharmony_ci mem += stride; 525d722e3fbSopenharmony_ci } 526d722e3fbSopenharmony_ci 527d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 528d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 529d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = colors_middle[x * 7 / width]; 530d722e3fbSopenharmony_ci mem += stride; 531d722e3fbSopenharmony_ci } 532d722e3fbSopenharmony_ci 533d722e3fbSopenharmony_ci for (; y < height; ++y) { 534d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 535d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = 536d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)]; 537d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 538d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = 539d722e3fbSopenharmony_ci colors_bottom[(x - width * 5 / 7) * 3 540d722e3fbSopenharmony_ci / (width / 7) + 4]; 541d722e3fbSopenharmony_ci for (; x < width; ++x) 542d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = colors_bottom[7]; 543d722e3fbSopenharmony_ci mem += stride; 544d722e3fbSopenharmony_ci } 545d722e3fbSopenharmony_ci} 546d722e3fbSopenharmony_ci 547d722e3fbSopenharmony_cistatic void fill_smpte_rgb16fp(const struct util_rgb_info *rgb, void *mem, 548d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 549d722e3fbSopenharmony_ci unsigned int stride) 550d722e3fbSopenharmony_ci{ 551d722e3fbSopenharmony_ci const uint64_t colors_top[] = { 552d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 192, 192, 255),/* grey */ 553d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 192, 0, 255), /* yellow */ 554d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 192, 192, 255), /* cyan */ 555d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 192, 0, 255), /* green */ 556d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 0, 192, 255), /* magenta */ 557d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 0, 0, 255), /* red */ 558d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 0, 192, 255), /* blue */ 559d722e3fbSopenharmony_ci }; 560d722e3fbSopenharmony_ci const uint64_t colors_middle[] = { 561d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 0, 192, 127), /* blue */ 562d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 127), /* black */ 563d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 0, 192, 127), /* magenta */ 564d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 127), /* black */ 565d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 192, 192, 127), /* cyan */ 566d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 127), /* black */ 567d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 192, 192, 192, 127),/* grey */ 568d722e3fbSopenharmony_ci }; 569d722e3fbSopenharmony_ci const uint64_t colors_bottom[] = { 570d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 0, 33, 76, 255), /* in-phase */ 571d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 255, 255, 255, 255),/* super white */ 572d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 50, 0, 106, 255), /* quadrature */ 573d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 255), /* black */ 574d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 9, 9, 9, 255), /* 3.5% */ 575d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 255), /* 7.5% */ 576d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 29, 29, 29, 255), /* 11.5% */ 577d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, 19, 19, 19, 255), /* black */ 578d722e3fbSopenharmony_ci }; 579d722e3fbSopenharmony_ci unsigned int x; 580d722e3fbSopenharmony_ci unsigned int y; 581d722e3fbSopenharmony_ci 582d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 583d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 584d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = colors_top[x * 7 / width]; 585d722e3fbSopenharmony_ci mem += stride; 586d722e3fbSopenharmony_ci } 587d722e3fbSopenharmony_ci 588d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 589d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 590d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = colors_middle[x * 7 / width]; 591d722e3fbSopenharmony_ci mem += stride; 592d722e3fbSopenharmony_ci } 593d722e3fbSopenharmony_ci 594d722e3fbSopenharmony_ci for (; y < height; ++y) { 595d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 596d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = 597d722e3fbSopenharmony_ci colors_bottom[x * 4 / (width * 5 / 7)]; 598d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 599d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = 600d722e3fbSopenharmony_ci colors_bottom[(x - width * 5 / 7) * 3 601d722e3fbSopenharmony_ci / (width / 7) + 4]; 602d722e3fbSopenharmony_ci for (; x < width; ++x) 603d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = colors_bottom[7]; 604d722e3fbSopenharmony_ci mem += stride; 605d722e3fbSopenharmony_ci } 606d722e3fbSopenharmony_ci} 607d722e3fbSopenharmony_ci 608d722e3fbSopenharmony_cistatic void fill_smpte_c8(void *mem, unsigned int width, unsigned int height, 609d722e3fbSopenharmony_ci unsigned int stride) 610d722e3fbSopenharmony_ci{ 611d722e3fbSopenharmony_ci unsigned int x; 612d722e3fbSopenharmony_ci unsigned int y; 613d722e3fbSopenharmony_ci 614d722e3fbSopenharmony_ci for (y = 0; y < height * 6 / 9; ++y) { 615d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 616d722e3fbSopenharmony_ci ((uint8_t *)mem)[x] = x * 7 / width; 617d722e3fbSopenharmony_ci mem += stride; 618d722e3fbSopenharmony_ci } 619d722e3fbSopenharmony_ci 620d722e3fbSopenharmony_ci for (; y < height * 7 / 9; ++y) { 621d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) 622d722e3fbSopenharmony_ci ((uint8_t *)mem)[x] = 7 + (x * 7 / width); 623d722e3fbSopenharmony_ci mem += stride; 624d722e3fbSopenharmony_ci } 625d722e3fbSopenharmony_ci 626d722e3fbSopenharmony_ci for (; y < height; ++y) { 627d722e3fbSopenharmony_ci for (x = 0; x < width * 5 / 7; ++x) 628d722e3fbSopenharmony_ci ((uint8_t *)mem)[x] = 629d722e3fbSopenharmony_ci 14 + (x * 4 / (width * 5 / 7)); 630d722e3fbSopenharmony_ci for (; x < width * 6 / 7; ++x) 631d722e3fbSopenharmony_ci ((uint8_t *)mem)[x] = 632d722e3fbSopenharmony_ci 14 + ((x - width * 5 / 7) * 3 633d722e3fbSopenharmony_ci / (width / 7) + 4); 634d722e3fbSopenharmony_ci for (; x < width; ++x) 635d722e3fbSopenharmony_ci ((uint8_t *)mem)[x] = 14 + 7; 636d722e3fbSopenharmony_ci mem += stride; 637d722e3fbSopenharmony_ci } 638d722e3fbSopenharmony_ci} 639d722e3fbSopenharmony_ci 640d722e3fbSopenharmony_civoid util_smpte_c8_gamma(unsigned size, struct drm_color_lut *lut) 641d722e3fbSopenharmony_ci{ 642d722e3fbSopenharmony_ci if (size < 7 + 7 + 8) { 643d722e3fbSopenharmony_ci printf("Error: gamma too small: %d < %d\n", size, 7 + 7 + 8); 644d722e3fbSopenharmony_ci return; 645d722e3fbSopenharmony_ci } 646d722e3fbSopenharmony_ci memset(lut, 0, size * sizeof(struct drm_color_lut)); 647d722e3fbSopenharmony_ci 648d722e3fbSopenharmony_ci#define FILL_COLOR(idx, r, g, b) \ 649d722e3fbSopenharmony_ci lut[idx].red = (r) << 8; \ 650d722e3fbSopenharmony_ci lut[idx].green = (g) << 8; \ 651d722e3fbSopenharmony_ci lut[idx].blue = (b) << 8 652d722e3fbSopenharmony_ci 653d722e3fbSopenharmony_ci FILL_COLOR( 0, 192, 192, 192); /* grey */ 654d722e3fbSopenharmony_ci FILL_COLOR( 1, 192, 192, 0 ); /* yellow */ 655d722e3fbSopenharmony_ci FILL_COLOR( 2, 0, 192, 192); /* cyan */ 656d722e3fbSopenharmony_ci FILL_COLOR( 3, 0, 192, 0 ); /* green */ 657d722e3fbSopenharmony_ci FILL_COLOR( 4, 192, 0, 192); /* magenta */ 658d722e3fbSopenharmony_ci FILL_COLOR( 5, 192, 0, 0 ); /* red */ 659d722e3fbSopenharmony_ci FILL_COLOR( 6, 0, 0, 192); /* blue */ 660d722e3fbSopenharmony_ci 661d722e3fbSopenharmony_ci FILL_COLOR( 7, 0, 0, 192); /* blue */ 662d722e3fbSopenharmony_ci FILL_COLOR( 8, 19, 19, 19 ); /* black */ 663d722e3fbSopenharmony_ci FILL_COLOR( 9, 192, 0, 192); /* magenta */ 664d722e3fbSopenharmony_ci FILL_COLOR(10, 19, 19, 19 ); /* black */ 665d722e3fbSopenharmony_ci FILL_COLOR(11, 0, 192, 192); /* cyan */ 666d722e3fbSopenharmony_ci FILL_COLOR(12, 19, 19, 19 ); /* black */ 667d722e3fbSopenharmony_ci FILL_COLOR(13, 192, 192, 192); /* grey */ 668d722e3fbSopenharmony_ci 669d722e3fbSopenharmony_ci FILL_COLOR(14, 0, 33, 76); /* in-phase */ 670d722e3fbSopenharmony_ci FILL_COLOR(15, 255, 255, 255); /* super white */ 671d722e3fbSopenharmony_ci FILL_COLOR(16, 50, 0, 106); /* quadrature */ 672d722e3fbSopenharmony_ci FILL_COLOR(17, 19, 19, 19); /* black */ 673d722e3fbSopenharmony_ci FILL_COLOR(18, 9, 9, 9); /* 3.5% */ 674d722e3fbSopenharmony_ci FILL_COLOR(19, 19, 19, 19); /* 7.5% */ 675d722e3fbSopenharmony_ci FILL_COLOR(20, 29, 29, 29); /* 11.5% */ 676d722e3fbSopenharmony_ci FILL_COLOR(21, 19, 19, 19); /* black */ 677d722e3fbSopenharmony_ci 678d722e3fbSopenharmony_ci#undef FILL_COLOR 679d722e3fbSopenharmony_ci} 680d722e3fbSopenharmony_ci 681d722e3fbSopenharmony_cistatic void fill_smpte(const struct util_format_info *info, void *planes[3], 682d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 683d722e3fbSopenharmony_ci unsigned int stride) 684d722e3fbSopenharmony_ci{ 685d722e3fbSopenharmony_ci unsigned char *u, *v; 686d722e3fbSopenharmony_ci 687d722e3fbSopenharmony_ci switch (info->format) { 688d722e3fbSopenharmony_ci case DRM_FORMAT_C8: 689d722e3fbSopenharmony_ci return fill_smpte_c8(planes[0], width, height, stride); 690d722e3fbSopenharmony_ci case DRM_FORMAT_UYVY: 691d722e3fbSopenharmony_ci case DRM_FORMAT_VYUY: 692d722e3fbSopenharmony_ci case DRM_FORMAT_YUYV: 693d722e3fbSopenharmony_ci case DRM_FORMAT_YVYU: 694d722e3fbSopenharmony_ci return fill_smpte_yuv_packed(&info->yuv, planes[0], width, 695d722e3fbSopenharmony_ci height, stride); 696d722e3fbSopenharmony_ci 697d722e3fbSopenharmony_ci case DRM_FORMAT_NV12: 698d722e3fbSopenharmony_ci case DRM_FORMAT_NV21: 699d722e3fbSopenharmony_ci case DRM_FORMAT_NV16: 700d722e3fbSopenharmony_ci case DRM_FORMAT_NV61: 701d722e3fbSopenharmony_ci u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; 702d722e3fbSopenharmony_ci v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; 703d722e3fbSopenharmony_ci return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v, 704d722e3fbSopenharmony_ci width, height, stride); 705d722e3fbSopenharmony_ci 706d722e3fbSopenharmony_ci case DRM_FORMAT_YUV420: 707d722e3fbSopenharmony_ci return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1], 708d722e3fbSopenharmony_ci planes[2], width, height, stride); 709d722e3fbSopenharmony_ci 710d722e3fbSopenharmony_ci case DRM_FORMAT_YVU420: 711d722e3fbSopenharmony_ci return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2], 712d722e3fbSopenharmony_ci planes[1], width, height, stride); 713d722e3fbSopenharmony_ci 714d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB4444: 715d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB4444: 716d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR4444: 717d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR4444: 718d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA4444: 719d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX4444: 720d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA4444: 721d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX4444: 722d722e3fbSopenharmony_ci case DRM_FORMAT_RGB565: 723d722e3fbSopenharmony_ci case DRM_FORMAT_BGR565: 724d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB1555: 725d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB1555: 726d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR1555: 727d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR1555: 728d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA5551: 729d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX5551: 730d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA5551: 731d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX5551: 732d722e3fbSopenharmony_ci return fill_smpte_rgb16(&info->rgb, planes[0], 733d722e3fbSopenharmony_ci width, height, stride); 734d722e3fbSopenharmony_ci 735d722e3fbSopenharmony_ci case DRM_FORMAT_BGR888: 736d722e3fbSopenharmony_ci case DRM_FORMAT_RGB888: 737d722e3fbSopenharmony_ci return fill_smpte_rgb24(&info->rgb, planes[0], 738d722e3fbSopenharmony_ci width, height, stride); 739d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB8888: 740d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB8888: 741d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR8888: 742d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR8888: 743d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA8888: 744d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX8888: 745d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA8888: 746d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX8888: 747d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB2101010: 748d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB2101010: 749d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR2101010: 750d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR2101010: 751d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA1010102: 752d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX1010102: 753d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA1010102: 754d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX1010102: 755d722e3fbSopenharmony_ci return fill_smpte_rgb32(&info->rgb, planes[0], 756d722e3fbSopenharmony_ci width, height, stride); 757d722e3fbSopenharmony_ci 758d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB16161616F: 759d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR16161616F: 760d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB16161616F: 761d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR16161616F: 762d722e3fbSopenharmony_ci return fill_smpte_rgb16fp(&info->rgb, planes[0], 763d722e3fbSopenharmony_ci width, height, stride); 764d722e3fbSopenharmony_ci } 765d722e3fbSopenharmony_ci} 766d722e3fbSopenharmony_ci 767d722e3fbSopenharmony_ci/* swap these for big endian.. */ 768d722e3fbSopenharmony_ci#define RED 2 769d722e3fbSopenharmony_ci#define GREEN 1 770d722e3fbSopenharmony_ci#define BLUE 0 771d722e3fbSopenharmony_ci 772d722e3fbSopenharmony_cistatic void make_pwetty(void *data, unsigned int width, unsigned int height, 773d722e3fbSopenharmony_ci unsigned int stride, uint32_t format) 774d722e3fbSopenharmony_ci{ 775d722e3fbSopenharmony_ci#if HAVE_CAIRO 776d722e3fbSopenharmony_ci cairo_surface_t *surface; 777d722e3fbSopenharmony_ci cairo_t *cr; 778d722e3fbSopenharmony_ci cairo_format_t cairo_format; 779d722e3fbSopenharmony_ci 780d722e3fbSopenharmony_ci /* we can ignore the order of R,G,B channels */ 781d722e3fbSopenharmony_ci switch (format) { 782d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB8888: 783d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB8888: 784d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR8888: 785d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR8888: 786d722e3fbSopenharmony_ci cairo_format = CAIRO_FORMAT_ARGB32; 787d722e3fbSopenharmony_ci break; 788d722e3fbSopenharmony_ci case DRM_FORMAT_RGB565: 789d722e3fbSopenharmony_ci case DRM_FORMAT_BGR565: 790d722e3fbSopenharmony_ci cairo_format = CAIRO_FORMAT_RGB16_565; 791d722e3fbSopenharmony_ci break; 792d722e3fbSopenharmony_ci#if CAIRO_VERSION_MAJOR > 1 || (CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR >= 12) 793d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB2101010: 794d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB2101010: 795d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR2101010: 796d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR2101010: 797d722e3fbSopenharmony_ci cairo_format = CAIRO_FORMAT_RGB30; 798d722e3fbSopenharmony_ci break; 799d722e3fbSopenharmony_ci#endif 800d722e3fbSopenharmony_ci default: 801d722e3fbSopenharmony_ci return; 802d722e3fbSopenharmony_ci } 803d722e3fbSopenharmony_ci 804d722e3fbSopenharmony_ci surface = cairo_image_surface_create_for_data(data, 805d722e3fbSopenharmony_ci cairo_format, 806d722e3fbSopenharmony_ci width, height, 807d722e3fbSopenharmony_ci stride); 808d722e3fbSopenharmony_ci cr = cairo_create(surface); 809d722e3fbSopenharmony_ci cairo_surface_destroy(surface); 810d722e3fbSopenharmony_ci 811d722e3fbSopenharmony_ci cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); 812d722e3fbSopenharmony_ci for (unsigned x = 0; x < width; x += 250) 813d722e3fbSopenharmony_ci for (unsigned y = 0; y < height; y += 250) { 814d722e3fbSopenharmony_ci char buf[64]; 815d722e3fbSopenharmony_ci 816d722e3fbSopenharmony_ci cairo_move_to(cr, x, y - 20); 817d722e3fbSopenharmony_ci cairo_line_to(cr, x, y + 20); 818d722e3fbSopenharmony_ci cairo_move_to(cr, x - 20, y); 819d722e3fbSopenharmony_ci cairo_line_to(cr, x + 20, y); 820d722e3fbSopenharmony_ci cairo_new_sub_path(cr); 821d722e3fbSopenharmony_ci cairo_arc(cr, x, y, 10, 0, M_PI * 2); 822d722e3fbSopenharmony_ci cairo_set_line_width(cr, 4); 823d722e3fbSopenharmony_ci cairo_set_source_rgb(cr, 0, 0, 0); 824d722e3fbSopenharmony_ci cairo_stroke_preserve(cr); 825d722e3fbSopenharmony_ci cairo_set_source_rgb(cr, 1, 1, 1); 826d722e3fbSopenharmony_ci cairo_set_line_width(cr, 2); 827d722e3fbSopenharmony_ci cairo_stroke(cr); 828d722e3fbSopenharmony_ci 829d722e3fbSopenharmony_ci snprintf(buf, sizeof buf, "%d, %d", x, y); 830d722e3fbSopenharmony_ci cairo_move_to(cr, x + 20, y + 20); 831d722e3fbSopenharmony_ci cairo_text_path(cr, buf); 832d722e3fbSopenharmony_ci cairo_set_source_rgb(cr, 0, 0, 0); 833d722e3fbSopenharmony_ci cairo_stroke_preserve(cr); 834d722e3fbSopenharmony_ci cairo_set_source_rgb(cr, 1, 1, 1); 835d722e3fbSopenharmony_ci cairo_fill(cr); 836d722e3fbSopenharmony_ci } 837d722e3fbSopenharmony_ci 838d722e3fbSopenharmony_ci cairo_destroy(cr); 839d722e3fbSopenharmony_ci#endif 840d722e3fbSopenharmony_ci} 841d722e3fbSopenharmony_ci 842d722e3fbSopenharmony_cistatic void fill_tiles_yuv_planar(const struct util_format_info *info, 843d722e3fbSopenharmony_ci unsigned char *y_mem, unsigned char *u_mem, 844d722e3fbSopenharmony_ci unsigned char *v_mem, unsigned int width, 845d722e3fbSopenharmony_ci unsigned int height, unsigned int stride) 846d722e3fbSopenharmony_ci{ 847d722e3fbSopenharmony_ci const struct util_yuv_info *yuv = &info->yuv; 848d722e3fbSopenharmony_ci unsigned int cs = yuv->chroma_stride; 849d722e3fbSopenharmony_ci unsigned int xsub = yuv->xsub; 850d722e3fbSopenharmony_ci unsigned int ysub = yuv->ysub; 851d722e3fbSopenharmony_ci unsigned int x; 852d722e3fbSopenharmony_ci unsigned int y; 853d722e3fbSopenharmony_ci 854d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 855d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) { 856d722e3fbSopenharmony_ci div_t d = div(x+y, width); 857d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 858d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 859d722e3fbSopenharmony_ci struct color_yuv color = 860d722e3fbSopenharmony_ci MAKE_YUV_601((rgb32 >> 16) & 0xff, 861d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff); 862d722e3fbSopenharmony_ci 863d722e3fbSopenharmony_ci y_mem[x] = color.y; 864d722e3fbSopenharmony_ci u_mem[x/xsub*cs] = color.u; 865d722e3fbSopenharmony_ci v_mem[x/xsub*cs] = color.v; 866d722e3fbSopenharmony_ci } 867d722e3fbSopenharmony_ci 868d722e3fbSopenharmony_ci y_mem += stride; 869d722e3fbSopenharmony_ci if ((y + 1) % ysub == 0) { 870d722e3fbSopenharmony_ci u_mem += stride * cs / xsub; 871d722e3fbSopenharmony_ci v_mem += stride * cs / xsub; 872d722e3fbSopenharmony_ci } 873d722e3fbSopenharmony_ci } 874d722e3fbSopenharmony_ci} 875d722e3fbSopenharmony_ci 876d722e3fbSopenharmony_cistatic void fill_tiles_yuv_packed(const struct util_format_info *info, 877d722e3fbSopenharmony_ci void *mem, unsigned int width, 878d722e3fbSopenharmony_ci unsigned int height, unsigned int stride) 879d722e3fbSopenharmony_ci{ 880d722e3fbSopenharmony_ci const struct util_yuv_info *yuv = &info->yuv; 881d722e3fbSopenharmony_ci unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; 882d722e3fbSopenharmony_ci unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; 883d722e3fbSopenharmony_ci unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; 884d722e3fbSopenharmony_ci unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; 885d722e3fbSopenharmony_ci unsigned int x; 886d722e3fbSopenharmony_ci unsigned int y; 887d722e3fbSopenharmony_ci 888d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 889d722e3fbSopenharmony_ci for (x = 0; x < width; x += 2) { 890d722e3fbSopenharmony_ci div_t d = div(x+y, width); 891d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 892d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 893d722e3fbSopenharmony_ci struct color_yuv color = 894d722e3fbSopenharmony_ci MAKE_YUV_601((rgb32 >> 16) & 0xff, 895d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff); 896d722e3fbSopenharmony_ci 897d722e3fbSopenharmony_ci y_mem[2*x] = color.y; 898d722e3fbSopenharmony_ci c_mem[2*x+u] = color.u; 899d722e3fbSopenharmony_ci y_mem[2*x+2] = color.y; 900d722e3fbSopenharmony_ci c_mem[2*x+v] = color.v; 901d722e3fbSopenharmony_ci } 902d722e3fbSopenharmony_ci 903d722e3fbSopenharmony_ci y_mem += stride; 904d722e3fbSopenharmony_ci c_mem += stride; 905d722e3fbSopenharmony_ci } 906d722e3fbSopenharmony_ci} 907d722e3fbSopenharmony_ci 908d722e3fbSopenharmony_cistatic void fill_tiles_rgb16(const struct util_format_info *info, void *mem, 909d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 910d722e3fbSopenharmony_ci unsigned int stride) 911d722e3fbSopenharmony_ci{ 912d722e3fbSopenharmony_ci const struct util_rgb_info *rgb = &info->rgb; 913d722e3fbSopenharmony_ci void *mem_base = mem; 914d722e3fbSopenharmony_ci unsigned int x, y; 915d722e3fbSopenharmony_ci 916d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 917d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) { 918d722e3fbSopenharmony_ci div_t d = div(x+y, width); 919d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 920d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 921d722e3fbSopenharmony_ci uint16_t color = 922d722e3fbSopenharmony_ci MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, 923d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff, 924d722e3fbSopenharmony_ci 255); 925d722e3fbSopenharmony_ci 926d722e3fbSopenharmony_ci ((uint16_t *)mem)[x] = color; 927d722e3fbSopenharmony_ci } 928d722e3fbSopenharmony_ci mem += stride; 929d722e3fbSopenharmony_ci } 930d722e3fbSopenharmony_ci 931d722e3fbSopenharmony_ci make_pwetty(mem_base, width, height, stride, info->format); 932d722e3fbSopenharmony_ci} 933d722e3fbSopenharmony_ci 934d722e3fbSopenharmony_cistatic void fill_tiles_rgb24(const struct util_format_info *info, void *mem, 935d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 936d722e3fbSopenharmony_ci unsigned int stride) 937d722e3fbSopenharmony_ci{ 938d722e3fbSopenharmony_ci const struct util_rgb_info *rgb = &info->rgb; 939d722e3fbSopenharmony_ci unsigned int x, y; 940d722e3fbSopenharmony_ci 941d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 942d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) { 943d722e3fbSopenharmony_ci div_t d = div(x+y, width); 944d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 945d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 946d722e3fbSopenharmony_ci struct color_rgb24 color = 947d722e3fbSopenharmony_ci MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff, 948d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff); 949d722e3fbSopenharmony_ci 950d722e3fbSopenharmony_ci ((struct color_rgb24 *)mem)[x] = color; 951d722e3fbSopenharmony_ci } 952d722e3fbSopenharmony_ci mem += stride; 953d722e3fbSopenharmony_ci } 954d722e3fbSopenharmony_ci} 955d722e3fbSopenharmony_ci 956d722e3fbSopenharmony_cistatic void fill_tiles_rgb32(const struct util_format_info *info, void *mem, 957d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 958d722e3fbSopenharmony_ci unsigned int stride) 959d722e3fbSopenharmony_ci{ 960d722e3fbSopenharmony_ci const struct util_rgb_info *rgb = &info->rgb; 961d722e3fbSopenharmony_ci void *mem_base = mem; 962d722e3fbSopenharmony_ci unsigned int x, y; 963d722e3fbSopenharmony_ci 964d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 965d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) { 966d722e3fbSopenharmony_ci div_t d = div(x+y, width); 967d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 968d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 969d722e3fbSopenharmony_ci uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255; 970d722e3fbSopenharmony_ci uint32_t color = 971d722e3fbSopenharmony_ci MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, 972d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff, 973d722e3fbSopenharmony_ci alpha); 974d722e3fbSopenharmony_ci 975d722e3fbSopenharmony_ci ((uint32_t *)mem)[x] = color; 976d722e3fbSopenharmony_ci } 977d722e3fbSopenharmony_ci mem += stride; 978d722e3fbSopenharmony_ci } 979d722e3fbSopenharmony_ci 980d722e3fbSopenharmony_ci make_pwetty(mem_base, width, height, stride, info->format); 981d722e3fbSopenharmony_ci} 982d722e3fbSopenharmony_ci 983d722e3fbSopenharmony_cistatic void fill_tiles_rgb16fp(const struct util_format_info *info, void *mem, 984d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 985d722e3fbSopenharmony_ci unsigned int stride) 986d722e3fbSopenharmony_ci{ 987d722e3fbSopenharmony_ci const struct util_rgb_info *rgb = &info->rgb; 988d722e3fbSopenharmony_ci unsigned int x, y; 989d722e3fbSopenharmony_ci 990d722e3fbSopenharmony_ci /* TODO: Give this actual fp16 precision */ 991d722e3fbSopenharmony_ci for (y = 0; y < height; ++y) { 992d722e3fbSopenharmony_ci for (x = 0; x < width; ++x) { 993d722e3fbSopenharmony_ci div_t d = div(x+y, width); 994d722e3fbSopenharmony_ci uint32_t rgb32 = 0x00130502 * (d.quot >> 6) 995d722e3fbSopenharmony_ci + 0x000a1120 * (d.rem >> 6); 996d722e3fbSopenharmony_ci uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255; 997d722e3fbSopenharmony_ci uint64_t color = 998d722e3fbSopenharmony_ci MAKE_RGBA8FP16(rgb, (rgb32 >> 16) & 0xff, 999d722e3fbSopenharmony_ci (rgb32 >> 8) & 0xff, rgb32 & 0xff, 1000d722e3fbSopenharmony_ci alpha); 1001d722e3fbSopenharmony_ci 1002d722e3fbSopenharmony_ci ((uint64_t *)mem)[x] = color; 1003d722e3fbSopenharmony_ci } 1004d722e3fbSopenharmony_ci mem += stride; 1005d722e3fbSopenharmony_ci } 1006d722e3fbSopenharmony_ci} 1007d722e3fbSopenharmony_ci 1008d722e3fbSopenharmony_cistatic void fill_tiles(const struct util_format_info *info, void *planes[3], 1009d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 1010d722e3fbSopenharmony_ci unsigned int stride) 1011d722e3fbSopenharmony_ci{ 1012d722e3fbSopenharmony_ci unsigned char *u, *v; 1013d722e3fbSopenharmony_ci 1014d722e3fbSopenharmony_ci switch (info->format) { 1015d722e3fbSopenharmony_ci case DRM_FORMAT_UYVY: 1016d722e3fbSopenharmony_ci case DRM_FORMAT_VYUY: 1017d722e3fbSopenharmony_ci case DRM_FORMAT_YUYV: 1018d722e3fbSopenharmony_ci case DRM_FORMAT_YVYU: 1019d722e3fbSopenharmony_ci return fill_tiles_yuv_packed(info, planes[0], 1020d722e3fbSopenharmony_ci width, height, stride); 1021d722e3fbSopenharmony_ci 1022d722e3fbSopenharmony_ci case DRM_FORMAT_NV12: 1023d722e3fbSopenharmony_ci case DRM_FORMAT_NV21: 1024d722e3fbSopenharmony_ci case DRM_FORMAT_NV16: 1025d722e3fbSopenharmony_ci case DRM_FORMAT_NV61: 1026d722e3fbSopenharmony_ci u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; 1027d722e3fbSopenharmony_ci v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; 1028d722e3fbSopenharmony_ci return fill_tiles_yuv_planar(info, planes[0], u, v, 1029d722e3fbSopenharmony_ci width, height, stride); 1030d722e3fbSopenharmony_ci 1031d722e3fbSopenharmony_ci case DRM_FORMAT_YUV420: 1032d722e3fbSopenharmony_ci return fill_tiles_yuv_planar(info, planes[0], planes[1], 1033d722e3fbSopenharmony_ci planes[2], width, height, stride); 1034d722e3fbSopenharmony_ci 1035d722e3fbSopenharmony_ci case DRM_FORMAT_YVU420: 1036d722e3fbSopenharmony_ci return fill_tiles_yuv_planar(info, planes[0], planes[2], 1037d722e3fbSopenharmony_ci planes[1], width, height, stride); 1038d722e3fbSopenharmony_ci 1039d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB4444: 1040d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB4444: 1041d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR4444: 1042d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR4444: 1043d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA4444: 1044d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX4444: 1045d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA4444: 1046d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX4444: 1047d722e3fbSopenharmony_ci case DRM_FORMAT_RGB565: 1048d722e3fbSopenharmony_ci case DRM_FORMAT_BGR565: 1049d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB1555: 1050d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB1555: 1051d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR1555: 1052d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR1555: 1053d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA5551: 1054d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX5551: 1055d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA5551: 1056d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX5551: 1057d722e3fbSopenharmony_ci return fill_tiles_rgb16(info, planes[0], 1058d722e3fbSopenharmony_ci width, height, stride); 1059d722e3fbSopenharmony_ci 1060d722e3fbSopenharmony_ci case DRM_FORMAT_BGR888: 1061d722e3fbSopenharmony_ci case DRM_FORMAT_RGB888: 1062d722e3fbSopenharmony_ci return fill_tiles_rgb24(info, planes[0], 1063d722e3fbSopenharmony_ci width, height, stride); 1064d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB8888: 1065d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB8888: 1066d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR8888: 1067d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR8888: 1068d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA8888: 1069d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX8888: 1070d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA8888: 1071d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX8888: 1072d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB2101010: 1073d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB2101010: 1074d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR2101010: 1075d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR2101010: 1076d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA1010102: 1077d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX1010102: 1078d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA1010102: 1079d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX1010102: 1080d722e3fbSopenharmony_ci return fill_tiles_rgb32(info, planes[0], 1081d722e3fbSopenharmony_ci width, height, stride); 1082d722e3fbSopenharmony_ci 1083d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB16161616F: 1084d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR16161616F: 1085d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB16161616F: 1086d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR16161616F: 1087d722e3fbSopenharmony_ci return fill_tiles_rgb16fp(info, planes[0], 1088d722e3fbSopenharmony_ci width, height, stride); 1089d722e3fbSopenharmony_ci } 1090d722e3fbSopenharmony_ci} 1091d722e3fbSopenharmony_ci 1092d722e3fbSopenharmony_cistatic void fill_plain(const struct util_format_info *info, void *planes[3], 1093d722e3fbSopenharmony_ci unsigned int height, 1094d722e3fbSopenharmony_ci unsigned int stride) 1095d722e3fbSopenharmony_ci{ 1096d722e3fbSopenharmony_ci switch (info->format) { 1097d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB16161616F: 1098d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR16161616F: 1099d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB16161616F: 1100d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR16161616F: 1101d722e3fbSopenharmony_ci /* 0x3838 = 0.5273 */ 1102d722e3fbSopenharmony_ci memset(planes[0], 0x38, stride * height); 1103d722e3fbSopenharmony_ci break; 1104d722e3fbSopenharmony_ci default: 1105d722e3fbSopenharmony_ci memset(planes[0], 0x77, stride * height); 1106d722e3fbSopenharmony_ci break; 1107d722e3fbSopenharmony_ci } 1108d722e3fbSopenharmony_ci} 1109d722e3fbSopenharmony_ci 1110d722e3fbSopenharmony_cistatic void fill_gradient_rgb32(const struct util_rgb_info *rgb, 1111d722e3fbSopenharmony_ci void *mem, 1112d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 1113d722e3fbSopenharmony_ci unsigned int stride) 1114d722e3fbSopenharmony_ci{ 1115d722e3fbSopenharmony_ci unsigned int i, j; 1116d722e3fbSopenharmony_ci 1117d722e3fbSopenharmony_ci for (i = 0; i < height / 2; i++) { 1118d722e3fbSopenharmony_ci uint32_t *row = mem; 1119d722e3fbSopenharmony_ci 1120d722e3fbSopenharmony_ci for (j = 0; j < width / 2; j++) { 1121d722e3fbSopenharmony_ci uint32_t value = MAKE_RGBA10(rgb, j & 0x3ff, j & 0x3ff, j & 0x3ff, 0); 1122d722e3fbSopenharmony_ci row[2*j] = row[2*j+1] = value; 1123d722e3fbSopenharmony_ci } 1124d722e3fbSopenharmony_ci mem += stride; 1125d722e3fbSopenharmony_ci } 1126d722e3fbSopenharmony_ci 1127d722e3fbSopenharmony_ci for (; i < height; i++) { 1128d722e3fbSopenharmony_ci uint32_t *row = mem; 1129d722e3fbSopenharmony_ci 1130d722e3fbSopenharmony_ci for (j = 0; j < width / 2; j++) { 1131d722e3fbSopenharmony_ci uint32_t value = MAKE_RGBA10(rgb, j & 0x3fc, j & 0x3fc, j & 0x3fc, 0); 1132d722e3fbSopenharmony_ci row[2*j] = row[2*j+1] = value; 1133d722e3fbSopenharmony_ci } 1134d722e3fbSopenharmony_ci mem += stride; 1135d722e3fbSopenharmony_ci } 1136d722e3fbSopenharmony_ci} 1137d722e3fbSopenharmony_ci 1138d722e3fbSopenharmony_cistatic void fill_gradient_rgb16fp(const struct util_rgb_info *rgb, 1139d722e3fbSopenharmony_ci void *mem, 1140d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 1141d722e3fbSopenharmony_ci unsigned int stride) 1142d722e3fbSopenharmony_ci{ 1143d722e3fbSopenharmony_ci unsigned int i, j; 1144d722e3fbSopenharmony_ci 1145d722e3fbSopenharmony_ci for (i = 0; i < height / 2; i++) { 1146d722e3fbSopenharmony_ci uint64_t *row = mem; 1147d722e3fbSopenharmony_ci 1148d722e3fbSopenharmony_ci for (j = 0; j < width / 2; j++) { 1149d722e3fbSopenharmony_ci uint64_t value = MAKE_RGBA10FP16(rgb, j & 0x3ff, j & 0x3ff, j & 0x3ff, 0); 1150d722e3fbSopenharmony_ci row[2*j] = row[2*j+1] = value; 1151d722e3fbSopenharmony_ci } 1152d722e3fbSopenharmony_ci mem += stride; 1153d722e3fbSopenharmony_ci } 1154d722e3fbSopenharmony_ci 1155d722e3fbSopenharmony_ci for (; i < height; i++) { 1156d722e3fbSopenharmony_ci uint64_t *row = mem; 1157d722e3fbSopenharmony_ci 1158d722e3fbSopenharmony_ci for (j = 0; j < width / 2; j++) { 1159d722e3fbSopenharmony_ci uint64_t value = MAKE_RGBA10FP16(rgb, j & 0x3fc, j & 0x3fc, j & 0x3fc, 0); 1160d722e3fbSopenharmony_ci row[2*j] = row[2*j+1] = value; 1161d722e3fbSopenharmony_ci } 1162d722e3fbSopenharmony_ci mem += stride; 1163d722e3fbSopenharmony_ci } 1164d722e3fbSopenharmony_ci} 1165d722e3fbSopenharmony_ci 1166d722e3fbSopenharmony_ci/* The gradient pattern creates two horizontal gray gradients, split 1167d722e3fbSopenharmony_ci * into two halves. The top half has 10bpc precision, the bottom half 1168d722e3fbSopenharmony_ci * has 8bpc precision. When using with a 10bpc fb format, there are 3 1169d722e3fbSopenharmony_ci * possible outcomes: 1170d722e3fbSopenharmony_ci * 1171d722e3fbSopenharmony_ci * - Pixel data is encoded as 8bpc to the display, no dithering. This 1172d722e3fbSopenharmony_ci * would lead to the top and bottom halves looking identical. 1173d722e3fbSopenharmony_ci * 1174d722e3fbSopenharmony_ci * - Pixel data is encoded as 8bpc to the display, with dithering. This 1175d722e3fbSopenharmony_ci * would lead to there being a visible difference between the two halves, 1176d722e3fbSopenharmony_ci * but the top half would look a little speck-y due to the dithering. 1177d722e3fbSopenharmony_ci * 1178d722e3fbSopenharmony_ci * - Pixel data is encoded at 10bpc+ to the display (which implies 1179d722e3fbSopenharmony_ci * the display is able to show this level of depth). This should 1180d722e3fbSopenharmony_ci * lead to the top half being a very clean gradient, and visibly different 1181d722e3fbSopenharmony_ci * from the bottom half. 1182d722e3fbSopenharmony_ci * 1183d722e3fbSopenharmony_ci * Once we support additional fb formats, this approach could be extended 1184d722e3fbSopenharmony_ci * to distinguish even higher bpc precisions. 1185d722e3fbSopenharmony_ci * 1186d722e3fbSopenharmony_ci * Note that due to practical size considerations, for the screens 1187d722e3fbSopenharmony_ci * where this matters, the pattern actually emits stripes 2-pixels 1188d722e3fbSopenharmony_ci * wide for each gradient color. Otherwise the difference may be a bit 1189d722e3fbSopenharmony_ci * hard to notice. 1190d722e3fbSopenharmony_ci */ 1191d722e3fbSopenharmony_cistatic void fill_gradient(const struct util_format_info *info, void *planes[3], 1192d722e3fbSopenharmony_ci unsigned int width, unsigned int height, 1193d722e3fbSopenharmony_ci unsigned int stride) 1194d722e3fbSopenharmony_ci{ 1195d722e3fbSopenharmony_ci switch (info->format) { 1196d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB8888: 1197d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB8888: 1198d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR8888: 1199d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR8888: 1200d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA8888: 1201d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX8888: 1202d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA8888: 1203d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX8888: 1204d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB2101010: 1205d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB2101010: 1206d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR2101010: 1207d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR2101010: 1208d722e3fbSopenharmony_ci case DRM_FORMAT_RGBA1010102: 1209d722e3fbSopenharmony_ci case DRM_FORMAT_RGBX1010102: 1210d722e3fbSopenharmony_ci case DRM_FORMAT_BGRA1010102: 1211d722e3fbSopenharmony_ci case DRM_FORMAT_BGRX1010102: 1212d722e3fbSopenharmony_ci return fill_gradient_rgb32(&info->rgb, planes[0], 1213d722e3fbSopenharmony_ci width, height, stride); 1214d722e3fbSopenharmony_ci 1215d722e3fbSopenharmony_ci case DRM_FORMAT_XRGB16161616F: 1216d722e3fbSopenharmony_ci case DRM_FORMAT_XBGR16161616F: 1217d722e3fbSopenharmony_ci case DRM_FORMAT_ARGB16161616F: 1218d722e3fbSopenharmony_ci case DRM_FORMAT_ABGR16161616F: 1219d722e3fbSopenharmony_ci return fill_gradient_rgb16fp(&info->rgb, planes[0], 1220d722e3fbSopenharmony_ci width, height, stride); 1221d722e3fbSopenharmony_ci } 1222d722e3fbSopenharmony_ci} 1223d722e3fbSopenharmony_ci 1224d722e3fbSopenharmony_ci/* 1225d722e3fbSopenharmony_ci * util_fill_pattern - Fill a buffer with a test pattern 1226d722e3fbSopenharmony_ci * @format: Pixel format 1227d722e3fbSopenharmony_ci * @pattern: Test pattern 1228d722e3fbSopenharmony_ci * @planes: Array of buffers 1229d722e3fbSopenharmony_ci * @width: Width in pixels 1230d722e3fbSopenharmony_ci * @height: Height in pixels 1231d722e3fbSopenharmony_ci * @stride: Line stride (pitch) in bytes 1232d722e3fbSopenharmony_ci * 1233d722e3fbSopenharmony_ci * Fill the buffers with the test pattern specified by the pattern parameter. 1234d722e3fbSopenharmony_ci * Supported formats vary depending on the selected pattern. 1235d722e3fbSopenharmony_ci */ 1236d722e3fbSopenharmony_civoid util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, 1237d722e3fbSopenharmony_ci void *planes[3], unsigned int width, 1238d722e3fbSopenharmony_ci unsigned int height, unsigned int stride) 1239d722e3fbSopenharmony_ci{ 1240d722e3fbSopenharmony_ci const struct util_format_info *info; 1241d722e3fbSopenharmony_ci 1242d722e3fbSopenharmony_ci info = util_format_info_find(format); 1243d722e3fbSopenharmony_ci if (info == NULL) 1244d722e3fbSopenharmony_ci return; 1245d722e3fbSopenharmony_ci 1246d722e3fbSopenharmony_ci switch (pattern) { 1247d722e3fbSopenharmony_ci case UTIL_PATTERN_TILES: 1248d722e3fbSopenharmony_ci return fill_tiles(info, planes, width, height, stride); 1249d722e3fbSopenharmony_ci 1250d722e3fbSopenharmony_ci case UTIL_PATTERN_SMPTE: 1251d722e3fbSopenharmony_ci return fill_smpte(info, planes, width, height, stride); 1252d722e3fbSopenharmony_ci 1253d722e3fbSopenharmony_ci case UTIL_PATTERN_PLAIN: 1254d722e3fbSopenharmony_ci return fill_plain(info, planes, height, stride); 1255d722e3fbSopenharmony_ci 1256d722e3fbSopenharmony_ci case UTIL_PATTERN_GRADIENT: 1257d722e3fbSopenharmony_ci return fill_gradient(info, planes, width, height, stride); 1258d722e3fbSopenharmony_ci 1259d722e3fbSopenharmony_ci default: 1260d722e3fbSopenharmony_ci printf("Error: unsupported test pattern %u.\n", pattern); 1261d722e3fbSopenharmony_ci break; 1262d722e3fbSopenharmony_ci } 1263d722e3fbSopenharmony_ci} 1264d722e3fbSopenharmony_ci 1265d722e3fbSopenharmony_cistatic const char *pattern_names[] = { 1266d722e3fbSopenharmony_ci [UTIL_PATTERN_TILES] = "tiles", 1267d722e3fbSopenharmony_ci [UTIL_PATTERN_SMPTE] = "smpte", 1268d722e3fbSopenharmony_ci [UTIL_PATTERN_PLAIN] = "plain", 1269d722e3fbSopenharmony_ci [UTIL_PATTERN_GRADIENT] = "gradient", 1270d722e3fbSopenharmony_ci}; 1271d722e3fbSopenharmony_ci 1272d722e3fbSopenharmony_cienum util_fill_pattern util_pattern_enum(const char *name) 1273d722e3fbSopenharmony_ci{ 1274d722e3fbSopenharmony_ci unsigned int i; 1275d722e3fbSopenharmony_ci 1276d722e3fbSopenharmony_ci for (i = 0; i < ARRAY_SIZE(pattern_names); i++) 1277d722e3fbSopenharmony_ci if (!strcmp(pattern_names[i], name)) 1278d722e3fbSopenharmony_ci return (enum util_fill_pattern)i; 1279d722e3fbSopenharmony_ci 1280d722e3fbSopenharmony_ci printf("Error: unsupported test pattern %s.\n", name); 1281d722e3fbSopenharmony_ci return UTIL_PATTERN_SMPTE; 1282d722e3fbSopenharmony_ci} 1283