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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/BitmapImage.cpp

Issue 2530443004: Add target color profile to BitmapImage::draw (Closed)
Patch Set: Created 4 years 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) 2006 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 size_t BitmapImage::totalFrameBytes() { 125 size_t BitmapImage::totalFrameBytes() {
126 const size_t numFrames = frameCount(); 126 const size_t numFrames = frameCount();
127 size_t totalBytes = 0; 127 size_t totalBytes = 0;
128 for (size_t i = 0; i < numFrames; ++i) 128 for (size_t i = 0; i < numFrames; ++i)
129 totalBytes += m_source.frameBytesAtIndex(i); 129 totalBytes += m_source.frameBytesAtIndex(i);
130 return totalBytes; 130 return totalBytes;
131 } 131 }
132 132
133 sk_sp<SkImage> BitmapImage::decodeAndCacheFrame(size_t index) { 133 sk_sp<SkImage> BitmapImage::decodeAndCacheFrame(
134 size_t index,
135 sk_sp<SkColorSpace> targetColorSpace) {
134 size_t numFrames = frameCount(); 136 size_t numFrames = frameCount();
135 if (m_frames.size() < numFrames) 137 if (m_frames.size() < numFrames)
136 m_frames.grow(numFrames); 138 m_frames.grow(numFrames);
137 139
138 // We are caching frame snapshots. This is OK even for partially decoded 140 // We are caching frame snapshots. This is OK even for partially decoded
139 // frames, as they are cleared by dataChanged() when new data arrives. 141 // frames, as they are cleared by dataChanged() when new data arrives.
140 sk_sp<SkImage> image = m_source.createFrameAtIndex(index); 142 sk_sp<SkImage> image = m_source.createFrameAtIndex(index, targetColorSpace);
141 m_cachedFrame = image; 143 m_cachedFrame = image;
142 m_cachedFrameIndex = index; 144 m_cachedFrameIndex = index;
145 m_cachedFrameColorSpace = std::move(targetColorSpace);
143 146
144 m_frames[index].m_orientation = m_source.orientationAtIndex(index); 147 m_frames[index].m_orientation = m_source.orientationAtIndex(index);
145 m_frames[index].m_haveMetadata = true; 148 m_frames[index].m_haveMetadata = true;
146 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index); 149 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index);
147 if (repetitionCount(false) != cAnimationNone) 150 if (repetitionCount(false) != cAnimationNone)
148 m_frames[index].m_duration = m_source.frameDurationAtIndex(index); 151 m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
149 m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index); 152 m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
150 m_frames[index].m_frameBytes = m_source.frameBytesAtIndex(index); 153 m_frames[index].m_frameBytes = m_source.frameBytesAtIndex(index);
151 154
152 notifyMemoryChanged(); 155 notifyMemoryChanged();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return m_source.filenameExtension(); 242 return m_source.filenameExtension();
240 } 243 }
241 244
242 void BitmapImage::draw( 245 void BitmapImage::draw(
243 SkCanvas* canvas, 246 SkCanvas* canvas,
244 const SkPaint& paint, 247 const SkPaint& paint,
245 const FloatRect& dstRect, 248 const FloatRect& dstRect,
246 const FloatRect& srcRect, 249 const FloatRect& srcRect,
247 RespectImageOrientationEnum shouldRespectImageOrientation, 250 RespectImageOrientationEnum shouldRespectImageOrientation,
248 ImageClampingMode clampMode) { 251 ImageClampingMode clampMode) {
252 drawInColorSpace(canvas, paint, dstRect, srcRect,
253 shouldRespectImageOrientation, clampMode, nullptr);
254 }
255
256 void BitmapImage::drawInColorSpace(
257 SkCanvas* canvas,
258 const SkPaint& paint,
259 const FloatRect& dstRect,
260 const FloatRect& srcRect,
261 RespectImageOrientationEnum shouldRespectImageOrientation,
262 ImageClampingMode clampMode,
263 sk_sp<SkColorSpace> targetColorSpace) {
249 TRACE_EVENT0("skia", "BitmapImage::draw"); 264 TRACE_EVENT0("skia", "BitmapImage::draw");
250 265
251 sk_sp<SkImage> image = imageForCurrentFrame(); 266 sk_sp<SkImage> image = frameAtIndex(currentFrame(), targetColorSpace);
252 if (!image) 267 if (!image)
253 return; // It's too early and we don't have an image yet. 268 return; // It's too early and we don't have an image yet.
254 269
255 FloatRect adjustedSrcRect = srcRect; 270 FloatRect adjustedSrcRect = srcRect;
256 adjustedSrcRect.intersect(SkRect::Make(image->bounds())); 271 adjustedSrcRect.intersect(SkRect::Make(image->bounds()));
257 272
258 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) 273 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty())
259 return; // Nothing to draw. 274 return; // Nothing to draw.
260 275
261 ImageOrientation orientation = DefaultImageOrientation; 276 ImageOrientation orientation = DefaultImageOrientation;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 if (m_sizeAvailable && hasVisibleImageSize(size())) { 332 if (m_sizeAvailable && hasVisibleImageSize(size())) {
318 BitmapImageMetrics::countDecodedImageType(m_source.filenameExtension()); 333 BitmapImageMetrics::countDecodedImageType(m_source.filenameExtension());
319 if (m_source.filenameExtension() == "jpg") 334 if (m_source.filenameExtension() == "jpg")
320 BitmapImageMetrics::countImageOrientation( 335 BitmapImageMetrics::countImageOrientation(
321 m_source.orientationAtIndex(0).orientation()); 336 m_source.orientationAtIndex(0).orientation());
322 } 337 }
323 338
324 return m_sizeAvailable; 339 return m_sizeAvailable;
325 } 340 }
326 341
327 sk_sp<SkImage> BitmapImage::frameAtIndex(size_t index) { 342 sk_sp<SkImage> BitmapImage::frameAtIndex(size_t index,
343 sk_sp<SkColorSpace> targetColorSpace) {
328 if (index >= frameCount()) 344 if (index >= frameCount())
329 return nullptr; 345 return nullptr;
330 346
331 if (index == m_cachedFrameIndex && m_cachedFrame) 347 // This should default to the global one with the mode off, otherwise
348 // default to sRGB.
349 if (!targetColorSpace)
350 targetColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
351
352 if (index == m_cachedFrameIndex && m_cachedFrame &&
353 SkColorSpace::Equals(targetColorSpace.get(),
354 m_cachedFrameColorSpace.get()))
332 return m_cachedFrame; 355 return m_cachedFrame;
333 356
334 return decodeAndCacheFrame(index); 357 return decodeAndCacheFrame(index, targetColorSpace);
335 } 358 }
336 359
337 bool BitmapImage::frameIsCompleteAtIndex(size_t index) const { 360 bool BitmapImage::frameIsCompleteAtIndex(size_t index) const {
338 if (index < m_frames.size() && m_frames[index].m_haveMetadata && 361 if (index < m_frames.size() && m_frames[index].m_haveMetadata &&
339 m_frames[index].m_isComplete) 362 m_frames[index].m_isComplete)
340 return true; 363 return true;
341 364
342 return m_source.frameIsCompleteAtIndex(index); 365 return m_source.frameIsCompleteAtIndex(index);
343 } 366 }
344 367
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 getImageObserver()->animationAdvanced(this); 644 getImageObserver()->animationAdvanced(this);
622 645
623 return true; 646 return true;
624 } 647 }
625 648
626 void BitmapImage::notifyObserversOfAnimationAdvance(TimerBase*) { 649 void BitmapImage::notifyObserversOfAnimationAdvance(TimerBase*) {
627 getImageObserver()->animationAdvanced(this); 650 getImageObserver()->animationAdvanced(this);
628 } 651 }
629 652
630 } // namespace blink 653 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698