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

Side by Side Diff: src/codec/SkCodec_libico.cpp

Issue 1277213002: Support more swizzles to 565 in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update new 565 swizzling functions for scaling Created 5 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 #include "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkCodec_libico.h" 9 #include "SkCodec_libico.h"
10 #include "SkCodec_libpng.h" 10 #include "SkCodec_libpng.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 for (int32_t i = 0; i < codecs->count(); i++) { 169 for (int32_t i = 0; i < codecs->count(); i++) {
170 SkImageInfo info = codecs->operator[](i)->getInfo(); 170 SkImageInfo info = codecs->operator[](i)->getInfo();
171 uint32_t size = info.width() * info.height(); 171 uint32_t size = info.width() * info.height();
172 if (size > maxSize) { 172 if (size > maxSize) {
173 maxSize = size; 173 maxSize = size;
174 maxIndex = i; 174 maxIndex = i;
175 } 175 }
176 } 176 }
177 SkImageInfo info = codecs->operator[](maxIndex)->getInfo(); 177 SkImageInfo info = codecs->operator[](maxIndex)->getInfo();
178 178
179 // ICOs contain an alpha mask after the image which means we cannot
180 // guarantee that an image is opaque, even if the sub-codec thinks it
181 // is.
182 // FIXME (msarett): The BMP decoder depends on the alpha type in order
183 // to decode correctly, otherwise it could report kUnpremul and we would
184 // not have to correct it here. Is there a better way?
185 // FIXME (msarett): This is only true for BMP in ICO - could a PNG in ICO
186 // be opaque? Is it okay that we missed out on the opportunity to mark
187 // such an image as opaque?
188 info = info.makeAlphaType(kUnpremul_SkAlphaType);
189
179 // Note that stream is owned by the embedded codec, the ico does not need 190 // Note that stream is owned by the embedded codec, the ico does not need
180 // direct access to the stream. 191 // direct access to the stream.
181 return SkNEW_ARGS(SkIcoCodec, (info, codecs.detach())); 192 return SkNEW_ARGS(SkIcoCodec, (info, codecs.detach()));
182 } 193 }
183 194
184 /* 195 /*
185 * Creates an instance of the decoder 196 * Creates an instance of the decoder
186 * Called only by NewFromStream 197 * Called only by NewFromStream
187 */ 198 */
188 SkIcoCodec::SkIcoCodec(const SkImageInfo& info, 199 SkIcoCodec::SkIcoCodec(const SkImageInfo& info,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 * Initiates the Ico decode 237 * Initiates the Ico decode
227 */ 238 */
228 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, 239 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo,
229 void* dst, size_t dstRowBytes, 240 void* dst, size_t dstRowBytes,
230 const Options& opts, SkPMColor* ct, 241 const Options& opts, SkPMColor* ct,
231 int* ptr) { 242 int* ptr) {
232 if (opts.fSubset) { 243 if (opts.fSubset) {
233 // Subsets are not supported. 244 // Subsets are not supported.
234 return kUnimplemented; 245 return kUnimplemented;
235 } 246 }
247
248 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
249 return kInvalidConversion;
250 }
251
236 // We return invalid scale if there is no candidate image with matching 252 // We return invalid scale if there is no candidate image with matching
237 // dimensions. 253 // dimensions.
238 Result result = kInvalidScale; 254 Result result = kInvalidScale;
239 for (int32_t i = 0; i < fEmbeddedCodecs->count(); i++) { 255 for (int32_t i = 0; i < fEmbeddedCodecs->count(); i++) {
256 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](i);
240 // If the dimensions match, try to decode 257 // If the dimensions match, try to decode
241 if (dstInfo.dimensions() == 258 if (dstInfo.dimensions() == embeddedCodec->getInfo().dimensions()) {
242 fEmbeddedCodecs->operator[](i)->getInfo().dimensions()) {
243 259
244 // Perform the decode 260 // Perform the decode
245 result = fEmbeddedCodecs->operator[](i)->getPixels(dstInfo, 261 // FIXME: (msarett): ICO is considered non-opaque, even if the embed ded BMP
246 dst, dstRowBytes, &opts, ct, ptr); 262 // incorrectly claims it has no alpha.
263 SkImageInfo info = dstInfo.makeAlphaType(embeddedCodec->getInfo().al phaType());
264 result = embeddedCodec->getPixels(info, dst, dstRowBytes, &opts, ct, ptr);
247 265
248 // On a fatal error, keep trying to find an image to decode 266 // On a fatal error, keep trying to find an image to decode
249 if (kInvalidConversion == result || kInvalidInput == result || 267 if (kInvalidConversion == result || kInvalidInput == result ||
250 kInvalidScale == result) { 268 kInvalidScale == result) {
251 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n"); 269 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n");
252 continue; 270 continue;
253 } 271 }
254 272
255 // On success or partial success, return the result 273 // On success or partial success, return the result
256 return result; 274 return result;
257 } 275 }
258 } 276 }
259 277
260 SkCodecPrintf("Error: No matching candidate image in ico.\n"); 278 SkCodecPrintf("Error: No matching candidate image in ico.\n");
261 return result; 279 return result;
262 } 280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698