msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 7 | #ifndef SkBmpStandardCodec_DEFINED |
| 8 | #define SkBmpStandardCodec_DEFINED |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 9 | |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame] | 10 | #include "SkBmpBaseCodec.h" |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 11 | #include "SkColorTable.h" |
| 12 | #include "SkImageInfo.h" |
| 13 | #include "SkSwizzler.h" |
| 14 | #include "SkTypes.h" |
| 15 | |
| 16 | /* |
| 17 | * This class implements the decoding for bmp images that use "standard" modes, |
| 18 | * which essentially means they do not contain bit masks or RLE codes. |
| 19 | */ |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame] | 20 | class SkBmpStandardCodec : public SkBmpBaseCodec { |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 21 | public: |
| 22 | |
| 23 | /* |
| 24 | * Creates an instance of the decoder |
| 25 | * |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 26 | * Called only by SkBmpCodec::MakeFromStream |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 27 | * There should be no other callers despite this being public |
| 28 | * |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 29 | * @param info contains properties of the encoded data |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 30 | * @param stream the stream of encoded image data |
| 31 | * @param bitsPerPixel the number of bits used to store each pixel |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 32 | * @param numColors the number of colors in the color table |
| 33 | * @param bytesPerColor the number of bytes in the stream used to represent |
| 34 | each color in the color table |
| 35 | * @param offset the offset of the image pixel data from the end of the |
| 36 | * headers |
| 37 | * @param rowOrder indicates whether rows are ordered top-down or bottom-up |
msarett | f4004f9 | 2016-02-11 10:49:31 -0800 | [diff] [blame] | 38 | * @param isOpaque indicates if the bmp itself is opaque (before applying |
| 39 | * the icp mask, if there is one) |
| 40 | * @param inIco indicates if the bmp is embedded in an ico file |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 41 | */ |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 42 | SkBmpStandardCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream> stream, |
| 43 | uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor, |
| 44 | uint32_t offset, SkCodec::SkScanlineOrder rowOrder, |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 45 | bool isOpaque, bool inIco); |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | |
| 49 | Result onGetPixels(const SkImageInfo& dstInfo, void* dst, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 50 | size_t dstRowBytes, const Options&, |
| 51 | int*) override; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 52 | |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 53 | bool onInIco() const override { |
| 54 | return fInIco; |
| 55 | } |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 56 | |
Matt Sarett | 1b96c6f | 2016-11-03 16:15:20 -0400 | [diff] [blame] | 57 | SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 58 | const SkCodec::Options& options) override; |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 59 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 60 | SkSampler* getSampler(bool createIfNecessary) override { |
| 61 | SkASSERT(fSwizzler); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 62 | return fSwizzler.get(); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 63 | } |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 64 | |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 65 | private: |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 66 | bool createColorTable(SkColorType colorType, SkAlphaType alphaType); |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 67 | SkEncodedInfo swizzlerInfo() const; |
msarett | b30d698 | 2016-02-15 10:18:45 -0800 | [diff] [blame] | 68 | void initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts); |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 69 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 70 | int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, |
| 71 | const Options& opts) override; |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 72 | |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 73 | /* |
| 74 | * @param stream This may be a pointer to the stream owned by the parent SkCodec |
| 75 | * or a sub-stream of the stream owned by the parent SkCodec. |
| 76 | * Either way, this stream is unowned. |
| 77 | */ |
| 78 | void decodeIcoMask(SkStream* stream, const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes); |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 79 | |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 80 | sk_sp<SkColorTable> fColorTable; |
benjaminwagner | 886e5e4 | 2015-12-04 08:48:26 -0800 | [diff] [blame] | 81 | // fNumColors is the number specified in the header, or 0 if not present in the header. |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 82 | const uint32_t fNumColors; |
| 83 | const uint32_t fBytesPerColor; |
| 84 | const uint32_t fOffset; |
| 85 | std::unique_ptr<SkSwizzler> fSwizzler; |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 86 | const bool fIsOpaque; |
| 87 | const bool fInIco; |
| 88 | const size_t fAndMaskRowBytes; // only used for fInIco decodes |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 89 | |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame] | 90 | typedef SkBmpBaseCodec INHERITED; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 91 | }; |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 92 | #endif // SkBmpStandardCodec_DEFINED |