| 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 |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, | 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and | 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. | 14 * limitations under the License. |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 #include "SkImageDecoder.h" | 17 #include "SkImageDecoder.h" |
| 18 #include "SkImageEncoder.h" | 18 #include "SkImageEncoder.h" |
| 19 #include "SkColorPriv.h" | 19 #include "SkColorPriv.h" |
| 20 #include "SkScaledBitmapSampler.h" | 20 #include "SkScaledBitmapSampler.h" |
| 21 #include "SkStream.h" | 21 #include "SkStream.h" |
| 22 #include "SkTemplates.h" | 22 #include "SkTemplates.h" |
| 23 #include "SkUtils.h" | 23 #include "SkUtils.h" |
| 24 #include "SkTScopedPtr.h" | |
| 25 | 24 |
| 26 // A WebP decoder only, on top of (subset of) libwebp | 25 // A WebP decoder only, on top of (subset of) libwebp |
| 27 // For more information on WebP image format, and libwebp library, see: | 26 // For more information on WebP image format, and libwebp library, see: |
| 28 // http://code.google.com/speed/webp/ | 27 // http://code.google.com/speed/webp/ |
| 29 // http://www.webmproject.org/code/#libwebp_webp_image_decoder_library | 28 // http://www.webmproject.org/code/#libwebp_webp_image_decoder_library |
| 30 // http://review.webmproject.org/gitweb?p=libwebp.git | 29 // http://review.webmproject.org/gitweb?p=libwebp.git |
| 31 | 30 |
| 32 #include <stdio.h> | 31 #include <stdio.h> |
| 33 extern "C" { | 32 extern "C" { |
| 34 // If moving libwebp out of skia source tree, path for webp headers must be | 33 // If moving libwebp out of skia source tree, path for webp headers must be |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 336 |
| 338 // The image can be decoded directly to decodedBitmap if | 337 // The image can be decoded directly to decodedBitmap if |
| 339 // 1. the region is within the image range | 338 // 1. the region is within the image range |
| 340 // 2. bitmap's config is compatible | 339 // 2. bitmap's config is compatible |
| 341 // 3. bitmap's size is same as the required region (after sampled) | 340 // 3. bitmap's size is same as the required region (after sampled) |
| 342 bool directDecode = (rect == region) && | 341 bool directDecode = (rect == region) && |
| 343 (decodedBitmap->isNull() || | 342 (decodedBitmap->isNull() || |
| 344 (is_config_compatible(*decodedBitmap) && | 343 (is_config_compatible(*decodedBitmap) && |
| 345 (decodedBitmap->width() == width) && | 344 (decodedBitmap->width() == width) && |
| 346 (decodedBitmap->height() == height))); | 345 (decodedBitmap->height() == height))); |
| 347 SkTScopedPtr<SkBitmap> adb; | 346 |
| 347 SkBitmap tmpBitmap; |
| 348 SkBitmap *bitmap = decodedBitmap; | 348 SkBitmap *bitmap = decodedBitmap; |
| 349 | 349 |
| 350 if (!directDecode) { | 350 if (!directDecode) { |
| 351 // allocates a temp bitmap | 351 bitmap = &tmpBitmap; |
| 352 bitmap = new SkBitmap; | |
| 353 adb.reset(bitmap); | |
| 354 } | 352 } |
| 355 | 353 |
| 356 if (bitmap->isNull()) { | 354 if (bitmap->isNull()) { |
| 357 if (!setDecodeConfig(bitmap, width, height)) { | 355 if (!setDecodeConfig(bitmap, width, height)) { |
| 358 return false; | 356 return false; |
| 359 } | 357 } |
| 360 // alloc from native heap if it is a temp bitmap. (prevent GC) | 358 // alloc from native heap if it is a temp bitmap. (prevent GC) |
| 361 bool allocResult = (bitmap == decodedBitmap) | 359 bool allocResult = (bitmap == decodedBitmap) |
| 362 ? allocPixelRef(bitmap, NULL) | 360 ? allocPixelRef(bitmap, NULL) |
| 363 : bitmap->allocPixels(); | 361 : bitmap->allocPixels(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // Magic matches, call decoder | 584 // Magic matches, call decoder |
| 587 return SkNEW(SkWEBPImageDecoder); | 585 return SkNEW(SkWEBPImageDecoder); |
| 588 } | 586 } |
| 589 | 587 |
| 590 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 588 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
| 591 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 589 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
| 592 } | 590 } |
| 593 | 591 |
| 594 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); | 592 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); |
| 595 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); | 593 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); |
| OLD | NEW |