Chia-I Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 1 | /* |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef ICD_FORMAT_H |
| 29 | #define ICD_FORMAT_H |
| 30 | |
| 31 | #include <stdbool.h> |
| 32 | #include "icd.h" |
| 33 | |
| 34 | static inline bool icd_format_is_undef(XGL_FORMAT format) |
| 35 | { |
| 36 | return (format.numericFormat == XGL_NUM_FMT_UNDEFINED); |
| 37 | } |
| 38 | |
| 39 | static inline bool icd_format_is_ds(XGL_FORMAT format) |
| 40 | { |
| 41 | return (format.numericFormat == XGL_NUM_FMT_DS); |
| 42 | } |
| 43 | |
| 44 | static inline bool icd_format_is_color(XGL_FORMAT format) |
| 45 | { |
| 46 | return !(icd_format_is_undef(format) || icd_format_is_ds(format)); |
| 47 | } |
| 48 | |
| 49 | static 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 | |
| 55 | static 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 | |
| 61 | static inline bool icd_format_is_float(XGL_FORMAT format) |
| 62 | { |
| 63 | return (format.numericFormat == XGL_NUM_FMT_FLOAT); |
| 64 | } |
| 65 | |
| 66 | static inline bool icd_format_is_srgb(XGL_FORMAT format) |
| 67 | { |
| 68 | return (format.numericFormat == XGL_NUM_FMT_SRGB); |
| 69 | } |
| 70 | |
Chia-I Wu | c581bd5 | 2015-01-18 14:51:02 +0800 | [diff] [blame] | 71 | static 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 Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 77 | static 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 Wu | 6320abc | 2014-10-20 13:50:43 +0800 | [diff] [blame] | 94 | static 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 Goeltzenleuchter | 74deb37 | 2014-10-14 18:14:31 -0600 | [diff] [blame] | 100 | static inline int icd_format_get_block_width(XGL_FORMAT format) |
Chia-I Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 101 | { |
| 102 | /* all compressed formats use 4x4 blocks */ |
| 103 | return (icd_format_is_compressed(format)) ? 4 : 1; |
| 104 | } |
| 105 | |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 106 | size_t icd_format_get_size(XGL_FORMAT format); |
Chia-I Wu | 40ee55b | 2014-10-08 09:12:58 +0800 | [diff] [blame] | 107 | |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame^] | 108 | XGL_IMAGE_FORMAT_CLASS icd_format_get_class(XGL_FORMAT format); |
| 109 | |
Jeremy Hayes | 4c329eb | 2015-01-14 14:58:37 -0700 | [diff] [blame] | 110 | unsigned int icd_format_get_channel_count(XGL_FORMAT format); |
Chia-I Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 111 | |
Chia-I Wu | 92096a9 | 2014-12-21 23:07:08 +0800 | [diff] [blame] | 112 | void icd_format_get_raw_value(XGL_FORMAT format, |
| 113 | const XGL_UINT32 color[4], |
| 114 | void *value); |
| 115 | |
Chia-I Wu | b5a1add | 2014-08-16 12:46:32 +0800 | [diff] [blame] | 116 | #endif /* ICD_FORMAT_H */ |