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

Side by Side Diff: Source/core/platform/image-decoders/ImageDecoder.h

Issue 15466003: Remove image decoder down sampling (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove virtual setSize() from GIF decoder Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008-2009 Torch Mobile, Inc.
4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
5 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
6 * 4 *
7 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
9 * are met: 7 * are met:
10 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
15 * 13 *
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // buffer except for GIF frames whose 196 // buffer except for GIF frames whose
199 // original rect was smaller than the 197 // original rect was smaller than the
200 // overall image size. 198 // overall image size.
201 FrameStatus m_status; 199 FrameStatus m_status;
202 unsigned m_duration; 200 unsigned m_duration;
203 FrameDisposalMethod m_disposalMethod; 201 FrameDisposalMethod m_disposalMethod;
204 bool m_premultiplyAlpha; 202 bool m_premultiplyAlpha;
205 }; 203 };
206 204
207 // ImageDecoder is a base for all format-specific decoders 205 // ImageDecoder is a base for all format-specific decoders
208 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. 206 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache.
209 //
210 // ENABLE(IMAGE_DECODER_DOWN_SAMPLING) allows image decoders to downsample
211 // at decode time. Image decoders will downsample any images larger than
212 // |m_maxNumPixels|. FIXME: Not yet supported by all decoders.
213 class ImageDecoder { 207 class ImageDecoder {
214 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; 208 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED;
215 public: 209 public:
216 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption) 210 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption)
217 : m_scaled(false) 211 : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
218 , m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
219 , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSo urce::GammaAndColorProfileIgnored) 212 , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSo urce::GammaAndColorProfileIgnored)
220 , m_sizeAvailable(false) 213 , m_sizeAvailable(false)
221 , m_maxNumPixels(-1)
222 , m_isAllDataReceived(false) 214 , m_isAllDataReceived(false)
223 , m_failed(false) { } 215 , m_failed(false) { }
224 216
225 virtual ~ImageDecoder() { } 217 virtual ~ImageDecoder() { }
226 218
227 // Returns a caller-owned decoder of the appropriate type. Returns 0 if 219 // Returns a caller-owned decoder of the appropriate type. Returns 0 if
228 // we can't sniff a supported type from the provided data (possibly 220 // we can't sniff a supported type from the provided data (possibly
229 // because there isn't enough data yet). 221 // because there isn't enough data yet).
230 static PassOwnPtr<ImageDecoder> create(const SharedBuffer& data, ImageSo urce::AlphaOption, ImageSource::GammaAndColorProfileOption); 222 static PassOwnPtr<ImageDecoder> create(const SharedBuffer& data, ImageSo urce::AlphaOption, ImageSource::GammaAndColorProfileOption);
231 223
(...skipping 12 matching lines...) Expand all
244 // Lazily-decodes enough of the image to get the size (if possible). 236 // Lazily-decodes enough of the image to get the size (if possible).
245 // FIXME: Right now that has to be done by each subclass; factor the 237 // FIXME: Right now that has to be done by each subclass; factor the
246 // decode call out and use it here. 238 // decode call out and use it here.
247 virtual bool isSizeAvailable() 239 virtual bool isSizeAvailable()
248 { 240 {
249 return !m_failed && m_sizeAvailable; 241 return !m_failed && m_sizeAvailable;
250 } 242 }
251 243
252 virtual IntSize size() const { return m_size; } 244 virtual IntSize size() const { return m_size; }
253 245
254 IntSize scaledSize() const
255 {
256 return m_scaled ? IntSize(m_scaledColumns.size(), m_scaledRows.size( )) : size();
257 }
258
259 // This will only differ from size() for ICO (where each frame is a 246 // This will only differ from size() for ICO (where each frame is a
260 // different icon) or other formats where different frames are different 247 // different icon) or other formats where different frames are different
261 // sizes. This does NOT differ from size() for GIF, since decoding GIFs 248 // sizes. This does NOT differ from size() for GIF, since decoding GIFs
262 // composites any smaller frames against previous frames to create full- 249 // composites any smaller frames against previous frames to create full-
263 // size frames. 250 // size frames.
264 virtual IntSize frameSizeAtIndex(size_t) const 251 virtual IntSize frameSizeAtIndex(size_t) const
265 { 252 {
266 return size(); 253 return size();
267 } 254 }
268 255
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return false; 356 return false;
370 } 357 }
371 358
372 bool failed() const { return m_failed; } 359 bool failed() const { return m_failed; }
373 360
374 // Clears decoded pixel data from before the provided frame unless that 361 // Clears decoded pixel data from before the provided frame unless that
375 // data may be needed to decode future frames (e.g. due to GIF frame 362 // data may be needed to decode future frames (e.g. due to GIF frame
376 // compositing). 363 // compositing).
377 virtual void clearFrameBufferCache(size_t) { } 364 virtual void clearFrameBufferCache(size_t) { }
378 365
379 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
380 void setMaxNumPixels(int m) { m_maxNumPixels = m; }
381 #endif
382
383 // If the image has a cursor hot-spot, stores it in the argument 366 // If the image has a cursor hot-spot, stores it in the argument
384 // and returns true. Otherwise returns false. 367 // and returns true. Otherwise returns false.
385 virtual bool hotSpot(IntPoint&) const { return false; } 368 virtual bool hotSpot(IntPoint&) const { return false; }
386 369
387 virtual void reportMemoryUsage(MemoryObjectInfo*) const; 370 virtual void reportMemoryUsage(MemoryObjectInfo*) const;
388 371
389 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) 372 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator)
390 { 373 {
391 // FIXME: this doesn't work for images with multiple frames. 374 // FIXME: this doesn't work for images with multiple frames.
392 if (m_frameBufferCache.isEmpty()) 375 if (m_frameBufferCache.isEmpty())
393 m_frameBufferCache.resize(1); 376 m_frameBufferCache.resize(1);
394 m_frameBufferCache[0].setMemoryAllocator(allocator); 377 m_frameBufferCache[0].setMemoryAllocator(allocator);
395 } 378 }
396 379
397 protected: 380 protected:
398 void prepareScaleDataIfNecessary();
399 int upperBoundScaledX(int origX, int searchStart = 0);
400 int lowerBoundScaledX(int origX, int searchStart = 0);
401 int upperBoundScaledY(int origY, int searchStart = 0);
402 int lowerBoundScaledY(int origY, int searchStart = 0);
403 int scaledY(int origY, int searchStart = 0);
404
405 RefPtr<SharedBuffer> m_data; // The encoded data. 381 RefPtr<SharedBuffer> m_data; // The encoded data.
406 Vector<ImageFrame, 1> m_frameBufferCache; 382 Vector<ImageFrame, 1> m_frameBufferCache;
407 bool m_scaled;
408 Vector<int> m_scaledColumns;
409 Vector<int> m_scaledRows;
410 bool m_premultiplyAlpha; 383 bool m_premultiplyAlpha;
411 bool m_ignoreGammaAndColorProfile; 384 bool m_ignoreGammaAndColorProfile;
412 ImageOrientation m_orientation; 385 ImageOrientation m_orientation;
413 386
414 private: 387 private:
415 // Some code paths compute the size of the image as "width * height * 4" 388 // Some code paths compute the size of the image as "width * height * 4"
416 // and return it as a (signed) int. Avoid overflow. 389 // and return it as a (signed) int. Avoid overflow.
417 static bool isOverSize(unsigned width, unsigned height) 390 static bool isOverSize(unsigned width, unsigned height)
418 { 391 {
419 unsigned long long total_size = static_cast<unsigned long long>(widt h) 392 unsigned long long total_size = static_cast<unsigned long long>(widt h)
420 * static_cast<unsigned long long>(heig ht); 393 * static_cast<unsigned long long>(heig ht);
421 return total_size > ((1 << 29) - 1); 394 return total_size > ((1 << 29) - 1);
422 } 395 }
423 396
424 IntSize m_size; 397 IntSize m_size;
425 bool m_sizeAvailable; 398 bool m_sizeAvailable;
426 int m_maxNumPixels;
427 bool m_isAllDataReceived; 399 bool m_isAllDataReceived;
428 bool m_failed; 400 bool m_failed;
429 }; 401 };
430 402
431 } // namespace WebCore 403 } // namespace WebCore
432 404
433 #endif 405 #endif
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/ImageSource.cpp ('k') | Source/core/platform/image-decoders/ImageDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698