OLD | NEW |
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 #include "SkImageDecoder.h" | 8 #include "SkImageDecoder.h" |
9 #include "SkImageEncoder.h" | 9 #include "SkImageEncoder.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 int w = rect.width() / sampleSize; | 816 int w = rect.width() / sampleSize; |
817 int h = rect.height() / sampleSize; | 817 int h = rect.height() / sampleSize; |
818 const bool swapOnly = (rect == region) && (w == decodedBitmap.width()) && | 818 const bool swapOnly = (rect == region) && (w == decodedBitmap.width()) && |
819 (h == decodedBitmap.height()) && bm->isNull(); | 819 (h == decodedBitmap.height()) && bm->isNull(); |
820 const bool needColorTable = kIndex_8_SkColorType == colorType; | 820 const bool needColorTable = kIndex_8_SkColorType == colorType; |
821 if (swapOnly) { | 821 if (swapOnly) { |
822 if (!this->allocPixelRef(&decodedBitmap, needColorTable ? colorTable : N
ULL)) { | 822 if (!this->allocPixelRef(&decodedBitmap, needColorTable ? colorTable : N
ULL)) { |
823 return false; | 823 return false; |
824 } | 824 } |
825 } else { | 825 } else { |
826 if (!decodedBitmap.allocPixels(NULL, needColorTable ? colorTable : NULL)
) { | 826 if (!decodedBitmap.tryAllocPixels(NULL, needColorTable ? colorTable : NU
LL)) { |
827 return false; | 827 return false; |
828 } | 828 } |
829 } | 829 } |
830 SkAutoLockPixels alp(decodedBitmap); | 830 SkAutoLockPixels alp(decodedBitmap); |
831 | 831 |
832 /* Turn on interlace handling. REQUIRED if you are not using | 832 /* Turn on interlace handling. REQUIRED if you are not using |
833 * png_read_image(). To see how to handle interlacing passes, | 833 * png_read_image(). To see how to handle interlacing passes, |
834 * see the png_read_row() method below: | 834 * see the png_read_row() method below: |
835 */ | 835 */ |
836 const int number_passes = (interlaceType != PNG_INTERLACE_NONE) ? | 836 const int number_passes = (interlaceType != PNG_INTERLACE_NONE) ? |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 return SkImageDecoder::kUnknown_Format; | 1278 return SkImageDecoder::kUnknown_Format; |
1279 } | 1279 } |
1280 | 1280 |
1281 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1281 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
1282 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1282 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
1283 } | 1283 } |
1284 | 1284 |
1285 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1285 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
1286 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1286 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
1287 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1287 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
OLD | NEW |