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

Side by Side Diff: src/images/SkDecodingImageGenerator.cpp

Issue 1226023003: Remove SkImageGenerator pieces only for SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@severIG
Patch Set: Change the public interface without staging it. Created 5 years, 5 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
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | src/lazy/SkCachingPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkDecodingImageGenerator.h" 9 #include "SkDecodingImageGenerator.h"
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 20 matching lines...) Expand all
31 const bool fDitherImage; 31 const bool fDitherImage;
32 32
33 DecodingImageGenerator(SkData* data, 33 DecodingImageGenerator(SkData* data,
34 SkStreamRewindable* stream, 34 SkStreamRewindable* stream,
35 const SkImageInfo& info, 35 const SkImageInfo& info,
36 int sampleSize, 36 int sampleSize,
37 bool ditherImage); 37 bool ditherImage);
38 38
39 protected: 39 protected:
40 SkData* onRefEncodedData() override; 40 SkData* onRefEncodedData() override;
41 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
41 Result onGetPixels(const SkImageInfo& info, 42 Result onGetPixels(const SkImageInfo& info,
42 void* pixels, size_t rowBytes, const Options&, 43 void* pixels, size_t rowBytes, const Options&,
43 SkPMColor ctable[], int* ctableCount) override; 44 SkPMColor ctable[], int* ctableCount) override;
45 #else
46 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
47 SkPMColor ctable[], int* ctableCount) override;
48 #endif
44 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 49 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
45 SkYUVColorSpace* colorSpace) override; 50 SkYUVColorSpace* colorSpace) override;
46 51
47 private: 52 private:
48 typedef SkImageGenerator INHERITED; 53 typedef SkImageGenerator INHERITED;
49 }; 54 };
50 55
51 /** 56 /**
52 * Special allocator used by getPixels(). Uses preallocated memory 57 * Special allocator used by getPixels(). Uses preallocated memory
53 * provided if possible, else fall-back on the default allocator 58 * provided if possible, else fall-back on the default allocator
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return NULL; 142 return NULL;
138 } 143 }
139 size_t length = fStream->getLength(); 144 size_t length = fStream->getLength();
140 if (length) { 145 if (length) {
141 fData = SkData::NewFromStream(fStream, length); 146 fData = SkData::NewFromStream(fStream, length);
142 } 147 }
143 } 148 }
144 return SkSafeRef(fData); 149 return SkSafeRef(fData);
145 } 150 }
146 151
152 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
147 SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo& info, 153 SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
148 void* pixels, size_t rowBytes, const Options& options, SkPMColor ctableE ntries[], 154 void* pixels, size_t rowBytes, const Options& options, SkPMColor ctableE ntries[],
149 int* ctableCount) { 155 int* ctableCount) {
156 #else
157 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
158 SkPMColor ctableEntries[], int* ctableC ount) {
159 #endif
150 if (fInfo != info) { 160 if (fInfo != info) {
151 // The caller has specified a different info. This is an 161 // The caller has specified a different info. This is an
152 // error for this kind of SkImageGenerator. Use the Options 162 // error for this kind of SkImageGenerator. Use the Options
153 // to change the settings. 163 // to change the settings.
164 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
154 if (info.dimensions() != fInfo.dimensions()) { 165 if (info.dimensions() != fInfo.dimensions()) {
155 return kInvalidScale; 166 return kInvalidScale;
156 } 167 }
157 return kInvalidConversion; 168 return kInvalidConversion;
169 #else
170 return false;
171 #endif
158 } 172 }
159 173
160 SkAssertResult(fStream->rewind()); 174 SkAssertResult(fStream->rewind());
161 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); 175 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
162 if (NULL == decoder.get()) { 176 if (NULL == decoder.get()) {
177 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
163 return kInvalidInput; 178 return kInvalidInput;
179 #else
180 return false;
181 #endif
164 } 182 }
165 decoder->setDitherImage(fDitherImage); 183 decoder->setDitherImage(fDitherImage);
166 decoder->setSampleSize(fSampleSize); 184 decoder->setSampleSize(fSampleSize);
167 decoder->setRequireUnpremultipliedColors(info.alphaType() == kUnpremul_SkAlp haType); 185 decoder->setRequireUnpremultipliedColors(info.alphaType() == kUnpremul_SkAlp haType);
168 186
169 SkBitmap bitmap; 187 SkBitmap bitmap;
170 TargetAllocator allocator(fInfo, pixels, rowBytes); 188 TargetAllocator allocator(fInfo, pixels, rowBytes);
171 decoder->setAllocator(&allocator); 189 decoder->setAllocator(&allocator);
172 const SkImageDecoder::Result decodeResult = decoder->decode(fStream, &bitmap , info.colorType(), 190 const SkImageDecoder::Result decodeResult = decoder->decode(fStream, &bitmap , info.colorType(),
173 SkImageDecoder:: kDecodePixels_Mode); 191 SkImageDecoder:: kDecodePixels_Mode);
174 decoder->setAllocator(NULL); 192 decoder->setAllocator(NULL);
175 if (SkImageDecoder::kFailure == decodeResult) { 193 if (SkImageDecoder::kFailure == decodeResult) {
194 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
176 return kInvalidInput; 195 return kInvalidInput;
196 #else
197 return false;
198 #endif
177 } 199 }
178 if (allocator.isReady()) { // Did not use pixels! 200 if (allocator.isReady()) { // Did not use pixels!
179 SkBitmap bm; 201 SkBitmap bm;
180 SkASSERT(bitmap.canCopyTo(info.colorType())); 202 SkASSERT(bitmap.canCopyTo(info.colorType()));
181 bool copySuccess = bitmap.copyTo(&bm, info.colorType(), &allocator); 203 bool copySuccess = bitmap.copyTo(&bm, info.colorType(), &allocator);
182 if (!copySuccess || allocator.isReady()) { 204 if (!copySuccess || allocator.isReady()) {
183 SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed."); 205 SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed.");
184 // Earlier we checked canCopyto(); we expect consistency. 206 // Earlier we checked canCopyto(); we expect consistency.
207 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
185 return kInvalidConversion; 208 return kInvalidConversion;
209 #else
210 return false;
211 #endif
186 } 212 }
187 SkASSERT(check_alpha(info.alphaType(), bm.alphaType())); 213 SkASSERT(check_alpha(info.alphaType(), bm.alphaType()));
188 } else { 214 } else {
189 SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType())); 215 SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType()));
190 } 216 }
191 217
192 if (kIndex_8_SkColorType == info.colorType()) { 218 if (kIndex_8_SkColorType == info.colorType()) {
193 if (kIndex_8_SkColorType != bitmap.colorType()) { 219 if (kIndex_8_SkColorType != bitmap.colorType()) {
194 // they asked for Index8, but we didn't receive that from decoder 220 // they asked for Index8, but we didn't receive that from decoder
221 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
195 return kInvalidConversion; 222 return kInvalidConversion;
223 #else
224 return false;
225 #endif
196 } 226 }
197 SkColorTable* ctable = bitmap.getColorTable(); 227 SkColorTable* ctable = bitmap.getColorTable();
198 if (NULL == ctable) { 228 if (NULL == ctable) {
229 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
199 return kInvalidConversion; 230 return kInvalidConversion;
231 #else
232 return false;
233 #endif
200 } 234 }
201 const int count = ctable->count(); 235 const int count = ctable->count();
202 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor)); 236 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
203 *ctableCount = count; 237 *ctableCount = count;
204 } 238 }
239 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
205 if (SkImageDecoder::kPartialSuccess == decodeResult) { 240 if (SkImageDecoder::kPartialSuccess == decodeResult) {
206 return kIncompleteInput; 241 return kIncompleteInput;
207 } 242 }
208 return kSuccess; 243 return kSuccess;
244 #else
245 return true;
246 #endif
209 } 247 }
210 248
211 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], 249 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
212 size_t rowBytes[3], SkYUVColorSpace * colorSpace) { 250 size_t rowBytes[3], SkYUVColorSpace * colorSpace) {
213 if (!fStream->rewind()) { 251 if (!fStream->rewind()) {
214 return false; 252 return false;
215 } 253 }
216 254
217 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); 255 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
218 if (NULL == decoder.get()) { 256 if (NULL == decoder.get()) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 326
289 SkImageGenerator* SkDecodingImageGenerator::Create( 327 SkImageGenerator* SkDecodingImageGenerator::Create(
290 SkStreamRewindable* stream, 328 SkStreamRewindable* stream,
291 const SkDecodingImageGenerator::Options& opts) { 329 const SkDecodingImageGenerator::Options& opts) {
292 SkASSERT(stream != NULL); 330 SkASSERT(stream != NULL);
293 if (stream == NULL) { 331 if (stream == NULL) {
294 return NULL; 332 return NULL;
295 } 333 }
296 return CreateDecodingImageGenerator(NULL, stream, opts); 334 return CreateDecodingImageGenerator(NULL, stream, opts);
297 } 335 }
OLDNEW
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | src/lazy/SkCachingPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698