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

Side by Side Diff: src/opts/SkColorXform_opts.h

Issue 2174493002: Add color space xform support to SkJpegCodec (includes F16!) (Closed) Base URL: https://skia.googlesource.com/skia.git@drop
Patch Set: Fix MSAN suppression Created 4 years, 4 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 | « src/core/SkOpts.cpp ('k') | src/opts/SkOpts_sse41.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 SkColorXform_opts_DEFINED 8 #ifndef SkColorXform_opts_DEFINED
9 #define SkColorXform_opts_DEFINED 9 #define SkColorXform_opts_DEFINED
10 10
(...skipping 23 matching lines...) Expand all
34 enum DstGamma { 34 enum DstGamma {
35 // 8888 35 // 8888
36 kSRGB_DstGamma, 36 kSRGB_DstGamma,
37 k2Dot2_DstGamma, 37 k2Dot2_DstGamma,
38 kTable_DstGamma, 38 kTable_DstGamma,
39 39
40 // F16 40 // F16
41 kLinear_DstGamma, 41 kLinear_DstGamma,
42 }; 42 };
43 43
44 template <DstGamma kDstGamma> 44 template <DstGamma kDstGamma, bool kSwapRB>
45 static void color_xform_RGB1(void* dst, const uint32_t* src, int len, 45 static void color_xform_RGB1(void* dst, const uint32_t* src, int len,
46 const float* const srcTables[3], const float matrix [16], 46 const float* const srcTables[3], const float matrix [16],
47 const uint8_t* const dstTables[3]) { 47 const uint8_t* const dstTables[3]) {
48 int kRShift = 0;
49 int kGShift = 8;
50 int kBShift = 16;
51 int kAShift = 24;
52 if (kSwapRB) {
53 kBShift = 0;
54 kRShift = 16;
55 }
56
48 Sk4f rXgXbX = Sk4f::Load(matrix + 0), 57 Sk4f rXgXbX = Sk4f::Load(matrix + 0),
49 rYgYbY = Sk4f::Load(matrix + 4), 58 rYgYbY = Sk4f::Load(matrix + 4),
50 rZgZbZ = Sk4f::Load(matrix + 8), 59 rZgZbZ = Sk4f::Load(matrix + 8),
51 rTgTbT = Sk4f::Load(matrix + 12); 60 rTgTbT = Sk4f::Load(matrix + 12);
52 61
53 if (len >= 4) { 62 if (len >= 4) {
54 Sk4f reds, greens, blues; 63 Sk4f reds, greens, blues;
55 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { 64 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] {
56 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], 65 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF],
57 srcTables[0][(src[1] >> 0) & 0xFF], 66 srcTables[0][(src[1] >> 0) & 0xFF],
(...skipping 12 matching lines...) Expand all
70 }; 79 };
71 80
72 Sk4f dstReds, dstGreens, dstBlues; 81 Sk4f dstReds, dstGreens, dstBlues;
73 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl ues, &rXgXbX, 82 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl ues, &rXgXbX,
74 &rYgYbY, &rZgZbZ, &rTgTbT] { 83 &rYgYbY, &rZgZbZ, &rTgTbT] {
75 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues + rT gTbT[0]; 84 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues + rT gTbT[0];
76 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues + rT gTbT[1]; 85 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues + rT gTbT[1];
77 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues + rT gTbT[2]; 86 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues + rT gTbT[2];
78 }; 87 };
79 88
80 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables] { 89 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables, kRShi ft, kGShift,
90 kBShift, kAShift] {
81 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { 91 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) {
82 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGa mma) ? 92 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGa mma) ?
83 sk_linear_to_srgb_needs_trunc : linear_to_2dot2; 93 sk_linear_to_srgb_needs_trunc : linear_to_2dot2;
84 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma ) ? 94 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma ) ?
85 Sk4f_trunc : Sk4f_round; 95 Sk4f_trunc : Sk4f_round;
86 96
87 dstReds = linear_to_curve(dstReds); 97 dstReds = linear_to_curve(dstReds);
88 dstGreens = linear_to_curve(dstGreens); 98 dstGreens = linear_to_curve(dstGreens);
89 dstBlues = linear_to_curve(dstBlues); 99 dstBlues = linear_to_curve(dstBlues);
90 100
91 dstReds = sk_clamp_0_255(dstReds); 101 dstReds = sk_clamp_0_255(dstReds);
92 dstGreens = sk_clamp_0_255(dstGreens); 102 dstGreens = sk_clamp_0_255(dstGreens);
93 dstBlues = sk_clamp_0_255(dstBlues); 103 dstBlues = sk_clamp_0_255(dstBlues);
94 104
95 auto rgba = (float_to_int(dstReds) << SK_R32_SHIFT) 105 auto rgba = (float_to_int(dstReds) << kRShift)
96 | (float_to_int(dstGreens) << SK_G32_SHIFT) 106 | (float_to_int(dstGreens) << kGShift)
97 | (float_to_int(dstBlues) << SK_B32_SHIFT) 107 | (float_to_int(dstBlues) << kBShift)
98 | (Sk4i{0xFF} << SK_A32_SHIFT); 108 | (Sk4i{0xFF} << kAShift);
99 rgba.store((uint32_t*) dst); 109 rgba.store((uint32_t*) dst);
100 110
101 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); 111 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t));
102 } else if (kTable_DstGamma == kDstGamma) { 112 } else if (kTable_DstGamma == kDstGamma) {
103 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0 f), 1023.0f); 113 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0 f), 1023.0f);
104 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0 f), 1023.0f); 114 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0 f), 1023.0f);
105 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0 f), 1023.0f); 115 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0 f), 1023.0f);
106 116
107 Sk4i indicesReds = Sk4f_round(scaledReds); 117 Sk4i indicesReds = Sk4f_round(scaledReds);
108 Sk4i indicesGreens = Sk4f_round(scaledGreens); 118 Sk4i indicesGreens = Sk4f_round(scaledGreens);
109 Sk4i indicesBlues = Sk4f_round(scaledBlues); 119 Sk4i indicesBlues = Sk4f_round(scaledBlues);
110 120
111 uint32_t* dst32 = (uint32_t*) dst; 121 uint32_t* dst32 = (uint32_t*) dst;
112 dst32[0] = dstTables[0][indicesReds [0]] << SK_R32_SHIFT 122 dst32[0] = dstTables[0][indicesReds [0]] << kRShift
113 | dstTables[1][indicesGreens[0]] << SK_G32_SHIFT 123 | dstTables[1][indicesGreens[0]] << kGShift
114 | dstTables[2][indicesBlues [0]] << SK_B32_SHIFT 124 | dstTables[2][indicesBlues [0]] << kBShift
115 | 0xFF << SK_A32_SHIFT; 125 | 0xFF << kAShift;
116 dst32[1] = dstTables[0][indicesReds [1]] << SK_R32_SHIFT 126 dst32[1] = dstTables[0][indicesReds [1]] << kRShift
117 | dstTables[1][indicesGreens[1]] << SK_G32_SHIFT 127 | dstTables[1][indicesGreens[1]] << kGShift
118 | dstTables[2][indicesBlues [1]] << SK_B32_SHIFT 128 | dstTables[2][indicesBlues [1]] << kBShift
119 | 0xFF << SK_A32_SHIFT; 129 | 0xFF << kAShift;
120 dst32[2] = dstTables[0][indicesReds [2]] << SK_R32_SHIFT 130 dst32[2] = dstTables[0][indicesReds [2]] << kRShift
121 | dstTables[1][indicesGreens[2]] << SK_G32_SHIFT 131 | dstTables[1][indicesGreens[2]] << kGShift
122 | dstTables[2][indicesBlues [2]] << SK_B32_SHIFT 132 | dstTables[2][indicesBlues [2]] << kBShift
123 | 0xFF << SK_A32_SHIFT; 133 | 0xFF << kAShift;
124 dst32[3] = dstTables[0][indicesReds [3]] << SK_R32_SHIFT 134 dst32[3] = dstTables[0][indicesReds [3]] << kRShift
125 | dstTables[1][indicesGreens[3]] << SK_G32_SHIFT 135 | dstTables[1][indicesGreens[3]] << kGShift
126 | dstTables[2][indicesBlues [3]] << SK_B32_SHIFT 136 | dstTables[2][indicesBlues [3]] << kBShift
127 | 0xFF << SK_A32_SHIFT; 137 | 0xFF << kAShift;
128 138
129 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); 139 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t));
130 } else { 140 } else {
131 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds), 141 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds),
132 SkFloatToHalf_finite(dstGreens), 142 SkFloatToHalf_finite(dstGreens),
133 SkFloatToHalf_finite(dstBlues), 143 SkFloatToHalf_finite(dstBlues),
134 SK_Half1); 144 SK_Half1);
135 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t)); 145 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t));
136 } 146 }
137 }; 147 };
(...skipping 22 matching lines...) Expand all
160 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? 170 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ?
161 sk_linear_to_srgb_needs_trunc : linear_to_2dot2; 171 sk_linear_to_srgb_needs_trunc : linear_to_2dot2;
162 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? 172 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ?
163 Sk4f_trunc : Sk4f_round; 173 Sk4f_trunc : Sk4f_round;
164 174
165 dstPixel = sk_clamp_0_255(linear_to_curve(dstPixel)); 175 dstPixel = sk_clamp_0_255(linear_to_curve(dstPixel));
166 176
167 uint32_t rgba; 177 uint32_t rgba;
168 SkNx_cast<uint8_t>(float_to_int(dstPixel)).store(&rgba); 178 SkNx_cast<uint8_t>(float_to_int(dstPixel)).store(&rgba);
169 rgba |= 0xFF000000; 179 rgba |= 0xFF000000;
170 *((uint32_t*) dst) = SkSwizzle_RGBA_to_PMColor(rgba); 180 if (kSwapRB) {
181 *((uint32_t*) dst) = SkSwizzle_RB(rgba);
182 } else {
183 *((uint32_t*) dst) = rgba;
184 }
171 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); 185 dst = SkTAddOffset<void>(dst, sizeof(uint32_t));
172 } else if (kTable_DstGamma == kDstGamma) { 186 } else if (kTable_DstGamma == kDstGamma) {
173 Sk4f scaledPixel = Sk4f::Min(Sk4f::Max(1023.0f * dstPixel, 0.0f), 10 23.0f); 187 Sk4f scaledPixel = Sk4f::Min(Sk4f::Max(1023.0f * dstPixel, 0.0f), 10 23.0f);
174 188
175 Sk4i indices = Sk4f_round(scaledPixel); 189 Sk4i indices = Sk4f_round(scaledPixel);
176 190
177 *((uint32_t*) dst) = dstTables[0][indices[0]] << SK_R32_SHIFT 191 *((uint32_t*) dst) = dstTables[0][indices[0]] << kRShift
178 | dstTables[1][indices[1]] << SK_G32_SHIFT 192 | dstTables[1][indices[1]] << kGShift
179 | dstTables[2][indices[2]] << SK_B32_SHIFT 193 | dstTables[2][indices[2]] << kBShift
180 | 0xFF << SK_A32_SHIFT; 194 | 0xFF << kAShift;
181 195
182 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); 196 dst = SkTAddOffset<void>(dst, sizeof(uint32_t));
183 } else { 197 } else {
184 uint64_t rgba; 198 uint64_t rgba;
185 SkFloatToHalf_finite(dstPixel).store(&rgba); 199 SkFloatToHalf_finite(dstPixel).store(&rgba);
186 rgba |= static_cast<uint64_t>(SK_Half1) << 48; 200 rgba |= static_cast<uint64_t>(SK_Half1) << 48;
187 *((uint64_t*) dst) = rgba; 201 *((uint64_t*) dst) = rgba;
188 dst = SkTAddOffset<void>(dst, sizeof(uint64_t)); 202 dst = SkTAddOffset<void>(dst, sizeof(uint64_t));
189 } 203 }
190 204
191 src += 1; 205 src += 1;
192 len -= 1; 206 len -= 1;
193 } 207 }
194 } 208 }
195 209
196 static void color_xform_RGB1_to_2dot2(uint32_t* dst, const uint32_t* src, int le n, 210 static void color_xform_RGB1_to_2dot2(uint32_t* dst, const uint32_t* src, int le n,
197 const float* const srcTables[3], const flo at matrix[16]) { 211 const float* const srcTables[3], const flo at matrix[16]) {
198 color_xform_RGB1<k2Dot2_DstGamma>(dst, src, len, srcTables, matrix, nullptr) ; 212 color_xform_RGB1<k2Dot2_DstGamma, false>(dst, src, len, srcTables, matrix, n ullptr);
199 } 213 }
200 214
201 static void color_xform_RGB1_to_srgb(uint32_t* dst, const uint32_t* src, int len , 215 static void color_xform_RGB1_to_srgb(uint32_t* dst, const uint32_t* src, int len ,
202 const float* const srcTables[3], const floa t matrix[16]) { 216 const float* const srcTables[3], const floa t matrix[16]) {
203 color_xform_RGB1<kSRGB_DstGamma>(dst, src, len, srcTables, matrix, nullptr); 217 color_xform_RGB1<kSRGB_DstGamma, false>(dst, src, len, srcTables, matrix, nu llptr);
204 } 218 }
205 219
206 static void color_xform_RGB1_to_table(uint32_t* dst, const uint32_t* src, int le n, 220 static void color_xform_RGB1_to_table(uint32_t* dst, const uint32_t* src, int le n,
207 const float* const srcTables[3], const flo at matrix[16], 221 const float* const srcTables[3], const flo at matrix[16],
208 const uint8_t* const dstTables[3]) { 222 const uint8_t* const dstTables[3]) {
209 color_xform_RGB1<kTable_DstGamma>(dst, src, len, srcTables, matrix, dstTable s); 223 color_xform_RGB1<kTable_DstGamma, false>(dst, src, len, srcTables, matrix, d stTables);
210 } 224 }
211 225
212 static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l en, 226 static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l en,
213 const float* const srcTables[3], const fl oat matrix[16]) { 227 const float* const srcTables[3], const fl oat matrix[16]) {
214 color_xform_RGB1<kLinear_DstGamma>(dst, src, len, srcTables, matrix, nullptr ); 228 color_xform_RGB1<kLinear_DstGamma, false>(dst, src, len, srcTables, matrix, nullptr);
229 }
230
231 static void color_xform_RGB1_to_2dot2_swaprb(uint32_t* dst, const uint32_t* src, int len,
232 const float* const srcTables[3],
233 const float matrix[16]) {
234 color_xform_RGB1<k2Dot2_DstGamma, true>(dst, src, len, srcTables, matrix, nu llptr);
235 }
236
237 static void color_xform_RGB1_to_srgb_swaprb(uint32_t* dst, const uint32_t* src, int len,
238 const float* const srcTables[3],
239 const float matrix[16]) {
240 color_xform_RGB1<kSRGB_DstGamma, true>(dst, src, len, srcTables, matrix, nul lptr);
241 }
242
243 static void color_xform_RGB1_to_table_swaprb(uint32_t* dst, const uint32_t* src, int len,
244 const float* const srcTables[3],
245 const float matrix[16],
246 const uint8_t* const dstTables[3]) {
247 color_xform_RGB1<kTable_DstGamma, true>(dst, src, len, srcTables, matrix, ds tTables);
215 } 248 }
216 249
217 } // namespace SK_OPTS_NS 250 } // namespace SK_OPTS_NS
218 251
219 #endif // SkColorXform_opts_DEFINED 252 #endif // SkColorXform_opts_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkOpts.cpp ('k') | src/opts/SkOpts_sse41.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698