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

Side by Side Diff: src/codec/SkPngCodec.cpp

Issue 2408133009: Add NewRGB() with float gamma to SkColorSpace public API
Patch Set: Created 4 years, 2 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 | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace.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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkColorSpace_Base.h" 11 #include "SkColorSpace.h"
12 #include "SkColorTable.h" 12 #include "SkColorTable.h"
13 #include "SkMath.h" 13 #include "SkMath.h"
14 #include "SkOpts.h" 14 #include "SkOpts.h"
15 #include "SkPngCodec.h" 15 #include "SkPngCodec.h"
16 #include "SkPoint3.h" 16 #include "SkPoint3.h"
17 #include "SkSize.h" 17 #include "SkSize.h"
18 #include "SkStream.h" 18 #include "SkStream.h"
19 #include "SkSwizzler.h" 19 #include "SkSwizzler.h"
20 #include "SkTemplates.h" 20 #include "SkTemplates.h"
21 #include "SkUtils.h" 21 #include "SkUtils.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 if (!primaries.toXYZD50(&toXYZD50)) { 380 if (!primaries.toXYZD50(&toXYZD50)) {
381 toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50); 381 toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50);
382 } 382 }
383 383
384 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { 384 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
385 float value = png_inverted_fixed_point_to_float(gamma); 385 float value = png_inverted_fixed_point_to_float(gamma);
386 gammas[0] = value; 386 gammas[0] = value;
387 gammas[1] = value; 387 gammas[1] = value;
388 gammas[2] = value; 388 gammas[2] = value;
389 389
390 return SkColorSpace_Base::NewRGB(gammas, toXYZD50); 390 return SkColorSpace::NewRGB(gammas, toXYZD50);
391 } 391 }
392 392
393 // Default to sRGB gamma if the image has color space information, 393 // Default to sRGB gamma if the image has color space information,
394 // but does not specify gamma. 394 // but does not specify gamma.
395 return SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZ D50); 395 return SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZ D50);
396 } 396 }
397 397
398 // Last, check for gamma. 398 // Last, check for gamma.
399 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { 399 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
400 400
401 // Set the gammas. 401 // Set the gammas.
402 float value = png_inverted_fixed_point_to_float(gamma); 402 float value = png_inverted_fixed_point_to_float(gamma);
403 gammas[0] = value; 403 gammas[0] = value;
404 gammas[1] = value; 404 gammas[1] = value;
405 gammas[2] = value; 405 gammas[2] = value;
406 406
407 // Since there is no cHRM, we will guess sRGB gamut. 407 // Since there is no cHRM, we will guess sRGB gamut.
408 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor); 408 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
409 toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50); 409 toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50);
410 410
411 return SkColorSpace_Base::NewRGB(gammas, toXYZD50); 411 return SkColorSpace::NewRGB(gammas, toXYZD50);
412 } 412 }
413 413
414 #endif // LIBPNG >= 1.6 414 #endif // LIBPNG >= 1.6
415 415
416 // Report that there is no color space information in the PNG. SkPngCodec i s currently 416 // Report that there is no color space information in the PNG. SkPngCodec i s currently
417 // implemented to guess sRGB in this case. 417 // implemented to guess sRGB in this case.
418 return nullptr; 418 return nullptr;
419 } 419 }
420 420
421 void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) { 421 void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 SkCodec* outCodec = nullptr; 1259 SkCodec* outCodec = nullptr;
1260 if (read_header(streamDeleter.get(), chunkReader, &outCodec, nullptr, nullpt r)) { 1260 if (read_header(streamDeleter.get(), chunkReader, &outCodec, nullptr, nullpt r)) {
1261 // Codec has taken ownership of the stream. 1261 // Codec has taken ownership of the stream.
1262 SkASSERT(outCodec); 1262 SkASSERT(outCodec);
1263 streamDeleter.release(); 1263 streamDeleter.release();
1264 return outCodec; 1264 return outCodec;
1265 } 1265 }
1266 1266
1267 return nullptr; 1267 return nullptr;
1268 } 1268 }
OLDNEW
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698