blob: 82937f385c9dda12f9597888b41c3631340b6255 [file] [log] [blame]
msarett4ab9d5f2015-08-06 15:34:42 -07001/*
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 Canary03a7f5f2017-02-10 09:06:38 -05007#ifndef SkBmpStandardCodec_DEFINED
8#define SkBmpStandardCodec_DEFINED
msarett4ab9d5f2015-08-06 15:34:42 -07009
Leon Scroggins IIId81fed92017-06-01 13:42:28 -040010#include "SkBmpBaseCodec.h"
msarett4ab9d5f2015-08-06 15:34:42 -070011#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 IIId81fed92017-06-01 13:42:28 -040020class SkBmpStandardCodec : public SkBmpBaseCodec {
msarett4ab9d5f2015-08-06 15:34:42 -070021public:
22
23 /*
24 * Creates an instance of the decoder
25 *
26 * Called only by SkBmpCodec::NewFromStream
27 * There should be no other callers despite this being public
28 *
msarettc30c4182016-04-20 11:53:35 -070029 * @param info contains properties of the encoded data
msarett4ab9d5f2015-08-06 15:34:42 -070030 * @param stream the stream of encoded image data
31 * @param bitsPerPixel the number of bits used to store each pixel
msarett4ab9d5f2015-08-06 15:34:42 -070032 * @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
msarettf4004f92016-02-11 10:49:31 -080038 * @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
msarett4ab9d5f2015-08-06 15:34:42 -070041 */
msarettc30c4182016-04-20 11:53:35 -070042 SkBmpStandardCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
msarett5406d6f2015-08-31 06:55:13 -070043 uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
msarettf4004f92016-02-11 10:49:31 -080044 uint32_t offset, SkCodec::SkScanlineOrder rowOrder, bool isOpaque,
45 bool inIco);
msarett4ab9d5f2015-08-06 15:34:42 -070046
47protected:
48
49 Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
50 size_t dstRowBytes, const Options&, SkPMColor*,
msarette6dd0042015-10-09 11:07:34 -070051 int*, int*) override;
msarett4ab9d5f2015-08-06 15:34:42 -070052
scroggob427db12015-08-12 07:24:13 -070053 bool onInIco() const override {
54 return fInIco;
55 }
msarett5406d6f2015-08-31 06:55:13 -070056
Matt Sarett1b96c6f2016-11-03 16:15:20 -040057 SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo,
msarett5406d6f2015-08-31 06:55:13 -070058 const SkCodec::Options& options, SkPMColor inputColorPtr[],
59 int* inputColorCount) override;
60
msarette6dd0042015-10-09 11:07:34 -070061
msarettf7eb6fc2016-09-13 09:04:11 -070062 uint64_t onGetFillValue(const SkImageInfo&) const override;
msarette6dd0042015-10-09 11:07:34 -070063
64 SkSampler* getSampler(bool createIfNecessary) override {
65 SkASSERT(fSwizzler);
Ben Wagner145dbcd2016-11-03 14:40:50 -040066 return fSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070067 }
scroggoe7fc14b2015-10-02 13:14:46 -070068
msarett4ab9d5f2015-08-06 15:34:42 -070069private:
70
71 /*
72 * Creates the color table
halcanary96fcdcc2015-08-27 07:41:13 -070073 * Sets colorCount to the new color count if it is non-nullptr
msarett4ab9d5f2015-08-06 15:34:42 -070074 */
msarett34e0ec42016-04-22 16:27:24 -070075 bool createColorTable(SkColorType colorType, SkAlphaType alphaType, int* colorCount);
msarett4ab9d5f2015-08-06 15:34:42 -070076
msarettb30d6982016-02-15 10:18:45 -080077 void initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
msarett4ab9d5f2015-08-06 15:34:42 -070078
msarette6dd0042015-10-09 11:07:34 -070079 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
80 const Options& opts) override;
msarett5406d6f2015-08-31 06:55:13 -070081
msarettbe8216a2015-12-04 08:00:50 -080082 /*
83 * @param stream This may be a pointer to the stream owned by the parent SkCodec
84 * or a sub-stream of the stream owned by the parent SkCodec.
85 * Either way, this stream is unowned.
86 */
87 void decodeIcoMask(SkStream* stream, const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes);
msarett4ab9d5f2015-08-06 15:34:42 -070088
Hal Canary67b39de2016-11-07 11:47:44 -050089 sk_sp<SkColorTable> fColorTable;
benjaminwagner886e5e42015-12-04 08:48:26 -080090 // fNumColors is the number specified in the header, or 0 if not present in the header.
Hal Canary67b39de2016-11-07 11:47:44 -050091 const uint32_t fNumColors;
92 const uint32_t fBytesPerColor;
93 const uint32_t fOffset;
94 std::unique_ptr<SkSwizzler> fSwizzler;
Hal Canary67b39de2016-11-07 11:47:44 -050095 const bool fIsOpaque;
96 const bool fInIco;
97 const size_t fAndMaskRowBytes; // only used for fInIco decodes
98 bool fXformOnDecode;
msarett4ab9d5f2015-08-06 15:34:42 -070099
Leon Scroggins IIId81fed92017-06-01 13:42:28 -0400100 typedef SkBmpBaseCodec INHERITED;
msarett4ab9d5f2015-08-06 15:34:42 -0700101};
Hal Canary03a7f5f2017-02-10 09:06:38 -0500102#endif // SkBmpStandardCodec_DEFINED