1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBmpCodec_DEFINED
#define SkBmpCodec_DEFINED
#include "SkCodec.h"
#include "SkColorTable.h"
#include "SkImageInfo.h"
#include "SkMaskSwizzler.h"
#include "SkStream.h"
#include "SkSwizzler.h"
#include "SkTypes.h"
/*
* This class enables code sharing between its bmp codec subclasses. The
* subclasses actually do the work.
*/
class SkBmpCodec : public SkCodec {
public:
/*
* Describes if rows of the input start at the top or bottom of the image
*/
enum RowOrder {
kTopDown_RowOrder,
kBottomUp_RowOrder
};
/*
* Checks the start of the stream to see if the image is a bmp
*/
static bool IsBmp(SkStream*);
/*
* Assumes IsBmp was called and returned true
* Creates a bmp decoder
* Reads enough of the stream to determine the image format
*/
static SkCodec* NewFromStream(SkStream*);
/*
* Creates a bmp decoder for a bmp embedded in ico
* Reads enough of the stream to determine the image format
*/
static SkCodec* NewFromIco(SkStream*);
protected:
SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel,
RowOrder rowOrder);
SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedFormat; }
/*
* Read enough of the stream to initialize the SkBmpCodec. Returns a bool
* representing success or failure. If it returned true, and codecOut was
* not NULL, it will be set to a new SkBmpCodec.
* Does *not* take ownership of the passed in SkStream.
*/
static bool ReadHeader(SkStream*, bool inIco, SkCodec** codecOut);
bool onRewind() override;
/*
* Returns whether this BMP is part of an ICO image.
*/
bool inIco() const {
return this->onInIco();
}
virtual bool onInIco() const {
return false;
}
/*
* Get the destination row to start filling from
* Used to fill the remainder of the image on incomplete input for bmps
* This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown,
* we start filling from where we left off, but for kBottomUp we start
* filling at the top of the image.
*/
void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const;
/*
* Compute the number of colors in the color table
*/
uint32_t computeNumColors(uint32_t numColors);
/*
* Accessors used by subclasses
*/
uint16_t bitsPerPixel() const { return fBitsPerPixel; }
RowOrder rowOrder() const { return fRowOrder; }
private:
/*
* Creates a bmp decoder
* Reads enough of the stream to determine the image format
*/
static SkCodec* NewFromStream(SkStream*, bool inIco);
const uint16_t fBitsPerPixel;
const RowOrder fRowOrder;
typedef SkCodec INHERITED;
};
#endif
|