13f012e29Smrg/* 23f012e29Smrg * Copyright 2008 Tungsten Graphics 33f012e29Smrg * Jakob Bornecrantz <jakob@tungstengraphics.com> 43f012e29Smrg * Copyright 2008 Intel Corporation 53f012e29Smrg * Jesse Barnes <jesse.barnes@intel.com> 63f012e29Smrg * 73f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 83f012e29Smrg * copy of this software and associated documentation files (the "Software"), 93f012e29Smrg * to deal in the Software without restriction, including without limitation 103f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 113f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 123f012e29Smrg * Software is furnished to do so, subject to the following conditions: 133f012e29Smrg * 143f012e29Smrg * The above copyright notice and this permission notice shall be included in 153f012e29Smrg * all copies or substantial portions of the Software. 163f012e29Smrg * 173f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 183f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 193f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 203f012e29Smrg * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 213f012e29Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 223f012e29Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 233f012e29Smrg * IN THE SOFTWARE. 243f012e29Smrg */ 253f012e29Smrg 263f012e29Smrg#include <stdint.h> 273f012e29Smrg#include <stdlib.h> 283f012e29Smrg#include <string.h> 293f012e29Smrg 303f012e29Smrg#include <drm_fourcc.h> 313f012e29Smrg 323f012e29Smrg#include "common.h" 333f012e29Smrg#include "format.h" 343f012e29Smrg 353f012e29Smrg#define MAKE_RGB_INFO(rl, ro, gl, go, bl, bo, al, ao) \ 363f012e29Smrg .rgb = { { (rl), (ro) }, { (gl), (go) }, { (bl), (bo) }, { (al), (ao) } } 373f012e29Smrg 383f012e29Smrg#define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \ 393f012e29Smrg .yuv = { (order), (xsub), (ysub), (chroma_stride) } 403f012e29Smrg 413f012e29Smrgstatic const struct util_format_info format_info[] = { 425324fb0dSmrg /* Indexed */ 43bbff01ceSmrg { DRM_FORMAT_C1, "C1", .ncolors = 2 }, 44bbff01ceSmrg { DRM_FORMAT_C2, "C2", .ncolors = 4 }, 45bbff01ceSmrg { DRM_FORMAT_C4, "C4", .ncolors = 16 }, 46bbff01ceSmrg { DRM_FORMAT_C8, "C8", .ncolors = 256 }, 473f012e29Smrg /* YUV packed */ 483f012e29Smrg { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) }, 493f012e29Smrg { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) }, 503f012e29Smrg { DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) }, 513f012e29Smrg { DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) }, 523f012e29Smrg /* YUV semi-planar */ 533f012e29Smrg { DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) }, 543f012e29Smrg { DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) }, 553f012e29Smrg { DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) }, 563f012e29Smrg { DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) }, 57bbff01ceSmrg { DRM_FORMAT_NV24, "NV24", MAKE_YUV_INFO(YUV_YCbCr, 1, 1, 2) }, 58bbff01ceSmrg { DRM_FORMAT_NV42, "NV42", MAKE_YUV_INFO(YUV_YCrCb, 1, 1, 2) }, 59bbff01ceSmrg { DRM_FORMAT_NV15, "NV15", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) }, 60bbff01ceSmrg { DRM_FORMAT_NV20, "NV20", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) }, 61bbff01ceSmrg { DRM_FORMAT_NV30, "NV30", MAKE_YUV_INFO(YUV_YCbCr, 1, 1, 2) }, 623f012e29Smrg /* YUV planar */ 633f012e29Smrg { DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) }, 643f012e29Smrg { DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) }, 656acbc0e0Smrg { DRM_FORMAT_YUV422, "YU16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 1) }, 666acbc0e0Smrg { DRM_FORMAT_YVU422, "YV16", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 1) }, 676acbc0e0Smrg { DRM_FORMAT_YUV444, "YU24", MAKE_YUV_INFO(YUV_YCbCr, 1, 1, 1) }, 686acbc0e0Smrg { DRM_FORMAT_YVU444, "YV24", MAKE_YUV_INFO(YUV_YCrCb, 1, 1, 1) }, 693f012e29Smrg /* RGB16 */ 703f012e29Smrg { DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) }, 713f012e29Smrg { DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) }, 723f012e29Smrg { DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) }, 733f012e29Smrg { DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) }, 743f012e29Smrg { DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) }, 753f012e29Smrg { DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) }, 763f012e29Smrg { DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) }, 773f012e29Smrg { DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) }, 783f012e29Smrg { DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) }, 793f012e29Smrg { DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) }, 803f012e29Smrg { DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) }, 813f012e29Smrg { DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) }, 823f012e29Smrg { DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) }, 833f012e29Smrg { DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) }, 843f012e29Smrg { DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) }, 853f012e29Smrg { DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) }, 863f012e29Smrg { DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) }, 873f012e29Smrg { DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) }, 88bbff01ceSmrg /* Big-endian RGB16 */ 89bbff01ceSmrg { DRM_FORMAT_XRGB1555 | DRM_FORMAT_BIG_ENDIAN, "XR15_BE", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) }, 90bbff01ceSmrg { DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN, "RG16_BE", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) }, 913f012e29Smrg /* RGB24 */ 923f012e29Smrg { DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, 933f012e29Smrg { DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, 943f012e29Smrg /* RGB32 */ 953f012e29Smrg { DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) }, 963f012e29Smrg { DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, 973f012e29Smrg { DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) }, 983f012e29Smrg { DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, 993f012e29Smrg { DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) }, 1003f012e29Smrg { DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) }, 1013f012e29Smrg { DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) }, 1023f012e29Smrg { DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) }, 1033f012e29Smrg { DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) }, 1043f012e29Smrg { DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) }, 1053f012e29Smrg { DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) }, 1063f012e29Smrg { DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) }, 1073f012e29Smrg { DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) }, 1083f012e29Smrg { DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) }, 1093f012e29Smrg { DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) }, 1103f012e29Smrg { DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) }, 1115324fb0dSmrg { DRM_FORMAT_XRGB16161616F, "XR4H", MAKE_RGB_INFO(16, 32, 16, 16, 16, 0, 0, 0) }, 1125324fb0dSmrg { DRM_FORMAT_XBGR16161616F, "XB4H", MAKE_RGB_INFO(16, 0, 16, 16, 16, 32, 0, 0) }, 1135324fb0dSmrg { DRM_FORMAT_ARGB16161616F, "AR4H", MAKE_RGB_INFO(16, 32, 16, 16, 16, 0, 16, 48) }, 1145324fb0dSmrg { DRM_FORMAT_ABGR16161616F, "AB4H", MAKE_RGB_INFO(16, 0, 16, 16, 16, 32, 16, 48) }, 1155324fb0dSmrg 1163f012e29Smrg}; 1173f012e29Smrg 1183f012e29Smrguint32_t util_format_fourcc(const char *name) 1193f012e29Smrg{ 1203f012e29Smrg unsigned int i; 1213f012e29Smrg 1223f012e29Smrg for (i = 0; i < ARRAY_SIZE(format_info); i++) 1233f012e29Smrg if (!strcmp(format_info[i].name, name)) 1243f012e29Smrg return format_info[i].format; 1253f012e29Smrg 1263f012e29Smrg return 0; 1273f012e29Smrg} 1283f012e29Smrg 1293f012e29Smrgconst struct util_format_info *util_format_info_find(uint32_t format) 1303f012e29Smrg{ 1313f012e29Smrg unsigned int i; 1323f012e29Smrg 1333f012e29Smrg for (i = 0; i < ARRAY_SIZE(format_info); i++) 1343f012e29Smrg if (format_info[i].format == format) 1353f012e29Smrg return &format_info[i]; 1363f012e29Smrg 1373f012e29Smrg return NULL; 1383f012e29Smrg} 139