1e64d31b9Smaya/* 2e64d31b9Smaya * Copyright 2017 Google 3e64d31b9Smaya * 4e64d31b9Smaya * Permission is hereby granted, free of charge, to any person obtaining a 5e64d31b9Smaya * copy of this software and associated documentation files (the 6e64d31b9Smaya * "Software"), to deal in the Software without restriction, including 7e64d31b9Smaya * without limitation the rights to use, copy, modify, merge, publish, 8e64d31b9Smaya * distribute, sub license, and/or sell copies of the Software, and to 9e64d31b9Smaya * permit persons to whom the Software is furnished to do so, subject to 10e64d31b9Smaya * the following conditions: 11e64d31b9Smaya * 12e64d31b9Smaya * The above copyright notice and this permission notice (including the 13e64d31b9Smaya * next paragraph) shall be included in all copies or substantial portions 14e64d31b9Smaya * of the Software. 15e64d31b9Smaya * 16e64d31b9Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17e64d31b9Smaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18e64d31b9Smaya * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 19e64d31b9Smaya * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 20e64d31b9Smaya * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21e64d31b9Smaya * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22e64d31b9Smaya * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23e64d31b9Smaya */ 24e64d31b9Smaya 25e64d31b9Smaya#include "formats.h" 26e64d31b9Smaya#include "util/macros.h" 27e64d31b9Smaya 28e64d31b9Smaya/** 29e64d31b9Smaya * For an sRGB format, return the corresponding linear color space format. 30e64d31b9Smaya * For non-sRGB formats, return the format as-is. 31e64d31b9Smaya */ 32e64d31b9Smayamesa_format 33e64d31b9Smaya_mesa_get_srgb_format_linear(mesa_format format) 34e64d31b9Smaya{ 35e64d31b9Smaya switch (format) { 36e64d31b9Smaya case MESA_FORMAT_A8B8G8R8_SRGB: 37e64d31b9Smaya return MESA_FORMAT_A8B8G8R8_UNORM; 38e64d31b9Smaya case MESA_FORMAT_B8G8R8A8_SRGB: 39e64d31b9Smaya return MESA_FORMAT_B8G8R8A8_UNORM; 40e64d31b9Smaya case MESA_FORMAT_A8R8G8B8_SRGB: 41e64d31b9Smaya return MESA_FORMAT_A8R8G8B8_UNORM; 42e64d31b9Smaya case MESA_FORMAT_B8G8R8X8_SRGB: 43e64d31b9Smaya return MESA_FORMAT_B8G8R8X8_UNORM; 44e64d31b9Smaya case MESA_FORMAT_X8R8G8B8_SRGB: 45e64d31b9Smaya return MESA_FORMAT_X8R8G8B8_UNORM; 46e64d31b9Smaya case MESA_FORMAT_R8G8B8A8_SRGB: 47e64d31b9Smaya return MESA_FORMAT_R8G8B8A8_UNORM; 48e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_SRGB: 49e64d31b9Smaya return MESA_FORMAT_R8G8B8X8_UNORM; 50e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_SRGB: 51e64d31b9Smaya return MESA_FORMAT_X8B8G8R8_UNORM; 52e64d31b9Smaya case MESA_FORMAT_R_SRGB8: 53e64d31b9Smaya return MESA_FORMAT_R_UNORM8; 54e64d31b9Smaya case MESA_FORMAT_L_SRGB8: 55e64d31b9Smaya return MESA_FORMAT_L_UNORM8; 5696c5ddc4Srjs case MESA_FORMAT_RG_SRGB8: 5796c5ddc4Srjs return MESA_FORMAT_RG_UNORM8; 5896c5ddc4Srjs case MESA_FORMAT_LA_SRGB8: 5996c5ddc4Srjs return MESA_FORMAT_LA_UNORM8; 60e64d31b9Smaya case MESA_FORMAT_BGR_SRGB8: 61e64d31b9Smaya return MESA_FORMAT_BGR_UNORM8; 62e64d31b9Smaya case MESA_FORMAT_SRGB_DXT1: 63e64d31b9Smaya return MESA_FORMAT_RGB_DXT1; 64e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT1: 65e64d31b9Smaya return MESA_FORMAT_RGBA_DXT1; 66e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT3: 67e64d31b9Smaya return MESA_FORMAT_RGBA_DXT3; 68e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT5: 69e64d31b9Smaya return MESA_FORMAT_RGBA_DXT5; 70e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8: 71e64d31b9Smaya return MESA_FORMAT_ETC2_RGB8; 72e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: 73e64d31b9Smaya return MESA_FORMAT_ETC2_RGBA8_EAC; 74e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: 75e64d31b9Smaya return MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; 76e64d31b9Smaya case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: 77e64d31b9Smaya return MESA_FORMAT_BPTC_RGBA_UNORM; 78e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4: 79e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_4x4; 80e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4: 81e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_5x4; 82e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5: 83e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_5x5; 84e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5: 85e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_6x5; 86e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6: 87e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_6x6; 88e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5: 89e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_8x5; 90e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6: 91e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_8x6; 92e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8: 93e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_8x8; 94e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5: 95e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_10x5; 96e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6: 97e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_10x6; 98e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8: 99e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_10x8; 100e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10: 101e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_10x10; 102e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10: 103e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_12x10; 104e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12: 105e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_12x12; 106e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3: 107e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_3x3x3; 108e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3: 109e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_4x3x3; 110e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3: 111e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_4x4x3; 112e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4: 113e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_4x4x4; 114e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4: 115e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_5x4x4; 116e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4: 117e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_5x5x4; 118e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5: 119e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_5x5x5; 120e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5: 121e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_6x5x5; 122e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5: 123e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_6x6x5; 124e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6: 125e64d31b9Smaya return MESA_FORMAT_RGBA_ASTC_6x6x6; 126e64d31b9Smaya default: 127e64d31b9Smaya return format; 128e64d31b9Smaya } 129e64d31b9Smaya} 130e64d31b9Smaya 131e64d31b9Smaya/** 132e64d31b9Smaya * For a linear format, return the corresponding sRGB color space format. 133e64d31b9Smaya * For an sRGB format, return the format as-is. 134e64d31b9Smaya * Assert-fails if the format is not sRGB and does not have an sRGB equivalent. 135e64d31b9Smaya */ 136e64d31b9Smayamesa_format 137e64d31b9Smaya_mesa_get_linear_format_srgb(mesa_format format) 138e64d31b9Smaya{ 139e64d31b9Smaya switch (format) { 140e64d31b9Smaya case MESA_FORMAT_A8B8G8R8_UNORM: 141e64d31b9Smaya return MESA_FORMAT_A8B8G8R8_SRGB; 142e64d31b9Smaya case MESA_FORMAT_B8G8R8A8_UNORM: 143e64d31b9Smaya return MESA_FORMAT_B8G8R8A8_SRGB; 144e64d31b9Smaya case MESA_FORMAT_A8R8G8B8_UNORM: 145e64d31b9Smaya return MESA_FORMAT_A8R8G8B8_SRGB; 146e64d31b9Smaya case MESA_FORMAT_B8G8R8X8_UNORM: 147e64d31b9Smaya return MESA_FORMAT_B8G8R8X8_SRGB; 148e64d31b9Smaya case MESA_FORMAT_X8R8G8B8_UNORM: 149e64d31b9Smaya return MESA_FORMAT_X8R8G8B8_SRGB; 150e64d31b9Smaya case MESA_FORMAT_R8G8B8A8_UNORM: 151e64d31b9Smaya return MESA_FORMAT_R8G8B8A8_SRGB; 152e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_UNORM: 153e64d31b9Smaya return MESA_FORMAT_R8G8B8X8_SRGB; 154e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_UNORM: 155e64d31b9Smaya return MESA_FORMAT_X8B8G8R8_SRGB; 156e64d31b9Smaya case MESA_FORMAT_R_UNORM8: 157e64d31b9Smaya return MESA_FORMAT_R_SRGB8; 158e64d31b9Smaya case MESA_FORMAT_L_UNORM8: 159e64d31b9Smaya return MESA_FORMAT_L_SRGB8; 16096c5ddc4Srjs case MESA_FORMAT_RG_UNORM8: 16196c5ddc4Srjs return MESA_FORMAT_RG_SRGB8; 16296c5ddc4Srjs case MESA_FORMAT_LA_UNORM8: 16396c5ddc4Srjs return MESA_FORMAT_LA_SRGB8; 164e64d31b9Smaya case MESA_FORMAT_BGR_UNORM8: 165e64d31b9Smaya return MESA_FORMAT_BGR_SRGB8; 166e64d31b9Smaya case MESA_FORMAT_RGB_DXT1: 167e64d31b9Smaya return MESA_FORMAT_SRGB_DXT1; 168e64d31b9Smaya case MESA_FORMAT_RGBA_DXT1: 169e64d31b9Smaya return MESA_FORMAT_SRGBA_DXT1; 170e64d31b9Smaya case MESA_FORMAT_RGBA_DXT3: 171e64d31b9Smaya return MESA_FORMAT_SRGBA_DXT3; 172e64d31b9Smaya case MESA_FORMAT_RGBA_DXT5: 173e64d31b9Smaya return MESA_FORMAT_SRGBA_DXT5; 174e64d31b9Smaya case MESA_FORMAT_ETC2_RGB8: 175e64d31b9Smaya return MESA_FORMAT_ETC2_SRGB8; 176e64d31b9Smaya case MESA_FORMAT_ETC2_RGBA8_EAC: 177e64d31b9Smaya return MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC; 178e64d31b9Smaya case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: 179e64d31b9Smaya return MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1; 180e64d31b9Smaya case MESA_FORMAT_BPTC_RGBA_UNORM: 181e64d31b9Smaya return MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM; 182e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_4x4: 183e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4; 184e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_5x4: 185e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4; 186e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_5x5: 187e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5; 188e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_6x5: 189e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5; 190e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_6x6: 191e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6; 192e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_8x5: 193e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5; 194e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_8x6: 195e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6; 196e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_8x8: 197e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8; 198e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_10x5: 199e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5; 200e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_10x6: 201e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6; 202e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_10x8: 203e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8; 204e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_10x10: 205e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10; 206e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_12x10: 207e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10; 208e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_12x12: 209e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12; 210e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_3x3x3: 211e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3; 212e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_4x3x3: 213e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3; 214e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_4x4x3: 215e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3; 216e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_4x4x4: 217e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4; 218e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_5x4x4: 219e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4; 220e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_5x5x4: 221e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4; 222e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_5x5x5: 223e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5; 224e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_6x5x5: 225e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5; 226e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_6x6x5: 227e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5; 228e64d31b9Smaya case MESA_FORMAT_RGBA_ASTC_6x6x6: 229e64d31b9Smaya return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6; 230e64d31b9Smaya case MESA_FORMAT_A8B8G8R8_SRGB: 231e64d31b9Smaya case MESA_FORMAT_B8G8R8A8_SRGB: 232e64d31b9Smaya case MESA_FORMAT_A8R8G8B8_SRGB: 233e64d31b9Smaya case MESA_FORMAT_B8G8R8X8_SRGB: 234e64d31b9Smaya case MESA_FORMAT_X8R8G8B8_SRGB: 235e64d31b9Smaya case MESA_FORMAT_R8G8B8A8_SRGB: 236e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_SRGB: 237e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_SRGB: 238e64d31b9Smaya case MESA_FORMAT_R_SRGB8: 239e64d31b9Smaya case MESA_FORMAT_L_SRGB8: 24096c5ddc4Srjs case MESA_FORMAT_RG_SRGB8: 24196c5ddc4Srjs case MESA_FORMAT_LA_SRGB8: 242e64d31b9Smaya case MESA_FORMAT_BGR_SRGB8: 243e64d31b9Smaya case MESA_FORMAT_SRGB_DXT1: 244e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT1: 245e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT3: 246e64d31b9Smaya case MESA_FORMAT_SRGBA_DXT5: 247e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8: 248e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: 249e64d31b9Smaya case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: 250e64d31b9Smaya case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: 251e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4: 252e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4: 253e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5: 254e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5: 255e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6: 256e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5: 257e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6: 258e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8: 259e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5: 260e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6: 261e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8: 262e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10: 263e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10: 264e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12: 265e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3: 266e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3: 267e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3: 268e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4: 269e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4: 270e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4: 271e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5: 272e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5: 273e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5: 274e64d31b9Smaya case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6: 275e64d31b9Smaya return format; 276e64d31b9Smaya default: 277e64d31b9Smaya unreachable("Given format does not have an sRGB equivalent"); 278e64d31b9Smaya } 279e64d31b9Smaya} 280e64d31b9Smaya 28196c5ddc4Srjs/** 28296c5ddc4Srjs * For an intensity format, return the corresponding red format. For other 28396c5ddc4Srjs * formats, return the format as-is. 28496c5ddc4Srjs */ 28596c5ddc4Srjsmesa_format 28696c5ddc4Srjs_mesa_get_intensity_format_red(mesa_format format) 28796c5ddc4Srjs{ 28896c5ddc4Srjs switch (format) { 28996c5ddc4Srjs case MESA_FORMAT_I_UNORM8: 29096c5ddc4Srjs return MESA_FORMAT_R_UNORM8; 29196c5ddc4Srjs case MESA_FORMAT_I_UNORM16: 29296c5ddc4Srjs return MESA_FORMAT_R_UNORM16; 29396c5ddc4Srjs case MESA_FORMAT_I_SNORM8: 29496c5ddc4Srjs return MESA_FORMAT_R_SNORM8; 29596c5ddc4Srjs case MESA_FORMAT_I_SNORM16: 29696c5ddc4Srjs return MESA_FORMAT_R_SNORM16; 29796c5ddc4Srjs case MESA_FORMAT_I_FLOAT16: 29896c5ddc4Srjs return MESA_FORMAT_R_FLOAT16; 29996c5ddc4Srjs case MESA_FORMAT_I_FLOAT32: 30096c5ddc4Srjs return MESA_FORMAT_R_FLOAT32; 30196c5ddc4Srjs case MESA_FORMAT_I_UINT8: 30296c5ddc4Srjs return MESA_FORMAT_R_UINT8; 30396c5ddc4Srjs case MESA_FORMAT_I_UINT16: 30496c5ddc4Srjs return MESA_FORMAT_R_UINT16; 30596c5ddc4Srjs case MESA_FORMAT_I_UINT32: 30696c5ddc4Srjs return MESA_FORMAT_R_UINT32; 30796c5ddc4Srjs case MESA_FORMAT_I_SINT8: 30896c5ddc4Srjs return MESA_FORMAT_R_SINT8; 30996c5ddc4Srjs case MESA_FORMAT_I_SINT16: 31096c5ddc4Srjs return MESA_FORMAT_R_SINT16; 31196c5ddc4Srjs case MESA_FORMAT_I_SINT32: 31296c5ddc4Srjs return MESA_FORMAT_R_SINT32; 31396c5ddc4Srjs default: 31496c5ddc4Srjs return format; 31596c5ddc4Srjs } 31696c5ddc4Srjs} 31796c5ddc4Srjs 318e64d31b9Smaya/** 319e64d31b9Smaya * If the format has an alpha channel, and there exists a non-alpha 320e64d31b9Smaya * variant of the format with an identical bit layout, then return 321e64d31b9Smaya * the non-alpha format. Otherwise return the original format. 322e64d31b9Smaya * 323e64d31b9Smaya * Examples: 324e64d31b9Smaya * Fallback exists: 325e64d31b9Smaya * MESA_FORMAT_R8G8B8X8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM 326e64d31b9Smaya * MESA_FORMAT_RGBX_UNORM16 -> MESA_FORMAT_RGBA_UNORM16 327e64d31b9Smaya * 328e64d31b9Smaya * No fallback: 329e64d31b9Smaya * MESA_FORMAT_R8G8B8A8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM 330e64d31b9Smaya * MESA_FORMAT_Z_FLOAT32 -> MESA_FORMAT_Z_FLOAT32 331e64d31b9Smaya */ 332e64d31b9Smayamesa_format 333e64d31b9Smaya_mesa_format_fallback_rgbx_to_rgba(mesa_format format) 334e64d31b9Smaya{ 335e64d31b9Smaya switch (format) { 336e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_UNORM: 337e64d31b9Smaya return MESA_FORMAT_A8B8G8R8_UNORM; 338e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_UNORM: 339e64d31b9Smaya return MESA_FORMAT_R8G8B8A8_UNORM; 340e64d31b9Smaya case MESA_FORMAT_B8G8R8X8_UNORM: 341e64d31b9Smaya return MESA_FORMAT_B8G8R8A8_UNORM; 342e64d31b9Smaya case MESA_FORMAT_X8R8G8B8_UNORM: 343e64d31b9Smaya return MESA_FORMAT_A8R8G8B8_UNORM; 344e64d31b9Smaya case MESA_FORMAT_B4G4R4X4_UNORM: 345e64d31b9Smaya return MESA_FORMAT_B4G4R4A4_UNORM; 346e64d31b9Smaya case MESA_FORMAT_X1B5G5R5_UNORM: 347e64d31b9Smaya return MESA_FORMAT_A1B5G5R5_UNORM; 348e64d31b9Smaya case MESA_FORMAT_B5G5R5X1_UNORM: 349e64d31b9Smaya return MESA_FORMAT_B5G5R5A1_UNORM; 350e64d31b9Smaya case MESA_FORMAT_B10G10R10X2_UNORM: 351e64d31b9Smaya return MESA_FORMAT_B10G10R10A2_UNORM; 352e64d31b9Smaya case MESA_FORMAT_R10G10B10X2_UNORM: 353e64d31b9Smaya return MESA_FORMAT_R10G10B10A2_UNORM; 354e64d31b9Smaya case MESA_FORMAT_RGBX_UNORM16: 355e64d31b9Smaya return MESA_FORMAT_RGBA_UNORM16; 356e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_SNORM: 357e64d31b9Smaya return MESA_FORMAT_A8B8G8R8_SNORM; 358e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_SNORM: 359e64d31b9Smaya return MESA_FORMAT_R8G8B8A8_SNORM; 360e64d31b9Smaya case MESA_FORMAT_RGBX_SNORM16: 361e64d31b9Smaya return MESA_FORMAT_RGBA_SNORM16; 362e64d31b9Smaya case MESA_FORMAT_B8G8R8X8_SRGB: 363e64d31b9Smaya return MESA_FORMAT_B8G8R8A8_SRGB; 364e64d31b9Smaya case MESA_FORMAT_X8R8G8B8_SRGB: 365e64d31b9Smaya return MESA_FORMAT_A8R8G8B8_SRGB; 366e64d31b9Smaya case MESA_FORMAT_R8G8B8X8_SRGB: 367e64d31b9Smaya return MESA_FORMAT_R8G8B8A8_SRGB; 368e64d31b9Smaya case MESA_FORMAT_X8B8G8R8_SRGB: 369e64d31b9Smaya return MESA_FORMAT_A8B8G8R8_SRGB; 370e64d31b9Smaya case MESA_FORMAT_RGBX_FLOAT16: 371e64d31b9Smaya return MESA_FORMAT_RGBA_FLOAT16; 372e64d31b9Smaya case MESA_FORMAT_RGBX_FLOAT32: 373e64d31b9Smaya return MESA_FORMAT_RGBA_FLOAT32; 374e64d31b9Smaya case MESA_FORMAT_RGBX_UINT16: 375e64d31b9Smaya return MESA_FORMAT_RGBA_UINT16; 376e64d31b9Smaya case MESA_FORMAT_RGBX_UINT32: 377e64d31b9Smaya return MESA_FORMAT_RGBA_UINT32; 378e64d31b9Smaya case MESA_FORMAT_RGBX_SINT8: 379e64d31b9Smaya return MESA_FORMAT_RGBA_SINT8; 380e64d31b9Smaya case MESA_FORMAT_RGBX_SINT16: 381e64d31b9Smaya return MESA_FORMAT_RGBA_SINT16; 382e64d31b9Smaya case MESA_FORMAT_RGBX_SINT32: 383e64d31b9Smaya return MESA_FORMAT_RGBA_SINT32; 384e64d31b9Smaya default: 385e64d31b9Smaya return format; 386e64d31b9Smaya } 387e64d31b9Smaya} 388