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