OLD | NEW |
(Empty) | |
| 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 "SkCodec.h" |
| 9 #include "SkImageInfo.h" |
| 10 #include "SkStream.h" |
| 11 #include "SkSwizzler.h" |
| 12 #include "SkTypes.h" |
| 13 |
| 14 #ifdef SK_SUPPORT_LEGACY_IMAGE_GENERATOR_RETURN |
| 15 #define onGetPixels onGetPixelsEnum |
| 16 #endif |
| 17 |
| 18 /* |
| 19 * |
| 20 * This class implements the decoding for bmp images |
| 21 * |
| 22 */ |
| 23 class SkBmpCodec : public SkCodec { |
| 24 public: |
| 25 |
| 26 /* |
| 27 * |
| 28 * Checks the start of the stream to see if the image is a bitmap |
| 29 * |
| 30 */ |
| 31 static bool IsBmp(SkStream* stream); |
| 32 |
| 33 /* |
| 34 * |
| 35 * Assumes IsBmp was called and returned true |
| 36 * Creates a bitmap decoder |
| 37 * Reads enough of the stream to determine the image format |
| 38 * |
| 39 */ |
| 40 static SkCodec* NewFromStream(SkStream* stream); |
| 41 |
| 42 protected: |
| 43 |
| 44 /* |
| 45 * |
| 46 * Initiates the bitmap decode |
| 47 * |
| 48 */ |
| 49 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, |
| 50 size_t dstRowBytes, SkPMColor* colorTable, |
| 51 int*) SK_OVERRIDE; |
| 52 |
| 53 private: |
| 54 |
| 55 /* |
| 56 * |
| 57 * Used to define the input format of the bitmap |
| 58 * |
| 59 */ |
| 60 enum BitmapInputFormat { |
| 61 kStandard_BitmapInputFormat, |
| 62 k4BitRLE_BitmapInputFormat, |
| 63 k8BitRLE_BitmapInputFormat, |
| 64 k24BitRLE_BitmapInputFormat, |
| 65 kBitMask_BitmapInputFormat, |
| 66 kUnknown_BitmapInputFormat |
| 67 }; |
| 68 |
| 69 /* |
| 70 * |
| 71 * Set an RLE pixel using the color table |
| 72 * |
| 73 */ |
| 74 void setPixel(SkPMColor* dst, uint32_t dstRowBytes, int height, |
| 75 uint32_t x, uint32_t y, uint8_t index); |
| 76 |
| 77 /* |
| 78 * |
| 79 * Performs the bitmap decoding for standard and bit masks input format |
| 80 * |
| 81 */ |
| 82 Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes); |
| 83 |
| 84 /* |
| 85 * |
| 86 * Performs the bitmap decoding for RLE input format |
| 87 * |
| 88 */ |
| 89 Result decodeRLE(const SkImageInfo& dstInfo, void* dst, |
| 90 uint32_t dstRowBytes); |
| 91 |
| 92 /* |
| 93 * |
| 94 * Creates an instance of the decoder |
| 95 * Called only by NewFromStream |
| 96 * |
| 97 */ |
| 98 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, |
| 99 uint16_t bitsPerPixel, BitmapInputFormat format, |
| 100 SkSwizzler::ColorMasks* bitMasks, SkPMColor* colorTable, |
| 101 bool inverted, uint32_t remainingBytes); |
| 102 |
| 103 // Fields |
| 104 const uint16_t fBitsPerPixel; |
| 105 const BitmapInputFormat fInputFormat; |
| 106 const SkAutoTDelete<SkSwizzler::ColorMasks> fBitMasks; |
| 107 const SkAutoTDeleteArray<SkPMColor> fColorTable; |
| 108 const bool fInverted; |
| 109 const uint32_t fRemainingBytes; |
| 110 |
| 111 typedef SkCodec INHERITED; |
| 112 }; |
OLD | NEW |