| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 public: | 55 public: |
| 56 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) | 56 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) |
| 57 : fStream(stream) | 57 : fStream(stream) |
| 58 , fPng_ptr(png_ptr) | 58 , fPng_ptr(png_ptr) |
| 59 , fInfo_ptr(info_ptr) | 59 , fInfo_ptr(info_ptr) |
| 60 , fColorType(kUnknown_SkColorType) { | 60 , fColorType(kUnknown_SkColorType) { |
| 61 SkASSERT(stream != NULL); | 61 SkASSERT(stream != NULL); |
| 62 stream->ref(); | 62 stream->ref(); |
| 63 } | 63 } |
| 64 ~SkPNGImageIndex() { | 64 ~SkPNGImageIndex() { |
| 65 if (NULL != fPng_ptr) { | 65 if (fPng_ptr) { |
| 66 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); | 66 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 SkAutoTUnref<SkStreamRewindable> fStream; | 70 SkAutoTUnref<SkStreamRewindable> fStream; |
| 71 png_structp fPng_ptr; | 71 png_structp fPng_ptr; |
| 72 png_infop fInfo_ptr; | 72 png_infop fInfo_ptr; |
| 73 SkColorType fColorType; | 73 SkColorType fColorType; |
| 74 }; | 74 }; |
| 75 | 75 |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 SkAutoLockPixels alp(bitmap); | 1156 SkAutoLockPixels alp(bitmap); |
| 1157 // readyToDraw checks for pixels (and colortable if that is required) | 1157 // readyToDraw checks for pixels (and colortable if that is required) |
| 1158 if (!bitmap.readyToDraw()) { | 1158 if (!bitmap.readyToDraw()) { |
| 1159 return false; | 1159 return false; |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 // we must do this after we have locked the pixels | 1162 // we must do this after we have locked the pixels |
| 1163 SkColorTable* ctable = bitmap.getColorTable(); | 1163 SkColorTable* ctable = bitmap.getColorTable(); |
| 1164 if (NULL != ctable) { | 1164 if (ctable) { |
| 1165 if (ctable->count() == 0) { | 1165 if (ctable->count() == 0) { |
| 1166 return false; | 1166 return false; |
| 1167 } | 1167 } |
| 1168 // check if we can store in fewer than 8 bits | 1168 // check if we can store in fewer than 8 bits |
| 1169 bitDepth = computeBitDepth(ctable->count()); | 1169 bitDepth = computeBitDepth(ctable->count()); |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 return doEncode(stream, bitmap, hasAlpha, colorType, bitDepth, ct, sig_bit); | 1172 return doEncode(stream, bitmap, hasAlpha, colorType, bitDepth, ct, sig_bit); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| (...skipping 103 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 |