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

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

Issue 23477009: Change SkImageDecoders to take an SkStreamRewindable. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Only switch to SkStreamRewindable when necessary. Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/animator/SkDrawBitmap.cpp ('k') | src/images/SkImageDecoder_FactoryDefault.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, 206 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect,
207 SkBitmap::Config pref) { 207 SkBitmap::Config pref) {
208 // we reset this to false before calling onDecodeSubset 208 // we reset this to false before calling onDecodeSubset
209 fShouldCancelDecode = false; 209 fShouldCancelDecode = false;
210 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false 210 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false
211 fDefaultPref = pref; 211 fDefaultPref = pref;
212 212
213 return this->onDecodeSubset(bm, rect); 213 return this->onDecodeSubset(bm, rect);
214 } 214 }
215 215
216 bool SkImageDecoder::buildTileIndex(SkStream* stream, 216 bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream,
217 int *width, int *height) { 217 int *width, int *height) {
218 // we reset this to false before calling onBuildTileIndex 218 // we reset this to false before calling onBuildTileIndex
219 fShouldCancelDecode = false; 219 fShouldCancelDecode = false;
220 220
221 return this->onBuildTileIndex(stream, width, height); 221 return this->onBuildTileIndex(stream, width, height);
222 } 222 }
223 223
224 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, 224 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
225 int dstX, int dstY, int width, int height, 225 int dstX, int dstY, int width, int height,
226 int srcX, int srcY) { 226 int srcX, int srcY) {
227 int w = width / sampleSize; 227 int w = width / sampleSize;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return true; 269 return true;
270 } 270 }
271 271
272 /////////////////////////////////////////////////////////////////////////////// 272 ///////////////////////////////////////////////////////////////////////////////
273 273
274 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, 274 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
275 SkBitmap::Config pref, Mode mode, Format* format) { 275 SkBitmap::Config pref, Mode mode, Format* format) {
276 SkASSERT(file); 276 SkASSERT(file);
277 SkASSERT(bm); 277 SkASSERT(bm);
278 278
279 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file)); 279 SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(file));
280 if (stream.get()) { 280 if (stream.get()) {
281 if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) { 281 if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) {
282 bm->pixelRef()->setURI(file); 282 bm->pixelRef()->setURI(file);
283 return true; 283 return true;
284 } 284 }
285 } 285 }
286 return false; 286 return false;
287 } 287 }
288 288
289 bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, 289 bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 bm.setConfig(bm.config(), bm.width(), bm.height(), target->fRowBytes); 439 bm.setConfig(bm.config(), bm.width(), bm.height(), target->fRowBytes);
440 } 440 }
441 441
442 // SkMemoryStream.rewind() will always return true. 442 // SkMemoryStream.rewind() will always return true.
443 SkAssertResult(stream.rewind()); 443 SkAssertResult(stream.rewind());
444 return decode_pixels_to_8888(decoder.get(), &stream, &bm, target->fAddr); 444 return decode_pixels_to_8888(decoder.get(), &stream, &bm, target->fAddr);
445 } 445 }
446 446
447 447
448 bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm, 448 bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm,
449 SkBitmap::Config pref, Mode mode, Format* format) { 449 SkBitmap::Config pref, Mode mode,
450 Format* format) {
450 SkASSERT(stream); 451 SkASSERT(stream);
451 SkASSERT(bm); 452 SkASSERT(bm);
452 453
453 bool success = false; 454 bool success = false;
454 SkImageDecoder* codec = SkImageDecoder::Factory(stream); 455 SkImageDecoder* codec = SkImageDecoder::Factory(stream);
455 456
456 if (NULL != codec) { 457 if (NULL != codec) {
457 success = codec->decode(stream, bm, pref, mode); 458 success = codec->decode(stream, bm, pref, mode);
458 if (success && format) { 459 if (success && format) {
459 *format = codec->getFormat(); 460 *format = codec->getFormat();
460 if (kUnknown_Format == *format) { 461 if (kUnknown_Format == *format) {
461 if (stream->rewind()) { 462 if (stream->rewind()) {
462 *format = GetStreamFormat(stream); 463 *format = GetStreamFormat(stream);
463 } 464 }
464 } 465 }
465 } 466 }
466 delete codec; 467 delete codec;
467 } 468 }
468 return success; 469 return success;
469 } 470 }
OLDNEW
« no previous file with comments | « src/animator/SkDrawBitmap.cpp ('k') | src/images/SkImageDecoder_FactoryDefault.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698