 Chromium Code Reviews
 Chromium Code Reviews Issue 1365313002:
  Merge SkCodec with SkScanlineDecoder  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master
    
  
    Issue 1365313002:
  Merge SkCodec with SkScanlineDecoder  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. | 
| 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 #include "SkCodec.h" | 8 #include "SkCodec.h" | 
| 9 #include "SkColorTable.h" | 9 #include "SkColorTable.h" | 
| 10 #include "SkImageInfo.h" | 10 #include "SkImageInfo.h" | 
| 11 #include "SkScanlineDecoder.h" | |
| 12 #include "SkSwizzler.h" | 11 #include "SkSwizzler.h" | 
| 13 | 12 | 
| 14 #include "gif_lib.h" | 13 #include "gif_lib.h" | 
| 15 | 14 | 
| 16 /* | 15 /* | 
| 17 * | 16 * | 
| 18 * This class implements the decoding for gif images | 17 * This class implements the decoding for gif images | 
| 19 * | 18 * | 
| 20 */ | 19 */ | 
| 21 class SkGifCodec : public SkCodec { | 20 class SkGifCodec : public SkCodec { | 
| 22 public: | 21 public: | 
| 23 | 22 | 
| 24 /* | 23 /* | 
| 25 * Checks the start of the stream to see if the image is a gif | 24 * Checks the start of the stream to see if the image is a gif | 
| 26 */ | 25 */ | 
| 27 static bool IsGif(SkStream*); | 26 static bool IsGif(SkStream*); | 
| 28 | 27 | 
| 29 /* | 28 /* | 
| 30 * Assumes IsGif was called and returned true | 29 * Assumes IsGif was called and returned true | 
| 31 * Creates a gif decoder | 30 * Creates a gif decoder | 
| 32 * Reads enough of the stream to determine the image format | 31 * Reads enough of the stream to determine the image format | 
| 33 */ | 32 */ | 
| 34 static SkCodec* NewFromStream(SkStream*); | 33 static SkCodec* NewFromStream(SkStream*); | 
| 35 | 34 | 
| 36 static SkScanlineDecoder* NewSDFromStream(SkStream* stream); | |
| 37 | |
| 38 protected: | 35 protected: | 
| 39 | 36 | 
| 40 /* | 37 /* | 
| 41 * Read enough of the stream to initialize the SkGifCodec. | 38 * Read enough of the stream to initialize the SkGifCodec. | 
| 42 * Returns a bool representing success or failure. | 39 * Returns a bool representing success or failure. | 
| 43 * | 40 * | 
| 44 * @param codecOut | 41 * @param codecOut | 
| 45 * If it returned true, and codecOut was not nullptr, | 42 * If it returned true, and codecOut was not nullptr, | 
| 46 * codecOut will be set to a new SkGifCodec. | 43 * codecOut will be set to a new SkGifCodec. | 
| 47 * | 44 * | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 76 /* | 73 /* | 
| 77 * A gif can contain multiple image frames. We will only decode the first | 74 * A gif can contain multiple image frames. We will only decode the first | 
| 78 * frame. This function reads up to the first image frame, processing | 75 * frame. This function reads up to the first image frame, processing | 
| 79 * transparency and/or animation information that comes before the image | 76 * transparency and/or animation information that comes before the image | 
| 80 * data. | 77 * data. | 
| 81 * | 78 * | 
| 82 * @param gif Pointer to the library type that manages the gif decode | 79 * @param gif Pointer to the library type that manages the gif decode | 
| 83 * @param transIndex This call will set the transparent index based on the | 80 * @param transIndex This call will set the transparent index based on the | 
| 84 * extension data. | 81 * extension data. | 
| 85 */ | 82 */ | 
| 86 static SkCodec::Result ReadUpToFirstImage(GifFileType* gif, uint32_t* trans Index); | 83 static Result ReadUpToFirstImage(GifFileType* gif, uint32_t* transIndex); | 
| 87 | 84 | 
| 88 /* | 85 /* | 
| 89 * A gif may contain many image frames, all of different sizes. | 86 * A gif may contain many image frames, all of different sizes. | 
| 90 * This function checks if the frame dimensions are valid and corrects | 87 * This function checks if the frame dimensions are valid and corrects | 
| 91 * them if necessary. It then sets fFrameDims to the corrected | 88 * them if necessary. It then sets fFrameDims to the corrected | 
| 92 * dimensions. | 89 * dimensions. | 
| 93 * | 90 * | 
| 94 * @param desc The image frame descriptor | 91 * @param desc The image frame descriptor | 
| 95 */ | 92 */ | 
| 96 bool setFrameDimensions(const GifImageDesc& desc); | 93 bool setFrameDimensions(const GifImageDesc& desc); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 107 * table to ensure that indexing is always in | 104 * table to ensure that indexing is always in | 
| 108 * bounds. | 105 * bounds. | 
| 109 */ | 106 */ | 
| 110 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr, | 107 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr, | 
| 111 int* inputColorCount); | 108 int* inputColorCount); | 
| 112 | 109 | 
| 113 /* | 110 /* | 
| 114 * Checks for invalid inputs and calls rewindIfNeeded(), setFramDimensions(), and | 111 * Checks for invalid inputs and calls rewindIfNeeded(), setFramDimensions(), and | 
| 115 * initializeColorTable() in the proper sequence. | 112 * initializeColorTable() in the proper sequence. | 
| 116 */ | 113 */ | 
| 117 SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* input ColorPtr, | 114 Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, | 
| 118 int* inputColorCount, const Options& opts); | 115 int* inputColorCount, const Options& opts); | 
| 119 | 116 | 
| 120 /* | 117 /* | 
| 121 * Initializes the swizzler. | 118 * Initializes the swizzler. | 
| 122 * | 119 * | 
| 123 * @param dstInfo Output image information. Dimensions may have been | 120 * @param dstInfo Output image information. Dimensions may have been | 
| 124 * adjusted if the image frame size does not match the size | 121 * adjusted if the image frame size does not match the size | 
| 125 * indicated in the header. | 122 * indicated in the header. | 
| 126 * @param zeroInit Indicates if destination memory is zero initialized. | 123 * @param zeroInit Indicates if destination memory is zero initialized. | 
| 127 */ | 124 */ | 
| 128 SkCodec::Result initializeSwizzler(const SkImageInfo& dstInfo, | 125 Result initializeSwizzler(const SkImageInfo& dstInfo, ZeroInitialized zeroIn it); | 
| 129 ZeroInitialized zeroInit); | |
| 130 | 126 | 
| 131 /* | 127 /* | 
| 132 * @return kSuccess if the read is successful and kIncompleteInput if the | 128 * @return kSuccess if the read is successful and kIncompleteInput if the | 
| 133 * read fails. | 129 * read fails. | 
| 134 */ | 130 */ | 
| 135 SkCodec::Result readRow(); | 131 Result readRow(); | 
| 132 | |
| 133 Result onStart(const SkImageInfo& dstInfo, const Options& opts, | |
| 134 SkPMColor inputColorPtr[], int* inputColorCount) override; | |
| 135 | |
| 136 Result onGetScanlines(void* dst, int count, size_t rowBytes) override; | |
| 137 | |
| 138 SkScanlineOrder onGetScanlineOrder() const override; | |
| 139 | |
| 140 int onGetY() const override; | |
| 136 | 141 | 
| 137 /* | 142 /* | 
| 138 * This function cleans up the gif object after the decode completes | 143 * This function cleans up the gif object after the decode completes | 
| 139 * It is used in a SkAutoTCallIProc template | 144 * It is used in a SkAutoTCallIProc template | 
| 140 */ | 145 */ | 
| 141 static void CloseGif(GifFileType* gif); | 146 static void CloseGif(GifFileType* gif); | 
| 142 | 147 | 
| 143 /* | 148 /* | 
| 144 * Frees any extension data used in the decode | 149 * Frees any extension data used in the decode | 
| 145 * Used in a SkAutoTCallVProc | 150 * Used in a SkAutoTCallVProc | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 161 | 166 | 
| 162 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned | 167 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned | 
| 163 SkAutoTDeleteArray<uint8_t> fSrcBuffer; | 168 SkAutoTDeleteArray<uint8_t> fSrcBuffer; | 
| 164 SkIRect fFrameDims; | 169 SkIRect fFrameDims; | 
| 165 const uint32_t fTransIndex; | 170 const uint32_t fTransIndex; | 
| 166 uint32_t fFillIndex; | 171 uint32_t fFillIndex; | 
| 167 bool fFrameIsSubset; | 172 bool fFrameIsSubset; | 
| 168 SkAutoTDelete<SkSwizzler> fSwizzler; | 173 SkAutoTDelete<SkSwizzler> fSwizzler; | 
| 169 SkAutoTUnref<SkColorTable> fColorTable; | 174 SkAutoTUnref<SkColorTable> fColorTable; | 
| 170 | 175 | 
| 171 friend class SkGifScanlineDecoder; | 176 friend class SkGifScanlineDecoder; | 
| 
scroggo
2015/09/25 16:07:49
Removed in next patch.
 | |
| 172 | 177 | 
| 173 typedef SkCodec INHERITED; | 178 typedef SkCodec INHERITED; | 
| 174 }; | 179 }; | 
| OLD | NEW |