| 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 #ifndef SkBmpCodec_DEFINED | 7 #ifndef SkBmpCodec_DEFINED |
| 8 #define SkBmpCodec_DEFINED | 8 #define SkBmpCodec_DEFINED |
| 9 | 9 |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| 11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
| 12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
| 13 #include "SkMaskSwizzler.h" | 13 #include "SkMaskSwizzler.h" |
| 14 #include "SkScanlineDecoder.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkSwizzler.h" | 16 #include "SkSwizzler.h" |
| 16 #include "SkTypes.h" | 17 #include "SkTypes.h" |
| 17 | 18 |
| 18 /* | 19 /* |
| 19 * This class enables code sharing between its bmp codec subclasses. The | 20 * This class enables code sharing between its bmp codec subclasses. The |
| 20 * subclasses actually do the work. | 21 * subclasses actually do the work. |
| 21 */ | 22 */ |
| 22 class SkBmpCodec : public SkCodec { | 23 class SkBmpCodec : public SkCodec { |
| 23 public: | 24 public: |
| 24 | 25 |
| 25 /* | 26 /* |
| 26 * Describes if rows of the input start at the top or bottom of the image | |
| 27 */ | |
| 28 enum RowOrder { | |
| 29 kTopDown_RowOrder, | |
| 30 kBottomUp_RowOrder | |
| 31 }; | |
| 32 | |
| 33 /* | |
| 34 * Checks the start of the stream to see if the image is a bmp | 27 * Checks the start of the stream to see if the image is a bmp |
| 35 */ | 28 */ |
| 36 static bool IsBmp(SkStream*); | 29 static bool IsBmp(SkStream*); |
| 37 | 30 |
| 38 /* | 31 /* |
| 39 * Assumes IsBmp was called and returned true | 32 * Assumes IsBmp was called and returned true |
| 40 * Creates a bmp decoder | 33 * Creates a bmp decoder |
| 41 * Reads enough of the stream to determine the image format | 34 * Reads enough of the stream to determine the image format |
| 42 */ | 35 */ |
| 43 static SkCodec* NewFromStream(SkStream*); | 36 static SkCodec* NewFromStream(SkStream*); |
| 44 | 37 |
| 45 /* | 38 /* |
| 46 * Creates a bmp decoder for a bmp embedded in ico | 39 * Creates a bmp decoder for a bmp embedded in ico |
| 47 * Reads enough of the stream to determine the image format | 40 * Reads enough of the stream to determine the image format |
| 48 */ | 41 */ |
| 49 static SkCodec* NewFromIco(SkStream*); | 42 static SkCodec* NewFromIco(SkStream*); |
| 50 | 43 |
| 44 /* |
| 45 * Assumes IsBmp was called and returned true |
| 46 * Creates a bmp scanline decoder |
| 47 * Takes ownership of the stream |
| 48 */ |
| 49 static SkScanlineDecoder* NewSDFromStream(SkStream* stream); |
| 50 |
| 51 protected: | 51 protected: |
| 52 | 52 |
| 53 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, | 53 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, |
| 54 RowOrder rowOrder); | 54 SkScanlineDecoder::SkScanlineOrder rowOrder); |
| 55 | 55 |
| 56 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF
ormat; } | 56 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF
ormat; } |
| 57 | 57 |
| 58 /* | 58 /* |
| 59 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | 59 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool |
| 60 * representing success or failure. If it returned true, and codecOut was | 60 * representing success or failure. If it returned true, and codecOut was |
| 61 * not nullptr, it will be set to a new SkBmpCodec. | 61 * not nullptr, it will be set to a new SkBmpCodec. |
| 62 * Does *not* take ownership of the passed in SkStream. | 62 * Does *not* take ownership of the passed in SkStream. |
| 63 */ | 63 */ |
| 64 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); | 64 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); |
| 65 | 65 |
| 66 bool onRewind() override; | 66 bool onRewind() override; |
| 67 | 67 |
| 68 /* | 68 /* |
| 69 * Returns whether this BMP is part of an ICO image. | 69 * Returns whether this BMP is part of an ICO image. |
| 70 */ | 70 */ |
| 71 bool inIco() const { | 71 bool inIco() const { |
| 72 return this->onInIco(); | 72 return this->onInIco(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual bool onInIco() const { | 75 virtual bool onInIco() const { |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 /* | 79 /* |
| 80 * Get the destination row number corresponding to the encoded row number. |
| 81 * For kTopDown, we simply return y, but for kBottomUp, the rows will be |
| 82 * decoded in reverse order. |
| 83 * |
| 84 * @param y Iterates from 0 to height, indicating the current row. |
| 85 * @param height The height of the current subset of the image that we are |
| 86 * decoding. This is generally equal to the full height |
| 87 * when we want to decode the full or one when we are |
| 88 * sampling. |
| 89 */ |
| 90 int32_t getDstRow(int32_t y, int32_t height); |
| 91 |
| 92 /* |
| 80 * Get the destination row to start filling from | 93 * Get the destination row to start filling from |
| 81 * Used to fill the remainder of the image on incomplete input for bmps | 94 * Used to fill the remainder of the image on incomplete input for bmps |
| 82 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, | 95 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, |
| 83 * we start filling from where we left off, but for kBottomUp we start | 96 * we start filling from where we left off, but for kBottomUp we start |
| 84 * filling at the top of the image. | 97 * filling at the top of the image. |
| 85 */ | 98 */ |
| 86 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; | 99 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; |
| 87 | 100 |
| 88 /* | 101 /* |
| 89 * Compute the number of colors in the color table | 102 * Compute the number of colors in the color table |
| 90 */ | 103 */ |
| 91 uint32_t computeNumColors(uint32_t numColors); | 104 uint32_t computeNumColors(uint32_t numColors); |
| 92 | 105 |
| 93 /* | 106 /* |
| 94 * Accessors used by subclasses | 107 * Accessors used by subclasses |
| 95 */ | 108 */ |
| 96 uint16_t bitsPerPixel() const { return fBitsPerPixel; } | 109 uint16_t bitsPerPixel() const { return fBitsPerPixel; } |
| 97 RowOrder rowOrder() const { return fRowOrder; } | 110 SkScanlineDecoder::SkScanlineOrder rowOrder() const { return fRowOrder; } |
| 111 |
| 112 /* |
| 113 * To be overriden by bmp subclasses, which provide unique implementations. |
| 114 * Performs subclass specific setup. |
| 115 * |
| 116 * @param dstInfo Contains output information. Height specifies |
| 117 * the total number of rows that will be decoded. |
| 118 * @param options Additonal options to pass to the decoder. |
| 119 * @param inputColorPtr Client-provided memory for a color table. Must |
| 120 * be enough for 256 colors. This will be |
| 121 * populated with colors if the encoded image uses |
| 122 * a color table. |
| 123 * @param inputColorCount If the encoded image uses a color table, this |
| 124 * will be set to the number of colors in the |
| 125 * color table. |
| 126 */ |
| 127 virtual SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo, |
| 128 const SkCodec::Options& options, SkPMColor inputColorPtr[], |
| 129 int* inputColorCount) = 0; |
| 98 | 130 |
| 99 private: | 131 private: |
| 100 | 132 |
| 101 /* | 133 /* |
| 102 * Creates a bmp decoder | 134 * Creates a bmp decoder |
| 103 * Reads enough of the stream to determine the image format | 135 * Reads enough of the stream to determine the image format |
| 104 */ | 136 */ |
| 105 static SkCodec* NewFromStream(SkStream*, bool inIco); | 137 static SkCodec* NewFromStream(SkStream*, bool inIco); |
| 106 | 138 |
| 107 const uint16_t fBitsPerPixel; | 139 /* |
| 108 const RowOrder fRowOrder; | 140 * Decodes the next dstInfo.height() lines. |
| 141 * |
| 142 * onGetPixels() uses this for full image decodes. |
| 143 * SkScaledCodec::onGetPixels() uses the scanline decoder to call this with |
| 144 * dstInfo.height() = 1, in order to implement sampling. |
| 145 * A potential future use is to allow the caller to decode a subset of the |
| 146 * lines in the image. |
| 147 * |
| 148 * @param dstInfo Contains output information. Height specifies the |
| 149 * number of rows to decode at this time. |
| 150 * @param dst Memory location to store output pixels |
| 151 * @param dstRowBytes Bytes in a row of the destination |
| 152 */ |
| 153 virtual Result decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstR
owBytes, |
| 154 const Options& opts) = 0; |
| 155 |
| 156 const uint16_t fBitsPerPixel; |
| 157 const SkScanlineDecoder::SkScanlineOrder fRowOrder; |
| 158 |
| 159 friend class SkBmpScanlineDecoder; |
| 109 | 160 |
| 110 typedef SkCodec INHERITED; | 161 typedef SkCodec INHERITED; |
| 111 }; | 162 }; |
| 112 | 163 |
| 113 #endif | 164 #endif |
| OLD | NEW |