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

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

Issue 647023006: Qualify the return value of SkImageDecoder::decode (Closed) Base URL: https://skia.googlesource.com/skia.git/+/master
Patch Set: fix a sample Created 6 years, 1 month 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
« no previous file with comments | « src/images/SkImageDecoder_ktx.cpp ('k') | src/images/SkImageDecoder_libgif.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 "SkStreamPriv.h" 15 #include "SkStreamPriv.h"
16 #include "SkTDArray.h" 16 #include "SkTDArray.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 protected: 26 protected:
27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ; 27 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRI DE;
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 bool is_bmp(SkStreamRewindable* stream) { 37 static bool is_bmp(SkStreamRewindable* stream) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 int height() const { return fHeight; } 85 int height() const { return fHeight; }
86 const uint8_t* rgb() const { return fRGB.begin(); } 86 const uint8_t* rgb() const { return fRGB.begin(); }
87 87
88 private: 88 private:
89 SkTDArray<uint8_t> fRGB; 89 SkTDArray<uint8_t> fRGB;
90 int fWidth; 90 int fWidth;
91 int fHeight; 91 int fHeight;
92 bool fJustBounds; 92 bool fJustBounds;
93 }; 93 };
94 94
95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { 95 SkImageDecoder::Result SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) {
96 // First read the entire stream, so that all of the data can be passed to 96 // First read the entire stream, so that all of the data can be passed to
97 // the BmpDecoderHelper. 97 // the BmpDecoderHelper.
98 98
99 // Allocated space used to hold the data. 99 // Allocated space used to hold the data.
100 SkAutoMalloc storage; 100 SkAutoMalloc storage;
101 // Byte length of all of the data. 101 // Byte length of all of the data.
102 const size_t length = SkCopyStreamToStorage(&storage, stream); 102 const size_t length = SkCopyStreamToStorage(&storage, stream);
103 if (0 == length) { 103 if (0 == length) {
104 return 0; 104 return kFailure;
105 } 105 }
106 106
107 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; 107 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
108 SkBmpDecoderCallback callback(justBounds); 108 SkBmpDecoderCallback callback(justBounds);
109 109
110 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] 110 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...]
111 { 111 {
112 image_codec::BmpDecoderHelper helper; 112 image_codec::BmpDecoderHelper helper;
113 const int max_pixels = 16383*16383; // max width*height 113 const int max_pixels = 16383*16383; // max width*height
114 if (!helper.DecodeImage((const char*)storage.get(), length, 114 if (!helper.DecodeImage((const char*)storage.get(), length,
115 max_pixels, &callback)) { 115 max_pixels, &callback)) {
116 return false; 116 return kFailure;
117 } 117 }
118 } 118 }
119 119
120 // we don't need this anymore, so free it now (before we try to allocate 120 // we don't need this anymore, so free it now (before we try to allocate
121 // the bitmap's pixels) rather than waiting for its destructor 121 // the bitmap's pixels) rather than waiting for its destructor
122 storage.free(); 122 storage.free();
123 123
124 int width = callback.width(); 124 int width = callback.width();
125 int height = callback.height(); 125 int height = callback.height();
126 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false); 126 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false);
127 127
128 // only accept prefConfig if it makes sense for us 128 // only accept prefConfig if it makes sense for us
129 if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType ) { 129 if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType ) {
130 colorType = kN32_SkColorType; 130 colorType = kN32_SkColorType;
131 } 131 }
132 132
133 SkScaledBitmapSampler sampler(width, height, getSampleSize()); 133 SkScaledBitmapSampler sampler(width, height, getSampleSize());
134 134
135 bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(), 135 bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(),
136 colorType, kOpaque_SkAlphaType)); 136 colorType, kOpaque_SkAlphaType));
137 137
138 if (justBounds) { 138 if (justBounds) {
139 return true; 139 return kSuccess;
140 } 140 }
141 141
142 if (!this->allocPixelRef(bm, NULL)) { 142 if (!this->allocPixelRef(bm, NULL)) {
143 return false; 143 return kFailure;
144 } 144 }
145 145
146 SkAutoLockPixels alp(*bm); 146 SkAutoLockPixels alp(*bm);
147 147
148 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { 148 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) {
149 return false; 149 return kFailure;
150 } 150 }
151 151
152 const int srcRowBytes = width * 3; 152 const int srcRowBytes = width * 3;
153 const int dstHeight = sampler.scaledHeight(); 153 const int dstHeight = sampler.scaledHeight();
154 const uint8_t* srcRow = callback.rgb(); 154 const uint8_t* srcRow = callback.rgb();
155 155
156 srcRow += sampler.srcY0() * srcRowBytes; 156 srcRow += sampler.srcY0() * srcRowBytes;
157 for (int y = 0; y < dstHeight; y++) { 157 for (int y = 0; y < dstHeight; y++) {
158 sampler.next(srcRow); 158 sampler.next(srcRow);
159 srcRow += sampler.srcDY() * srcRowBytes; 159 srcRow += sampler.srcDY() * srcRowBytes;
160 } 160 }
161 return true; 161 return kSuccess;
162 } 162 }
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_ktx.cpp ('k') | src/images/SkImageDecoder_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698