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

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

Issue 167763003: Fix issue in image decoders where the bitmap config was not properly set. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: comments Created 6 years, 10 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
« no previous file with comments | « src/images/SkImageDecoder_libpng.cpp ('k') | no next file » | 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 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #include "SkImageRef.h" 8 #include "SkImageRef.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 12 matching lines...) Expand all
23 : INHERITED(info, mutex), fErrorInDecoding(false) 23 : INHERITED(info, mutex), fErrorInDecoding(false)
24 { 24 {
25 SkASSERT(stream); 25 SkASSERT(stream);
26 stream->ref(); 26 stream->ref();
27 fStream = stream; 27 fStream = stream;
28 fSampleSize = sampleSize; 28 fSampleSize = sampleSize;
29 fDoDither = true; 29 fDoDither = true;
30 fPrev = fNext = NULL; 30 fPrev = fNext = NULL;
31 fFactory = NULL; 31 fFactory = NULL;
32 32
33 // This sets the colortype/alphatype to exactly match our info, so that this
34 // can get communicated down to the codec.
35 fBitmap.setConfig(info);
36
33 #ifdef DUMP_IMAGEREF_LIFECYCLE 37 #ifdef DUMP_IMAGEREF_LIFECYCLE
34 SkDebugf("add ImageRef %p [%d] data=%d\n", 38 SkDebugf("add ImageRef %p [%d] data=%d\n",
35 this, this->info().fColorType, (int)stream->getLength()); 39 this, this->info().fColorType, (int)stream->getLength());
36 #endif 40 #endif
37 } 41 }
38 42
39 SkImageRef::~SkImageRef() { 43 SkImageRef::~SkImageRef() {
40 44
41 #ifdef DUMP_IMAGEREF_LIFECYCLE 45 #ifdef DUMP_IMAGEREF_LIFECYCLE
42 SkDebugf("delete ImageRef %p [%d] data=%d\n", 46 SkDebugf("delete ImageRef %p [%d] data=%d\n",
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } else { 115 } else {
112 codec = SkImageDecoder::Factory(fStream); 116 codec = SkImageDecoder::Factory(fStream);
113 } 117 }
114 118
115 if (codec) { 119 if (codec) {
116 SkAutoTDelete<SkImageDecoder> ad(codec); 120 SkAutoTDelete<SkImageDecoder> ad(codec);
117 121
118 codec->setSampleSize(fSampleSize); 122 codec->setSampleSize(fSampleSize);
119 codec->setDitherImage(fDoDither); 123 codec->setDitherImage(fDoDither);
120 if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) { 124 if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) {
125 if (kOpaque_SkAlphaType == fBitmap.alphaType()) {
126 this->changeAlphaType(kOpaque_SkAlphaType);
127 }
128 SkASSERT(this->info().fColorType == fBitmap.colorType());
129 SkASSERT(this->info().fWidth == fBitmap.width());
130 SkASSERT(this->info().fHeight == fBitmap.height());
121 return true; 131 return true;
122 } 132 }
123 } 133 }
124 134
125 #ifdef DUMP_IMAGEREF_LIFECYCLE 135 #ifdef DUMP_IMAGEREF_LIFECYCLE
126 if (NULL == codec) { 136 if (NULL == codec) {
127 SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI()); 137 SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI());
128 } else { 138 } else {
129 SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n", 139 SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n",
130 this->getURI(), mode); 140 this->getURI(), mode);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 size_t length = buffer.getArrayCount(); 181 size_t length = buffer.getArrayCount();
172 if (buffer.validateAvailable(length)) { 182 if (buffer.validateAvailable(length)) {
173 fStream = SkNEW_ARGS(SkMemoryStream, (length)); 183 fStream = SkNEW_ARGS(SkMemoryStream, (length));
174 buffer.readByteArray((void*)fStream->getMemoryBase(), length); 184 buffer.readByteArray((void*)fStream->getMemoryBase(), length);
175 } else { 185 } else {
176 fStream = NULL; 186 fStream = NULL;
177 } 187 }
178 188
179 fPrev = fNext = NULL; 189 fPrev = fNext = NULL;
180 fFactory = NULL; 190 fFactory = NULL;
191
192 // This sets the colortype/alphatype to exactly match our info, so that this
193 // can get communicated down to the codec.
194 fBitmap.setConfig(this->info());
181 } 195 }
182 196
183 void SkImageRef::flatten(SkWriteBuffer& buffer) const { 197 void SkImageRef::flatten(SkWriteBuffer& buffer) const {
184 this->INHERITED::flatten(buffer); 198 this->INHERITED::flatten(buffer);
185 199
186 buffer.writeInt(fSampleSize); 200 buffer.writeInt(fSampleSize);
187 buffer.writeBool(fDoDither); 201 buffer.writeBool(fDoDither);
188 // FIXME: Consider moving this logic should go into writeStream itself. 202 // FIXME: Consider moving this logic should go into writeStream itself.
189 // writeStream currently has no other callers, so this may be fine for 203 // writeStream currently has no other callers, so this may be fine for
190 // now. 204 // now.
191 if (!fStream->rewind()) { 205 if (!fStream->rewind()) {
192 SkDEBUGF(("Failed to rewind SkImageRef stream!")); 206 SkDEBUGF(("Failed to rewind SkImageRef stream!"));
193 buffer.write32(0); 207 buffer.write32(0);
194 } else { 208 } else {
195 // FIXME: Handle getLength properly here. Perhaps this class should 209 // FIXME: Handle getLength properly here. Perhaps this class should
196 // take an SkStreamAsset. 210 // take an SkStreamAsset.
197 buffer.writeStream(fStream, fStream->getLength()); 211 buffer.writeStream(fStream, fStream->getLength());
198 } 212 }
199 } 213 }
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libpng.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698