blob: 9c4170017ddd7a907e120b8836fc368227424814 [file] [log] [blame]
Chia-I Wub5a1add2014-08-16 12:46:32 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wub5a1add2014-08-16 12:46:32 +080026 */
27
28#ifndef ICD_FORMAT_H
29#define ICD_FORMAT_H
30
31#include <stdbool.h>
32#include "icd.h"
33
34static inline bool icd_format_is_undef(XGL_FORMAT format)
35{
36 return (format.numericFormat == XGL_NUM_FMT_UNDEFINED);
37}
38
39static inline bool icd_format_is_ds(XGL_FORMAT format)
40{
41 return (format.numericFormat == XGL_NUM_FMT_DS);
42}
43
44static inline bool icd_format_is_color(XGL_FORMAT format)
45{
46 return !(icd_format_is_undef(format) || icd_format_is_ds(format));
47}
48
49static inline bool icd_format_is_norm(XGL_FORMAT format)
50{
51 return (format.numericFormat == XGL_NUM_FMT_UNORM ||
52 format.numericFormat == XGL_NUM_FMT_SNORM);
53};
54
55static inline bool icd_format_is_int(XGL_FORMAT format)
56{
57 return (format.numericFormat == XGL_NUM_FMT_UINT ||
58 format.numericFormat == XGL_NUM_FMT_SINT);
59}
60
61static inline bool icd_format_is_float(XGL_FORMAT format)
62{
63 return (format.numericFormat == XGL_NUM_FMT_FLOAT);
64}
65
66static inline bool icd_format_is_srgb(XGL_FORMAT format)
67{
68 return (format.numericFormat == XGL_NUM_FMT_SRGB);
69}
70
Chia-I Wuc581bd52015-01-18 14:51:02 +080071static inline bool icd_format_is_scaled(XGL_FORMAT format)
72{
73 return (format.numericFormat == XGL_NUM_FMT_USCALED ||
74 format.numericFormat == XGL_NUM_FMT_SSCALED);
75}
76
Chia-I Wub5a1add2014-08-16 12:46:32 +080077static inline bool icd_format_is_compressed(XGL_FORMAT format)
78{
79 switch (format.channelFormat) {
80 case XGL_CH_FMT_BC1:
81 case XGL_CH_FMT_BC2:
82 case XGL_CH_FMT_BC3:
83 case XGL_CH_FMT_BC4:
84 case XGL_CH_FMT_BC5:
85 case XGL_CH_FMT_BC6U:
86 case XGL_CH_FMT_BC6S:
87 case XGL_CH_FMT_BC7:
88 return true;
89 default:
90 return false;
91 }
92}
93
Chia-I Wu6320abc2014-10-20 13:50:43 +080094static inline bool icd_format_is_equal(XGL_FORMAT a, XGL_FORMAT b)
95{
96 return (a.channelFormat == b.channelFormat &&
97 a.numericFormat == b.numericFormat);
98}
99
Courtney Goeltzenleuchter74deb372014-10-14 18:14:31 -0600100static inline int icd_format_get_block_width(XGL_FORMAT format)
Chia-I Wub5a1add2014-08-16 12:46:32 +0800101{
102 /* all compressed formats use 4x4 blocks */
103 return (icd_format_is_compressed(format)) ? 4 : 1;
104}
105
Chia-I Wu54ed0792014-12-27 14:14:50 +0800106size_t icd_format_get_size(XGL_FORMAT format);
Chia-I Wu40ee55b2014-10-08 09:12:58 +0800107
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700108XGL_IMAGE_FORMAT_CLASS icd_format_get_class(XGL_FORMAT format);
109
Jeremy Hayes4c329eb2015-01-14 14:58:37 -0700110unsigned int icd_format_get_channel_count(XGL_FORMAT format);
Chia-I Wub5a1add2014-08-16 12:46:32 +0800111
Chia-I Wu92096a92014-12-21 23:07:08 +0800112void icd_format_get_raw_value(XGL_FORMAT format,
113 const XGL_UINT32 color[4],
114 void *value);
115
Chia-I Wub5a1add2014-08-16 12:46:32 +0800116#endif /* ICD_FORMAT_H */