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

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

Issue 12604006: Upstream Android modifications to the image encoders/decoders. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 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"
11 #include "SkImagePriv.h" 11 #include "SkImagePriv.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTemplates.h" 14 #include "SkTemplates.h"
15 #include "SkCanvas.h"
15 16
16 SK_DEFINE_INST_COUNT(SkImageDecoder::Peeker) 17 SK_DEFINE_INST_COUNT(SkImageDecoder::Peeker)
17 SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser) 18 SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser)
18 SK_DEFINE_INST_COUNT(SkImageDecoderFactory) 19 SK_DEFINE_INST_COUNT(SkImageDecoderFactory)
19 20
21 const char *SkImageDecoder::kFormatName[] = {
22 "Unknown Format",
23 "BMP",
24 "GIF",
25 "ICO",
26 "JPEG",
27 "PNG",
28 "WBMP",
29 "WEBP",
30 };
31
20 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; 32 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config;
21 33
22 SkBitmap::Config SkImageDecoder::GetDeviceConfig() 34 SkBitmap::Config SkImageDecoder::GetDeviceConfig()
23 { 35 {
24 return gDeviceConfig; 36 return gDeviceConfig;
25 } 37 }
26 38
27 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) 39 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config)
28 { 40 {
29 gDeviceConfig = config; 41 gDeviceConfig = config;
30 } 42 }
31 43
32 /////////////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////////////
33 45
34 SkImageDecoder::SkImageDecoder() 46 SkImageDecoder::SkImageDecoder()
35 : fPeeker(NULL), fChooser(NULL), fAllocator(NULL), fSampleSize(1), 47 : fPeeker(NULL), fChooser(NULL), fAllocator(NULL), fSampleSize(1),
36 fDefaultPref(SkBitmap::kNo_Config), fDitherImage(true), 48 fDefaultPref(SkBitmap::kNo_Config), fDitherImage(true),
37 fUsePrefTable(false) { 49 fUsePrefTable(false),fPreferQualityOverSpeed(false) {
38 } 50 }
39 51
40 SkImageDecoder::~SkImageDecoder() { 52 SkImageDecoder::~SkImageDecoder() {
41 SkSafeUnref(fPeeker); 53 SkSafeUnref(fPeeker);
42 SkSafeUnref(fChooser); 54 SkSafeUnref(fChooser);
43 SkSafeUnref(fAllocator); 55 SkSafeUnref(fAllocator);
44 } 56 }
45 57
46 SkImageDecoder::Format SkImageDecoder::getFormat() const { 58 SkImageDecoder::Format SkImageDecoder::getFormat() const {
47 return kUnknown_Format; 59 return kUnknown_Format;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 config = fDefaultPref; 134 config = fDefaultPref;
123 } 135 }
124 136
125 if (SkBitmap::kNo_Config == config) { 137 if (SkBitmap::kNo_Config == config) {
126 config = SkImageDecoder::GetDeviceConfig(); 138 config = SkImageDecoder::GetDeviceConfig();
127 } 139 }
128 return config; 140 return config;
129 } 141 }
130 142
131 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, 143 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm,
132 SkBitmap::Config pref, Mode mode) { 144 SkBitmap::Config pref, Mode mode, bool reuseBitmap) {
133 // pass a temporary bitmap, so that if we return false, we are assured of 145 // pass a temporary bitmap, so that if we return false, we are assured of
134 // leaving the caller's bitmap untouched. 146 // leaving the caller's bitmap untouched.
135 SkBitmap tmp; 147 SkBitmap tmp;
136 148
137 // we reset this to false before calling onDecode 149 // we reset this to false before calling onDecode
138 fShouldCancelDecode = false; 150 fShouldCancelDecode = false;
139 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false 151 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false
140 fDefaultPref = pref; 152 fDefaultPref = pref;
141 153
154 if (reuseBitmap) {
155 SkAutoLockPixels alp(*bm);
robertphillips 2013/03/11 18:25:55 NULL goes on lhs
djsollen 2013/03/11 19:43:24 Done.
156 if (bm->getPixels() != NULL) {
157 return this->onDecode(stream, bm, mode);
158 }
159 }
robertphillips 2013/03/11 18:25:55 Move tmp down here?
djsollen 2013/03/11 19:43:24 Done.
142 if (!this->onDecode(stream, &tmp, mode)) { 160 if (!this->onDecode(stream, &tmp, mode)) {
143 return false; 161 return false;
144 } 162 }
145 bm->swap(tmp); 163 bm->swap(tmp);
146 return true; 164 return true;
147 } 165 }
148 166
167 bool SkImageDecoder::decodeRegion(SkBitmap* bm, const SkIRect& rect,
168 SkBitmap::Config pref) {
169 // we reset this to false before calling onDecodeRegion
170 fShouldCancelDecode = false;
171 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false
172 fDefaultPref = pref;
173
robertphillips 2013/03/11 18:25:55 just "return this->onDecodeRegion(bm, rect));"
djsollen 2013/03/11 19:43:24 Done.
174 if (!this->onDecodeRegion(bm, rect)) {
175 return false;
176 }
177 return true;
178 }
179
180 bool SkImageDecoder::buildTileIndex(SkStream* stream,
181 int *width, int *height) {
182 // we reset this to false before calling onBuildTileIndex
183 fShouldCancelDecode = false;
184
185 return this->onBuildTileIndex(stream, width, height);
186 }
187
188 void SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
189 int dstX, int dstY, int width, int height,
190 int srcX, int srcY) {
191 int w = width / sampleSize;
192 int h = height / sampleSize;
193 // if the destination has no pixels then we must allocate them.
194 if (dst->isNull()) {
195 dst->setConfig(src->getConfig(), w, h);
196 dst->setIsOpaque(src->isOpaque());
197
198 if (!this->allocPixelRef(dst, NULL)) {
199 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap"));
200 return;
201 }
202 }
203 // check to see if the destination is large enough to decode the desired
204 // region. If this assert fails we will just draw as much of the source
205 // into the destination that we can.
206 SkASSERT(dst->width() >= w && dst->height() >= h);
207
208 // Set the Src_Mode for the paint to prevent transparency issue in the
209 // dest in the event that the dest was being re-used.
210 SkPaint paint;
211 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
212
213 SkCanvas canvas(*dst);
214 canvas.drawSprite(*src, (srcX - dstX) / sampleSize,
215 (srcY - dstY) / sampleSize,
216 &paint);
217 }
218
149 /////////////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////////////
150 220
151 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, 221 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
152 SkBitmap::Config pref, Mode mode, Format* format) { 222 SkBitmap::Config pref, Mode mode, Format* format) {
153 SkASSERT(file); 223 SkASSERT(file);
154 SkASSERT(bm); 224 SkASSERT(bm);
155 225
156 SkFILEStream stream(file); 226 SkFILEStream stream(file);
157 if (stream.isValid()) { 227 if (stream.isValid()) {
158 if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format)) { 228 if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format)) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 317
248 if (NULL != codec) { 318 if (NULL != codec) {
249 success = codec->decode(stream, bm, pref, mode); 319 success = codec->decode(stream, bm, pref, mode);
250 if (success && format) { 320 if (success && format) {
251 *format = codec->getFormat(); 321 *format = codec->getFormat();
252 } 322 }
253 delete codec; 323 delete codec;
254 } 324 }
255 return success; 325 return success;
256 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698