| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 even if our decodedBitmap doesn't, due to the request that we | 392 even if our decodedBitmap doesn't, due to the request that we |
| 393 upscale png's palette to a direct model | 393 upscale png's palette to a direct model |
| 394 */ | 394 */ |
| 395 const SkPMColor* colors = colorTable ? colorTable->readColors() : nullpt
r; | 395 const SkPMColor* colors = colorTable ? colorTable->readColors() : nullpt
r; |
| 396 if (!sampler.begin(decodedBitmap, sc, *this, colors)) { | 396 if (!sampler.begin(decodedBitmap, sc, *this, colors)) { |
| 397 return kFailure; | 397 return kFailure; |
| 398 } | 398 } |
| 399 const int height = decodedBitmap->height(); | 399 const int height = decodedBitmap->height(); |
| 400 | 400 |
| 401 if (number_passes > 1) { | 401 if (number_passes > 1) { |
| 402 SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel); | 402 SkAutoTMalloc<uint8_t> storage(origWidth * origHeight * srcBytesPerP
ixel); |
| 403 uint8_t* base = (uint8_t*)storage.get(); | 403 uint8_t* base = storage.get(); |
| 404 size_t rowBytes = origWidth * srcBytesPerPixel; | 404 size_t rowBytes = origWidth * srcBytesPerPixel; |
| 405 | 405 |
| 406 for (int i = 0; i < number_passes; i++) { | 406 for (int i = 0; i < number_passes; i++) { |
| 407 uint8_t* row = base; | 407 uint8_t* row = base; |
| 408 for (png_uint_32 y = 0; y < origHeight; y++) { | 408 for (png_uint_32 y = 0; y < origHeight; y++) { |
| 409 uint8_t* bmRow = row; | 409 uint8_t* bmRow = row; |
| 410 png_read_rows(png_ptr, &bmRow, png_bytepp_NULL, 1); | 410 png_read_rows(png_ptr, &bmRow, png_bytepp_NULL, 1); |
| 411 row += rowBytes; | 411 row += rowBytes; |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 // now sample it | 414 // now sample it |
| 415 base += sampler.srcY0() * rowBytes; | 415 base += sampler.srcY0() * rowBytes; |
| 416 for (int y = 0; y < height; y++) { | 416 for (int y = 0; y < height; y++) { |
| 417 reallyHasAlpha |= sampler.next(base); | 417 reallyHasAlpha |= sampler.next(base); |
| 418 base += sampler.srcDY() * rowBytes; | 418 base += sampler.srcDY() * rowBytes; |
| 419 } | 419 } |
| 420 } else { | 420 } else { |
| 421 SkAutoMalloc storage(origWidth * srcBytesPerPixel); | 421 SkAutoTMalloc<uint8_t> storage(origWidth * srcBytesPerPixel); |
| 422 uint8_t* srcRow = (uint8_t*)storage.get(); | 422 uint8_t* srcRow = storage.get(); |
| 423 skip_src_rows(png_ptr, srcRow, sampler.srcY0()); | 423 skip_src_rows(png_ptr, srcRow, sampler.srcY0()); |
| 424 | 424 |
| 425 for (int y = 0; y < height; y++) { | 425 for (int y = 0; y < height; y++) { |
| 426 uint8_t* tmp = srcRow; | 426 uint8_t* tmp = srcRow; |
| 427 png_read_rows(png_ptr, &tmp, png_bytepp_NULL, 1); | 427 png_read_rows(png_ptr, &tmp, png_bytepp_NULL, 1); |
| 428 reallyHasAlpha |= sampler.next(srcRow); | 428 reallyHasAlpha |= sampler.next(srcRow); |
| 429 if (y < height - 1) { | 429 if (y < height - 1) { |
| 430 skip_src_rows(png_ptr, srcRow, sampler.srcDY() - 1); | 430 skip_src_rows(png_ptr, srcRow, sampler.srcDY() - 1); |
| 431 } | 431 } |
| 432 } | 432 } |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 if (numTrans > 0) { | 957 if (numTrans > 0) { |
| 958 png_set_tRNS(png_ptr, info_ptr, trans, numTrans, nullptr); | 958 png_set_tRNS(png_ptr, info_ptr, trans, numTrans, nullptr); |
| 959 } | 959 } |
| 960 } | 960 } |
| 961 #ifdef PNG_sBIT_SUPPORTED | 961 #ifdef PNG_sBIT_SUPPORTED |
| 962 png_set_sBIT(png_ptr, info_ptr, &sig_bit); | 962 png_set_sBIT(png_ptr, info_ptr, &sig_bit); |
| 963 #endif | 963 #endif |
| 964 png_write_info(png_ptr, info_ptr); | 964 png_write_info(png_ptr, info_ptr); |
| 965 | 965 |
| 966 const char* srcImage = (const char*)bitmap.getPixels(); | 966 const char* srcImage = (const char*)bitmap.getPixels(); |
| 967 SkAutoSMalloc<1024> rowStorage(bitmap.width() << 2); | 967 SkAutoSTMalloc<1024, char> rowStorage(bitmap.width() << 2); |
| 968 char* storage = (char*)rowStorage.get(); | 968 char* storage = rowStorage.get(); |
| 969 transform_scanline_proc proc = choose_proc(ct, hasAlpha); | 969 transform_scanline_proc proc = choose_proc(ct, hasAlpha); |
| 970 | 970 |
| 971 for (int y = 0; y < bitmap.height(); y++) { | 971 for (int y = 0; y < bitmap.height(); y++) { |
| 972 png_bytep row_ptr = (png_bytep)storage; | 972 png_bytep row_ptr = (png_bytep)storage; |
| 973 proc(srcImage, bitmap.width(), storage); | 973 proc(srcImage, bitmap.width(), storage); |
| 974 png_write_rows(png_ptr, &row_ptr, 1); | 974 png_write_rows(png_ptr, &row_ptr, 1); |
| 975 srcImage += bitmap.rowBytes(); | 975 srcImage += bitmap.rowBytes(); |
| 976 } | 976 } |
| 977 | 977 |
| 978 png_write_end(png_ptr, info_ptr); | 978 png_write_end(png_ptr, info_ptr); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 return SkImageDecoder::kUnknown_Format; | 1010 return SkImageDecoder::kUnknown_Format; |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1013 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
| 1014 return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : nullptr; | 1014 return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : nullptr; |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1017 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
| 1018 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1018 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
| 1019 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1019 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
| OLD | NEW |