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>
41 #include "tdm_macro.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, 0) },
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_RGB24(rgb, r, g, b) \
190 { .value = MAKE_RGBA(rgb, r, g, b, 0) }
193 fill_smpte_yuv_planar(const struct yuv_info *yuv,
194 unsigned char *y_mem, unsigned char *u_mem,
195 unsigned char *v_mem, unsigned int width,
196 unsigned int height, unsigned int stride)
198 const struct color_yuv colors_top[] = {
199 MAKE_YUV_601(191, 192, 192), /* grey */
200 MAKE_YUV_601(192, 192, 0), /* yellow */
201 MAKE_YUV_601(0, 192, 192), /* cyan */
202 MAKE_YUV_601(0, 192, 0), /* green */
203 MAKE_YUV_601(192, 0, 192), /* magenta */
204 MAKE_YUV_601(192, 0, 0), /* red */
205 MAKE_YUV_601(0, 0, 192), /* blue */
207 const struct color_yuv colors_middle[] = {
208 MAKE_YUV_601(0, 0, 192), /* blue */
209 MAKE_YUV_601(19, 19, 19), /* black */
210 MAKE_YUV_601(192, 0, 192), /* magenta */
211 MAKE_YUV_601(19, 19, 19), /* black */
212 MAKE_YUV_601(0, 192, 192), /* cyan */
213 MAKE_YUV_601(19, 19, 19), /* black */
214 MAKE_YUV_601(192, 192, 192), /* grey */
216 const struct color_yuv colors_bottom[] = {
217 MAKE_YUV_601(0, 33, 76), /* in-phase */
218 MAKE_YUV_601(255, 255, 255), /* super white */
219 MAKE_YUV_601(50, 0, 106), /* quadrature */
220 MAKE_YUV_601(19, 19, 19), /* black */
221 MAKE_YUV_601(9, 9, 9), /* 3.5% */
222 MAKE_YUV_601(19, 19, 19), /* 7.5% */
223 MAKE_YUV_601(29, 29, 29), /* 11.5% */
224 MAKE_YUV_601(19, 19, 19), /* black */
226 unsigned int cs = yuv->chroma_stride;
227 unsigned int xsub = yuv->xsub;
228 unsigned int ysub = yuv->ysub;
233 for (y = 0; y < height * 6 / 9; ++y) {
234 for (x = 0; x < width; ++x)
235 y_mem[x] = colors_top[x * 7 / width].y;
239 for (; y < height * 7 / 9; ++y) {
240 for (x = 0; x < width; ++x)
241 y_mem[x] = colors_middle[x * 7 / width].y;
245 for (; y < height; ++y) {
246 for (x = 0; x < width * 5 / 7; ++x)
247 y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
248 for (; x < width * 6 / 7; ++x)
249 y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3
250 / (width / 7) + 4].y;
251 for (; x < width; ++x)
252 y_mem[x] = colors_bottom[7].y;
257 for (y = 0; y < height / ysub * 6 / 9; ++y) {
258 for (x = 0; x < width; x += xsub) {
259 u_mem[x * cs / xsub] = colors_top[x * 7 / width].u;
260 v_mem[x * cs / xsub] = colors_top[x * 7 / width].v;
262 u_mem += stride * cs / xsub;
263 v_mem += stride * cs / xsub;
266 for (; y < height / ysub * 7 / 9; ++y) {
267 for (x = 0; x < width; x += xsub) {
268 u_mem[x * cs / xsub] = colors_middle[x * 7 / width].u;
269 v_mem[x * cs / xsub] = colors_middle[x * 7 / width].v;
271 u_mem += stride * cs / xsub;
272 v_mem += stride * cs / xsub;
275 for (; y < height / ysub; ++y) {
276 for (x = 0; x < width * 5 / 7; x += xsub) {
277 u_mem[x * cs / xsub] =
278 colors_bottom[x * 4 / (width * 5 / 7)].u;
279 v_mem[x * cs / xsub] =
280 colors_bottom[x * 4 / (width * 5 / 7)].v;
282 for (; x < width * 6 / 7; x += xsub) {
283 u_mem[x * cs / xsub] = colors_bottom[(x - width * 5 / 7) *
284 3 / (width / 7) + 4].u;
285 v_mem[x * cs / xsub] = colors_bottom[(x - width * 5 / 7) *
286 3 / (width / 7) + 4].v;
288 for (; x < width; x += xsub) {
289 u_mem[x * cs / xsub] = colors_bottom[7].u;
290 v_mem[x * cs / xsub] = colors_bottom[7].v;
292 u_mem += stride * cs / xsub;
293 v_mem += stride * cs / xsub;
298 fill_smpte_yuv_packed(const struct yuv_info *yuv, unsigned char *mem,
299 unsigned int width, unsigned int height,
302 const struct color_yuv colors_top[] = {
303 MAKE_YUV_601(191, 192, 192), /* grey */
304 MAKE_YUV_601(192, 192, 0), /* yellow */
305 MAKE_YUV_601(0, 192, 192), /* cyan */
306 MAKE_YUV_601(0, 192, 0), /* green */
307 MAKE_YUV_601(192, 0, 192), /* magenta */
308 MAKE_YUV_601(192, 0, 0), /* red */
309 MAKE_YUV_601(0, 0, 192), /* blue */
311 const struct color_yuv colors_middle[] = {
312 MAKE_YUV_601(0, 0, 192), /* blue */
313 MAKE_YUV_601(19, 19, 19), /* black */
314 MAKE_YUV_601(192, 0, 192), /* magenta */
315 MAKE_YUV_601(19, 19, 19), /* black */
316 MAKE_YUV_601(0, 192, 192), /* cyan */
317 MAKE_YUV_601(19, 19, 19), /* black */
318 MAKE_YUV_601(192, 192, 192), /* grey */
320 const struct color_yuv colors_bottom[] = {
321 MAKE_YUV_601(0, 33, 76), /* in-phase */
322 MAKE_YUV_601(255, 255, 255), /* super white */
323 MAKE_YUV_601(50, 0, 106), /* quadrature */
324 MAKE_YUV_601(19, 19, 19), /* black */
325 MAKE_YUV_601(9, 9, 9), /* 3.5% */
326 MAKE_YUV_601(19, 19, 19), /* 7.5% */
327 MAKE_YUV_601(29, 29, 29), /* 11.5% */
328 MAKE_YUV_601(19, 19, 19), /* black */
330 unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
331 unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
332 unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
333 unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
341 for (y = 0; y < height * 6 / 9; ++y) {
342 for (x = 0; x < width; ++x)
343 y_mem[2 * x] = colors_top[x * 7 / width].y;
347 for (; y < height * 7 / 9; ++y) {
348 for (x = 0; x < width; ++x)
349 y_mem[2 * x] = colors_middle[x * 7 / width].y;
353 for (; y < height; ++y) {
354 for (x = 0; x < width * 5 / 7; ++x)
355 y_mem[2 * x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
356 for (; x < width * 6 / 7; ++x)
357 y_mem[2 * x] = colors_bottom[(x - width * 5 / 7) * 3
358 / (width / 7) + 4].y;
359 for (; x < width; ++x)
360 y_mem[2 * x] = colors_bottom[7].y;
365 for (y = 0; y < height * 6 / 9; ++y) {
366 for (x = 0; x < width; x += 2) {
367 c_mem[2 * x + u] = colors_top[x * 7 / width].u;
368 c_mem[2 * x + v] = colors_top[x * 7 / width].v;
373 for (; y < height * 7 / 9; ++y) {
374 for (x = 0; x < width; x += 2) {
375 c_mem[2 * x + u] = colors_middle[x * 7 / width].u;
376 c_mem[2 * x + v] = colors_middle[x * 7 / width].v;
381 for (; y < height; ++y) {
382 for (x = 0; x < width * 5 / 7; x += 2) {
383 c_mem[2 * x + u] = colors_bottom[x * 4 / (width * 5 / 7)].u;
384 c_mem[2 * x + v] = colors_bottom[x * 4 / (width * 5 / 7)].v;
386 for (; x < width * 6 / 7; x += 2) {
387 c_mem[2 * x + u] = colors_bottom[(x - width * 5 / 7) *
388 3 / (width / 7) + 4].u;
389 c_mem[2 * x + v] = colors_bottom[(x - width * 5 / 7) *
390 3 / (width / 7) + 4].v;
392 for (; x < width; x += 2) {
393 c_mem[2 * x + u] = colors_bottom[7].u;
394 c_mem[2 * x + v] = colors_bottom[7].v;
401 fill_smpte_rgb16(const struct rgb_info *rgb, unsigned char *mem,
402 unsigned int width, unsigned int height, unsigned int stride)
404 const uint16_t colors_top[] = {
405 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
406 MAKE_RGBA(rgb, 192, 192, 0, ALPHA_VALUE), /* yellow */
407 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
408 MAKE_RGBA(rgb, 0, 192, 0, ALPHA_VALUE), /* green */
409 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
410 MAKE_RGBA(rgb, 192, 0, 0, ALPHA_VALUE), /* red */
411 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
413 const uint16_t colors_middle[] = {
414 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
415 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
416 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
417 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
418 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
419 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
420 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
422 const uint16_t colors_bottom[] = {
423 MAKE_RGBA(rgb, 0, 33, 76, ALPHA_VALUE), /* in-phase */
424 MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE), /* super white */
425 MAKE_RGBA(rgb, 50, 0, 106, ALPHA_VALUE), /* quadrature */
426 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
427 MAKE_RGBA(rgb, 9, 9, 9, ALPHA_VALUE), /* 3.5% */
428 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* 7.5% */
429 MAKE_RGBA(rgb, 29, 29, 29, ALPHA_VALUE), /* 11.5% */
430 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
438 for (y = 0; y < height * 6 / 9; ++y) {
439 for (x = 0; x < width; ++x)
440 ((uint16_t *)mem)[x] = colors_top[x * 7 / width];
444 for (; y < height * 7 / 9; ++y) {
445 for (x = 0; x < width; ++x)
446 ((uint16_t *)mem)[x] = colors_middle[x * 7 / width];
450 for (; y < height; ++y) {
451 for (x = 0; x < width * 5 / 7; ++x)
452 ((uint16_t *)mem)[x] =
453 colors_bottom[x * 4 / (width * 5 / 7)];
454 for (; x < width * 6 / 7; ++x)
455 ((uint16_t *)mem)[x] =
456 colors_bottom[(x - width * 5 / 7) * 3
458 for (; x < width; ++x)
459 ((uint16_t *)mem)[x] = colors_bottom[7];
465 fill_smpte_rgb24(const struct rgb_info *rgb, void *mem,
466 unsigned int width, unsigned int height, unsigned int stride)
468 const struct color_rgb24 colors_top[] = {
469 MAKE_RGB24(rgb, 192, 192, 192), /* grey */
470 MAKE_RGB24(rgb, 192, 192, 0), /* yellow */
471 MAKE_RGB24(rgb, 0, 192, 192), /* cyan */
472 MAKE_RGB24(rgb, 0, 192, 0), /* green */
473 MAKE_RGB24(rgb, 192, 0, 192), /* magenta */
474 MAKE_RGB24(rgb, 192, 0, 0), /* red */
475 MAKE_RGB24(rgb, 0, 0, 192), /* blue */
477 const struct color_rgb24 colors_middle[] = {
478 MAKE_RGB24(rgb, 0, 0, 192), /* blue */
479 MAKE_RGB24(rgb, 19, 19, 19), /* black */
480 MAKE_RGB24(rgb, 192, 0, 192), /* magenta */
481 MAKE_RGB24(rgb, 19, 19, 19), /* black */
482 MAKE_RGB24(rgb, 0, 192, 192), /* cyan */
483 MAKE_RGB24(rgb, 19, 19, 19), /* black */
484 MAKE_RGB24(rgb, 192, 192, 192), /* grey */
486 const struct color_rgb24 colors_bottom[] = {
487 MAKE_RGB24(rgb, 0, 33, 76), /* in-phase */
488 MAKE_RGB24(rgb, 255, 255, 255), /* super white */
489 MAKE_RGB24(rgb, 50, 0, 106), /* quadrature */
490 MAKE_RGB24(rgb, 19, 19, 19), /* black */
491 MAKE_RGB24(rgb, 9, 9, 9), /* 3.5% */
492 MAKE_RGB24(rgb, 19, 19, 19), /* 7.5% */
493 MAKE_RGB24(rgb, 29, 29, 29), /* 11.5% */
494 MAKE_RGB24(rgb, 19, 19, 19), /* black */
502 for (y = 0; y < height * 6 / 9; ++y) {
503 for (x = 0; x < width; ++x)
504 ((struct color_rgb24 *)mem)[x] =
505 colors_top[x * 7 / width];
509 for (; y < height * 7 / 9; ++y) {
510 for (x = 0; x < width; ++x)
511 ((struct color_rgb24 *)mem)[x] =
512 colors_middle[x * 7 / width];
516 for (; y < height; ++y) {
517 for (x = 0; x < width * 5 / 7; ++x)
518 ((struct color_rgb24 *)mem)[x] =
519 colors_bottom[x * 4 / (width * 5 / 7)];
520 for (; x < width * 6 / 7; ++x)
521 ((struct color_rgb24 *)mem)[x] =
522 colors_bottom[(x - width * 5 / 7) * 3
524 for (; x < width; ++x)
525 ((struct color_rgb24 *)mem)[x] = colors_bottom[7];
531 fill_smpte_rgb32(const struct rgb_info *rgb, unsigned char *mem,
532 unsigned int width, unsigned int height, unsigned int stride)
534 const uint32_t colors_top[] = {
535 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
536 MAKE_RGBA(rgb, 192, 192, 0, ALPHA_VALUE), /* yellow */
537 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
538 MAKE_RGBA(rgb, 0, 192, 0, ALPHA_VALUE), /* green */
539 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
540 MAKE_RGBA(rgb, 192, 0, 0, ALPHA_VALUE), /* red */
541 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
543 const uint32_t colors_middle[] = {
544 MAKE_RGBA(rgb, 0, 0, 192, ALPHA_VALUE), /* blue */
545 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
546 MAKE_RGBA(rgb, 192, 0, 192, ALPHA_VALUE), /* magenta */
547 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
548 MAKE_RGBA(rgb, 0, 192, 192, ALPHA_VALUE), /* cyan */
549 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
550 MAKE_RGBA(rgb, 192, 192, 192, ALPHA_VALUE), /* grey */
552 const uint32_t colors_bottom[] = {
553 MAKE_RGBA(rgb, 0, 33, 76, ALPHA_VALUE), /* in-phase */
554 MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE), /* super white */
555 MAKE_RGBA(rgb, 50, 0, 106, ALPHA_VALUE), /* quadrature */
556 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
557 MAKE_RGBA(rgb, 9, 9, 9, ALPHA_VALUE), /* 3.5% */
558 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* 7.5% */
559 MAKE_RGBA(rgb, 29, 29, 29, ALPHA_VALUE), /* 11.5% */
560 MAKE_RGBA(rgb, 19, 19, 19, ALPHA_VALUE), /* black */
568 for (y = 0; y < height * 6 / 9; ++y) {
569 for (x = 0; x < width; ++x)
570 ((uint32_t *)mem)[x] = colors_top[x * 7 / width];
574 for (; y < height * 7 / 9; ++y) {
575 for (x = 0; x < width; ++x)
576 ((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
580 for (; y < height; ++y) {
581 for (x = 0; x < width * 5 / 7; ++x)
582 ((uint32_t *)mem)[x] =
583 colors_bottom[x * 4 / (width * 5 / 7)];
584 for (; x < width * 6 / 7; ++x)
585 ((uint32_t *)mem)[x] =
586 colors_bottom[(x - width * 5 / 7) * 3
588 for (; x < width; ++x)
589 ((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);
595 fill_smpte(const struct format_info *info, void *planes[3], unsigned int width,
596 unsigned int height, unsigned int stride)
598 unsigned char *u, *v;
600 switch (info->format) {
601 case TBM_FORMAT_UYVY:
602 case TBM_FORMAT_VYUY:
603 case TBM_FORMAT_YUYV:
604 case TBM_FORMAT_YVYU:
605 return fill_smpte_yuv_packed(&info->yuv, planes[0], width,
608 case TBM_FORMAT_NV12:
609 case TBM_FORMAT_NV21:
610 case TBM_FORMAT_NV16:
611 case TBM_FORMAT_NV61:
612 u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
613 v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
614 return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v,
615 width, height, stride);
617 case TBM_FORMAT_YUV420:
618 return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1],
619 planes[2], width, height, stride);
621 case TBM_FORMAT_YVU420:
622 return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2],
623 planes[1], width, height, stride);
625 case TBM_FORMAT_ARGB4444:
626 case TBM_FORMAT_XRGB4444:
627 case TBM_FORMAT_ABGR4444:
628 case TBM_FORMAT_XBGR4444:
629 case TBM_FORMAT_RGBA4444:
630 case TBM_FORMAT_RGBX4444:
631 case TBM_FORMAT_BGRA4444:
632 case TBM_FORMAT_BGRX4444:
633 case TBM_FORMAT_RGB565:
634 case TBM_FORMAT_BGR565:
635 case TBM_FORMAT_ARGB1555:
636 case TBM_FORMAT_XRGB1555:
637 case TBM_FORMAT_ABGR1555:
638 case TBM_FORMAT_XBGR1555:
639 case TBM_FORMAT_RGBA5551:
640 case TBM_FORMAT_RGBX5551:
641 case TBM_FORMAT_BGRA5551:
642 case TBM_FORMAT_BGRX5551:
643 return fill_smpte_rgb16(&info->rgb, planes[0],
644 width, height, stride);
646 case TBM_FORMAT_BGR888:
647 case TBM_FORMAT_RGB888:
648 return fill_smpte_rgb24(&info->rgb, planes[0],
649 width, height, stride);
650 case TBM_FORMAT_ARGB8888:
651 case TBM_FORMAT_XRGB8888:
652 case TBM_FORMAT_ABGR8888:
653 case TBM_FORMAT_XBGR8888:
654 case TBM_FORMAT_RGBA8888:
655 case TBM_FORMAT_RGBX8888:
656 case TBM_FORMAT_BGRA8888:
657 case TBM_FORMAT_BGRX8888:
658 case TBM_FORMAT_ARGB2101010:
659 case TBM_FORMAT_XRGB2101010:
660 case TBM_FORMAT_ABGR2101010:
661 case TBM_FORMAT_XBGR2101010:
662 case TBM_FORMAT_RGBA1010102:
663 case TBM_FORMAT_RGBX1010102:
664 case TBM_FORMAT_BGRA1010102:
665 case TBM_FORMAT_BGRX1010102:
666 return fill_smpte_rgb32(&info->rgb, planes[0],
667 width, height, stride);
672 fill_tiles_yuv_planar(const struct format_info *info,
673 unsigned char *y_mem, unsigned char *u_mem,
674 unsigned char *v_mem, unsigned int width,
675 unsigned int height, unsigned int stride)
677 const struct yuv_info *yuv = &info->yuv;
678 unsigned int cs = yuv->chroma_stride;
679 unsigned int xsub = yuv->xsub;
680 unsigned int ysub = yuv->ysub;
684 for (y = 0; y < height; ++y) {
685 for (x = 0; x < width; ++x) {
686 div_t d = div(x + y, width);
687 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
688 + 0x000a1120 * (d.rem >> 6);
689 struct color_yuv color =
690 MAKE_YUV_601((rgb32 >> 16) & 0xff,
691 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
694 u_mem[x / xsub * cs] = color.u;
695 v_mem[x / xsub * cs] = color.v;
699 if ((y + 1) % ysub == 0) {
700 u_mem += stride * cs / xsub;
701 v_mem += stride * cs / xsub;
707 fill_tiles_yuv_packed(const struct format_info *info, unsigned char *mem,
708 unsigned int width, unsigned int height,
711 const struct yuv_info *yuv = &info->yuv;
712 unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
713 unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
714 unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
715 unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
719 for (y = 0; y < height; ++y) {
720 for (x = 0; x < width; x += 2) {
721 div_t d = div(x + y, width);
722 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
723 + 0x000a1120 * (d.rem >> 6);
724 struct color_yuv color =
725 MAKE_YUV_601((rgb32 >> 16) & 0xff,
726 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
728 y_mem[2 * x] = color.y;
729 c_mem[2 * x + u] = color.u;
730 y_mem[2 * x + 2] = color.y;
731 c_mem[2 * x + v] = color.v;
740 fill_tiles_rgb16(const struct format_info *info, unsigned char *mem,
741 unsigned int width, unsigned int height, unsigned int stride)
743 const struct rgb_info *rgb = &info->rgb;
746 for (y = 0; y < height; ++y) {
747 for (x = 0; x < width; ++x) {
748 div_t d = div(x + y, width);
749 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
750 + 0x000a1120 * (d.rem >> 6);
752 MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
753 (rgb32 >> 8) & 0xff, rgb32 & 0xff,
756 ((uint16_t *)mem)[x] = color;
763 fill_tiles_rgb24(const struct format_info *info, unsigned char *mem,
764 unsigned int width, unsigned int height, unsigned int stride)
766 const struct rgb_info *rgb = &info->rgb;
769 for (y = 0; y < height; ++y) {
770 for (x = 0; x < width; ++x) {
771 div_t d = div(x + y, width);
772 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
773 + 0x000a1120 * (d.rem >> 6);
774 struct color_rgb24 color =
775 MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff,
776 (rgb32 >> 8) & 0xff, rgb32 & 0xff);
778 ((struct color_rgb24 *)mem)[x] = color;
785 fill_tiles_rgb32(const struct format_info *info, unsigned char *mem,
786 unsigned int width, unsigned int height, unsigned int stride)
788 const struct rgb_info *rgb = &info->rgb;
791 for (y = 0; y < height; ++y) {
792 for (x = 0; x < width; ++x) {
793 div_t d = div(x + y, width);
794 uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
795 + 0x000a1120 * (d.rem >> 6);
797 MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
798 (rgb32 >> 8) & 0xff, rgb32 & 0xff,
801 ((uint32_t *)mem)[x] = color;
808 fill_tiles(const struct format_info *info, void *planes[3], unsigned int width,
809 unsigned int height, unsigned int stride)
811 unsigned char *u, *v;
813 switch (info->format) {
814 case TBM_FORMAT_UYVY:
815 case TBM_FORMAT_VYUY:
816 case TBM_FORMAT_YUYV:
817 case TBM_FORMAT_YVYU:
818 return fill_tiles_yuv_packed(info, planes[0],
819 width, height, stride);
821 case TBM_FORMAT_NV12:
822 case TBM_FORMAT_NV21:
823 case TBM_FORMAT_NV16:
824 case TBM_FORMAT_NV61:
825 u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
826 v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
827 return fill_tiles_yuv_planar(info, planes[0], u, v,
828 width, height, stride);
830 case TBM_FORMAT_YUV420:
831 return fill_tiles_yuv_planar(info, planes[0], planes[1],
832 planes[2], width, height, stride);
834 case TBM_FORMAT_YVU420:
835 return fill_tiles_yuv_planar(info, planes[0], planes[2],
836 planes[1], width, height, stride);
838 case TBM_FORMAT_ARGB4444:
839 case TBM_FORMAT_XRGB4444:
840 case TBM_FORMAT_ABGR4444:
841 case TBM_FORMAT_XBGR4444:
842 case TBM_FORMAT_RGBA4444:
843 case TBM_FORMAT_RGBX4444:
844 case TBM_FORMAT_BGRA4444:
845 case TBM_FORMAT_BGRX4444:
846 case TBM_FORMAT_RGB565:
847 case TBM_FORMAT_BGR565:
848 case TBM_FORMAT_ARGB1555:
849 case TBM_FORMAT_XRGB1555:
850 case TBM_FORMAT_ABGR1555:
851 case TBM_FORMAT_XBGR1555:
852 case TBM_FORMAT_RGBA5551:
853 case TBM_FORMAT_RGBX5551:
854 case TBM_FORMAT_BGRA5551:
855 case TBM_FORMAT_BGRX5551:
856 return fill_tiles_rgb16(info, planes[0],
857 width, height, stride);
859 case TBM_FORMAT_BGR888:
860 case TBM_FORMAT_RGB888:
861 return fill_tiles_rgb24(info, planes[0],
862 width, height, stride);
863 case TBM_FORMAT_ARGB8888:
864 case TBM_FORMAT_XRGB8888:
865 case TBM_FORMAT_ABGR8888:
866 case TBM_FORMAT_XBGR8888:
867 case TBM_FORMAT_RGBA8888:
868 case TBM_FORMAT_RGBX8888:
869 case TBM_FORMAT_BGRA8888:
870 case TBM_FORMAT_BGRX8888:
871 case TBM_FORMAT_ARGB2101010:
872 case TBM_FORMAT_XRGB2101010:
873 case TBM_FORMAT_ABGR2101010:
874 case TBM_FORMAT_XBGR2101010:
875 case TBM_FORMAT_RGBA1010102:
876 case TBM_FORMAT_RGBX1010102:
877 case TBM_FORMAT_BGRA1010102:
878 case TBM_FORMAT_BGRX1010102:
879 return fill_tiles_rgb32(info, planes[0],
880 width, height, stride);
885 fill_plain(const struct format_info *info, void *planes[3], unsigned int width,
886 unsigned int height, unsigned int stride)
888 memset(planes[0], 0x77, stride * height);
892 * fill_pattern - Fill a buffer with a test pattern
893 * @format: Pixel format
894 * @pattern: Test pattern
895 * @buffer: Buffer memory
896 * @width: Width in pixels
897 * @height: Height in pixels
898 * @stride: Line stride (pitch) in bytes
900 * Fill the buffer with the test pattern specified by the pattern parameter.
901 * Supported formats vary depending on the selected pattern.
904 fill_pattern(unsigned int format, enum fill_pattern pattern, void *planes[3],
905 unsigned int width, unsigned int height, unsigned int stride)
907 const struct format_info *info = NULL;
910 for (i = 0; i < ARRAY_SIZE(format_info); ++i) {
911 if (format_info[i].format == format) {
912 info = &format_info[i];
922 return fill_tiles(info, planes, width, height, stride);
925 return fill_smpte(info, planes, width, height, stride);
928 return fill_plain(info, planes, width, height, stride);
931 printf("Error: unsupported test pattern %u.\n", pattern);
937 tdm_test_buffer_fill(tbm_surface_h buffer, int pattern)
939 tbm_surface_info_s info;
944 rand_seed = time(NULL);
946 ret = tbm_surface_map(buffer, TBM_OPTION_WRITE, &info);
947 TDM_EXIT_IF_FAIL(ret == 0);
949 plane[0] = info.planes[0].ptr;
950 plane[1] = info.planes[1].ptr;
951 plane[2] = info.planes[2].ptr;
952 fill_pattern(info.format, pattern, plane, info.width, info.height, info.planes[0].stride);
953 tbm_surface_unmap(buffer);