blob: 725b7bb68f7798afee81c42195239111eb999834 [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 */
7
8#include "SkBmpCodec.h"
9#include "SkColorTable.h"
10#include "SkImageInfo.h"
11#include "SkSwizzler.h"
12#include "SkTypes.h"
13
14/*
15 * This class implements the decoding for bmp images that use "standard" modes,
16 * which essentially means they do not contain bit masks or RLE codes.
17 */
18class SkBmpStandardCodec : public SkBmpCodec {
19public:
20
21 /*
22 * Creates an instance of the decoder
23 *
24 * Called only by SkBmpCodec::NewFromStream
25 * There should be no other callers despite this being public
26 *
27 * @param srcInfo contains the source width and height
28 * @param stream the stream of encoded image data
29 * @param bitsPerPixel the number of bits used to store each pixel
msarett4ab9d5f2015-08-06 15:34:42 -070030 * @param numColors the number of colors in the color table
31 * @param bytesPerColor the number of bytes in the stream used to represent
32 each color in the color table
33 * @param offset the offset of the image pixel data from the end of the
34 * headers
35 * @param rowOrder indicates whether rows are ordered top-down or bottom-up
msarettf4004f92016-02-11 10:49:31 -080036 * @param isOpaque indicates if the bmp itself is opaque (before applying
37 * the icp mask, if there is one)
38 * @param inIco indicates if the bmp is embedded in an ico file
msarett4ab9d5f2015-08-06 15:34:42 -070039 */
40 SkBmpStandardCodec(const SkImageInfo& srcInfo, SkStream* stream,
msarett5406d6f2015-08-31 06:55:13 -070041 uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
msarettf4004f92016-02-11 10:49:31 -080042 uint32_t offset, SkCodec::SkScanlineOrder rowOrder, bool isOpaque,
43 bool inIco);
msarett4ab9d5f2015-08-06 15:34:42 -070044
45protected:
46
47 Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
48 size_t dstRowBytes, const Options&, SkPMColor*,
msarette6dd0042015-10-09 11:07:34 -070049 int*, int*) override;
msarett4ab9d5f2015-08-06 15:34:42 -070050
scroggob427db12015-08-12 07:24:13 -070051 bool onInIco() const override {
52 return fInIco;
53 }
msarett5406d6f2015-08-31 06:55:13 -070054
55 SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo,
56 const SkCodec::Options& options, SkPMColor inputColorPtr[],
57 int* inputColorCount) override;
58
msarette6dd0042015-10-09 11:07:34 -070059
scroggoc5560be2016-02-03 09:42:42 -080060 uint32_t onGetFillValue(SkColorType) const override;
msarette6dd0042015-10-09 11:07:34 -070061
62 SkSampler* getSampler(bool createIfNecessary) override {
63 SkASSERT(fSwizzler);
64 return fSwizzler;
65 }
scroggoe7fc14b2015-10-02 13:14:46 -070066
msarett4ab9d5f2015-08-06 15:34:42 -070067private:
68
69 /*
70 * Creates the color table
halcanary96fcdcc2015-08-27 07:41:13 -070071 * Sets colorCount to the new color count if it is non-nullptr
msarett4ab9d5f2015-08-06 15:34:42 -070072 */
73 bool createColorTable(SkAlphaType alphaType, int* colorCount);
74
75 bool initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
76
msarette6dd0042015-10-09 11:07:34 -070077 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
78 const Options& opts) override;
msarett5406d6f2015-08-31 06:55:13 -070079
msarettbe8216a2015-12-04 08:00:50 -080080 /*
81 * @param stream This may be a pointer to the stream owned by the parent SkCodec
82 * or a sub-stream of the stream owned by the parent SkCodec.
83 * Either way, this stream is unowned.
84 */
85 void decodeIcoMask(SkStream* stream, const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes);
msarett4ab9d5f2015-08-06 15:34:42 -070086
87 SkAutoTUnref<SkColorTable> fColorTable; // owned
benjaminwagner886e5e42015-12-04 08:48:26 -080088 // fNumColors is the number specified in the header, or 0 if not present in the header.
msarett4ab9d5f2015-08-06 15:34:42 -070089 const uint32_t fNumColors;
90 const uint32_t fBytesPerColor;
91 const uint32_t fOffset;
92 SkAutoTDelete<SkSwizzler> fSwizzler;
msarett5406d6f2015-08-31 06:55:13 -070093 const size_t fSrcRowBytes;
msarett4ab9d5f2015-08-06 15:34:42 -070094 SkAutoTDeleteArray<uint8_t> fSrcBuffer;
msarettf4004f92016-02-11 10:49:31 -080095 const bool fIsOpaque;
msarett4ab9d5f2015-08-06 15:34:42 -070096 const bool fInIco;
msarettbe8216a2015-12-04 08:00:50 -080097 const size_t fAndMaskRowBytes; // only used for fInIco decodes
msarett4ab9d5f2015-08-06 15:34:42 -070098
99 typedef SkBmpCodec INHERITED;
100};