| 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 "SkMaskSwizzler.h" | |
| 11 #include "SkStream.h" | |
| 12 #include "SkSwizzler.h" | |
| 13 #include "SkTypes.h" | |
| 14 | |
| 15 // TODO: rename SkCodec_libbmp files to SkBmpCodec | |
| 16 // TODO: define a wrapper for SkDebugf that doesn't always print | |
| 17 /* | |
| 18 * | |
| 19 * This class implements the decoding for bmp images | |
| 20 * | |
| 21 */ | |
| 22 class SkBmpCodec : public SkCodec { | |
| 23 public: | |
| 24 | |
| 25 /* | |
| 26 * | |
| 27 * Describes if rows of the input start at the top or bottom of the image | |
| 28 * | |
| 29 */ | |
| 30 enum RowOrder { | |
| 31 kTopDown_RowOrder, | |
| 32 kBottomUp_RowOrder | |
| 33 }; | |
| 34 | |
| 35 /* | |
| 36 * | |
| 37 * Checks the start of the stream to see if the image is a bitmap | |
| 38 * | |
| 39 */ | |
| 40 static bool IsBmp(SkStream*); | |
| 41 | |
| 42 /* | |
| 43 * | |
| 44 * Assumes IsBmp was called and returned true | |
| 45 * Creates a bitmap decoder | |
| 46 * Reads enough of the stream to determine the image format | |
| 47 * | |
| 48 */ | |
| 49 static SkCodec* NewFromStream(SkStream*); | |
| 50 | |
| 51 protected: | |
| 52 | |
| 53 /* | |
| 54 * | |
| 55 * Initiates the bitmap decode | |
| 56 * | |
| 57 */ | |
| 58 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, | |
| 59 size_t dstRowBytes, SkPMColor*, | |
| 60 int*) SK_OVERRIDE; | |
| 61 | |
| 62 private: | |
| 63 | |
| 64 /* | |
| 65 * | |
| 66 * Used to define the input format of the bitmap | |
| 67 * | |
| 68 */ | |
| 69 enum BitmapInputFormat { | |
| 70 kStandard_BitmapInputFormat, | |
| 71 kRLE_BitmapInputFormat, | |
| 72 kBitMask_BitmapInputFormat, | |
| 73 kUnknown_BitmapInputFormat | |
| 74 }; | |
| 75 | |
| 76 /* | |
| 77 * | |
| 78 * Performs the bitmap decoding for bit masks input format | |
| 79 * | |
| 80 */ | |
| 81 Result decodeMask(const SkImageInfo& dstInfo, void* dst, | |
| 82 size_t dstRowBytes); | |
| 83 | |
| 84 /* | |
| 85 * | |
| 86 * Set an RLE pixel using the color table | |
| 87 * | |
| 88 */ | |
| 89 void setRLEPixel(SkPMColor* dst, size_t dstRowBytes, int height, | |
| 90 uint32_t x, uint32_t y, uint8_t index); | |
| 91 | |
| 92 /* | |
| 93 * | |
| 94 * Performs the bitmap decoding for RLE input format | |
| 95 * | |
| 96 */ | |
| 97 Result decodeRLE(const SkImageInfo& dstInfo, void* dst, | |
| 98 size_t dstRowBytes); | |
| 99 | |
| 100 /* | |
| 101 * | |
| 102 * Performs the bitmap decoding for standard input format | |
| 103 * | |
| 104 */ | |
| 105 Result decode(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes); | |
| 106 | |
| 107 /* | |
| 108 * | |
| 109 * Creates an instance of the decoder | |
| 110 * Called only by NewFromStream | |
| 111 * | |
| 112 * @param srcInfo contains the source width and height | |
| 113 * @param stream the stream of image data | |
| 114 * @param bitsPerPixel the number of bits used to store each pixel | |
| 115 * @param format the format of the bmp file | |
| 116 * @param masks optional color masks for certain bmp formats, passes | |
| 117 ownership to SkBmpCodec | |
| 118 * @param colorTable array representing the color table for index-based bmp | |
| 119 * formats, colors are unpremultiplied, passes ownership | |
| 120 * to SkBmpCodec | |
| 121 * @param rowOrder indicates whether rows are ordered top-down or bottom-up | |
| 122 * @param remainingBytes used only for RLE decodes, as we must decode all | |
| 123 * of the data at once rather than row by row | |
| 124 * it indicates the amount of data left in the stream | |
| 125 * after decoding the headers | |
| 126 * | |
| 127 */ | |
| 128 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, | |
| 129 uint16_t bitsPerPixel, BitmapInputFormat format, | |
| 130 SkMasks* masks, SkPMColor* colorTable, | |
| 131 RowOrder rowOrder, uint32_t remainingBytes); | |
| 132 | |
| 133 // Fields | |
| 134 const uint16_t fBitsPerPixel; | |
| 135 const BitmapInputFormat fInputFormat; | |
| 136 SkAutoTDelete<SkMasks> fMasks; // owned | |
| 137 const SkAutoTDeleteArray<SkPMColor> fColorTable; // owned, unpremul | |
| 138 const RowOrder fRowOrder; | |
| 139 const uint32_t fRemainingBytes; | |
| 140 | |
| 141 typedef SkCodec INHERITED; | |
| 142 }; | |
| OLD | NEW |