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

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: 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 341 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));
369 }
370
371 void ImageDecoder::setColorSpaceAndComputeTransform(
372 sk_sp<SkColorSpace> srcSpace) {
373 if (!srcSpace) {
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