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

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

Issue 14567011: Test region decoding in skimage, plus fixes. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) 28 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config)
29 { 29 {
30 gDeviceConfig = config; 30 gDeviceConfig = config;
31 } 31 }
32 32
33 /////////////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////////////
34 34
35 SkImageDecoder::SkImageDecoder() 35 SkImageDecoder::SkImageDecoder()
36 : fPeeker(NULL), fChooser(NULL), fAllocator(NULL), fSampleSize(1), 36 : fPeeker(NULL)
37 fDefaultPref(SkBitmap::kNo_Config), fDitherImage(true), 37 , fChooser(NULL)
38 fUsePrefTable(false),fPreferQualityOverSpeed(false) { 38 , fAllocator(NULL)
39 , fSampleSize(1)
40 , fDefaultPref(SkBitmap::kNo_Config)
41 , fDitherImage(true)
42 , fUsePrefTable(false)
43 , fPreferQualityOverSpeed(false) {
39 } 44 }
40 45
41 SkImageDecoder::~SkImageDecoder() { 46 SkImageDecoder::~SkImageDecoder() {
42 SkSafeUnref(fPeeker); 47 SkSafeUnref(fPeeker);
43 SkSafeUnref(fChooser); 48 SkSafeUnref(fChooser);
44 SkSafeUnref(fAllocator); 49 SkSafeUnref(fAllocator);
45 } 50 }
46 51
47 SkImageDecoder::Format SkImageDecoder::getFormat() const { 52 SkImageDecoder::Format SkImageDecoder::getFormat() const {
48 return kUnknown_Format; 53 return kUnknown_Format;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // pass a temporary bitmap, so that if we return false, we are assured of 175 // pass a temporary bitmap, so that if we return false, we are assured of
171 // leaving the caller's bitmap untouched. 176 // leaving the caller's bitmap untouched.
172 SkBitmap tmp; 177 SkBitmap tmp;
173 if (!this->onDecode(stream, &tmp, mode)) { 178 if (!this->onDecode(stream, &tmp, mode)) {
174 return false; 179 return false;
175 } 180 }
176 bm->swap(tmp); 181 bm->swap(tmp);
177 return true; 182 return true;
178 } 183 }
179 184
180 bool SkImageDecoder::decodeRegion(SkBitmap* bm, const SkIRect& rect, 185 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect,
181 SkBitmap::Config pref) { 186 SkBitmap::Config pref) {
182 // we reset this to false before calling onDecodeRegion 187 // we reset this to false before calling onDecodeSubset
183 fShouldCancelDecode = false; 188 fShouldCancelDecode = false;
184 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false 189 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false
185 fDefaultPref = pref; 190 fDefaultPref = pref;
186 191
187 return this->onDecodeRegion(bm, rect); 192 return this->onDecodeSubset(bm, rect);
188 } 193 }
189 194
190 bool SkImageDecoder::buildTileIndex(SkStream* stream, 195 bool SkImageDecoder::buildTileIndex(SkStream* stream,
191 int *width, int *height) { 196 int *width, int *height) {
192 // we reset this to false before calling onBuildTileIndex 197 // we reset this to false before calling onBuildTileIndex
193 fShouldCancelDecode = false; 198 fShouldCancelDecode = false;
194 199
195 return this->onBuildTileIndex(stream, width, height); 200 return this->onBuildTileIndex(stream, width, height);
196 } 201 }
197 202
198 void SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, 203 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
199 int dstX, int dstY, int width, int height, 204 int dstX, int dstY, int width, int height,
200 int srcX, int srcY) { 205 int srcX, int srcY) {
201 int w = width / sampleSize; 206 int w = width / sampleSize;
202 int h = height / sampleSize; 207 int h = height / sampleSize;
208 if (src->getConfig() == SkBitmap::kIndex8_Config) {
209 int x = (dstX - srcX) / sampleSize;
210 int y = (dstY - srcY) / sampleSize;
211 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h);
212 return src->extractSubset(dst, subset);
213 }
203 // if the destination has no pixels then we must allocate them. 214 // if the destination has no pixels then we must allocate them.
204 if (dst->isNull()) { 215 if (dst->isNull()) {
205 dst->setConfig(src->getConfig(), w, h); 216 dst->setConfig(src->getConfig(), w, h);
206 dst->setIsOpaque(src->isOpaque()); 217 dst->setIsOpaque(src->isOpaque());
207 218
208 if (!this->allocPixelRef(dst, NULL)) { 219 if (!this->allocPixelRef(dst, NULL)) {
209 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); 220 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap"));
210 return; 221 return false;
211 } 222 }
212 } 223 }
213 // check to see if the destination is large enough to decode the desired 224 // check to see if the destination is large enough to decode the desired
214 // region. If this assert fails we will just draw as much of the source 225 // region. If this assert fails we will just draw as much of the source
215 // into the destination that we can. 226 // into the destination that we can.
216 SkASSERT(dst->width() >= w && dst->height() >= h); 227 //SkASSERT(dst->width() >= w && dst->height() >= h);
djsollen 2013/05/03 13:50:29 seems like this should be an SkDEBUGF statement or
scroggo 2013/05/03 17:09:24 Agreed. I have turned it into an SkDEBUGF statemen
217 228
218 // Set the Src_Mode for the paint to prevent transparency issue in the 229 // Set the Src_Mode for the paint to prevent transparency issue in the
219 // dest in the event that the dest was being re-used. 230 // dest in the event that the dest was being re-used.
220 SkPaint paint; 231 SkPaint paint;
221 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 232 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
222 233
223 SkCanvas canvas(*dst); 234 SkCanvas canvas(*dst);
224 canvas.drawSprite(*src, (srcX - dstX) / sampleSize, 235 canvas.drawSprite(*src, (srcX - dstX) / sampleSize,
225 (srcY - dstY) / sampleSize, 236 (srcY - dstY) / sampleSize,
226 &paint); 237 &paint);
238 return true;
227 } 239 }
228 240
229 /////////////////////////////////////////////////////////////////////////////// 241 ///////////////////////////////////////////////////////////////////////////////
230 242
231 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, 243 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
232 SkBitmap::Config pref, Mode mode, Format* format) { 244 SkBitmap::Config pref, Mode mode, Format* format) {
233 SkASSERT(file); 245 SkASSERT(file);
234 SkASSERT(bm); 246 SkASSERT(bm);
235 247
236 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file)); 248 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 CreateICOImageDecoder(); 368 CreateICOImageDecoder();
357 CreateWBMPImageDecoder(); 369 CreateWBMPImageDecoder();
358 // Only link GIF and PNG on platforms that build them. See images.gyp 370 // Only link GIF and PNG on platforms that build them. See images.gyp
359 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUIL D_FOR_NACL) 371 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUIL D_FOR_NACL)
360 CreateGIFImageDecoder(); 372 CreateGIFImageDecoder();
361 #endif 373 #endif
362 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) 374 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN)
363 CreatePNGImageDecoder(); 375 CreatePNGImageDecoder();
364 #endif 376 #endif
365 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698