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" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrDirectContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/SkGr.h" |
Robert Phillips | 53eaa64 | 2021-08-10 13:49:51 -0400 | [diff] [blame] | 15 | #include "src/gpu/SurfaceContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tests/Test.h" |
Robert Phillips | 168296b | 2021-08-16 11:41:27 -0400 | [diff] [blame] | 17 | #include "tests/TestUtils.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 | } |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 38 | } // namespace |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 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 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 123 | void read_and_check_pixels(skiatest::Reporter* reporter, |
| 124 | GrDirectContext* dContext, |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame] | 125 | skgpu::SurfaceContext* sc, |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 126 | uint32_t* origData, |
| 127 | const SkImageInfo& dstInfo, CheckFn checker, float error, |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 128 | const char* subtestName) { |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 129 | auto [w, h] = dstInfo.dimensions(); |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 130 | GrPixmap readPM = GrPixmap::Allocate(dstInfo); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 131 | memset(readPM.addr(), 0, sizeof(uint32_t)*w*h); |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 132 | |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame] | 133 | if (!sc->readPixels(dContext, readPM, {0, 0})) { |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 134 | ERRORF(reporter, "Could not read pixels for %s.", subtestName); |
| 135 | return; |
| 136 | } |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 137 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 138 | for (int j = 0; j < h; ++j) { |
| 139 | for (int i = 0; i < w; ++i) { |
| 140 | uint32_t orig = origData[j * w + i]; |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 141 | uint32_t read = static_cast<uint32_t*>(readPM.addr())[j * w + i]; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 142 | |
| 143 | if (!checker(orig, read, error)) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 144 | ERRORF(reporter, "Original 0x%08x, read back as 0x%08x in %s at %d, %d).", orig, |
| 145 | read, subtestName, i, j); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 152 | namespace { |
| 153 | enum class Encoding { |
| 154 | kUntagged, |
| 155 | kLinear, |
| 156 | kSRGB, |
| 157 | }; |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 158 | } // namespace |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 159 | |
| 160 | static sk_sp<SkColorSpace> encoding_as_color_space(Encoding encoding) { |
| 161 | switch (encoding) { |
| 162 | case Encoding::kUntagged: return nullptr; |
| 163 | case Encoding::kLinear: return SkColorSpace::MakeSRGBLinear(); |
| 164 | case Encoding::kSRGB: return SkColorSpace::MakeSRGB(); |
| 165 | } |
| 166 | return nullptr; |
| 167 | } |
| 168 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 169 | static const char* encoding_as_str(Encoding encoding) { |
| 170 | switch (encoding) { |
| 171 | case Encoding::kUntagged: return "untagged"; |
| 172 | case Encoding::kLinear: return "linear"; |
| 173 | case Encoding::kSRGB: return "sRGB"; |
| 174 | } |
| 175 | return nullptr; |
| 176 | } |
| 177 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 178 | static constexpr int kW = 255; |
| 179 | static constexpr int kH = 255; |
| 180 | |
| 181 | static std::unique_ptr<uint32_t[]> make_data() { |
| 182 | std::unique_ptr<uint32_t[]> data(new uint32_t[kW * kH]); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 183 | for (int j = 0; j < kH; ++j) { |
| 184 | for (int i = 0; i < kW; ++i) { |
Brian Osman | f494bd2 | 2018-07-12 10:47:01 -0400 | [diff] [blame] | 185 | data[j * kW + i] = (0xFF << 24) | (i << 16) | (i << 8) | i; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 188 | return data; |
| 189 | } |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 190 | |
Robert Phillips | 53eaa64 | 2021-08-10 13:49:51 -0400 | [diff] [blame] | 191 | static std::unique_ptr<skgpu::SurfaceContext> make_surface_context(Encoding contextEncoding, |
| 192 | GrRecordingContext* rContext, |
| 193 | skiatest::Reporter* reporter) { |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 194 | GrImageInfo info(GrColorType::kRGBA_8888, |
| 195 | kPremul_SkAlphaType, |
| 196 | encoding_as_color_space(contextEncoding), |
| 197 | kW, kH); |
| 198 | |
Robert Phillips | 168296b | 2021-08-16 11:41:27 -0400 | [diff] [blame] | 199 | auto sc = CreateSurfaceContext(rContext, |
| 200 | info, |
| 201 | SkBackingFit::kExact, |
| 202 | kBottomLeft_GrSurfaceOrigin, |
| 203 | GrRenderable::kYes); |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 204 | if (!sc) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 205 | ERRORF(reporter, "Could not create %s surface context.", encoding_as_str(contextEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 206 | } |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 207 | return sc; |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 210 | static void test_write_read(Encoding contextEncoding, Encoding writeEncoding, Encoding readEncoding, |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 211 | float error, CheckFn check, GrDirectContext* dContext, |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 212 | skiatest::Reporter* reporter) { |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 213 | auto surfaceContext = make_surface_context(contextEncoding, dContext, reporter); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 214 | if (!surfaceContext) { |
| 215 | return; |
| 216 | } |
| 217 | auto writeII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 218 | encoding_as_color_space(writeEncoding)); |
| 219 | auto data = make_data(); |
Brian Salomon | 5392c94 | 2021-03-30 16:14:37 -0400 | [diff] [blame] | 220 | GrCPixmap dataPM(writeII, data.get(), kW*sizeof(uint32_t)); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 221 | if (!surfaceContext->writePixels(dContext, dataPM, {0, 0})) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 222 | ERRORF(reporter, "Could not write %s to %s surface context.", |
| 223 | encoding_as_str(writeEncoding), encoding_as_str(contextEncoding)); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | auto readII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 228 | encoding_as_color_space(readEncoding)); |
| 229 | SkString testName; |
| 230 | testName.printf("write %s data to a %s context and read as %s.", encoding_as_str(writeEncoding), |
| 231 | encoding_as_str(contextEncoding), encoding_as_str(readEncoding)); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 232 | read_and_check_pixels(reporter, dContext, surfaceContext.get(), data.get(), readII, check, |
| 233 | error, testName.c_str()); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | // Test all combinations of writePixels/readPixels where the surface context/write source/read dst |
| 237 | // are sRGB, linear, or untagged RGBA_8888. |
| 238 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 239 | auto context = ctxInfo.directContext(); |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 240 | if (!context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888_SRGB, |
| 241 | GrRenderable::kNo).isValid()) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | // We allow more error on GPUs with lower precision shader variables. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 245 | float error = context->priv().caps()->shaderCaps()->halfIs32Bits() ? 0.5f : 1.2f; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 246 | // For the all-sRGB case, we allow a small error only for devices that have |
| 247 | // precision variation because the sRGB data gets converted to linear and back in |
| 248 | // the shader. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 249 | float smallError = context->priv().caps()->shaderCaps()->halfIs32Bits() ? 0.0f : 1.f; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 250 | |
| 251 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 252 | // Write sRGB data to a sRGB context - no conversion on the write. |
| 253 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 254 | // back to sRGB - no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 255 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kSRGB, smallError, |
| 256 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 257 | // Reading back to untagged should be a pass through with no conversion. |
| 258 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kUntagged, error, |
| 259 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 260 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 261 | // Converts back to linear |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 262 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kLinear, error, |
| 263 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 264 | |
Mike Klein | 12d4b6e | 2018-08-17 14:09:55 -0400 | [diff] [blame] | 265 | // Untagged source data should be interpreted as sRGB. |
| 266 | test_write_read(Encoding::kSRGB, Encoding::kUntagged, Encoding::kSRGB, smallError, |
| 267 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 268 | |
| 269 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 270 | // Write linear data to a sRGB context. It gets converted to sRGB on write. The reads |
| 271 | // 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] | 272 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kSRGB, error, |
| 273 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 274 | // When the dst buffer is untagged there should be no conversion on the read. |
| 275 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kUntagged, error, |
| 276 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 277 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kLinear, error, |
| 278 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 279 | |
| 280 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 281 | // Write data to an untagged context. The write does no conversion no matter what encoding the |
| 282 | // src data has. |
| 283 | for (auto writeEncoding : {Encoding::kSRGB, Encoding::kUntagged, Encoding::kLinear}) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 284 | // The read from untagged to sRGB also does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 285 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kSRGB, error, |
| 286 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 287 | // Reading untagged back as untagged should do no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 288 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kUntagged, error, |
| 289 | check_no_conversion, context, reporter); |
Brian Osman | 4f98dbe | 2019-03-28 11:49:01 -0400 | [diff] [blame] | 290 | // Reading untagged back as linear does convert (context is source, so treated as sRGB), |
| 291 | // dst is tagged. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 292 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kLinear, error, |
Brian Osman | 4f98dbe | 2019-03-28 11:49:01 -0400 | [diff] [blame] | 293 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 297 | // Write sRGB data to a linear context - converts to sRGB on the write. |
| 298 | |
| 299 | // converts back to sRGB on read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 300 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kSRGB, error, |
| 301 | check_srgb_to_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 302 | // Reading untagged data from linear currently does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 303 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kUntagged, error, |
| 304 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 305 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 306 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kLinear, error, |
| 307 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 308 | |
Mike Klein | 12d4b6e | 2018-08-17 14:09:55 -0400 | [diff] [blame] | 309 | // Untagged source data should be interpreted as sRGB. |
| 310 | test_write_read(Encoding::kLinear, Encoding::kUntagged, Encoding::kSRGB, error, |
| 311 | check_srgb_to_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 312 | |
| 313 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 314 | // Write linear data to a linear context. Does no conversion. |
| 315 | |
| 316 | // Reading to sRGB does a conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 317 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kSRGB, error, |
| 318 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 319 | // Reading to untagged does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 320 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kUntagged, error, |
| 321 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 322 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 323 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kLinear, error, |
| 324 | check_no_conversion, context, reporter); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 325 | } |