Chromium Code Reviews| 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); | |
|
scroggo
2015/02/27 17:04:03
Nit: typically I think we leave out the parameter
| |
| 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 kBitMask_BitmapInputFormat, | |
| 65 kUnknown_BitmapInputFormat | |
| 66 }; | |
| 67 | |
| 68 /* | |
| 69 * | |
| 70 * Set an RLE pixel using the color table | |
| 71 * | |
| 72 */ | |
| 73 void setPixel(SkPMColor* dst, uint32_t dstRowBytes, int height, | |
| 74 uint32_t x, uint32_t y, uint8_t index); | |
| 75 | |
| 76 /* | |
| 77 * | |
| 78 * Performs the bitmap decoding for standard and bit masks input format | |
| 79 * | |
| 80 */ | |
| 81 Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes); | |
| 82 | |
| 83 /* | |
| 84 * | |
| 85 * Performs the bitmap decoding for RLE input format | |
| 86 * | |
| 87 */ | |
| 88 Result decodeRLE(const SkImageInfo& dstInfo, void* dst, | |
| 89 uint32_t dstRowBytes); | |
| 90 | |
| 91 /* | |
| 92 * | |
| 93 * Creates an instance of the decoder | |
| 94 * Called only by NewFromStream | |
| 95 * | |
| 96 */ | |
| 97 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, | |
| 98 uint16_t bitsPerPixel, BitmapInputFormat format, | |
| 99 SkSwizzler::ColorMasks* bitMasks, SkPMColor* colorTable, | |
|
scroggo
2015/02/27 17:04:03
Could you add some comments describing which of th
| |
| 100 bool inverted, uint32_t remainingBytes); | |
| 101 | |
| 102 // Fields | |
| 103 const uint16_t fBitsPerPixel; | |
| 104 const BitmapInputFormat fInputFormat; | |
| 105 const SkAutoTDelete<SkSwizzler::ColorMasks> fBitMasks; | |
| 106 const SkAutoTDeleteArray<SkPMColor> fColorTable; | |
| 107 const bool fInverted; | |
| 108 const uint32_t fRemainingBytes; | |
| 109 | |
| 110 typedef SkCodec INHERITED; | |
| 111 }; | |
| OLD | NEW |