OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "bmpdecoderhelper.h" | 10 #include "bmpdecoderhelper.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 typedef SkImageDecoder INHERITED; | 30 typedef SkImageDecoder INHERITED; |
31 }; | 31 }; |
32 | 32 |
33 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
34 DEFINE_DECODER_CREATOR(BMPImageDecoder); | 34 DEFINE_DECODER_CREATOR(BMPImageDecoder); |
35 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
36 | 36 |
37 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { | 37 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { |
38 static const char kBmpMagic[] = { 'B', 'M' }; | 38 static const char kBmpMagic[] = { 'B', 'M' }; |
39 | 39 |
40 size_t len = stream->getLength(); | 40 |
41 char buffer[sizeof(kBmpMagic)]; | 41 char buffer[sizeof(kBmpMagic)]; |
42 | 42 |
43 if (len > sizeof(kBmpMagic) && | 43 if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && |
44 stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | 44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) { |
45 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) { | |
46 return SkNEW(SkBMPImageDecoder); | 45 return SkNEW(SkBMPImageDecoder); |
47 } | 46 } |
48 return NULL; | 47 return NULL; |
49 } | 48 } |
50 | 49 |
51 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); | 50 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); |
52 | 51 |
53 /////////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////////// |
54 | 53 |
55 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { | 54 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const int dstHeight = sampler.scaledHeight(); | 144 const int dstHeight = sampler.scaledHeight(); |
146 const uint8_t* srcRow = callback.rgb(); | 145 const uint8_t* srcRow = callback.rgb(); |
147 | 146 |
148 srcRow += sampler.srcY0() * srcRowBytes; | 147 srcRow += sampler.srcY0() * srcRowBytes; |
149 for (int y = 0; y < dstHeight; y++) { | 148 for (int y = 0; y < dstHeight; y++) { |
150 sampler.next(srcRow); | 149 sampler.next(srcRow); |
151 srcRow += sampler.srcDY() * srcRowBytes; | 150 srcRow += sampler.srcDY() * srcRowBytes; |
152 } | 151 } |
153 return true; | 152 return true; |
154 } | 153 } |
OLD | NEW |