OLD | NEW |
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_libbmp.h" |
11 #include "SkCodec_libpng.h" | 11 #include "SkCodec_libpng.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 | 13 |
14 struct DecoderProc { | 14 struct DecoderProc { |
15 bool (*IsFormat)(SkStream*); | 15 bool (*IsFormat)(SkStream*); |
16 SkCodec* (*NewFromStream)(SkStream*); | 16 SkCodec* (*NewFromStream)(SkStream*); |
17 }; | 17 }; |
18 | 18 |
19 static const DecoderProc gDecoderProcs[] = { | 19 static const DecoderProc gDecoderProcs[] = { |
20 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, | 20 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
21 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream } | 21 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream } |
22 }; | 22 }; |
23 | 23 |
24 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | 24 SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
25 if (!stream) { | 25 if (!stream) { |
26 return NULL; | 26 return NULL; |
27 } | 27 } |
28 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 28 for (DecoderProc proc : gDecoderProcs) { |
29 DecoderProc proc = gDecoderProcs[i]; | |
30 const bool correctFormat = proc.IsFormat(stream); | 29 const bool correctFormat = proc.IsFormat(stream); |
31 if (!stream->rewind()) { | 30 if (!stream->rewind()) { |
32 return NULL; | 31 return NULL; |
33 } | 32 } |
34 if (correctFormat) { | 33 if (correctFormat) { |
35 return proc.NewFromStream(stream); | 34 return proc.NewFromStream(stream); |
36 } | 35 } |
37 } | 36 } |
38 return NULL; | 37 return NULL; |
39 } | 38 } |
(...skipping 11 matching lines...) Expand all Loading... |
51 , fNeedsRewind(false) | 50 , fNeedsRewind(false) |
52 {} | 51 {} |
53 | 52 |
54 bool SkCodec::rewindIfNeeded() { | 53 bool SkCodec::rewindIfNeeded() { |
55 // Store the value of fNeedsRewind so we can update it. Next read will | 54 // Store the value of fNeedsRewind so we can update it. Next read will |
56 // require a rewind. | 55 // require a rewind. |
57 const bool neededRewind = fNeedsRewind; | 56 const bool neededRewind = fNeedsRewind; |
58 fNeedsRewind = true; | 57 fNeedsRewind = true; |
59 return !neededRewind || fStream->rewind(); | 58 return !neededRewind || fStream->rewind(); |
60 } | 59 } |
OLD | NEW |