Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkImageDecoder_DEFINED | 8 #ifndef SkImageDecoder_DEFINED |
| 9 #define SkImageDecoder_DEFINED | 9 #define SkImageDecoder_DEFINED |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkImage.h" | 12 #include "SkImage.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 #include "SkTRegistry.h" | 15 #include "SkTRegistry.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 | 17 |
| 18 class SkStream; | 18 class SkStream; |
| 19 class SkStreamRewindable; | 19 class SkStreamRewindable; |
| 20 | 20 |
| 21 /** \class SkImagePlanes | |
| 22 | |
| 23 SkImagePlanes can be used to decode color components into provided buffers | |
| 24 instead of using an SkBitmap. | |
| 25 */ | |
| 26 class SkImagePlanes : public SkRefCnt { | |
| 27 public: | |
| 28 SkImagePlanes(); | |
| 29 SkImagePlanes(void* planes[3], size_t rowBytes[3]); | |
| 30 | |
| 31 void* plane(int); | |
| 32 size_t rowBytes(int) const; | |
| 33 | |
| 34 private: | |
| 35 void* m_planes[3]; | |
| 36 size_t m_rowBytes[3]; | |
| 37 }; | |
| 38 | |
| 21 /** \class SkImageDecoder | 39 /** \class SkImageDecoder |
| 22 | 40 |
| 23 Base class for decoding compressed images into a SkBitmap | 41 Base class for decoding compressed images into a SkBitmap |
| 24 */ | 42 */ |
| 25 class SkImageDecoder : SkNoncopyable { | 43 class SkImageDecoder : SkNoncopyable { |
| 26 public: | 44 public: |
| 27 virtual ~SkImageDecoder(); | 45 virtual ~SkImageDecoder(); |
| 28 | 46 |
| 29 enum Format { | 47 enum Format { |
| 30 kUnknown_Format, | 48 kUnknown_Format, |
| 31 kBMP_Format, | 49 kBMP_Format, |
| 32 kGIF_Format, | 50 kGIF_Format, |
| 33 kICO_Format, | 51 kICO_Format, |
| 34 kJPEG_Format, | 52 kJPEG_Format, |
| 35 kPNG_Format, | 53 kPNG_Format, |
| 36 kWBMP_Format, | 54 kWBMP_Format, |
| 37 kWEBP_Format, | 55 kWEBP_Format, |
| 38 kPKM_Format, | 56 kPKM_Format, |
| 39 kKTX_Format, | 57 kKTX_Format, |
| 40 kASTC_Format, | 58 kASTC_Format, |
| 41 | 59 |
| 42 kLastKnownFormat = kKTX_Format, | 60 kLastKnownFormat = kKTX_Format, |
| 43 }; | 61 }; |
| 44 | 62 |
| 45 /** Return the format of image this decoder can decode. If this decoder can decode multiple | 63 /** Return the format of image this decoder can decode. If this decoder can decode multiple |
| 46 formats, kUnknown_Format will be returned. | 64 formats, kUnknown_Format will be returned. |
| 47 */ | 65 */ |
| 48 virtual Format getFormat() const; | 66 virtual Format getFormat() const; |
| 49 | 67 |
| 68 /** Returns the sizes of each component of the image | |
| 69 @param sizes On success, returns the sizes of each component of the imag e. | |
| 70 */ | |
| 71 bool getYUVComponentSizes(SkStream* stream, SkISize sizes[3]); | |
| 72 | |
| 73 /** Decodes the YUV planes into the provided planes | |
| 74 Returns whether the decoding to YUV was successful. | |
| 75 */ | |
| 76 bool decodeToYUV(SkStream* stream, SkISize componentSizes[3], void* planes[3 ], | |
| 77 size_t rowBytes[3]); | |
| 78 | |
| 50 /** Return the format of the SkStreamRewindable or kUnknown_Format if it can not be determined. | 79 /** Return the format of the SkStreamRewindable or kUnknown_Format if it can not be determined. |
| 51 Rewinds the stream before returning. | 80 Rewinds the stream before returning. |
| 52 */ | 81 */ |
| 53 static Format GetStreamFormat(SkStreamRewindable*); | 82 static Format GetStreamFormat(SkStreamRewindable*); |
| 54 | 83 |
| 55 /** Return a readable string of the Format provided. | 84 /** Return a readable string of the Format provided. |
| 56 */ | 85 */ |
| 57 static const char* GetFormatName(Format); | 86 static const char* GetFormatName(Format); |
| 58 | 87 |
| 59 /** Return a readable string of the value returned by getFormat(). | 88 /** Return a readable string of the value returned by getFormat(). |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) { | 361 virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) { |
| 333 return false; | 362 return false; |
| 334 } | 363 } |
| 335 | 364 |
| 336 // If the decoder wants to support tiled based decoding, | 365 // If the decoder wants to support tiled based decoding, |
| 337 // this method must be overridden. This guy is called by decodeRegion(...) | 366 // this method must be overridden. This guy is called by decodeRegion(...) |
| 338 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { | 367 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { |
| 339 return false; | 368 return false; |
| 340 } | 369 } |
| 341 | 370 |
| 371 /** If imagePlanes is NULL, decodes the header and computes componentSizes | |
| 372 for memory allocation. | |
| 373 Otherwise, decodes the YUV planes into the provided image planes and | |
| 374 updates componentSizes to the final image size. | |
| 375 Returns whether the decoding was successful. | |
| 376 */ | |
| 377 virtual bool onDecodeToYUV(SkStream* stream, SkISize componentSizes[3], | |
| 378 SkImagePlanes* imagePlanes) { | |
|
reed1
2014/10/13 13:15:35
I thnk passing the planes and sizes arrays is bett
sugoi1
2014/10/14 15:07:36
Done. This was added only to mimic what is used in
| |
| 379 return false; | |
| 380 } | |
| 381 | |
| 342 /* | 382 /* |
| 343 * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are | 383 * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are |
| 344 * both sampled by sampleSize from an original Bitmap. | 384 * both sampled by sampleSize from an original Bitmap. |
| 345 * | 385 * |
| 346 * @param dst the destination bitmap. | 386 * @param dst the destination bitmap. |
| 347 * @param src the source bitmap that is sampled by sampleSize from the | 387 * @param src the source bitmap that is sampled by sampleSize from the |
| 348 * original bitmap. | 388 * original bitmap. |
| 349 * @param sampleSize the sample size that src is sampled from the original b itmap. | 389 * @param sampleSize the sample size that src is sampled from the original b itmap. |
| 350 * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of | 390 * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of |
| 351 * the coordinate in the original bitmap. | 391 * the coordinate in the original bitmap. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 517 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
| 478 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 518 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
| 479 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 519 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
| 480 | 520 |
| 481 // Typedefs to make registering decoder and formatter callbacks easier. | 521 // Typedefs to make registering decoder and formatter callbacks easier. |
| 482 // These have to be defined outside SkImageDecoder. :( | 522 // These have to be defined outside SkImageDecoder. :( |
| 483 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; | 523 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; |
| 484 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; | 524 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; |
| 485 | 525 |
| 486 #endif | 526 #endif |
| OLD | NEW |