OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 #ifndef SkImageEncoder_DEFINED | 8 #ifndef SkImageEncoder_DEFINED |
9 #define SkImageEncoder_DEFINED | 9 #define SkImageEncoder_DEFINED |
10 | 10 |
11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
12 #include "SkTRegistry.h" | 12 #include "SkTRegistry.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkData; | 15 class SkData; |
| 16 class SkPixmap; |
| 17 class SkPixelSerializer; |
16 class SkWStream; | 18 class SkWStream; |
17 | 19 |
18 class SkImageEncoder { | 20 class SkImageEncoder { |
19 public: | 21 public: |
20 // TODO (scroggo): Merge with SkEncodedFormat. | 22 // TODO (scroggo): Merge with SkEncodedFormat. |
21 enum Type { | 23 enum Type { |
22 kUnknown_Type, | 24 kUnknown_Type, |
23 kBMP_Type, | 25 kBMP_Type, |
24 kGIF_Type, | 26 kGIF_Type, |
25 kICO_Type, | 27 kICO_Type, |
(...skipping 27 matching lines...) Expand all Loading... |
53 */ | 55 */ |
54 bool encodeFile(const char file[], const SkBitmap& bm, int quality); | 56 bool encodeFile(const char file[], const SkBitmap& bm, int quality); |
55 | 57 |
56 /** | 58 /** |
57 * Encode bitmap 'bm' in the desired format, writing results to | 59 * Encode bitmap 'bm' in the desired format, writing results to |
58 * stream 'stream', at quality level 'quality' (which can be in | 60 * stream 'stream', at quality level 'quality' (which can be in |
59 * range 0-100). Returns false on failure. | 61 * range 0-100). Returns false on failure. |
60 */ | 62 */ |
61 bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality); | 63 bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality); |
62 | 64 |
| 65 SkPixelSerializer* refSerializer(); |
| 66 |
63 static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t row
Bytes, | 67 static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t row
Bytes, |
64 Type, int quality); | 68 Type, int quality); |
| 69 static SkData* EncodeData(const SkPixmap&, Type, int quality); |
65 static SkData* EncodeData(const SkBitmap&, Type, int quality); | 70 static SkData* EncodeData(const SkBitmap&, Type, int quality); |
66 | 71 |
67 static bool EncodeFile(const char file[], const SkBitmap&, Type, | 72 static bool EncodeFile(const char file[], const SkBitmap&, Type, |
68 int quality); | 73 int quality); |
69 static bool EncodeStream(SkWStream*, const SkBitmap&, Type, | 74 static bool EncodeStream(SkWStream*, const SkBitmap&, Type, |
70 int quality); | 75 int quality); |
71 | 76 |
| 77 /** |
| 78 * If the existing data can be re-encoded into the specified type (efficien
tly), this |
| 79 * returns that new data (which the caller must unref()). If not, this retu
rns null. |
| 80 */ |
| 81 static SkData* ReencodeData(SkData* encoded, Type); |
| 82 |
72 protected: | 83 protected: |
73 /** | 84 /** |
74 * Encode bitmap 'bm' in the desired format, writing results to | 85 * Encode bitmap 'bm' in the desired format, writing results to |
75 * stream 'stream', at quality level 'quality' (which can be in | 86 * stream 'stream', at quality level 'quality' (which can be in |
76 * range 0-100). | 87 * range 0-100). |
77 * | 88 * |
78 * This must be overridden by each SkImageEncoder implementation. | 89 * This must be overridden by each SkImageEncoder implementation. |
79 */ | 90 */ |
80 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) =
0; | 91 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) =
0; |
| 92 |
| 93 virtual SkData* onReencodeData(SkData*) { return nullptr; } |
81 }; | 94 }; |
82 | 95 |
83 // This macro declares a global (i.e., non-class owned) creation entry point | 96 // This macro declares a global (i.e., non-class owned) creation entry point |
84 // for each encoder (e.g., CreateJPEGImageEncoder) | 97 // for each encoder (e.g., CreateJPEGImageEncoder) |
85 #define DECLARE_ENCODER_CREATOR(codec) \ | 98 #define DECLARE_ENCODER_CREATOR(codec) \ |
86 SkImageEncoder *Create ## codec (); | 99 SkImageEncoder *Create ## codec (); |
87 | 100 |
88 // This macro defines the global creation entry point for each encoder. Each | 101 // This macro defines the global creation entry point for each encoder. Each |
89 // encoder implementation that registers with the encoder factory must call it. | 102 // encoder implementation that registers with the encoder factory must call it. |
90 #define DEFINE_ENCODER_CREATOR(codec) \ | 103 #define DEFINE_ENCODER_CREATOR(codec) \ |
(...skipping 12 matching lines...) Expand all Loading... |
103 DECLARE_ENCODER_CREATOR(WEBPImageEncoder); | 116 DECLARE_ENCODER_CREATOR(WEBPImageEncoder); |
104 | 117 |
105 #ifdef SK_BUILD_FOR_IOS | 118 #ifdef SK_BUILD_FOR_IOS |
106 DECLARE_ENCODER_CREATOR(PNGImageEncoder_IOS); | 119 DECLARE_ENCODER_CREATOR(PNGImageEncoder_IOS); |
107 #endif | 120 #endif |
108 | 121 |
109 // Typedef to make registering encoder callback easier | 122 // Typedef to make registering encoder callback easier |
110 // This has to be defined outside SkImageEncoder. :( | 123 // This has to be defined outside SkImageEncoder. :( |
111 typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_Enc
odeReg; | 124 typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_Enc
odeReg; |
112 #endif | 125 #endif |
OLD | NEW |