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

Side by Side Diff: include/images/SkImageDecoder.h

Issue 12604006: Upstream Android modifications to the image encoders/decoders. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: minor fixes Created 7 years, 9 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
« no previous file with comments | « include/images/SkBitmapRegionDecoder.h ('k') | include/images/SkImageEncoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkImageDecoder_DEFINED 10 #ifndef SkImageDecoder_DEFINED
11 #define SkImageDecoder_DEFINED 11 #define SkImageDecoder_DEFINED
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkBitmapFactory.h" 14 #include "SkBitmapFactory.h"
15 #include "SkImage.h" 15 #include "SkImage.h"
16 #include "SkRect.h"
16 #include "SkRefCnt.h" 17 #include "SkRefCnt.h"
17 18
18 class SkStream; 19 class SkStream;
19 20
20 /** \class SkImageDecoder 21 /** \class SkImageDecoder
21 22
22 Base class for decoding compressed images into a SkBitmap 23 Base class for decoding compressed images into a SkBitmap
23 */ 24 */
24 class SkImageDecoder { 25 class SkImageDecoder {
25 public: 26 public:
26 virtual ~SkImageDecoder(); 27 virtual ~SkImageDecoder();
27 28
29 // Should be consistent with kFormatName
28 enum Format { 30 enum Format {
29 kUnknown_Format, 31 kUnknown_Format,
30 kBMP_Format, 32 kBMP_Format,
31 kGIF_Format, 33 kGIF_Format,
32 kICO_Format, 34 kICO_Format,
33 kJPEG_Format, 35 kJPEG_Format,
34 kPNG_Format, 36 kPNG_Format,
35 kWBMP_Format, 37 kWBMP_Format,
38 kWEBP_Format,
36 39
37 kLastKnownFormat = kWBMP_Format 40 kLastKnownFormat = kWEBP_Format
38 }; 41 };
39 42
40 /** Return the compressed data's format (see Format enum) 43 /** Return the compressed data's format (see Format enum)
41 */ 44 */
42 virtual Format getFormat() const; 45 virtual Format getFormat() const;
43 46
47 /** Return the compressed data's format name.
48 */
49 const char* getFormatName() const;
50
44 /** Returns true if the decoder should try to dither the resulting image. 51 /** Returns true if the decoder should try to dither the resulting image.
45 The default setting is true. 52 The default setting is true.
46 */ 53 */
47 bool getDitherImage() const { return fDitherImage; } 54 bool getDitherImage() const { return fDitherImage; }
48 55
49 /** Set to true if the the decoder should try to dither the resulting image. 56 /** Set to true if the the decoder should try to dither the resulting image.
50 The default setting is true. 57 The default setting is true.
51 */ 58 */
52 void setDitherImage(bool dither) { fDitherImage = dither; } 59 void setDitherImage(bool dither) { fDitherImage = dither; }
53 60
61 /** Returns true if the decoder should try to decode the
62 resulting image to a higher quality even at the expense of
63 the decoding speed.
64 */
65 bool getPreferQualityOverSpeed() const { return fPreferQualityOverSpeed; }
66
67 /** Set to true if the the decoder should try to decode the
68 resulting image to a higher quality even at the expense of
69 the decoding speed.
70 */
71 void setPreferQualityOverSpeed(bool qualityOverSpeed) {
72 fPreferQualityOverSpeed = qualityOverSpeed;
73 }
74
54 /** \class Peeker 75 /** \class Peeker
55 76
56 Base class for optional callbacks to retrieve meta/chunk data out of 77 Base class for optional callbacks to retrieve meta/chunk data out of
57 an image as it is being decoded. 78 an image as it is being decoded.
58 */ 79 */
59 class Peeker : public SkRefCnt { 80 class Peeker : public SkRefCnt {
60 public: 81 public:
61 SK_DECLARE_INST_COUNT(Peeker) 82 SK_DECLARE_INST_COUNT(Peeker)
62 83
63 /** Return true to continue decoding, or false to indicate an error, whi ch 84 /** Return true to continue decoding, or false to indicate an error, whi ch
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 which will allocated a pixelRef. To access the pixel memory, the codec 189 which will allocated a pixelRef. To access the pixel memory, the codec
169 needs to call lockPixels/unlockPixels on the 190 needs to call lockPixels/unlockPixels on the
170 bitmap. It can then set the pixels with the decompressed image. 191 bitmap. It can then set the pixels with the decompressed image.
171 * If the image cannot be decompressed, return false. After the 192 * If the image cannot be decompressed, return false. After the
172 * decoding, the function converts the decoded config in bitmap 193 * decoding, the function converts the decoded config in bitmap
173 * to pref if possible. Whether a conversion is feasible is 194 * to pref if possible. Whether a conversion is feasible is
174 * tested by Bitmap::canCopyTo(pref). 195 * tested by Bitmap::canCopyTo(pref).
175 196
176 note: document use of Allocator, Peeker and Chooser 197 note: document use of Allocator, Peeker and Chooser
177 */ 198 */
178 bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode); 199 bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode, bool r euseBitmap = false);
179 bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { 200 bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode, bool reuseBitmap = false) {
180 return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode); 201 return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode, reuseBit map);
181 } 202 }
182 203
204 /**
205 * Given a stream, build an index for doing tile-based decode.
206 * The built index will be saved in the decoder, and the image size will
207 * be returned in width and height.
208 *
209 * Return true for success or false on failure.
210 */
211 bool buildTileIndex(SkStream*, int *width, int *height);
212
213 /**
214 * Decode a rectangle region in the image specified by rect.
215 * The method can only be called after buildTileIndex().
216 *
217 * Return true for success.
218 * Return false if the index is never built or failing in decoding.
219 */
220 bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect, SkBitmap::Config pr ef);
221
183 /** Given a stream, this will try to find an appropriate decoder object. 222 /** Given a stream, this will try to find an appropriate decoder object.
184 If none is found, the method returns NULL. 223 If none is found, the method returns NULL.
185 */ 224 */
186 static SkImageDecoder* Factory(SkStream*); 225 static SkImageDecoder* Factory(SkStream*);
187 226
188 /** Decode the image stored in the specified file, and store the result 227 /** Decode the image stored in the specified file, and store the result
189 in bitmap. Return true for success or false on failure. 228 in bitmap. Return true for success or false on failure.
190 229
191 If pref is kNo_Config, then the decoder is free to choose the most natur al 230 If pref is kNo_Config, then the decoder is free to choose the most natur al
192 config given the image data. If pref something other than kNo_Config, 231 config given the image data. If pref something other than kNo_Config,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 static void SetDeviceConfig(SkBitmap::Config); 328 static void SetDeviceConfig(SkBitmap::Config);
290 329
291 /** @cond UNIT_TEST */ 330 /** @cond UNIT_TEST */
292 SkDEBUGCODE(static void UnitTest();) 331 SkDEBUGCODE(static void UnitTest();)
293 /** @endcond */ 332 /** @endcond */
294 333
295 protected: 334 protected:
296 // must be overridden in subclasses. This guy is called by decode(...) 335 // must be overridden in subclasses. This guy is called by decode(...)
297 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; 336 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0;
298 337
338 // If the decoder wants to support tiled based decoding,
339 // this method must be overridden. This guy is called by buildTileIndex(...)
340 virtual bool onBuildTileIndex(SkStream*, int *width, int *height) {
341 return false;
342 }
343
344 // If the decoder wants to support tiled based decoding,
345 // this method must be overridden. This guy is called by decodeRegion(...)
346 virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) {
347 return false;
348 }
349
350 /*
351 * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are
352 * both sampled by sampleSize from an original Bitmap.
353 *
354 * @param dst the destination bitmap.
355 * @param src the source bitmap that is sampled by sampleSize from the
356 * original bitmap.
357 * @param sampleSize the sample size that src is sampled from the original b itmap.
358 * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of
359 * the coordinate in the original bitmap.
360 * @param (width, height) the width and height of the unsampled dst.
361 * @param (srcX, srcY) the upper-left point of the src bitimap in terms of
362 * the coordinate in the original bitmap.
363 */
364 void cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
365 int dstX, int dstY, int width, int height,
366 int srcX, int srcY);
367
368
369
299 /** Can be queried from within onDecode, to see if the user (possibly in 370 /** Can be queried from within onDecode, to see if the user (possibly in
300 a different thread) has requested the decode to cancel. If this returns 371 a different thread) has requested the decode to cancel. If this returns
301 true, your onDecode() should stop and return false. 372 true, your onDecode() should stop and return false.
302 Each subclass needs to decide how often it can query this, to balance 373 Each subclass needs to decide how often it can query this, to balance
303 responsiveness with performance. 374 responsiveness with performance.
304 375
305 Calling this outside of onDecode() may return undefined values. 376 Calling this outside of onDecode() may return undefined values.
306 */ 377 */
307 378
308 public: 379 public:
(...skipping 30 matching lines...) Expand all
339 private: 410 private:
340 Peeker* fPeeker; 411 Peeker* fPeeker;
341 Chooser* fChooser; 412 Chooser* fChooser;
342 SkBitmap::Allocator* fAllocator; 413 SkBitmap::Allocator* fAllocator;
343 int fSampleSize; 414 int fSampleSize;
344 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false 415 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false
345 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true 416 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true
346 bool fDitherImage; 417 bool fDitherImage;
347 bool fUsePrefTable; 418 bool fUsePrefTable;
348 mutable bool fShouldCancelDecode; 419 mutable bool fShouldCancelDecode;
420 bool fPreferQualityOverSpeed;
421
422 /** Contains the image format name.
423 * This should be consistent with Format.
424 *
425 * The format name gives a more meaningful error message than enum.
426 */
427 static const char* sFormatName[];
349 428
350 // illegal 429 // illegal
351 SkImageDecoder(const SkImageDecoder&); 430 SkImageDecoder(const SkImageDecoder&);
352 SkImageDecoder& operator=(const SkImageDecoder&); 431 SkImageDecoder& operator=(const SkImageDecoder&);
353 }; 432 };
354 433
355 /** Calling newDecoder with a stream returns a new matching imagedecoder 434 /** Calling newDecoder with a stream returns a new matching imagedecoder
356 instance, or NULL if none can be found. The caller must manage its ownership 435 instance, or NULL if none can be found. The caller must manage its ownership
357 of the stream as usual, calling unref() when it is done, as the returned 436 of the stream as usual, calling unref() when it is done, as the returned
358 decoder may have called ref() (and if so, the decoder is responsible for 437 decoder may have called ref() (and if so, the decoder is responsible for
(...skipping 30 matching lines...) Expand all
389 } 468 }
390 469
391 // All the decoders known by Skia. Note that, depending on the compiler settings , 470 // All the decoders known by Skia. Note that, depending on the compiler settings ,
392 // not all of these will be available 471 // not all of these will be available
393 DECLARE_DECODER_CREATOR(BMPImageDecoder); 472 DECLARE_DECODER_CREATOR(BMPImageDecoder);
394 DECLARE_DECODER_CREATOR(GIFImageDecoder); 473 DECLARE_DECODER_CREATOR(GIFImageDecoder);
395 DECLARE_DECODER_CREATOR(ICOImageDecoder); 474 DECLARE_DECODER_CREATOR(ICOImageDecoder);
396 DECLARE_DECODER_CREATOR(JPEGImageDecoder); 475 DECLARE_DECODER_CREATOR(JPEGImageDecoder);
397 DECLARE_DECODER_CREATOR(PNGImageDecoder); 476 DECLARE_DECODER_CREATOR(PNGImageDecoder);
398 DECLARE_DECODER_CREATOR(WBMPImageDecoder); 477 DECLARE_DECODER_CREATOR(WBMPImageDecoder);
478 DECLARE_DECODER_CREATOR(WEBPImageDecoder);
399 479
400 #endif 480 #endif
OLDNEW
« no previous file with comments | « include/images/SkBitmapRegionDecoder.h ('k') | include/images/SkImageEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698