| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010, The Android Open Source Project | 2 * Copyright 2010, The Android Open Source Project |
| 3 * | 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
| 7 * | 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * | 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 config->options.use_cropping = 1; | 272 config->options.use_cropping = 1; |
| 273 config->options.crop_left = region.fLeft; | 273 config->options.crop_left = region.fLeft; |
| 274 config->options.crop_top = region.fTop; | 274 config->options.crop_top = region.fTop; |
| 275 config->options.crop_width = region.width(); | 275 config->options.crop_width = region.width(); |
| 276 config->options.crop_height = region.height(); | 276 config->options.crop_height = region.height(); |
| 277 | 277 |
| 278 return true; | 278 return true; |
| 279 } | 279 } |
| 280 | 280 |
| 281 bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, | 281 bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, int width, int
height) { |
| 282 int width, int height) { | 282 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, SkToBool(fHa
sAlpha)); |
| 283 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, SkToBool(fHas
Alpha)); | |
| 284 | 283 |
| 285 // YUV converter supports output in RGB565, RGBA4444 and RGBA8888 formats. | 284 // YUV converter supports output in RGB565, RGBA4444 and RGBA8888 formats. |
| 286 if (fHasAlpha) { | 285 if (fHasAlpha) { |
| 287 if (config != SkBitmap::kARGB_4444_Config) { | 286 if (colorType != kARGB_4444_SkColorType) { |
| 288 config = SkBitmap::kARGB_8888_Config; | 287 colorType = kN32_SkColorType; |
| 289 } | 288 } |
| 290 } else { | 289 } else { |
| 291 if (config != SkBitmap::kRGB_565_Config && | 290 if (colorType != kRGB_565_SkColorType && colorType != kARGB_4444_SkColor
Type) { |
| 292 config != SkBitmap::kARGB_4444_Config) { | 291 colorType = kN32_SkColorType; |
| 293 config = SkBitmap::kARGB_8888_Config; | |
| 294 } | 292 } |
| 295 } | 293 } |
| 296 | 294 |
| 297 if (!this->chooseFromOneChoice(config, width, height)) { | 295 if (!this->chooseFromOneChoice(colorType, width, height)) { |
| 298 return false; | 296 return false; |
| 299 } | 297 } |
| 300 | 298 |
| 301 SkImageInfo info; | 299 SkAlphaType alphaType = kOpaque_SkAlphaType; |
| 302 info.fWidth = width; | |
| 303 info.fHeight = height; | |
| 304 info.fColorType = SkBitmapConfigToColorType(config); | |
| 305 if (SkToBool(fHasAlpha)) { | 300 if (SkToBool(fHasAlpha)) { |
| 306 if (this->getRequireUnpremultipliedColors()) { | 301 if (this->getRequireUnpremultipliedColors()) { |
| 307 info.fAlphaType = kUnpremul_SkAlphaType; | 302 alphaType = kUnpremul_SkAlphaType; |
| 308 } else { | 303 } else { |
| 309 info.fAlphaType = kPremul_SkAlphaType; | 304 alphaType = kPremul_SkAlphaType; |
| 310 } | 305 } |
| 311 } else { | |
| 312 info.fAlphaType = kOpaque_SkAlphaType; | |
| 313 } | 306 } |
| 314 return decodedBitmap->setInfo(info); | 307 return decodedBitmap->setInfo(SkImageInfo::Make(width, height, colorType, al
phaType)); |
| 315 } | 308 } |
| 316 | 309 |
| 317 bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, | 310 bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, |
| 318 int *width, int *height) { | 311 int *width, int *height) { |
| 319 int origWidth, origHeight, hasAlpha; | 312 int origWidth, origHeight, hasAlpha; |
| 320 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { | 313 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { |
| 321 return false; | 314 return false; |
| 322 } | 315 } |
| 323 | 316 |
| 324 if (!stream->rewind()) { | 317 if (!stream->rewind()) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // alloc from native heap if it is a temp bitmap. (prevent GC) | 375 // alloc from native heap if it is a temp bitmap. (prevent GC) |
| 383 bool allocResult = (bitmap == decodedBitmap) | 376 bool allocResult = (bitmap == decodedBitmap) |
| 384 ? allocPixelRef(bitmap, NULL) | 377 ? allocPixelRef(bitmap, NULL) |
| 385 : bitmap->allocPixels(); | 378 : bitmap->allocPixels(); |
| 386 if (!allocResult) { | 379 if (!allocResult) { |
| 387 return return_false(*decodedBitmap, "allocPixelRef"); | 380 return return_false(*decodedBitmap, "allocPixelRef"); |
| 388 } | 381 } |
| 389 } else { | 382 } else { |
| 390 // This is also called in setDecodeConfig in above block. | 383 // This is also called in setDecodeConfig in above block. |
| 391 // i.e., when bitmap->isNull() is true. | 384 // i.e., when bitmap->isNull() is true. |
| 392 if (!chooseFromOneChoice(bitmap->config(), width, height)) { | 385 if (!chooseFromOneChoice(bitmap->colorType(), width, height)) { |
| 393 return false; | 386 return false; |
| 394 } | 387 } |
| 395 } | 388 } |
| 396 | 389 |
| 397 SkAutoLockPixels alp(*bitmap); | 390 SkAutoLockPixels alp(*bitmap); |
| 398 WebPDecoderConfig config; | 391 WebPDecoderConfig config; |
| 399 if (!webp_get_config_resize_crop(&config, bitmap, rect, | 392 if (!webp_get_config_resize_crop(&config, bitmap, rect, |
| 400 this->shouldPremultiply())) { | 393 this->shouldPremultiply())) { |
| 401 return false; | 394 return false; |
| 402 } | 395 } |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 return SkImageDecoder::kUnknown_Format; | 679 return SkImageDecoder::kUnknown_Format; |
| 687 } | 680 } |
| 688 | 681 |
| 689 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 682 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
| 690 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 683 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
| 691 } | 684 } |
| 692 | 685 |
| 693 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); | 686 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); |
| 694 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); | 687 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); |
| 695 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); | 688 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); |
| OLD | NEW |