| 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 "SkEncodedFormat.h" |
| 10 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 11 #include "SkMaskSwizzler.h" | 12 #include "SkMaskSwizzler.h" |
| 12 #include "SkStream.h" | 13 #include "SkStream.h" |
| 13 #include "SkSwizzler.h" | 14 #include "SkSwizzler.h" |
| 14 #include "SkTypes.h" | 15 #include "SkTypes.h" |
| 15 | 16 |
| 16 // TODO: rename SkCodec_libbmp files to SkBmpCodec | 17 // TODO: rename SkCodec_libbmp files to SkBmpCodec |
| 17 // TODO: define a wrapper for SkDebugf that doesn't always print | 18 // TODO: define a wrapper for SkDebugf that doesn't always print |
| 18 /* | 19 /* |
| 19 * | 20 * |
| 20 * This class implements the decoding for bmp images | 21 * This class implements the decoding for bmp images |
| 21 * | 22 * |
| 22 */ | 23 */ |
| 23 class SkBmpCodec : public SkCodec { | 24 class SkBmpCodec : public SkCodec { |
| 24 public: | 25 public: |
| 25 | 26 |
| 26 /* | 27 /* |
| 27 * | 28 * |
| 28 * Describes if rows of the input start at the top or bottom of the image | 29 * Describes if rows of the input start at the top or bottom of the image |
| 29 * | 30 * |
| 30 */ | 31 */ |
| 31 enum RowOrder { | 32 enum RowOrder { |
| 32 kTopDown_RowOrder, | 33 kTopDown_RowOrder, |
| 33 kBottomUp_RowOrder | 34 kBottomUp_RowOrder |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 /* | 37 /* |
| 37 * | 38 * |
| 38 * Checks the start of the stream to see if the image is a bmp | 39 * Checks the start of the stream to see if the image is a bitmap |
| 39 * | 40 * |
| 40 */ | 41 */ |
| 41 static bool IsBmp(SkStream*); | 42 static bool IsBmp(SkStream*); |
| 42 | 43 |
| 43 /* | 44 /* |
| 44 * | 45 * |
| 45 * Assumes IsBmp was called and returned true | 46 * Assumes IsBmp was called and returned true |
| 46 * Creates a bmp decoder | 47 * Creates a bitmap decoder |
| 47 * Reads enough of the stream to determine the image format | 48 * Reads enough of the stream to determine the image format |
| 48 * | 49 * |
| 49 */ | 50 */ |
| 50 static SkCodec* NewFromStream(SkStream*); | 51 static SkCodec* NewFromStream(SkStream*); |
| 51 | 52 |
| 52 /* | |
| 53 * | |
| 54 * Creates a bmp decoder for a bmp embedded in ico | |
| 55 * Reads enough of the stream to determine the image format | |
| 56 * | |
| 57 */ | |
| 58 static SkCodec* NewFromIco(SkStream*); | |
| 59 | |
| 60 protected: | 53 protected: |
| 61 | 54 |
| 62 /* | 55 /* |
| 63 * | 56 * |
| 64 * Initiates the bmp decode | 57 * Initiates the bitmap decode |
| 65 * | 58 * |
| 66 */ | 59 */ |
| 67 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, | 60 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, |
| 68 size_t dstRowBytes, const Options&, SkPMColor*, | 61 size_t dstRowBytes, const Options&, SkPMColor*, |
| 69 int*) SK_OVERRIDE; | 62 int*) SK_OVERRIDE; |
| 70 | 63 |
| 71 SkEncodedFormat onGetEncodedFormat() const SK_OVERRIDE { return kBMP_SkEncod
edFormat; } | 64 SkEncodedFormat onGetEncodedFormat() const SK_OVERRIDE { return kBMP_SkEncod
edFormat; } |
| 72 | |
| 73 private: | 65 private: |
| 74 | 66 |
| 75 /* | 67 /* |
| 76 * | 68 * |
| 77 * Used to define the input format of the bmp | 69 * Used to define the input format of the bitmap |
| 78 * | 70 * |
| 79 */ | 71 */ |
| 80 enum BitmapInputFormat { | 72 enum BitmapInputFormat { |
| 81 kStandard_BitmapInputFormat, | 73 kStandard_BitmapInputFormat, |
| 82 kRLE_BitmapInputFormat, | 74 kRLE_BitmapInputFormat, |
| 83 kBitMask_BitmapInputFormat, | 75 kBitMask_BitmapInputFormat, |
| 84 kUnknown_BitmapInputFormat | 76 kUnknown_BitmapInputFormat |
| 85 }; | 77 }; |
| 86 | 78 |
| 87 /* | 79 /* |
| 88 * | 80 * |
| 89 * Creates the color table | 81 * Creates the color table |
| 90 * | 82 * |
| 91 */ | 83 */ |
| 92 bool createColorTable(SkAlphaType alphaType); | 84 bool createColorTable(SkAlphaType alphaType); |
| 93 | 85 |
| 94 /* | 86 /* |
| 95 * | 87 * |
| 96 * Creates a bmp decoder | |
| 97 * Reads enough of the stream to determine the image format | |
| 98 * | |
| 99 */ | |
| 100 static SkCodec* NewFromStream(SkStream*, bool isIco); | |
| 101 | |
| 102 /* | |
| 103 * | |
| 104 * Performs the bitmap decoding for bit masks input format | 88 * Performs the bitmap decoding for bit masks input format |
| 105 * | 89 * |
| 106 */ | 90 */ |
| 107 Result decodeMask(const SkImageInfo& dstInfo, void* dst, | 91 Result decodeMask(const SkImageInfo& dstInfo, void* dst, |
| 108 size_t dstRowBytes); | 92 size_t dstRowBytes); |
| 109 | 93 |
| 110 /* | 94 /* |
| 111 * | 95 * |
| 112 * Set an RLE pixel using the color table | 96 * Set an RLE pixel using the color table |
| 113 * | 97 * |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 * @param rowOrder indicates whether rows are ordered top-down or bottom-up | 142 * @param rowOrder indicates whether rows are ordered top-down or bottom-up |
| 159 * @param RLEBytes used only for RLE decodes, as we must decode all | 143 * @param RLEBytes used only for RLE decodes, as we must decode all |
| 160 * of the data at once rather than row by row | 144 * of the data at once rather than row by row |
| 161 * it indicates the amount of data left in the stream | 145 * it indicates the amount of data left in the stream |
| 162 * after decoding the headers | 146 * after decoding the headers |
| 163 * | 147 * |
| 164 */ | 148 */ |
| 165 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, | 149 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, |
| 166 uint16_t bitsPerPixel, BitmapInputFormat format, | 150 uint16_t bitsPerPixel, BitmapInputFormat format, |
| 167 SkMasks* masks, uint32_t numColors, uint32_t bytesPerColor, | 151 SkMasks* masks, uint32_t numColors, uint32_t bytesPerColor, |
| 168 uint32_t offset, RowOrder rowOrder, size_t RLEBytes, | 152 uint32_t offset, RowOrder rowOrder, size_t RLEByes); |
| 169 bool isIco); | |
| 170 | 153 |
| 171 // Fields | 154 // Fields |
| 172 const uint16_t fBitsPerPixel; | 155 const uint16_t fBitsPerPixel; |
| 173 const BitmapInputFormat fInputFormat; | 156 const BitmapInputFormat fInputFormat; |
| 174 SkAutoTDelete<SkMasks> fMasks; // owned | 157 SkAutoTDelete<SkMasks> fMasks; // owned |
| 175 SkAutoTDelete<SkColorTable> fColorTable; // owned | 158 SkAutoTDelete<SkColorTable> fColorTable; // owned |
| 176 uint32_t fNumColors; | 159 uint32_t fNumColors; |
| 177 const uint32_t fBytesPerColor; | 160 const uint32_t fBytesPerColor; |
| 178 const uint32_t fOffset; | 161 const uint32_t fOffset; |
| 179 const RowOrder fRowOrder; | 162 const RowOrder fRowOrder; |
| 180 const size_t fRLEBytes; | 163 const size_t fRLEBytes; |
| 181 const bool fIsIco; | |
| 182 | 164 |
| 183 typedef SkCodec INHERITED; | 165 typedef SkCodec INHERITED; |
| 184 }; | 166 }; |
| OLD | NEW |