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: |
| 24 | 25 |
| 25 /* | 26 /* |
| 26 * Describes if rows of the input start at the top or bottom of the image | 27 * Describes if rows of the input start at the top or bottom of the image |
| 27 */ | 28 */ |
| 28 enum RowOrder { | 29 enum RowOrder { |
| 29 kTopDown_RowOrder, | 30 kTopDown_RowOrder, |
| 30 kBottomUp_RowOrder | 31 kBottomUp_RowOrder |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 /* | 34 /* |
| 35 * Used to define the input format of the bmp | |
| 36 */ | |
| 37 enum BmpInputFormat { | |
| 38 kStandard_BmpInputFormat, | |
| 39 kRLE_BmpInputFormat, | |
| 40 kBitMask_BmpInputFormat, | |
| 41 kUnknown_BmpInputFormat | |
| 42 }; | |
| 43 | |
| 44 /* | |
| 34 * Checks the start of the stream to see if the image is a bmp | 45 * Checks the start of the stream to see if the image is a bmp |
| 35 */ | 46 */ |
| 36 static bool IsBmp(SkStream*); | 47 static bool IsBmp(SkStream*); |
| 37 | 48 |
| 38 /* | 49 /* |
| 39 * Assumes IsBmp was called and returned true | 50 * Assumes IsBmp was called and returned true |
| 40 * Creates a bmp decoder | 51 * Creates a bmp decoder |
| 41 * Reads enough of the stream to determine the image format | 52 * Reads enough of the stream to determine the image format |
| 42 */ | 53 */ |
| 43 static SkCodec* NewFromStream(SkStream*); | 54 static SkCodec* NewFromStream(SkStream*); |
| 44 | 55 |
| 45 /* | 56 /* |
| 46 * Creates a bmp decoder for a bmp embedded in ico | 57 * Creates a bmp decoder for a bmp embedded in ico |
| 47 * Reads enough of the stream to determine the image format | 58 * Reads enough of the stream to determine the image format |
| 48 */ | 59 */ |
| 49 static SkCodec* NewFromIco(SkStream*); | 60 static SkCodec* NewFromIco(SkStream*); |
| 50 | 61 |
| 62 /* | |
| 63 * Assumes IsBmp was called and returned true | |
| 64 * Creates a bmp scanline decoder | |
| 65 * Takes ownership of the stream | |
| 66 */ | |
| 67 static SkScanlineDecoder* NewSDFromStream(SkStream* stream); | |
| 68 | |
| 51 protected: | 69 protected: |
| 52 | 70 |
| 53 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, | 71 SkBmpCodec(const SkImageInfo& info, SkStream* stream, BmpInputFormat inputFo rmat, |
| 54 RowOrder rowOrder); | 72 uint16_t bitsPerPixel, RowOrder rowOrder); |
| 55 | 73 |
| 56 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } | 74 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } |
| 57 | 75 |
| 58 /* | 76 /* |
| 59 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | 77 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool |
| 60 * representing success or failure. If it returned true, and codecOut was | 78 * representing success or failure. If it returned true, and codecOut was |
| 61 * not NULL, it will be set to a new SkBmpCodec. | 79 * not NULL, it will be set to a new SkBmpCodec. |
| 62 * Does *not* take ownership of the passed in SkStream. | 80 * Does *not* take ownership of the passed in SkStream. |
| 63 */ | 81 */ |
| 64 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); | 82 static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 RowOrder rowOrder() const { return fRowOrder; } | 115 RowOrder rowOrder() const { return fRowOrder; } |
| 98 | 116 |
| 99 private: | 117 private: |
| 100 | 118 |
| 101 /* | 119 /* |
| 102 * Creates a bmp decoder | 120 * Creates a bmp decoder |
| 103 * Reads enough of the stream to determine the image format | 121 * Reads enough of the stream to determine the image format |
| 104 */ | 122 */ |
| 105 static SkCodec* NewFromStream(SkStream*, bool inIco); | 123 static SkCodec* NewFromStream(SkStream*, bool inIco); |
| 106 | 124 |
| 107 const uint16_t fBitsPerPixel; | 125 /* |
| 108 const RowOrder fRowOrder; | 126 * Allow to BmpCodec subclasses to implement unique onStart() functions |
|
scroggo
2015/08/14 21:53:00
Maybe mention that this relates to scanline decodi
msarett
2015/08/17 19:16:13
This is now shared with onGetPixels().
| |
| 127 */ | |
| 128 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::O ptions& options, | |
|
scroggo
2015/08/14 21:53:01
I do not know whether it's good or bad that this s
msarett
2015/08/17 19:16:13
I think it makes sense to change the name because
| |
| 129 SkPMColor inputColorPtr[], int* inputColorCount) = 0; | |
| 130 | |
| 131 /* | |
| 132 * Performs the row by row decode | |
| 133 * Unique for each of the bmp subclasses | |
| 134 */ | |
| 135 virtual Result decode(const SkImageInfo& dstInfo, void* dst, size_t dstRowBy tes, | |
|
scroggo
2015/08/14 21:53:01
Can you add a description for these parameters? I
msarett
2015/08/17 19:16:13
Yeah I'm adding comments, this is awkward. Ideall
| |
| 136 const Options& opts) = 0; | |
| 137 | |
| 138 const BmpInputFormat fInputFormat; | |
| 139 const uint16_t fBitsPerPixel; | |
| 140 const RowOrder fRowOrder; | |
| 141 | |
| 142 friend class SkBmpScanlineDecoder; | |
| 109 | 143 |
| 110 typedef SkCodec INHERITED; | 144 typedef SkCodec INHERITED; |
| 111 }; | 145 }; |
| 112 | 146 |
| 113 #endif | 147 #endif |
| OLD | NEW |