2 * DRM based mode setting test program
3 * Copyright 2008 Tungsten Graphics
4 * Jakob Bornecrantz <jakob@tungstengraphics.com>
5 * Copyright 2008 Intel Corporation
6 * Jesse Barnes <jesse.barnes@intel.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
37 #include <tbm_bufmgr.h>
38 #include <tbm_surface.h>
44 #define ALPHA_VALUE 100
45 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
47 /* -----------------------------------------------------------------------------
51 struct color_component {
57 struct color_component red;
58 struct color_component green;
59 struct color_component blue;
60 struct color_component alpha;
74 unsigned int chroma_stride;
80 const struct rgb_info rgb;
81 const struct yuv_info yuv;
84 #define MAKE_RGB_INFO(rl, ro, bl, bo, gl, go, al, ao) \
85 .rgb = { { (rl), (ro) }, { (bl), (bo) }, { (gl), (go) }, { (al), (ao) } }
87 #define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \
88 .yuv = { (order), (xsub), (ysub), (chroma_stride) }
90 static const struct format_info format_info[] = {
92 { TBM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) },
93 { TBM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) },
94 { TBM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) },
95 { TBM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) },
97 { TBM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) },
98 { TBM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) },
99 { TBM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) },
100 { TBM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) },
102 { TBM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) },
103 { TBM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) },
105 { TBM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) },
106 { TBM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) },
107 { TBM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) },
108 { TBM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) },
109 { TBM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) },
110 { TBM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) },
111 { TBM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) },
112 { TBM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) },
113 { TBM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) },
114 { TBM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) },
115 { TBM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) },
116 { TBM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) },
117 { TBM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) },
118 { TBM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) },
119 { TBM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) },
120 { TBM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) },
121 { TBM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) },
122 { TBM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) },
124 { TBM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
125 { TBM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
127 { TBM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
128 { TBM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 24) },
129 { TBM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
130 { TBM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
131 { TBM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
132 { TBM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) },
133 { TBM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) },
134 { TBM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) },
135 { TBM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) },
136 { TBM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) },
137 { TBM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) },
138 { TBM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) },
139 { TBM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) },
140 { TBM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) },
141 { TBM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) },
142 { TBM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) },
145 static unsigned int rand_seed;
147 unsigned int format_fourcc(const char *name)
150 for (i = 0; i < ARRAY_SIZE(format_info); i++) {
151 if (!strcmp(format_info[i].name, name))
152 return format_info[i].format;
157 /* -----------------------------------------------------------------------------
162 unsigned int value:24;
163 } __attribute__((__packed__));
171 #define MAKE_YUV_601_Y(r, g, b) \
172 (((66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16)
173 #define MAKE_YUV_601_U(r, g, b) \
174 (((-38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128)
175 #define MAKE_YUV_601_V(r, g, b) \
176 (((112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128)
178 #define MAKE_YUV_601(r, g, b) \
179 { .y = MAKE_YUV_601_Y(r, g, b), \
180 .u = MAKE_YUV_601_U(r, g, b), \
181 .v = MAKE_YUV_601_V(r, g, b) }
183 #define MAKE_RGBA(rgb, r, g, b, a) \
184 ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
185 (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
186 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
187 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
189 #define MAKE_RGBX(rgb, r, g, b) \
190 ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
191 (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
192 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
193 (255 << (rgb)->alpha.offset))
195 #define MAKE_RGB24(rgb, r, g, b) \
196 { .value = MAKE_RGBA(rgb, r, g, b, 0) }
199 fill_smpte_yuv_planar(const struct yuv_info *yuv,
200 unsigned char *y_mem, unsigned char *u_mem,
201 unsigned char *v_mem, unsigned int width,
202 unsigned int height, unsigned int stride)
204 const struct color_yuv colors_top[] = {
205 MAKE_YUV_601(191, 192, 192), /* grey */
206 MAKE_YUV_601(192, 192, 0), /* yellow */
207 MAKE_YUV_601(0, 192, 192), /* cyan */
208 MAKE_YUV_601(0, 192, 0), /* green */
209 MAKE_YUV_601(192, 0, 192), /* magenta */
210 MAKE_YUV_601(192, 0, 0), /* red */
211 MAKE_YUV_601(0, 0, 192), /* blue */
213 const struct color_yuv colors_middle[] = {
214 MAKE_YUV_601(0, 0, 192), /* blue */
215 MAKE_YUV_601(19, 19, 19), /* black */
216 MAKE_YUV_601(192, 0, 192), /* magenta */
217 MAKE_YUV_601(19, 19, 19), /* black */
218 MAKE_YUV_601(0, 192, 192), /* cyan */
219 MAKE_YUV_601(19, 19, 19), /* black */
220 MAKE_YUV_601(192, 192, 192), /* grey */
222 const struct color_yuv colors_bottom[] = {
223 MAKE_YUV_601(0, 33, 76), /* in-phase */
224 MAKE_YUV_601(255, 255, 255), /* super white */
225 MAKE_YUV_601(50, 0, 106), /* quadrature */
226 MAKE_YUV_601(19, 19, 19), /* black */
227 MAKE_YUV_601(9, 9, 9), /* 3.5% */
228 MAKE_YUV_601(19, 19, 19), /* 7.5% */
229 MAKE_YUV_601(29, 29, 29), /* 11.5% */
230 MAKE_YUV_601(19, 19, 19), /* black */
232 unsigned int cs = yuv->chroma_stride;
233 unsigned int xsub = yuv->xsub;
234 unsigned int ysub = yuv->ysub;
239 for (y = 0; y < height * 6 / 9; ++y) {
240 for (x = 0; x < width; ++x)
241 y_mem[x] = colors_top[x * 7 / width].y;
245 for (; y < height * 7 / 9; ++y) {
246 for (x = 0; x < width; ++x)
247 y_mem[x] = colors_middle[x * 7 / width].y;
251 for (; y < height; ++y) {
252 for (x = 0; x < width * 5 / 7; ++x)
253 y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
254 for (; x < width * 6 / 7; ++x)
255 y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3
256 / (width / 7) + 4].y;
257 for (; x < width; ++x) {
258 if (rand_r(&rand_seed) % 2)
259 y_mem[x] = colors_bottom[1].y;
261 y_mem[x] = colors_bottom[7].y;
267 for (y = 0; y < height / ysub * 6 / 9; ++y) {
268 for (x = 0; x < width; x += xsub) {
269 u_mem[x * cs / xsub] = colors_top[x * 7 / width].u;
270 v_mem[x * cs / xsub] = colors_top[x * 7 / width].v;
272 u_mem += stride * cs / xsub;
273 v_mem += stride * cs / xsub;
276 for (; y < height / ysub * 7 / 9; ++y) {
277 for (x = 0; x < width; x += xsub) {
278 u_mem[x * cs / xsub] = colors_middle[x * 7 / width].u;
279 v_mem[x * cs / xsub] = colors_middle[x * 7 / width].v;
281 u_mem += stride * cs / xsub;
282 v_mem += stride * cs / xsub;
285 for (; y < height / ysub; ++y) {
286 for (x = 0; x < width * 5 / 7; x += xsub) {
287 u_mem[x * cs / xsub] =
288 colors_bottom[x * 4 / (width * 5 / 7)].u;
289 v_mem[x * cs / xsub] =
290 colors_bottom[x * 4 / (width * 5 / 7)].v;
292 for (; x < width * 6 / 7; x += xsub) {
293 u_mem[x * cs / xsub] = colors_bottom[(x - width * 5 / 7) *
294 3 / (width / 7) + 4].u;
295 v_mem[x * cs / xsub] = colors_bottom[(x - width * 5 / 7) *
296 3 / (width / 7) + 4].v;
298 for (; x < width; x += xsub) {
299 if (rand_r(&rand_seed) % 2) {
300 u_mem[x * cs / xsub] = colors_bottom[1].u;
301 v_mem[x * cs / xsub] = colors_bottom[1].v;
303 u_mem[x * cs / xsub] = colors_bottom[7].u;
304 v_mem[x * cs / xsub] = colors_bottom[7].v;
307 u_mem += stride * cs / xsub;
308 v_mem += stride * cs / xsub;
313 fill_smpte_yuv_packed(const struct yuv_info *yuv, unsigned char *mem,
314 unsigned int width, unsigned int height,
317 const struct color_yuv colors_top[] = {
318 MAKE_YUV_601(191, 192, 192), /* grey */
319 MAKE_YUV_601(192, 192, 0), /* yellow */
320 MAKE_YUV_601(0, 192, 192), /* cyan */
321 MAKE_YUV_601(0, 192, 0), /* green */
322 MAKE_YUV_601(192, 0, 192), /* magenta */
323 MAKE_YUV_601(192, 0, 0), /* red */
324 MAKE_YUV_601(0, 0, 192), /* blue */
326 const struct color_yuv colors_middle[] = {
327 MAKE_YUV_601(0, 0, 192), /* blue */
328 MAKE_YUV_601(19, 19, 19), /* black */
329 MAKE_YUV_601(192, 0, 192), /* magenta */
330 MAKE_YUV_601(19, 19, 19), /* black */
331 MAKE_YUV_601(0, 192, 192), /* cyan */
332 MAKE_YUV_601(19, 19, 19), /* black */
333 MAKE_YUV_601(192, 192, 192), /* grey */
335 const struct color_yuv colors_bottom[] = {
336 MAKE_YUV_601(0, 33, 76), /* in-phase */
337 MAKE_YUV_601(255, 255, 255), /* super white */
338 MAKE_YUV_601(50, 0, 106), /* quadrature */
339 MAKE_YUV_601(19, 19, 19), /* black */
340 MAKE_YUV_601(9, 9, 9), /* 3.5% */
341 MAKE_YUV_601(19, 19, 19), /* 7.5% */
342 MAKE_YUV_601(29, 29, 29), /* 11.5% */
343 MAKE_YUV_601(19, 19, 19), /* black */
345 unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
346 unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
347 unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
348 unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
356 for (y = 0; y < height * 6 / 9; ++y) {
357 for (x = 0; x < width; ++x)
358 y_mem[2 * x] = colors_top[x * 7 / width].y;
362 for (; y < height * 7 / 9; ++y) {
363 for (x = 0; x < width; ++x)
364 y_mem[2 * x] = colors_middle[x * 7 / width].y;
368 for (; y < height; ++y) {
369 for (x = 0; x < width * 5 / 7; ++x)
370 y_mem[2 * x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
371 for (; x < width * 6 / 7; ++x)
372 y_mem[2 * x] = colors_bottom[(x - width * 5 / 7) * 3
373 / (width / 7) + 4].y;
374 for (; x < width; ++x)
375 y_mem[2 * x] = colors_bottom[7].y;
380 for (y = 0; y < height * 6 / 9; ++y) {
381 for (x = 0; x < width; x += 2) {
382 c_mem[2 * x + u] = colors_top[x * 7 / width].u;
383 c_mem[2 * x + v] = colors_top[x * 7 / width].v;
388 for (; y < height * 7 / 9; ++y) {
389 for (x = 0; x < width; x += 2) {
390 c_mem[2 * x + u] = colors_middle[x * 7 / width].u;
391 c_mem[2 * x + v] = colors_middle[x * 7 / width].v;
396 for (; y < height; ++y) {
397 for (x = 0; x < width * 5 / 7; x += 2) {
398 c_mem[2 * x + u] = colors_bottom[x * 4 / (width * 5 / 7)].u;
399 c_mem[2 * x + v] = colors_bottom[x * 4 / (width * 5 / 7)].v;
401 for (; x < width * 6 / 7; x += 2) {
402 c_mem[2 * x + u] = colors_bottom[(x - width * 5 / 7) *
403 3 / (width / 7) + 4].u;
404 c_mem[2 * x + v] = colors_bottom[(x - width * 5 / 7) *
405 3 / (width / 7) + 4].v;
407 for (; x < width; x += 2) {
408 c_mem[2 * x + u] = colors_bottom[7].u;
409 c_mem[2 * x + v] = colors_bottom[7].v;
416 fill_smpte_rgb16(const struct rgb_info *rgb, unsigned char *mem,
417 unsigned int width, unsigned int height, unsigned int stride)
419 const uint16_t colors_top[] = {
420 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
421 MAKE_RGBA(rgb, 192, 192, 0, ALPHA_VALUE), /* yellow */
422 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
423 MAKE_RGBA(rgb, 0, 192, 0, ALPHA_VALUE), /* green */
424 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
425 MAKE_RGBA(rgb, 192, 0, 0, ALPHA_VALUE), /* red */
426 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
428 const uint16_t colors_middle[] = {
429 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
430 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
431 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
432 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
433 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
434 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
435 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
437 const uint16_t colors_bottom[] = {
438 MAKE_RGBA(rgb, 0, 33, 76, ALPHA_VALUE), /* in-phase */
439 MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE), /* super white */
440 MAKE_RGBA(rgb, 50, 0, 106, ALPHA_VALUE), /* quadrature */
441 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
442 MAKE_RGBA(rgb, 9, 9, 9, ALPHA_VALUE), /* 3.5% */
443 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* 7.5% */
444 MAKE_RGBA(rgb, 29, 29, 29, ALPHA_VALUE), /* 11.5% */
445 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
453 for (y = 0; y < height * 6 / 9; ++y) {
454 for (x = 0; x < width; ++x)
455 ((uint16_t *)mem)[x] = colors_top[x * 7 / width];
459 for (; y < height * 7 / 9; ++y) {
460 for (x = 0; x < width; ++x)
461 ((uint16_t *)mem)[x] = colors_middle[x * 7 / width];
465 for (; y < height; ++y) {
466 for (x = 0; x < width * 5 / 7; ++x)
467 ((uint16_t *)mem)[x] =
468 colors_bottom[x * 4 / (width * 5 / 7)];
469 for (; x < width * 6 / 7; ++x)
470 ((uint16_t *)mem)[x] =
471 colors_bottom[(x - width * 5 / 7) * 3
473 for (; x < width; ++x)
474 ((uint16_t *)mem)[x] = colors_bottom[7];
480 fill_smpte_rgb24(const struct rgb_info *rgb, void *mem,
481 unsigned int width, unsigned int height, unsigned int stride)
483 const struct color_rgb24 colors_top[] = {
484 MAKE_RGB24(rgb, 192, 192, 192), /* grey */
485 MAKE_RGB24(rgb, 192, 192, 0), /* yellow */
486 MAKE_RGB24(rgb, 0, 192, 192), /* cyan */
487 MAKE_RGB24(rgb, 0, 192, 0), /* green */
488 MAKE_RGB24(rgb, 192, 0, 192), /* magenta */
489 MAKE_RGB24(rgb, 192, 0, 0), /* red */
490 MAKE_RGB24(rgb, 0, 0, 192), /* blue */
492 const struct color_rgb24 colors_middle[] = {
493 MAKE_RGB24(rgb, 0, 0, 192), /* blue */
494 MAKE_RGB24(rgb, 19, 19, 19), /* black */
495 MAKE_RGB24(rgb, 192, 0, 192), /* magenta */
496 MAKE_RGB24(rgb, 19, 19, 19), /* black */
497 MAKE_RGB24(rgb, 0, 192, 192), /* cyan */
498 MAKE_RGB24(rgb, 19, 19, 19), /* black */
499 MAKE_RGB24(rgb, 192, 192, 192), /* grey */
501 const struct color_rgb24 colors_bottom[] = {
502 MAKE_RGB24(rgb, 0, 33, 76), /* in-phase */
503 MAKE_RGB24(rgb, 255, 255, 255), /* super white */
504 MAKE_RGB24(rgb, 50, 0, 106), /* quadrature */
505 MAKE_RGB24(rgb, 19, 19, 19), /* black */
506 MAKE_RGB24(rgb, 9, 9, 9), /* 3.5% */
507 MAKE_RGB24(rgb, 19, 19, 19), /* 7.5% */
508 MAKE_RGB24(rgb, 29, 29, 29), /* 11.5% */
509 MAKE_RGB24(rgb, 19, 19, 19), /* black */
517 for (y = 0; y < height * 6 / 9; ++y) {
518 for (x = 0; x < width; ++x)
519 ((struct color_rgb24 *)mem)[x] =
520 colors_top[x * 7 / width];
524 for (; y < height * 7 / 9; ++y) {
525 for (x = 0; x < width; ++x)
526 ((struct color_rgb24 *)mem)[x] =
527 colors_middle[x * 7 / width];
531 for (; y < height; ++y) {
532 for (x = 0; x < width * 5 / 7; ++x)
533 ((struct color_rgb24 *)mem)[x] =
534 colors_bottom[x * 4 / (width * 5 / 7)];
535 for (; x < width * 6 / 7; ++x)
536 ((struct color_rgb24 *)mem)[x] =
537 colors_bottom[(x - width * 5 / 7) * 3
539 for (; x < width; ++x)
540 ((struct color_rgb24 *)mem)[x] = colors_bottom[7];
546 fill_smpte_rgb32(const struct rgb_info *rgb, unsigned char *mem,
547 unsigned int width, unsigned int height, unsigned int stride)
549 const uint32_t colors_top[] = {
550 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
551 MAKE_RGBA(rgb, 192, 192, 0, ALPHA_VALUE), /* yellow */
552 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
553 MAKE_RGBA(rgb, 0, 192, 0, ALPHA_VALUE), /* green */
554 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
555 MAKE_RGBA(rgb, 192, 0, 0, ALPHA_VALUE), /* red */
556 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
558 const uint32_t colors_middle[] = {
559 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
560 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
561 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
562 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
563 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
564 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
565 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
567 const uint32_t colors_bottom[] = {
568 MAKE_RGBA(rgb, 0, 33, 76, ALPHA_VALUE), /* in-phase */
569 MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE), /* super white */
570 MAKE_RGBA(rgb, 50, 0, 106, ALPHA_VALUE), /* quadrature */
571 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
572 MAKE_RGBA(rgb, 9, 9, 9, ALPHA_VALUE), /* 3.5% */
573 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* 7.5% */
574 MAKE_RGBA(rgb, 29, 29, 29, ALPHA_VALUE), /* 11.5% */
575 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
583 for (y = 0; y < height * 6 / 9; ++y) {
584 for (x = 0; x < width; ++x)
585 ((uint32_t *)mem)[x] = colors_top[x * 7 / width];
589 for (; y < height * 7 / 9; ++y) {
590 for (x = 0; x < width; ++x)
591 ((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
595 for (; y < height; ++y) {
596 for (x = 0; x < width * 5 / 7; ++x)
597 ((uint32_t *)mem)[x] =
598 colors_bottom[x * 4 / (width * 5 / 7)];
599 for (; x < width * 6 / 7; ++x)
600 ((uint32_t *)mem)[x] =
601 colors_bottom[(x - width * 5 / 7) * 3
603 for (; x < width; ++x)
604 ((uint32_t *)mem)[x] = (rand_r(&rand_seed) % 2) ? MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE) : MAKE_RGBA(rgb, 0, 0, 0, ALPHA_VALUE);
610 fill_smpte_rgb32_dont_care_alpha(const struct rgb_info *rgb, unsigned char *mem,
611 unsigned int width, unsigned int height, unsigned int stride)
613 const uint32_t colors_top[] = {
614 MAKE_RGBX(rgb, 192, 192, 192), /* grey */
615 MAKE_RGBX(rgb, 192, 192, 0), /* yellow */
616 MAKE_RGBX(rgb, 0, 192, 192), /* cyan */
617 MAKE_RGBX(rgb, 0, 192, 0), /* green */
618 MAKE_RGBX(rgb, 192, 0, 192), /* magenta */
619 MAKE_RGBX(rgb, 192, 0, 0), /* red */
620 MAKE_RGBX(rgb, 0, 0, 192), /* blue */
622 const uint32_t colors_middle[] = {
623 MAKE_RGBX(rgb, 0, 0, 192), /* blue */
624 MAKE_RGBX(rgb, 19, 19, 19), /* black */
625 MAKE_RGBX(rgb, 192, 0, 192), /* magenta */
626 MAKE_RGBX(rgb, 19, 19, 19), /* black */
627 MAKE_RGBX(rgb, 0, 192, 192), /* cyan */
628 MAKE_RGBX(rgb, 19, 19, 19), /* black */
629 MAKE_RGBX(rgb, 192, 192, 192), /* grey */
631 const uint32_t colors_bottom[] = {
632 MAKE_RGBX(rgb, 0, 33, 76), /* in-phase */
633 MAKE_RGBX(rgb, 255, 255, 255), /* super white */
634 MAKE_RGBX(rgb, 50, 0, 106), /* quadrature */
635 MAKE_RGBX(rgb, 19, 19, 19), /* black */
636 MAKE_RGBX(rgb, 9, 9, 9), /* 3.5% */
637 MAKE_RGBX(rgb, 19, 19, 19), /* 7.5% */
638 MAKE_RGBX(rgb, 29, 29, 29), /* 11.5% */
639 MAKE_RGBX(rgb, 19, 19, 19), /* black */
647 for (y = 0; y < height * 6 / 9; ++y) {
648 for (x = 0; x < width; ++x)
649 ((uint32_t *)mem)[x] = colors_top[x * 7 / width];
653 for (; y < height * 7 / 9; ++y) {
654 for (x = 0; x < width; ++x)
655 ((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
659 for (; y < height; ++y) {
660 for (x = 0; x < width * 5 / 7; ++x)
661 ((uint32_t *)mem)[x] =
662 colors_bottom[x * 4 / (width * 5 / 7)];
663 for (; x < width * 6 / 7; ++x)
664 ((uint32_t *)mem)[x] =
665 colors_bottom[(x - width * 5 / 7) * 3
667 for (; x < width; ++x)
668 ((uint32_t *)mem)[x] = (rand_r(&rand_seed) % 2) ? MAKE_RGBX(rgb, 255, 255, 255) : MAKE_RGBX(rgb, 0, 0, 0);
674 fill_smpte(const struct format_info *info, void *planes[3], unsigned int width,
675 unsigned int height, unsigned int stride)
677 unsigned char *u, *v;
679 switch (info->format) {
680 case TBM_FORMAT_UYVY:
681 case TBM_FORMAT_VYUY:
682 case TBM_FORMAT_YUYV:
683 case TBM_FORMAT_YVYU:
684 return fill_smpte_yuv_packed(&info->yuv, planes[0], width,
687 case TBM_FORMAT_NV12:
688 case TBM_FORMAT_NV21:
689 case TBM_FORMAT_NV16:
690 case TBM_FORMAT_NV61:
691 u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
692 v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
693 return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v,
694 width, height, stride);
696 case TBM_FORMAT_YUV420:
697 return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1],
698 planes[2], width, height, stride);
700 case TBM_FORMAT_YVU420:
701 return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2],
702 planes[1], width, height, stride);
704 case TBM_FORMAT_ARGB4444:
705 case TBM_FORMAT_XRGB4444:
706 case TBM_FORMAT_ABGR4444:
707 case TBM_FORMAT_XBGR4444:
708 case TBM_FORMAT_RGBA4444:
709 case TBM_FORMAT_RGBX4444:
710 case TBM_FORMAT_BGRA4444:
711 case TBM_FORMAT_BGRX4444:
712 case TBM_FORMAT_RGB565:
713 case TBM_FORMAT_BGR565:
714 case TBM_FORMAT_ARGB1555:
715 case TBM_FORMAT_XRGB1555:
716 case TBM_FORMAT_ABGR1555:
717 case TBM_FORMAT_XBGR1555:
718 case TBM_FORMAT_RGBA5551:
719 case TBM_FORMAT_RGBX5551:
720 case TBM_FORMAT_BGRA5551:
721 case TBM_FORMAT_BGRX5551:
722 return fill_smpte_rgb16(&info->rgb, planes[0],
723 width, height, stride);
725 case TBM_FORMAT_BGR888:
726 case TBM_FORMAT_RGB888:
727 return fill_smpte_rgb24(&info->rgb, planes[0],
728 width, height, stride);
729 case TBM_FORMAT_ARGB8888:
730 case TBM_FORMAT_ABGR8888:
731 case TBM_FORMAT_XBGR8888:
732 case TBM_FORMAT_RGBA8888:
733 case TBM_FORMAT_RGBX8888:
734 case TBM_FORMAT_BGRA8888:
735 case TBM_FORMAT_BGRX8888:
736 case TBM_FORMAT_ARGB2101010:
737 case TBM_FORMAT_XRGB2101010:
738 case TBM_FORMAT_ABGR2101010:
739 case TBM_FORMAT_XBGR2101010:
740 case TBM_FORMAT_RGBA1010102:
741 case TBM_FORMAT_RGBX1010102:
742 case TBM_FORMAT_BGRA1010102:
743 case TBM_FORMAT_BGRX1010102:
744 return fill_smpte_rgb32(&info->rgb, planes[0],
745 width, height, stride);
746 case TBM_FORMAT_XRGB8888:
747 return fill_smpte_rgb32_dont_care_alpha(&info->rgb, planes[0],
748 width, height, stride);
753 fill_tiles_yuv_planar(const struct format_info *info,
754 unsigned char *y_mem, unsigned char *u_mem,
755 unsigned char *v_mem, unsigned int width,
756 unsigned int height, unsigned int stride)
758 const struct yuv_info *yuv = &info->yuv;
759 unsigned int cs = yuv->chroma_stride;
760 unsigned int xsub = yuv->xsub;
761 unsigned int ysub = yuv->ysub;
765 for (y = 0; y < height; ++y) {
766 for (x = 0; x < width; ++x) {
767 div_t d = div(x + y, width);
768 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
769 + 0x000a1120 * (d.rem >> 6);
770 struct color_yuv color =
771 MAKE_YUV_601((rgb32 >> 16) & 0xff,
772 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
775 u_mem[x / xsub * cs] = color.u;
776 v_mem[x / xsub * cs] = color.v;
780 if ((y + 1) % ysub == 0) {
781 u_mem += stride * cs / xsub;
782 v_mem += stride * cs / xsub;
788 fill_tiles_yuv_packed(const struct format_info *info, unsigned char *mem,
789 unsigned int width, unsigned int height,
792 const struct yuv_info *yuv = &info->yuv;
793 unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
794 unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
795 unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
796 unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
800 for (y = 0; y < height; ++y) {
801 for (x = 0; x < width; x += 2) {
802 div_t d = div(x + y, width);
803 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
804 + 0x000a1120 * (d.rem >> 6);
805 struct color_yuv color =
806 MAKE_YUV_601((rgb32 >> 16) & 0xff,
807 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
809 y_mem[2 * x] = color.y;
810 c_mem[2 * x + u] = color.u;
811 y_mem[2 * x + 2] = color.y;
812 c_mem[2 * x + v] = color.v;
821 fill_tiles_rgb16(const struct format_info *info, unsigned char *mem,
822 unsigned int width, unsigned int height, unsigned int stride)
824 const struct rgb_info *rgb = &info->rgb;
827 for (y = 0; y < height; ++y) {
828 for (x = 0; x < width; ++x) {
829 div_t d = div(x + y, width);
830 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
831 + 0x000a1120 * (d.rem >> 6);
833 MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
834 (rgb32 >> 8) & 0xff, rgb32 & 0xff,
837 ((uint16_t *)mem)[x] = color;
844 fill_tiles_rgb24(const struct format_info *info, unsigned char *mem,
845 unsigned int width, unsigned int height, unsigned int stride)
847 const struct rgb_info *rgb = &info->rgb;
850 for (y = 0; y < height; ++y) {
851 for (x = 0; x < width; ++x) {
852 div_t d = div(x + y, width);
853 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
854 + 0x000a1120 * (d.rem >> 6);
855 struct color_rgb24 color =
856 MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff,
857 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
859 ((struct color_rgb24 *)mem)[x] = color;
866 fill_tiles_rgb32(const struct format_info *info, unsigned char *mem,
867 unsigned int width, unsigned int height, unsigned int stride)
869 const struct rgb_info *rgb = &info->rgb;
872 for (y = 0; y < height; ++y) {
873 for (x = 0; x < width; ++x) {
874 div_t d = div(x + y, width);
875 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
876 + 0x000a1120 * (d.rem >> 6);
878 MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
879 (rgb32 >> 8) & 0xff, rgb32 & 0xff,
882 ((uint32_t *)mem)[x] = color;
889 fill_tiles(const struct format_info *info, void *planes[3], unsigned int width,
890 unsigned int height, unsigned int stride)
892 unsigned char *u, *v;
894 switch (info->format) {
895 case TBM_FORMAT_UYVY:
896 case TBM_FORMAT_VYUY:
897 case TBM_FORMAT_YUYV:
898 case TBM_FORMAT_YVYU:
899 return fill_tiles_yuv_packed(info, planes[0],
900 width, height, stride);
902 case TBM_FORMAT_NV12:
903 case TBM_FORMAT_NV21:
904 case TBM_FORMAT_NV16:
905 case TBM_FORMAT_NV61:
906 u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
907 v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
908 return fill_tiles_yuv_planar(info, planes[0], u, v,
909 width, height, stride);
911 case TBM_FORMAT_YUV420:
912 return fill_tiles_yuv_planar(info, planes[0], planes[1],
913 planes[2], width, height, stride);
915 case TBM_FORMAT_YVU420:
916 return fill_tiles_yuv_planar(info, planes[0], planes[2],
917 planes[1], width, height, stride);
919 case TBM_FORMAT_ARGB4444:
920 case TBM_FORMAT_XRGB4444:
921 case TBM_FORMAT_ABGR4444:
922 case TBM_FORMAT_XBGR4444:
923 case TBM_FORMAT_RGBA4444:
924 case TBM_FORMAT_RGBX4444:
925 case TBM_FORMAT_BGRA4444:
926 case TBM_FORMAT_BGRX4444:
927 case TBM_FORMAT_RGB565:
928 case TBM_FORMAT_BGR565:
929 case TBM_FORMAT_ARGB1555:
930 case TBM_FORMAT_XRGB1555:
931 case TBM_FORMAT_ABGR1555:
932 case TBM_FORMAT_XBGR1555:
933 case TBM_FORMAT_RGBA5551:
934 case TBM_FORMAT_RGBX5551:
935 case TBM_FORMAT_BGRA5551:
936 case TBM_FORMAT_BGRX5551:
937 return fill_tiles_rgb16(info, planes[0],
938 width, height, stride);
940 case TBM_FORMAT_BGR888:
941 case TBM_FORMAT_RGB888:
942 return fill_tiles_rgb24(info, planes[0],
943 width, height, stride);
944 case TBM_FORMAT_ARGB8888:
945 case TBM_FORMAT_XRGB8888:
946 case TBM_FORMAT_ABGR8888:
947 case TBM_FORMAT_XBGR8888:
948 case TBM_FORMAT_RGBA8888:
949 case TBM_FORMAT_RGBX8888:
950 case TBM_FORMAT_BGRA8888:
951 case TBM_FORMAT_BGRX8888:
952 case TBM_FORMAT_ARGB2101010:
953 case TBM_FORMAT_XRGB2101010:
954 case TBM_FORMAT_ABGR2101010:
955 case TBM_FORMAT_XBGR2101010:
956 case TBM_FORMAT_RGBA1010102:
957 case TBM_FORMAT_RGBX1010102:
958 case TBM_FORMAT_BGRA1010102:
959 case TBM_FORMAT_BGRX1010102:
960 return fill_tiles_rgb32(info, planes[0],
961 width, height, stride);
966 fill_plain(const struct format_info *info, void *planes[3], unsigned int width,
967 unsigned int height, unsigned int stride)
969 memset(planes[0], 0x77, stride * height);
973 * fill_pattern - Fill a buffer with a test pattern
974 * @format: Pixel format
975 * @pattern: Test pattern
976 * @buffer: Buffer memory
977 * @width: Width in pixels
978 * @height: Height in pixels
979 * @stride: Line stride (pitch) in bytes
981 * Fill the buffer with the test pattern specified by the pattern parameter.
982 * Supported formats vary depending on the selected pattern.
985 fill_pattern(unsigned int format, enum fill_pattern pattern, void *planes[3],
986 unsigned int width, unsigned int height, unsigned int stride)
988 const struct format_info *info = NULL;
991 for (i = 0; i < ARRAY_SIZE(format_info); ++i) {
992 if (format_info[i].format == format) {
993 info = &format_info[i];
1003 return fill_tiles(info, planes, width, height, stride);
1006 return fill_smpte(info, planes, width, height, stride);
1009 return fill_plain(info, planes, width, height, stride);
1012 printf("Error: unsupported test pattern %u.\n", pattern);
1018 tdm_test_buffer_fill(tbm_surface_h buffer, int pattern)
1020 tbm_surface_info_s info;
1025 rand_seed = time(NULL);
1027 ret = tbm_surface_map(buffer, TBM_OPTION_WRITE, &info);
1030 plane[0] = info.planes[0].ptr;
1031 plane[1] = info.planes[1].ptr;
1032 plane[2] = info.planes[2].ptr;
1033 fill_pattern(info.format, pattern, plane, info.width, info.height, info.planes[0].stride);
1034 tbm_surface_unmap(buffer);