Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: src/core/SkSRGB.h

Issue 2162063003: Tune linear->sRGB constants to round-trip all bytes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/SRGBTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkSRGB_DEFINED 8 #ifndef SkSRGB_DEFINED
9 #define SkSRGB_DEFINED 9 #define SkSRGB_DEFINED
10 10
(...skipping 12 matching lines...) Expand all
23 * The overflow is small enough to be handled by rounding. 23 * The overflow is small enough to be handled by rounding.
24 * (But if you don't trust the inputs are in [0,1], you'd better clamp both sid es immediately.) 24 * (But if you don't trust the inputs are in [0,1], you'd better clamp both sid es immediately.)
25 * 25 *
26 * sk_linear_to_srgb() will run a little faster than usual when compiled with S SE4.1+. 26 * sk_linear_to_srgb() will run a little faster than usual when compiled with S SE4.1+.
27 */ 27 */
28 28
29 extern const float sk_linear_from_srgb[256]; 29 extern const float sk_linear_from_srgb[256];
30 30
31 static inline Sk4f sk_linear_to_srgb(const Sk4f& x) { 31 static inline Sk4f sk_linear_to_srgb(const Sk4f& x) {
32 // Approximation of the sRGB gamma curve (within 1 when scaled to 8-bit pixe ls). 32 // Approximation of the sRGB gamma curve (within 1 when scaled to 8-bit pixe ls).
33 // For 0.00000f <= x < 0.00349f, 12.92 * x 33 // Tuned by brute force to minimize the number of bytes that fail to round t rip, here 0.
34 // For 0.00349f <= x <= 1.00000f, 0.679*(x.^0.5) + 0.423*x.^(0.25) - 0.10 1 34 //
35 // Note that 0.00349 was selected because it is a point where both functions produce the 35 // TODO: It was easy enough to find these constants that we should probably further tune
36 // same pixel value when rounded. 36 // to find one that round trips all bytes correctly while minimizing some ov erall error.
mtklein 2016/07/20 00:57:50 Another thought for a follow up: 12.93, -0.097, 0
37
37 auto rsqrt = x.rsqrt(), 38 auto rsqrt = x.rsqrt(),
38 sqrt = rsqrt.invert(), 39 sqrt = rsqrt.invert(),
39 ftrt = rsqrt.rsqrt(); 40 ftrt = rsqrt.rsqrt();
40 41
41 auto lo = (12.92f * 255.0f) * x; 42 auto lo = (12.31f * 255.0f) * x;
42 43
43 auto hi = (-0.101115084998961f * 255.0f) + 44 auto hi = (-0.099f * 255.0f)
44 (+0.678513029959381f * 255.0f) * sqrt + 45 + (+0.689f * 255.0f) * sqrt
45 (+0.422602055039580f * 255.0f) * ftrt; 46 + (+0.411f * 255.0f) * ftrt;
46 47
47 return (x < 0.00349f).thenElse(lo, hi); 48 return (x < 0.005f).thenElse(lo, hi);
48 } 49 }
49 50
50 #endif//SkSRGB_DEFINED 51 #endif//SkSRGB_DEFINED
OLDNEW
« no previous file with comments | « no previous file | tests/SRGBTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698