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

Side by Side Diff: src/codec/SkCodec.cpp

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Moved bmp specific code out of the swizzler 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 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkCodec_libbmp.h"
10 #include "SkCodec_libpng.h" 11 #include "SkCodec_libpng.h"
11 #include "SkStream.h" 12 #include "SkStream.h"
12 13
13 SkCodec* SkCodec::NewFromStream(SkStream* stream) { 14 SkCodec* SkCodec::NewFromStream(SkStream* stream) {
14 if (!stream) { 15 if (!stream) {
15 return NULL; 16 return NULL;
16 } 17 }
17 SkAutoTDelete<SkStream> streamDeleter(stream); 18 SkAutoTDelete<SkStream> streamDeleter(stream);
19 const bool isBmp = SkBmpCodec::IsBmp(stream);
20 if (!stream->rewind()) {
21 return NULL;
22 }
23 if (isBmp) {
24 streamDeleter.detach();
25 return SkBmpCodec::NewFromStream(stream);
26 }
18 const bool isPng = SkPngCodec::IsPng(stream); 27 const bool isPng = SkPngCodec::IsPng(stream);
scroggo 2015/03/06 18:56:12 nit: PNG should be first, since we'll see more PNG
19 if (!stream->rewind()) { 28 if (!stream->rewind()) {
20 return NULL; 29 return NULL;
21 } 30 }
22 if (isPng) { 31 if (isPng) {
23 streamDeleter.detach(); 32 streamDeleter.detach();
24 return SkPngCodec::NewFromStream(stream); 33 return SkPngCodec::NewFromStream(stream);
25 } 34 }
26 // TODO: Check other image types. 35 // TODO: Check other image types.
27 return NULL; 36 return NULL;
28 } 37 }
29 38
30 SkCodec* SkCodec::NewFromData(SkData* data) { 39 SkCodec* SkCodec::NewFromData(SkData* data) {
31 if (!data) { 40 if (!data) {
32 return NULL; 41 return NULL;
33 } 42 }
34 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); 43 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data)));
35 } 44 }
36 45
37 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) 46 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
38 : fInfo(info) 47 : fInfo(info)
39 , fStream(stream) 48 , fStream(stream)
40 , fNeedsRewind(false) 49 , fNeedsRewind(false)
41 {} 50 {}
42 51
43 bool SkCodec::couldRewindIfNeeded() { 52 bool SkCodec::couldRewindIfNeeded() {
44 // Store the value of fNeedsRewind so we can update it. Next read will 53 // Store the value of fNeedsRewind so we can update it. Next read will
45 // require a rewind. 54 // require a rewind.
46 const bool neededRewind = fNeedsRewind; 55 const bool neededRewind = fNeedsRewind;
47 fNeedsRewind = true; 56 fNeedsRewind = true;
msarett 2015/03/05 23:13:17 Why does this method set fNeedsRewind to true. It
scroggo 2015/03/06 18:56:12 I'm trying to make it so that a caller (for exampl
48 return !neededRewind || fStream->rewind(); 57 return !neededRewind || fStream->rewind();
49 } 58 }
OLDNEW
« no previous file with comments | « include/codec/SkCodec.h ('k') | src/codec/SkCodec_libbmp.h » ('j') | src/codec/SkCodec_libbmp.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698