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" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkScaledBitmapSampler.h" | 13 #include "SkScaledBitmapSampler.h" |
14 #include "SkStream.h" | 14 #include "SkStream.h" |
15 #include "SkStreamHelpers.h" | 15 #include "SkStreamHelpers.h" |
16 #include "SkTDArray.h" | 16 #include "SkTDArray.h" |
17 #include "SkTRegistry.h" | 17 #include "SkTRegistry.h" |
18 | 18 |
19 class SkBMPImageDecoder : public SkImageDecoder { | 19 class SkBMPImageDecoder : public SkImageDecoder { |
20 public: | 20 public: |
21 SkBMPImageDecoder() {} | 21 SkBMPImageDecoder() {} |
22 | 22 |
23 virtual Format getFormat() const SK_OVERRIDE { | 23 virtual Format getFormat() const SK_OVERRIDE { |
24 return kBMP_Format; | 24 return kBMP_Format; |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE
; | 28 virtual bool onDecode(SkStreamRewindable* stream, SkBitmap* bm, Mode mode) S
K_OVERRIDE; |
29 | 29 |
30 private: | 30 private: |
31 typedef SkImageDecoder INHERITED; | 31 typedef SkImageDecoder INHERITED; |
32 }; | 32 }; |
33 | 33 |
34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
35 DEFINE_DECODER_CREATOR(BMPImageDecoder); | 35 DEFINE_DECODER_CREATOR(BMPImageDecoder); |
36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
37 | 37 |
38 static bool is_bmp(SkStream* stream) { | 38 static bool is_bmp(SkStreamRewindable* stream) { |
39 static const char kBmpMagic[] = { 'B', 'M' }; | 39 static const char kBmpMagic[] = { 'B', 'M' }; |
40 | 40 |
41 | 41 |
42 char buffer[sizeof(kBmpMagic)]; | 42 char buffer[sizeof(kBmpMagic)]; |
43 | 43 |
44 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | 44 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && |
45 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); | 45 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); |
46 } | 46 } |
47 | 47 |
48 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { | 48 static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) { |
49 if (is_bmp(stream)) { | 49 if (is_bmp(stream)) { |
50 return SkNEW(SkBMPImageDecoder); | 50 return SkNEW(SkBMPImageDecoder); |
51 } | 51 } |
52 return NULL; | 52 return NULL; |
53 } | 53 } |
54 | 54 |
55 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); | 55 static SkTRegistry<SkImageDecoder*, SkStreamRewindable*> gReg(sk_libbmp_dfactory
); |
56 | 56 |
57 static SkImageDecoder::Format get_format_bmp(SkStream* stream) { | 57 static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) { |
58 if (is_bmp(stream)) { | 58 if (is_bmp(stream)) { |
59 return SkImageDecoder::kBMP_Format; | 59 return SkImageDecoder::kBMP_Format; |
60 } | 60 } |
61 return SkImageDecoder::kUnknown_Format; | 61 return SkImageDecoder::kUnknown_Format; |
62 } | 62 } |
63 | 63 |
64 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_bmp)
; | 64 static SkTRegistry<SkImageDecoder::Format, SkStreamRewindable*> gFormatReg(get_f
ormat_bmp); |
65 | 65 |
66 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
67 | 67 |
68 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { | 68 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { |
69 public: | 69 public: |
70 // we don't copy the bitmap, just remember the pointer | 70 // we don't copy the bitmap, just remember the pointer |
71 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} | 71 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} |
72 | 72 |
73 // override from BmpDecoderCallback | 73 // override from BmpDecoderCallback |
74 virtual uint8* SetSize(int width, int height) { | 74 virtual uint8* SetSize(int width, int height) { |
(...skipping 11 matching lines...) Expand all Loading... |
86 int height() const { return fHeight; } | 86 int height() const { return fHeight; } |
87 const uint8_t* rgb() const { return fRGB.begin(); } | 87 const uint8_t* rgb() const { return fRGB.begin(); } |
88 | 88 |
89 private: | 89 private: |
90 SkTDArray<uint8_t> fRGB; | 90 SkTDArray<uint8_t> fRGB; |
91 int fWidth; | 91 int fWidth; |
92 int fHeight; | 92 int fHeight; |
93 bool fJustBounds; | 93 bool fJustBounds; |
94 }; | 94 }; |
95 | 95 |
96 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { | 96 bool SkBMPImageDecoder::onDecode(SkStreamRewindable* stream, SkBitmap* bm, Mode
mode) { |
97 // First read the entire stream, so that all of the data can be passed to | 97 // First read the entire stream, so that all of the data can be passed to |
98 // the BmpDecoderHelper. | 98 // the BmpDecoderHelper. |
99 | 99 |
100 // Allocated space used to hold the data. | 100 // Allocated space used to hold the data. |
101 SkAutoMalloc storage; | 101 SkAutoMalloc storage; |
102 // Byte length of all of the data. | 102 // Byte length of all of the data. |
103 const size_t length = CopyStreamToStorage(&storage, stream); | 103 const size_t length = CopyStreamToStorage(&storage, stream); |
104 if (0 == length) { | 104 if (0 == length) { |
105 return 0; | 105 return 0; |
106 } | 106 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 const int dstHeight = sampler.scaledHeight(); | 155 const int dstHeight = sampler.scaledHeight(); |
156 const uint8_t* srcRow = callback.rgb(); | 156 const uint8_t* srcRow = callback.rgb(); |
157 | 157 |
158 srcRow += sampler.srcY0() * srcRowBytes; | 158 srcRow += sampler.srcY0() * srcRowBytes; |
159 for (int y = 0; y < dstHeight; y++) { | 159 for (int y = 0; y < dstHeight; y++) { |
160 sampler.next(srcRow); | 160 sampler.next(srcRow); |
161 srcRow += sampler.srcDY() * srcRowBytes; | 161 srcRow += sampler.srcDY() * srcRowBytes; |
162 } | 162 } |
163 return true; | 163 return true; |
164 } | 164 } |
OLD | NEW |