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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
76 class SkPNGImageDecoder : public SkImageDecoder { | 76 class SkPNGImageDecoder : public SkImageDecoder { |
77 public: | 77 public: |
78 SkPNGImageDecoder() { | 78 SkPNGImageDecoder() { |
79 fImageIndex = NULL; | 79 fImageIndex = NULL; |
80 } | 80 } |
81 virtual Format getFormat() const SK_OVERRIDE { | 81 Format getFormat() const SK_OVERRIDE { |
82 return kPNG_Format; | 82 return kPNG_Format; |
83 } | 83 } |
84 | 84 |
85 virtual ~SkPNGImageDecoder() { | 85 virtual ~SkPNGImageDecoder() { |
86 SkDELETE(fImageIndex); | 86 SkDELETE(fImageIndex); |
87 } | 87 } |
88 | 88 |
89 protected: | 89 protected: |
90 #ifdef SK_BUILD_FOR_ANDROID | 90 #ifdef SK_BUILD_FOR_ANDROID |
91 virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *h
eight) SK_OVERRIDE; | 91 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) S
K_OVERRIDE; |
92 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) SK_OVER
RIDE; | 92 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) SK_OVERRIDE; |
93 #endif | 93 #endif |
94 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; | 94 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; |
95 | 95 |
96 private: | 96 private: |
97 SkPNGImageIndex* fImageIndex; | 97 SkPNGImageIndex* fImageIndex; |
98 | 98 |
99 bool onDecodeInit(SkStream* stream, png_structp *png_ptrp, png_infop *info_p
trp); | 99 bool onDecodeInit(SkStream* stream, png_structp *png_ptrp, png_infop *info_p
trp); |
100 bool decodePalette(png_structp png_ptr, png_infop info_ptr, | 100 bool decodePalette(png_structp png_ptr, png_infop info_ptr, |
101 bool * SK_RESTRICT hasAlphap, bool *reallyHasAlphap, | 101 bool * SK_RESTRICT hasAlphap, bool *reallyHasAlphap, |
102 SkColorTable **colorTablep); | 102 SkColorTable **colorTablep); |
103 bool getBitmapColorType(png_structp, png_infop, SkColorType*, bool* hasAlpha
, | 103 bool getBitmapColorType(png_structp, png_infop, SkColorType*, bool* hasAlpha
, |
104 SkPMColor* theTranspColor); | 104 SkPMColor* theTranspColor); |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 SkPMColor c = *colors++; | 1083 SkPMColor c = *colors++; |
1084 palette[i].red = SkGetPackedR32(c); | 1084 palette[i].red = SkGetPackedR32(c); |
1085 palette[i].green = SkGetPackedG32(c); | 1085 palette[i].green = SkGetPackedG32(c); |
1086 palette[i].blue = SkGetPackedB32(c); | 1086 palette[i].blue = SkGetPackedB32(c); |
1087 } | 1087 } |
1088 return num_trans; | 1088 return num_trans; |
1089 } | 1089 } |
1090 | 1090 |
1091 class SkPNGImageEncoder : public SkImageEncoder { | 1091 class SkPNGImageEncoder : public SkImageEncoder { |
1092 protected: | 1092 protected: |
1093 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK
_OVERRIDE; | 1093 bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK_OVERRID
E; |
1094 private: | 1094 private: |
1095 bool doEncode(SkWStream* stream, const SkBitmap& bm, | 1095 bool doEncode(SkWStream* stream, const SkBitmap& bm, |
1096 const bool& hasAlpha, int colorType, | 1096 const bool& hasAlpha, int colorType, |
1097 int bitDepth, SkColorType ct, | 1097 int bitDepth, SkColorType ct, |
1098 png_color_8& sig_bit); | 1098 png_color_8& sig_bit); |
1099 | 1099 |
1100 typedef SkImageEncoder INHERITED; | 1100 typedef SkImageEncoder INHERITED; |
1101 }; | 1101 }; |
1102 | 1102 |
1103 bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
/*quality*/) { | 1103 bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
/*quality*/) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 return SkImageDecoder::kUnknown_Format; | 1269 return SkImageDecoder::kUnknown_Format; |
1270 } | 1270 } |
1271 | 1271 |
1272 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1272 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
1273 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1273 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
1274 } | 1274 } |
1275 | 1275 |
1276 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1276 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
1277 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1277 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
1278 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1278 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
OLD | NEW |