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

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: Fix legacy ImageFrame 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) { 363 setColorSpaceAndComputeTransform(SkColorSpace::NewICC(iccData, iccLength));
364 // Sub-classes should not call this if they were instructed to ignore embedded 364 }
365 // color profiles.
366 DCHECK(!m_ignoreGammaAndColorProfile);
367 365
368 m_colorProfile.assign(iccData, iccLength); 366 void ImageDecoder::setColorSpaceAndComputeTransform(
369 m_hasColorProfile = true; 367 sk_sp<SkColorSpace> srcSpace) {
368 DCHECK(!m_ignoreColorSpace);
369
370 m_srcSpace = srcSpace;
371 m_sourceToOutputDeviceColorTransform = nullptr;
370 372
371 // With color correct rendering, we do not transform to the output color space 373 // 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 374 // at decode time. Instead, we tag the raw image pixels and pass the tagged
373 // SkImage to Skia. 375 // SkImage to Skia.
374 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) 376 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled())
375 return; 377 return;
376 378
377 m_sourceToOutputDeviceColorTransform = nullptr; 379 if (!m_srcSpace)
378
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; 380 return;
389 381
390 // Take a lock around initializing and accessing the global device color 382 // Take a lock around initializing and accessing the global device color
391 // profile. 383 // profile.
392 SpinLock::Guard guard(gTargetColorSpaceLock); 384 SpinLock::Guard guard(gTargetColorSpaceLock);
393 385
394 // Initialize the output device profile to sRGB if it has not yet been 386 // Initialize the output device profile to sRGB if it has not yet been
395 // initialized. 387 // initialized.
396 if (!gTargetColorSpace) { 388 if (!gTargetColorSpace) {
397 gTargetColorSpace = 389 gTargetColorSpace =
398 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).release(); 390 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).release();
399 } 391 }
400 392
401 if (SkColorSpace::Equals(srcSpace.get(), gTargetColorSpace)) { 393 if (SkColorSpace::Equals(srcSpace.get(), gTargetColorSpace)) {
402 return; 394 return;
403 } 395 }
404 396
405 m_sourceToOutputDeviceColorTransform = 397 m_sourceToOutputDeviceColorTransform =
406 SkColorSpaceXform::New(srcSpace.get(), gTargetColorSpace); 398 SkColorSpaceXform::New(srcSpace.get(), gTargetColorSpace);
407 } 399 }
408 400
409 } // namespace blink 401 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698