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 16 matching lines...) Expand all Loading... |
27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE
; | 27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE
; |
28 | 28 |
29 private: | 29 private: |
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 bool is_bmp(SkStream* stream) { |
38 static const char kBmpMagic[] = { 'B', 'M' }; | 38 static const char kBmpMagic[] = { 'B', 'M' }; |
39 | 39 |
40 | 40 |
41 char buffer[sizeof(kBmpMagic)]; | 41 char buffer[sizeof(kBmpMagic)]; |
42 | 42 |
43 if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | 43 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && |
44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) { | 44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); |
| 45 } |
| 46 |
| 47 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { |
| 48 if (is_bmp(stream)) { |
45 return SkNEW(SkBMPImageDecoder); | 49 return SkNEW(SkBMPImageDecoder); |
46 } | 50 } |
47 return NULL; | 51 return NULL; |
48 } | 52 } |
49 | 53 |
50 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); | 54 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); |
51 | 55 |
| 56 static SkImageDecoder::Format get_format_bmp(SkStream* stream) { |
| 57 if (is_bmp(stream)) { |
| 58 return SkImageDecoder::kBMP_Format; |
| 59 } |
| 60 return SkImageDecoder::kUnknown_Format; |
| 61 } |
| 62 |
| 63 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_bmp)
; |
| 64 |
52 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
53 | 66 |
54 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { | 67 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { |
55 public: | 68 public: |
56 // we don't copy the bitmap, just remember the pointer | 69 // we don't copy the bitmap, just remember the pointer |
57 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} | 70 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} |
58 | 71 |
59 // override from BmpDecoderCallback | 72 // override from BmpDecoderCallback |
60 virtual uint8* SetSize(int width, int height) { | 73 virtual uint8* SetSize(int width, int height) { |
61 fWidth = width; | 74 fWidth = width; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 const int dstHeight = sampler.scaledHeight(); | 157 const int dstHeight = sampler.scaledHeight(); |
145 const uint8_t* srcRow = callback.rgb(); | 158 const uint8_t* srcRow = callback.rgb(); |
146 | 159 |
147 srcRow += sampler.srcY0() * srcRowBytes; | 160 srcRow += sampler.srcY0() * srcRowBytes; |
148 for (int y = 0; y < dstHeight; y++) { | 161 for (int y = 0; y < dstHeight; y++) { |
149 sampler.next(srcRow); | 162 sampler.next(srcRow); |
150 srcRow += sampler.srcDY() * srcRowBytes; | 163 srcRow += sampler.srcDY() * srcRowBytes; |
151 } | 164 } |
152 return true; | 165 return true; |
153 } | 166 } |
OLD | NEW |