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

Side by Side Diff: gm/labpcsdemo.cpp

Issue 2444553002: Refactored SkColorSpace_A2B to allow arbitrary ordering of elements (Closed)
Patch Set: responding to comments Created 4 years, 1 month 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 | src/core/SkColorSpace_A2B.h » ('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 #include <cmath> 8 #include <cmath>
9 #include "gm.h" 9 #include "gm.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 const int imageHeight = codec->getInfo().height(); 168 const int imageHeight = codec->getInfo().height();
169 // Using nullptr as the color space instructs the codec to decode in leg acy mode, 169 // Using nullptr as the color space instructs the codec to decode in leg acy mode,
170 // meaning that we will get the raw encoded bytes without any color corr ection. 170 // meaning that we will get the raw encoded bytes without any color corr ection.
171 SkImageInfo imageInfo = SkImageInfo::Make(imageWidth, imageHeight, kN32_ SkColorType, 171 SkImageInfo imageInfo = SkImageInfo::Make(imageWidth, imageHeight, kN32_ SkColorType,
172 kOpaque_SkAlphaType, nullptr); 172 kOpaque_SkAlphaType, nullptr);
173 bitmap.allocPixels(imageInfo); 173 bitmap.allocPixels(imageInfo);
174 codec->getPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes()); 174 codec->getPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes());
175 if (convertLabToXYZ) { 175 if (convertLabToXYZ) {
176 SkASSERT(SkColorSpace_Base::Type::kA2B == as_CSB(colorSpace)->type() ); 176 SkASSERT(SkColorSpace_Base::Type::kA2B == as_CSB(colorSpace)->type() );
177 SkColorSpace_A2B& cs = *static_cast<SkColorSpace_A2B*>(colorSpace.ge t()); 177 SkColorSpace_A2B& cs = *static_cast<SkColorSpace_A2B*>(colorSpace.ge t());
178 const SkColorLookUpTable* colorLUT = nullptr;
178 bool printConversions = false; 179 bool printConversions = false;
179 SkASSERT(cs.colorLUT());
180 // We're skipping evaluating the TRCs and the matrix here since they aren't 180 // We're skipping evaluating the TRCs and the matrix here since they aren't
181 // in the ICC profile initially used here. 181 // in the ICC profile initially used here.
182 SkASSERT(kLinear_SkGammaNamed == cs.aCurveNamed()); 182 for (size_t e = 0; e < cs.count(); ++e) {
183 SkASSERT(kLinear_SkGammaNamed == cs.mCurveNamed()); 183 switch (cs.element(e).type()) {
184 SkASSERT(kLinear_SkGammaNamed == cs.bCurveNamed()); 184 case SkColorSpace_A2B::Element::Type::kGammaNamed:
185 SkASSERT(cs.matrix().isIdentity()); 185 SkASSERT(kLinear_SkGammaNamed == cs.element(e).gammaName d());
186 break;
187 case SkColorSpace_A2B::Element::Type::kGammas:
188 SkASSERT(false);
189 break;
190 case SkColorSpace_A2B::Element::Type::kCLUT:
191 colorLUT = &cs.element(e).colorLUT();
192 break;
193 case SkColorSpace_A2B::Element::Type::kMatrix:
194 SkASSERT(cs.element(e).matrix().isIdentity());
195 break;
196 }
197 }
198 SkASSERT(colorLUT);
186 for (int y = 0; y < imageHeight; ++y) { 199 for (int y = 0; y < imageHeight; ++y) {
187 for (int x = 0; x < imageWidth; ++x) { 200 for (int x = 0; x < imageWidth; ++x) {
188 uint32_t& p = *bitmap.getAddr32(x, y); 201 uint32_t& p = *bitmap.getAddr32(x, y);
189 const int r = SkColorGetR(p); 202 const int r = SkColorGetR(p);
190 const int g = SkColorGetG(p); 203 const int g = SkColorGetG(p);
191 const int b = SkColorGetB(p); 204 const int b = SkColorGetB(p);
192 if (printConversions) { 205 if (printConversions) {
193 SkColorSpacePrintf("\nraw = (%d, %d, %d)\t", r, g, b); 206 SkColorSpacePrintf("\nraw = (%d, %d, %d)\t", r, g, b);
194 } 207 }
195 208
196 float lab[4] = { r * (1.f/255.f), g * (1.f/255.f), b * (1.f/ 255.f), 1.f }; 209 float lab[4] = { r * (1.f/255.f), g * (1.f/255.f), b * (1.f/ 255.f), 1.f };
197 210
198 interp_3d_clut(lab, lab, cs.colorLUT()); 211 interp_3d_clut(lab, lab, colorLUT);
199 212
200 // Lab has ranges [0,100] for L and [-128,127] for a and b 213 // Lab has ranges [0,100] for L and [-128,127] for a and b
201 // but the ICC profile loader stores as [0,1]. The ICC 214 // but the ICC profile loader stores as [0,1]. The ICC
202 // specifies an offset of -128 to convert. 215 // specifies an offset of -128 to convert.
203 // note: formula could be adjusted to remove this conversion , 216 // note: formula could be adjusted to remove this conversion ,
204 // but for now let's keep it like this for clarity unt il 217 // but for now let's keep it like this for clarity unt il
205 // an optimized version is added. 218 // an optimized version is added.
206 lab[0] *= 100.f; 219 lab[0] *= 100.f;
207 lab[1] = 255.f * lab[1] - 128.f; 220 lab[1] = 255.f * lab[1] - 128.f;
208 lab[2] = 255.f * lab[2] - 128.f; 221 lab[2] = 255.f * lab[2] - 128.f;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 276 }
264 277
265 private: 278 private:
266 const int fWidth; 279 const int fWidth;
267 const int fHeight; 280 const int fHeight;
268 281
269 typedef skiagm::GM INHERITED; 282 typedef skiagm::GM INHERITED;
270 }; 283 };
271 284
272 DEF_GM( return new LabPCSDemoGM; ) 285 DEF_GM( return new LabPCSDemoGM; )
OLDNEW
« no previous file with comments | « no previous file | src/core/SkColorSpace_A2B.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698