SkBmpStandardCodec.h revision 46c574725676b26ada63ac15e42cda309dcd5090
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 */ 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 30 * @param format the format of the bmp file 31 * @param numColors the number of colors in the color table 32 * @param bytesPerColor the number of bytes in the stream used to represent 33 each color in the color table 34 * @param offset the offset of the image pixel data from the end of the 35 * headers 36 * @param rowOrder indicates whether rows are ordered top-down or bottom-up 37 */ 38 SkBmpStandardCodec(const SkImageInfo& srcInfo, SkStream* stream, 39 uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor, 40 uint32_t offset, SkCodec::SkScanlineOrder rowOrder, 41 bool isIco); 42 43protected: 44 45 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, 46 size_t dstRowBytes, const Options&, SkPMColor*, 47 int*) override; 48 49 bool onInIco() const override { 50 return fInIco; 51 } 52 53 SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo, 54 const SkCodec::Options& options, SkPMColor inputColorPtr[], 55 int* inputColorCount) override; 56 57private: 58 59 /* 60 * Creates the color table 61 * Sets colorCount to the new color count if it is non-nullptr 62 */ 63 bool createColorTable(SkAlphaType alphaType, int* colorCount); 64 65 bool initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts); 66 67 Result decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, 68 const Options& opts) override; 69 70 Result decodeIcoMask(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes); 71 72 SkAutoTUnref<SkColorTable> fColorTable; // owned 73 const uint32_t fNumColors; 74 const uint32_t fBytesPerColor; 75 const uint32_t fOffset; 76 SkAutoTDelete<SkSwizzler> fSwizzler; 77 const size_t fSrcRowBytes; 78 SkAutoTDeleteArray<uint8_t> fSrcBuffer; 79 const bool fInIco; 80 81 typedef SkBmpCodec INHERITED; 82}; 83