Chromium Code Reviews| 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: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 41 * Reads enough of the stream to determine the image format | 42 * Reads enough of the stream to determine the image format |
| 42 */ | 43 */ |
| 43 static SkCodec* NewFromStream(SkStream*); | 44 static SkCodec* NewFromStream(SkStream*); |
| 44 | 45 |
| 45 /* | 46 /* |
| 46 * Creates a bmp decoder for a bmp embedded in ico | 47 * Creates a bmp decoder for a bmp embedded in ico |
| 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 static SkCodec* NewFromIco(SkStream*); | 50 static SkCodec* NewFromIco(SkStream*); |
| 50 | 51 |
| 52 /* | |
| 53 * Assumes IsBmp was called and returned true | |
| 54 * Creates a bmp scanline decoder | |
| 55 * Takes ownership of the stream | |
| 56 */ | |
| 57 static SkScanlineDecoder* NewSDFromStream(SkStream* stream); | |
| 58 | |
| 51 protected: | 59 protected: |
| 52 | 60 |
| 53 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, | 61 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, |
| 54 RowOrder rowOrder); | 62 RowOrder rowOrder); |
| 55 | 63 |
| 56 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } | 64 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } |
| 57 | 65 |
| 58 /* | 66 /* |
| 59 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | 67 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool |
| 60 * representing success or failure. If it returned true, and codecOut was | 68 * representing success or failure. If it returned true, and codecOut was |
| 61 * not NULL, it will be set to a new SkBmpCodec. | 69 * not NULL, it will be set to a new SkBmpCodec. |
| 62 * Does *not* take ownership of the passed in SkStream. | 70 * Does *not* take ownership of the passed in SkStream. |
| 63 */ | 71 */ |
| 64 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); | 72 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); |
| 65 | 73 |
| 66 bool onRewind() override; | 74 bool onRewind() override; |
| 67 | 75 |
| 68 /* | 76 /* |
| 69 * Returns whether this BMP is part of an ICO image. | 77 * Returns whether this BMP is part of an ICO image. |
| 70 */ | 78 */ |
| 71 bool inIco() const { | 79 bool inIco() const { |
| 72 return this->onInIco(); | 80 return this->onInIco(); |
| 73 } | 81 } |
| 74 | 82 |
| 75 virtual bool onInIco() const { | 83 virtual bool onInIco() const { |
| 76 return false; | 84 return false; |
| 77 } | 85 } |
| 78 | 86 |
| 79 /* | 87 /* |
| 88 * Get the destination row number corresponsing to the encoded row number. | |
| 89 * For kTopDown, we simply return y, but for kBottomUp, the rows will be | |
| 90 * decoded in reverse order. | |
| 91 */ | |
| 92 int32_t getDstRow(int32_t y); | |
| 93 | |
| 94 /* | |
| 80 * Get the destination row to start filling from | 95 * Get the destination row to start filling from |
| 81 * Used to fill the remainder of the image on incomplete input for bmps | 96 * 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, | 97 * 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 | 98 * we start filling from where we left off, but for kBottomUp we start |
| 84 * filling at the top of the image. | 99 * filling at the top of the image. |
| 85 */ | 100 */ |
| 86 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; | 101 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; |
| 87 | 102 |
| 88 /* | 103 /* |
| 89 * Compute the number of colors in the color table | 104 * Compute the number of colors in the color table |
| 90 */ | 105 */ |
| 91 uint32_t computeNumColors(uint32_t numColors); | 106 uint32_t computeNumColors(uint32_t numColors); |
| 92 | 107 |
| 93 /* | 108 /* |
| 94 * Accessors used by subclasses | 109 * Accessors used by subclasses |
| 95 */ | 110 */ |
| 96 uint16_t bitsPerPixel() const { return fBitsPerPixel; } | 111 uint16_t bitsPerPixel() const { return fBitsPerPixel; } |
| 97 RowOrder rowOrder() const { return fRowOrder; } | 112 RowOrder rowOrder() const { return fRowOrder; } |
| 98 | 113 |
| 99 private: | 114 private: |
| 100 | 115 |
| 101 /* | 116 /* |
| 102 * Creates a bmp decoder | 117 * Creates a bmp decoder |
| 103 * Reads enough of the stream to determine the image format | 118 * Reads enough of the stream to determine the image format |
| 104 */ | 119 */ |
| 105 static SkCodec* NewFromStream(SkStream*, bool inIco); | 120 static SkCodec* NewFromStream(SkStream*, bool inIco); |
| 106 | 121 |
| 107 const uint16_t fBitsPerPixel; | 122 /* |
| 108 const RowOrder fRowOrder; | 123 * To be overriden by bmp subclasses, which provide unique implementations. |
| 124 * Performs subclass specific setup. | |
| 125 */ | |
| 126 virtual SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo, | |
|
scroggo
2015/08/26 22:40:09
Can you add comments explaining the parameters? Do
msarett
2015/08/27 15:00:27
Added comments and made this protected. Is there
scroggo
2015/08/27 20:14:22
Good question. This was just my memory of how we d
| |
| 127 const SkCodec::Options& options, SkPMColor inputColorPtr[], | |
| 128 int* inputColorCount) = 0; | |
| 129 | |
| 130 /* | |
| 131 * Decodes the next dstInfo.height() lines. | |
| 132 * | |
| 133 * onGetPixels() uses this for full image decodes. | |
| 134 * SkScaledCodec::onGetPixels() uses the scanline decoder to call this with | |
| 135 * dstInfo.height() = 1, in order to implement sampling. | |
| 136 * A potential future use is to allow the caller to decode a subset of the | |
| 137 * lines in the image. | |
| 138 * | |
| 139 * @param dstInfo Contains output information. Height specifies the | |
| 140 * number of rows to decode at this time. | |
| 141 * @param dst Memory location to store output pixels | |
| 142 * @param dstRowBytes Bytes in a row of the destination | |
| 143 */ | |
| 144 virtual Result decode(const SkImageInfo& dstInfo, void* dst, size_t dstRowBy tes, | |
| 145 const Options& opts) = 0; | |
| 146 | |
| 147 const uint16_t fBitsPerPixel; | |
| 148 const RowOrder fRowOrder; | |
| 149 | |
| 150 friend class SkBmpScanlineDecoder; | |
| 109 | 151 |
| 110 typedef SkCodec INHERITED; | 152 typedef SkCodec INHERITED; |
| 111 }; | 153 }; |
| 112 | 154 |
| 113 #endif | 155 #endif |
| OLD | NEW |