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

Side by Side Diff: src/images/SkImageDecoder_libbmp.cpp

Issue 14363003: Updates to skimage tool to use it for testing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Implement onGetFormat for other decoders. Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "SkImageDecoder.h" 11 #include "SkImageDecoder.h"
12 #include "SkScaledBitmapSampler.h" 12 #include "SkScaledBitmapSampler.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkColorPriv.h" 14 #include "SkColorPriv.h"
15 #include "SkTDArray.h" 15 #include "SkTDArray.h"
16 #include "SkTRegistry.h" 16 #include "SkTRegistry.h"
17 17
18 class SkBMPImageDecoder : public SkImageDecoder { 18 class SkBMPImageDecoder : public SkImageDecoder {
19 public: 19 public:
20 SkBMPImageDecoder() {} 20 SkBMPImageDecoder() {}
21 21
22 virtual Format getFormat() const SK_OVERRIDE { 22 virtual Format getFormat() const SK_OVERRIDE {
23 return kBMP_Format; 23 return kBMP_Format;
24 } 24 }
25 25
26 virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
27
26 protected: 28 protected:
27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ; 29 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ;
28 30
29 private: 31 private:
30 typedef SkImageDecoder INHERITED; 32 typedef SkImageDecoder INHERITED;
31 }; 33 };
32 34
33 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
34 DEFINE_DECODER_CREATOR(BMPImageDecoder); 36 DEFINE_DECODER_CREATOR(BMPImageDecoder);
35 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
36 38
37 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { 39 static bool is_bmp(SkStream* stream) {
38 static const char kBmpMagic[] = { 'B', 'M' }; 40 static const char kBmpMagic[] = { 'B', 'M' };
39 41
40 42
41 char buffer[sizeof(kBmpMagic)]; 43 char buffer[sizeof(kBmpMagic)];
42 44
43 if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && 45 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) &&
44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) { 46 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic));
47 }
48
49 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
50 if (is_bmp(stream)) {
45 return SkNEW(SkBMPImageDecoder); 51 return SkNEW(SkBMPImageDecoder);
46 } 52 }
47 return NULL; 53 return NULL;
48 } 54 }
49 55
50 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); 56 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory);
51 57
52 /////////////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////////////
53 59
54 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { 60 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback {
(...skipping 17 matching lines...) Expand all
72 int height() const { return fHeight; } 78 int height() const { return fHeight; }
73 const uint8_t* rgb() const { return fRGB.begin(); } 79 const uint8_t* rgb() const { return fRGB.begin(); }
74 80
75 private: 81 private:
76 SkTDArray<uint8_t> fRGB; 82 SkTDArray<uint8_t> fRGB;
77 int fWidth; 83 int fWidth;
78 int fHeight; 84 int fHeight;
79 bool fJustBounds; 85 bool fJustBounds;
80 }; 86 };
81 87
88 SkImageDecoder::Format SkBMPImageDecoder::onGetFormat(SkStream* stream) const {
89 if (is_bmp(stream)) {
90 return kBMP_Format;
91 }
92 return kUnknown_Format;
93 }
94
82 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { 95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
83 96
84 size_t length = stream->getLength(); 97 size_t length = stream->getLength();
85 SkAutoMalloc storage(length); 98 SkAutoMalloc storage(length);
86 99
87 if (stream->read(storage.get(), length) != length) { 100 if (stream->read(storage.get(), length) != length) {
88 return false; 101 return false;
89 } 102 }
90 103
91 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; 104 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698