bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 9 | #include "GrCaps.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 10 | #include "GrContext.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 12 | #include "GrSurfaceContext.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 13 | #include "SkCanvas.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 14 | #include "SkGr.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 15 | #include "SkSurface.h" |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 16 | |
| 17 | // using anonymous namespace because these functions are used as template params. |
| 18 | namespace { |
| 19 | /** convert 0..1 srgb value to 0..1 linear */ |
| 20 | float srgb_to_linear(float srgb) { |
| 21 | if (srgb <= 0.04045f) { |
| 22 | return srgb / 12.92f; |
| 23 | } else { |
| 24 | return powf((srgb + 0.055f) / 1.055f, 2.4f); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /** convert 0..1 linear value to 0..1 srgb */ |
| 29 | float linear_to_srgb(float linear) { |
| 30 | if (linear <= 0.0031308) { |
| 31 | return linear * 12.92f; |
| 32 | } else { |
| 33 | return 1.055f * powf(linear, 1.f / 2.4f) - 0.055f; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** tests a conversion with an error tolerance */ |
| 39 | template <float (*CONVERT)(float)> static bool check_conversion(uint32_t input, uint32_t output, |
| 40 | float error) { |
| 41 | // alpha should always be exactly preserved. |
| 42 | if ((input & 0xff000000) != (output & 0xff000000)) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | for (int c = 0; c < 3; ++c) { |
| 47 | uint8_t inputComponent = (uint8_t) ((input & (0xff << (c*8))) >> (c*8)); |
| 48 | float lower = SkTMax(0.f, (float) inputComponent - error); |
| 49 | float upper = SkTMin(255.f, (float) inputComponent + error); |
| 50 | lower = CONVERT(lower / 255.f); |
| 51 | upper = CONVERT(upper / 255.f); |
| 52 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 53 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 54 | uint8_t outputComponent = (output & (0xff << (c*8))) >> (c*8); |
| 55 | if (outputComponent < SkScalarFloorToInt(lower * 255.f) || |
| 56 | outputComponent > SkScalarCeilToInt(upper * 255.f)) { |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | /** tests a forward and backward conversion with an error tolerance */ |
| 64 | template <float (*FORWARD)(float), float (*BACKWARD)(float)> |
| 65 | static bool check_double_conversion(uint32_t input, uint32_t output, float error) { |
| 66 | // alpha should always be exactly preserved. |
| 67 | if ((input & 0xff000000) != (output & 0xff000000)) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | for (int c = 0; c < 3; ++c) { |
| 72 | uint8_t inputComponent = (uint8_t) ((input & (0xff << (c*8))) >> (c*8)); |
| 73 | float lower = SkTMax(0.f, (float) inputComponent - error); |
| 74 | float upper = SkTMin(255.f, (float) inputComponent + error); |
| 75 | lower = FORWARD(lower / 255.f); |
| 76 | upper = FORWARD(upper / 255.f); |
| 77 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 78 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 79 | uint8_t upperComponent = SkScalarCeilToInt(upper * 255.f); |
| 80 | uint8_t lowerComponent = SkScalarFloorToInt(lower * 255.f); |
| 81 | lower = SkTMax(0.f, (float) lowerComponent - error); |
| 82 | upper = SkTMin(255.f, (float) upperComponent + error); |
| 83 | lower = BACKWARD(lowerComponent / 255.f); |
| 84 | upper = BACKWARD(upperComponent / 255.f); |
| 85 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 86 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 87 | upperComponent = SkScalarCeilToInt(upper * 255.f); |
| 88 | lowerComponent = SkScalarFloorToInt(lower * 255.f); |
| 89 | |
| 90 | uint8_t outputComponent = (output & (0xff << (c*8))) >> (c*8); |
| 91 | if (outputComponent < lowerComponent || outputComponent > upperComponent) { |
| 92 | return false; |
| 93 | } |
| 94 | } |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | static bool check_srgb_to_linear_conversion(uint32_t srgb, uint32_t linear, float error) { |
| 99 | return check_conversion<srgb_to_linear>(srgb, linear, error); |
| 100 | } |
| 101 | |
| 102 | static bool check_linear_to_srgb_conversion(uint32_t linear, uint32_t srgb, float error) { |
| 103 | return check_conversion<linear_to_srgb>(linear, srgb, error); |
| 104 | } |
| 105 | |
| 106 | static bool check_linear_to_srgb_to_linear_conversion(uint32_t input, uint32_t output, float error) { |
| 107 | return check_double_conversion<linear_to_srgb, srgb_to_linear>(input, output, error); |
| 108 | } |
| 109 | |
| 110 | static bool check_srgb_to_linear_to_srgb_conversion(uint32_t input, uint32_t output, float error) { |
| 111 | return check_double_conversion<srgb_to_linear, linear_to_srgb>(input, output, error); |
| 112 | } |
| 113 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 114 | static bool check_no_conversion(uint32_t input, uint32_t output, float error) { |
| 115 | // This is a bit of a hack to check identity transformations that may lose precision. |
| 116 | return check_srgb_to_linear_to_srgb_conversion(input, output, error); |
| 117 | } |
| 118 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 119 | typedef bool (*CheckFn) (uint32_t orig, uint32_t actual, float error); |
| 120 | |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 121 | void read_and_check_pixels(skiatest::Reporter* reporter, GrSurfaceContext* context, |
| 122 | uint32_t* origData, |
| 123 | const SkImageInfo& dstInfo, CheckFn checker, float error, |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 124 | const char* subtestName) { |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 125 | int w = dstInfo.width(); |
| 126 | int h = dstInfo.height(); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 127 | SkAutoTMalloc<uint32_t> readData(w * h); |
| 128 | memset(readData.get(), 0, sizeof(uint32_t) * w * h); |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 129 | |
| 130 | if (!context->readPixels(dstInfo, readData.get(), 0, 0, 0)) { |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 131 | ERRORF(reporter, "Could not read pixels for %s.", subtestName); |
| 132 | return; |
| 133 | } |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 134 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 135 | for (int j = 0; j < h; ++j) { |
| 136 | for (int i = 0; i < w; ++i) { |
| 137 | uint32_t orig = origData[j * w + i]; |
| 138 | uint32_t read = readData[j * w + i]; |
| 139 | |
| 140 | if (!checker(orig, read, error)) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 141 | ERRORF(reporter, "Original 0x%08x, read back as 0x%08x in %s at %d, %d).", orig, |
| 142 | read, subtestName, i, j); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 149 | namespace { |
| 150 | enum class Encoding { |
| 151 | kUntagged, |
| 152 | kLinear, |
| 153 | kSRGB, |
| 154 | }; |
| 155 | } |
| 156 | |
| 157 | static sk_sp<SkColorSpace> encoding_as_color_space(Encoding encoding) { |
| 158 | switch (encoding) { |
| 159 | case Encoding::kUntagged: return nullptr; |
| 160 | case Encoding::kLinear: return SkColorSpace::MakeSRGBLinear(); |
| 161 | case Encoding::kSRGB: return SkColorSpace::MakeSRGB(); |
| 162 | } |
| 163 | return nullptr; |
| 164 | } |
| 165 | |
| 166 | static GrPixelConfig encoding_as_pixel_config(Encoding encoding) { |
| 167 | switch (encoding) { |
| 168 | case Encoding::kUntagged: return kRGBA_8888_GrPixelConfig; |
| 169 | case Encoding::kLinear: return kRGBA_8888_GrPixelConfig; |
| 170 | case Encoding::kSRGB: return kSRGBA_8888_GrPixelConfig; |
| 171 | } |
| 172 | return kUnknown_GrPixelConfig; |
| 173 | } |
| 174 | |
| 175 | static const char* encoding_as_str(Encoding encoding) { |
| 176 | switch (encoding) { |
| 177 | case Encoding::kUntagged: return "untagged"; |
| 178 | case Encoding::kLinear: return "linear"; |
| 179 | case Encoding::kSRGB: return "sRGB"; |
| 180 | } |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 184 | static constexpr int kW = 255; |
| 185 | static constexpr int kH = 255; |
| 186 | |
| 187 | static std::unique_ptr<uint32_t[]> make_data() { |
| 188 | std::unique_ptr<uint32_t[]> data(new uint32_t[kW * kH]); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 189 | for (int j = 0; j < kH; ++j) { |
| 190 | for (int i = 0; i < kW; ++i) { |
Brian Osman | f494bd2 | 2018-07-12 10:47:01 -0400 | [diff] [blame] | 191 | data[j * kW + i] = (0xFF << 24) | (i << 16) | (i << 8) | i; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 194 | return data; |
| 195 | } |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 196 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 197 | static sk_sp<GrSurfaceContext> make_surface_context(Encoding contextEncoding, GrContext* context, |
| 198 | skiatest::Reporter* reporter) { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 199 | GrSurfaceDesc desc; |
| 200 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 201 | desc.fWidth = kW; |
| 202 | desc.fHeight = kH; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 203 | desc.fConfig = encoding_as_pixel_config(contextEncoding); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 204 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 205 | auto surfaceContext = context->contextPriv().makeDeferredSurfaceContext( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 206 | desc, kBottomLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact, |
| 207 | SkBudgeted::kNo, encoding_as_color_space(contextEncoding)); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 208 | if (!surfaceContext) { |
| 209 | ERRORF(reporter, "Could not create %s surface context.", encoding_as_str(contextEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 210 | } |
| 211 | return surfaceContext; |
| 212 | } |
| 213 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 214 | static void test_write_read(Encoding contextEncoding, Encoding writeEncoding, Encoding readEncoding, |
| 215 | float error, CheckFn check, GrContext* context, |
| 216 | skiatest::Reporter* reporter) { |
| 217 | auto surfaceContext = make_surface_context(contextEncoding, context, reporter); |
| 218 | if (!surfaceContext) { |
| 219 | return; |
| 220 | } |
| 221 | auto writeII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 222 | encoding_as_color_space(writeEncoding)); |
| 223 | auto data = make_data(); |
| 224 | if (!surfaceContext->writePixels(writeII, data.get(), 0, 0, 0)) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 225 | ERRORF(reporter, "Could not write %s to %s surface context.", |
| 226 | encoding_as_str(writeEncoding), encoding_as_str(contextEncoding)); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | auto readII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 231 | encoding_as_color_space(readEncoding)); |
| 232 | SkString testName; |
| 233 | testName.printf("write %s data to a %s context and read as %s.", encoding_as_str(writeEncoding), |
| 234 | encoding_as_str(contextEncoding), encoding_as_str(readEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 235 | read_and_check_pixels(reporter, surfaceContext.get(), data.get(), readII, check, error, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 236 | testName.c_str()); |
| 237 | } |
| 238 | |
| 239 | // Test all combinations of writePixels/readPixels where the surface context/write source/read dst |
| 240 | // are sRGB, linear, or untagged RGBA_8888. |
| 241 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { |
| 242 | GrContext* context = ctxInfo.grContext(); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 243 | if (!context->contextPriv().caps()->isConfigRenderable(kSRGBA_8888_GrPixelConfig) && |
| 244 | !context->contextPriv().caps()->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | // We allow more error on GPUs with lower precision shader variables. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 248 | float error = context->contextPriv().caps()->shaderCaps()->halfIs32Bits() ? 0.5f : 1.2f; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 249 | // For the all-sRGB case, we allow a small error only for devices that have |
| 250 | // precision variation because the sRGB data gets converted to linear and back in |
| 251 | // the shader. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 252 | float smallError = context->contextPriv().caps()->shaderCaps()->halfIs32Bits() ? 0.0f : 1.f; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 253 | |
| 254 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 255 | // Write sRGB data to a sRGB context - no conversion on the write. |
| 256 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 257 | // back to sRGB - no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 258 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kSRGB, smallError, |
| 259 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 260 | // Reading back to untagged should be a pass through with no conversion. |
| 261 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kUntagged, error, |
| 262 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 263 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 264 | // Converts back to linear |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 265 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kLinear, error, |
| 266 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 267 | |
Mike Klein | 12d4b6e | 2018-08-17 14:09:55 -0400 | [diff] [blame] | 268 | // Untagged source data should be interpreted as sRGB. |
| 269 | test_write_read(Encoding::kSRGB, Encoding::kUntagged, Encoding::kSRGB, smallError, |
| 270 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 271 | |
| 272 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 273 | // Write linear data to a sRGB context. It gets converted to sRGB on write. The reads |
| 274 | // are all the same as the above cases where the original data was untagged. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 275 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kSRGB, error, |
| 276 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 277 | // When the dst buffer is untagged there should be no conversion on the read. |
| 278 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kUntagged, error, |
| 279 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 280 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kLinear, error, |
| 281 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 282 | |
| 283 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 284 | // Write data to an untagged context. The write does no conversion no matter what encoding the |
| 285 | // src data has. |
| 286 | for (auto writeEncoding : {Encoding::kSRGB, Encoding::kUntagged, Encoding::kLinear}) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 287 | // The read from untagged to sRGB also does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 288 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kSRGB, error, |
| 289 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 290 | // Reading untagged back as untagged should do no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 291 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kUntagged, error, |
| 292 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 293 | // Reading untagged back as linear does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 294 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kLinear, error, |
| 295 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 299 | // Write sRGB data to a linear context - converts to sRGB on the write. |
| 300 | |
| 301 | // converts back to sRGB on read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 302 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kSRGB, error, |
| 303 | check_srgb_to_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 304 | // Reading untagged data from linear currently does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 305 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kUntagged, error, |
| 306 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 307 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 308 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kLinear, error, |
| 309 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 310 | |
Mike Klein | 12d4b6e | 2018-08-17 14:09:55 -0400 | [diff] [blame] | 311 | // Untagged source data should be interpreted as sRGB. |
| 312 | test_write_read(Encoding::kLinear, Encoding::kUntagged, Encoding::kSRGB, error, |
| 313 | check_srgb_to_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 314 | |
| 315 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 316 | // Write linear data to a linear context. Does no conversion. |
| 317 | |
| 318 | // Reading to sRGB does a conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 319 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kSRGB, error, |
| 320 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 321 | // Reading to untagged does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 322 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kUntagged, error, |
| 323 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 324 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 325 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kLinear, error, |
| 326 | check_no_conversion, context, reporter); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 327 | } |