Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: include/codec/SkCodec.h

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Various fixes from Leon's comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkCodec_DEFINED 8 #ifndef SkCodec_DEFINED
9 #define SkCodec_DEFINED 9 #define SkCodec_DEFINED
10 10
11 #include "SkEndian.h"
11 #include "SkImageGenerator.h" 12 #include "SkImageGenerator.h"
12 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
13 #include "SkSize.h" 14 #include "SkSize.h"
14 #include "SkTemplates.h" 15 #include "SkTemplates.h"
15 #include "SkTypes.h" 16 #include "SkTypes.h"
16 17
17 class SkData; 18 class SkData;
18 class SkStream; 19 class SkStream;
19 20
20 /** 21 /**
(...skipping 20 matching lines...) Expand all
41 42
42 /** 43 /**
43 * Return a size that approximately supports the desired scale factor. 44 * Return a size that approximately supports the desired scale factor.
44 * The codec may not be able to scale efficiently to the exact scale 45 * The codec may not be able to scale efficiently to the exact scale
45 * factor requested, so return a size that approximates that scale. 46 * factor requested, so return a size that approximates that scale.
46 * 47 *
47 * FIXME: Move to SkImageGenerator? 48 * FIXME: Move to SkImageGenerator?
48 */ 49 */
49 SkISize getScaledDimensions(float desiredScale) const; 50 SkISize getScaledDimensions(float desiredScale) const;
50 51
52 /*
53 *
54 * Checks if alpha types are premul and unpremul
55 *
56 */
57 static bool premul_and_unpremul(SkAlphaType dst, SkAlphaType src) {
scroggo 2015/03/12 15:19:57 I think it'd be better if we moved all these stati
msarett 2015/03/12 18:37:46 Agreed. I didn't really think they belonged here,
58 return kPremul_SkAlphaType == dst && kUnpremul_SkAlphaType == src;
59 }
60
51 protected: 61 protected:
52 SkCodec(const SkImageInfo&, SkStream*); 62 SkCodec(const SkImageInfo&, SkStream*);
53 63
54 /** 64 /**
55 * The SkAlphaType is a conservative answer. i.e. it is possible that it 65 * The SkAlphaType is a conservative answer. i.e. it is possible that it
56 * initially returns a non-opaque answer, but completing the decode 66 * initially returns a non-opaque answer, but completing the decode
57 * reveals that the image is actually opaque. 67 * reveals that the image is actually opaque.
58 */ 68 */
59 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { 69 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE {
60 *info = fInfo; 70 *info = fInfo;
(...skipping 15 matching lines...) Expand all
76 * - if the stream needed to be rewound, and the rewind 86 * - if the stream needed to be rewound, and the rewind
77 * succeeded. 87 * succeeded.
78 * - if the stream did not need to be rewound. 88 * - if the stream did not need to be rewound.
79 * false 89 * false
80 * - if the stream needed to be rewound, and rewind failed. 90 * - if the stream needed to be rewound, and rewind failed.
81 * Subclasses MUST call this function before reading the stream (e.g. in 91 * Subclasses MUST call this function before reading the stream (e.g. in
82 * onGetPixels). If it returns false, onGetPixels should return 92 * onGetPixels). If it returns false, onGetPixels should return
83 * kCouldNotRewind. 93 * kCouldNotRewind.
84 */ 94 */
85 bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); 95 bool SK_WARN_UNUSED_RESULT rewindIfNeeded();
96
97 // Additional helper methods for subclasses
98
99 /*
100 *
101 * Get method for the input stream
102 *
103 */
104 SkStream* stream() {
105 return fStream.get();
106 }
107
108 /*
109 *
110 * Get a byte from a buffer
111 * This method is unsafe, the caller is responsible for performing a check
112 *
113 */
114 static uint8_t get_byte(uint8_t* buffer, uint32_t i) {
115 return buffer[i];
116 }
117
118 /*
119 *
120 * Get a short from a buffer
121 * This method is unsafe, the caller is responsible for performing a check
122 *
123 */
124 static uint16_t get_short(uint8_t* buffer, uint32_t i) {
125 uint16_t result;
126 memcpy(&result, &(buffer[i]), 2);
127 #ifdef SK_CPU_BENDIAN
128 return SkEndianSwap16(result);
129 #else
130 return result;
131 #endif
132 }
133
134 /*
135 *
136 * Get an int from a buffer
137 * This method is unsafe, the caller is responsible for performing a check
138 *
139 */
140 static uint32_t get_int(uint8_t* buffer, uint32_t i) {
141 uint32_t result;
142 memcpy(&result, &(buffer[i]), 4);
143 #ifdef SK_CPU_BENDIAN
144 return SkEndianSwap32(result);
145 #else
146 return result;
147 #endif
148 }
86 149
87 private: 150 private:
88 const SkImageInfo fInfo; 151 const SkImageInfo fInfo;
89 SkAutoTDelete<SkStream> fStream; 152 SkAutoTDelete<SkStream> fStream;
90 bool fNeedsRewind; 153 bool fNeedsRewind;
91 }; 154 };
92 #endif // SkCodec_DEFINED 155 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkCodec.cpp » ('j') | src/codec/SkCodec_libbmp.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698