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