Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: src/codec/SkBmpCodec.h

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments from previous patch sets Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
scroggo 2015/08/27 20:14:22 corresponding*
msarett 2015/08/27 21:21:46 Sorry. Fixed!
89 * For kTopDown, we simply return y, but for kBottomUp, the rows will be
90 * decoded in reverse order.
91 *
92 * @param y Iterates from 0 to height, indicating the current row.
93 * @param height The height of the current subset of the image that we are
94 * decoding. This is generally equal to the full height
95 * when we want to decode the full or one when we are
96 * sampling.
97 */
98 int32_t getDstRow(int32_t y, int32_t height);
99
100 /*
80 * Get the destination row to start filling from 101 * Get the destination row to start filling from
81 * Used to fill the remainder of the image on incomplete input for bmps 102 * 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, 103 * 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 104 * we start filling from where we left off, but for kBottomUp we start
84 * filling at the top of the image. 105 * filling at the top of the image.
85 */ 106 */
86 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; 107 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const;
87 108
88 /* 109 /*
89 * Compute the number of colors in the color table 110 * Compute the number of colors in the color table
90 */ 111 */
91 uint32_t computeNumColors(uint32_t numColors); 112 uint32_t computeNumColors(uint32_t numColors);
92 113
93 /* 114 /*
94 * Accessors used by subclasses 115 * Accessors used by subclasses
95 */ 116 */
96 uint16_t bitsPerPixel() const { return fBitsPerPixel; } 117 uint16_t bitsPerPixel() const { return fBitsPerPixel; }
97 RowOrder rowOrder() const { return fRowOrder; } 118 RowOrder rowOrder() const { return fRowOrder; }
98 119
120 /*
121 * To be overriden by bmp subclasses, which provide unique implementations.
122 * Performs subclass specific setup.
123 *
124 * @param dstInfo Contains output information. Height specifies
125 * the total number of rows that can be decoded.
scroggo 2015/08/27 20:14:23 will be decoded?
msarett 2015/08/27 21:21:46 Done.
126 * @param optoins Additonal options to pass to the decoder.
scroggo 2015/08/27 20:14:23 options*
msarett 2015/08/27 21:21:46 Done.
127 * @param inputColorPtr Client provides memory for a color table. This
scroggo 2015/08/27 20:14:22 Maybe this should be Client-provided memory for a
msarett 2015/08/27 21:21:46 Done.
128 * will be populated with colors if the encoded
129 * image uses a color table.
130 * @param inputColorCount If the encoded image uses a color table, this
131 * will be set to the number of colors in the
132 * color table.
133 */
134 virtual SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo,
135 const SkCodec::Options& options, SkPMColor inputColorPtr[],
136 int* inputColorCount) = 0;
137
99 private: 138 private:
100 139
101 /* 140 /*
102 * Creates a bmp decoder 141 * Creates a bmp decoder
103 * Reads enough of the stream to determine the image format 142 * Reads enough of the stream to determine the image format
104 */ 143 */
105 static SkCodec* NewFromStream(SkStream*, bool inIco); 144 static SkCodec* NewFromStream(SkStream*, bool inIco);
106 145
107 const uint16_t fBitsPerPixel; 146 /*
108 const RowOrder fRowOrder; 147 * Decodes the next dstInfo.height() lines.
148 *
149 * onGetPixels() uses this for full image decodes.
150 * SkScaledCodec::onGetPixels() uses the scanline decoder to call this with
151 * dstInfo.height() = 1, in order to implement sampling.
152 * A potential future use is to allow the caller to decode a subset of the
153 * lines in the image.
154 *
155 * @param dstInfo Contains output information. Height specifies the
156 * number of rows to decode at this time.
157 * @param dst Memory location to store output pixels
158 * @param dstRowBytes Bytes in a row of the destination
159 */
160 virtual Result decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstR owBytes,
161 const Options& opts) = 0;
162
163 const uint16_t fBitsPerPixel;
164 const RowOrder fRowOrder;
165
166 friend class SkBmpScanlineDecoder;
109 167
110 typedef SkCodec INHERITED; 168 typedef SkCodec INHERITED;
111 }; 169 };
112 170
113 #endif 171 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698