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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 2454123002: Refactor image decoders to use 'colorSpace' instead of 'colorProfile' (Closed)
Patch Set: More profile -> space 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 // This needs to be updated if we ever add a matches*Signature() which requires 66 // This needs to be updated if we ever add a matches*Signature() which requires
67 // more characters. 67 // more characters.
68 static constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 68 static constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
69 69
70 std::unique_ptr<ImageDecoder> ImageDecoder::create( 70 std::unique_ptr<ImageDecoder> ImageDecoder::create(
71 PassRefPtr<SegmentReader> passData, 71 PassRefPtr<SegmentReader> passData,
72 bool dataComplete, 72 bool dataComplete,
73 AlphaOption alphaOption, 73 AlphaOption alphaOption,
74 GammaAndColorProfileOption colorOptions) { 74 ColorSpaceOption colorOptions) {
75 RefPtr<SegmentReader> data = passData; 75 RefPtr<SegmentReader> data = passData;
76 76
77 // We need at least kLongestSignatureLength bytes to run the signature 77 // We need at least kLongestSignatureLength bytes to run the signature
78 // matcher. 78 // matcher.
79 if (data->size() < kLongestSignatureLength) 79 if (data->size() < kLongestSignatureLength)
80 return nullptr; 80 return nullptr;
81 81
82 const size_t maxDecodedBytes = 82 const size_t maxDecodedBytes =
83 Platform::current() ? Platform::current()->maxDecodedImageBytes() 83 Platform::current() ? Platform::current()->maxDecodedImageBytes()
84 : noDecodedImageByteLimit; 84 : noDecodedImageByteLimit;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return; 352 return;
353 353
354 gTargetColorSpace = 354 gTargetColorSpace =
355 SkColorSpace::NewICC(profile.data(), profile.size()).release(); 355 SkColorSpace::NewICC(profile.data(), profile.size()).release();
356 356
357 // UMA statistics. 357 // UMA statistics.
358 BitmapImageMetrics::countGamma(gTargetColorSpace); 358 BitmapImageMetrics::countGamma(gTargetColorSpace);
359 } 359 }
360 360
361 void ImageDecoder::setColorSpaceAndComputeTransform(const char* iccData, 361 void ImageDecoder::setColorSpaceAndComputeTransform(const char* iccData,
362 unsigned iccLength, 362 unsigned iccLength) {
363 bool useSRGB) {
364 // Sub-classes should not call this if they were instructed to ignore embedded 363 // Sub-classes should not call this if they were instructed to ignore embedded
365 // color profiles. 364 // color profiles.
366 DCHECK(!m_ignoreGammaAndColorProfile); 365 DCHECK(!m_ignoreColorSpace);
367 366
368 m_colorProfile.assign(iccData, iccLength); 367 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData, iccLength);
369 m_hasColorProfile = true; 368 setColorSpaceAndComputeTransform(std::move(srcSpace));
f(malita) 2016/10/27 17:57:24 nit: I would just inline these and skip the move.
msarett 2016/10/27 18:21:42 sgtm
369 }
370
371 void ImageDecoder::setColorSpaceAndComputeTransform(
372 sk_sp<SkColorSpace> srcSpace) {
373 if (!srcSpace) {
f(malita) 2016/10/27 17:57:24 Why is this early out needed? Don't we want to cl
msarett 2016/10/27 18:21:42 I think it makes sense to check before attempting
374 return;
375 }
376
377 m_srcSpace = srcSpace;
370 378
371 // With color correct rendering, we do not transform to the output color space 379 // With color correct rendering, we do not transform to the output color space
372 // at decode time. Instead, we tag the raw image pixels and pass the tagged 380 // at decode time. Instead, we tag the raw image pixels and pass the tagged
373 // SkImage to Skia. 381 // SkImage to Skia.
374 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) 382 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled())
375 return; 383 return;
376 384
377 m_sourceToOutputDeviceColorTransform = nullptr; 385 m_sourceToOutputDeviceColorTransform = nullptr;
378 386
379 // Create the input profile.
380 sk_sp<SkColorSpace> srcSpace = nullptr;
381 if (useSRGB) {
382 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
383 } else {
384 srcSpace = SkColorSpace::NewICC(iccData, iccLength);
385 }
386
387 if (!srcSpace)
388 return;
389
390 // Take a lock around initializing and accessing the global device color 387 // Take a lock around initializing and accessing the global device color
391 // profile. 388 // profile.
392 SpinLock::Guard guard(gTargetColorSpaceLock); 389 SpinLock::Guard guard(gTargetColorSpaceLock);
393 390
394 // Initialize the output device profile to sRGB if it has not yet been 391 // Initialize the output device profile to sRGB if it has not yet been
395 // initialized. 392 // initialized.
396 if (!gTargetColorSpace) { 393 if (!gTargetColorSpace) {
397 gTargetColorSpace = 394 gTargetColorSpace =
398 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).release(); 395 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).release();
399 } 396 }
400 397
401 if (SkColorSpace::Equals(srcSpace.get(), gTargetColorSpace)) { 398 if (SkColorSpace::Equals(srcSpace.get(), gTargetColorSpace)) {
402 return; 399 return;
403 } 400 }
404 401
405 m_sourceToOutputDeviceColorTransform = 402 m_sourceToOutputDeviceColorTransform =
406 SkColorSpaceXform::New(srcSpace.get(), gTargetColorSpace); 403 SkColorSpaceXform::New(srcSpace.get(), gTargetColorSpace);
407 } 404 }
408 405
409 } // namespace blink 406 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698