OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #ifndef SkImageEncoder_DEFINED | 8 #ifndef SkImageEncoder_DEFINED |
9 #define SkImageEncoder_DEFINED | 9 #define SkImageEncoder_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.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 SkImage; |
16 class SkWStream; | 17 class SkWStream; |
17 | 18 |
18 class SkImageEncoder { | 19 class SkImageEncoder { |
19 public: | 20 public: |
20 enum Type { | 21 enum Type { |
21 kUnknown_Type, | 22 kUnknown_Type, |
22 kBMP_Type, | 23 kBMP_Type, |
23 kGIF_Type, | 24 kGIF_Type, |
24 kICO_Type, | 25 kICO_Type, |
25 kJPEG_Type, | 26 kJPEG_Type, |
(...skipping 27 matching lines...) Expand all Loading... |
53 bool encodeFile(const char file[], const SkBitmap& bm, int quality); | 54 bool encodeFile(const char file[], const SkBitmap& bm, int quality); |
54 | 55 |
55 /** | 56 /** |
56 * Encode bitmap 'bm' in the desired format, writing results to | 57 * Encode bitmap 'bm' in the desired format, writing results to |
57 * stream 'stream', at quality level 'quality' (which can be in | 58 * stream 'stream', at quality level 'quality' (which can be in |
58 * range 0-100). Returns false on failure. | 59 * range 0-100). Returns false on failure. |
59 */ | 60 */ |
60 bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality); | 61 bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality); |
61 | 62 |
62 static SkData* EncodeData(const SkBitmap&, Type, int quality); | 63 static SkData* EncodeData(const SkBitmap&, Type, int quality); |
| 64 |
| 65 /** |
| 66 * Encode the image's pixels and return the result as a new SkData, which |
| 67 * the caller must manage (i.e. call unref() when they are done). |
| 68 * |
| 69 * If the image type cannot be encoded, or the requested encoder type is |
| 70 * not supported, this will return NULL. |
| 71 */ |
| 72 static SkData* EncodeData(const SkImage&, Type, int quality); |
| 73 |
63 static bool EncodeFile(const char file[], const SkBitmap&, Type, | 74 static bool EncodeFile(const char file[], const SkBitmap&, Type, |
64 int quality); | 75 int quality); |
65 static bool EncodeStream(SkWStream*, const SkBitmap&, Type, | 76 static bool EncodeStream(SkWStream*, const SkBitmap&, Type, |
66 int quality); | 77 int quality); |
67 | 78 |
68 protected: | 79 protected: |
69 /** | 80 /** |
70 * Encode bitmap 'bm' in the desired format, writing results to | 81 * Encode bitmap 'bm' in the desired format, writing results to |
71 * stream 'stream', at quality level 'quality' (which can be in | 82 * stream 'stream', at quality level 'quality' (which can be in |
72 * range 0-100). | 83 * range 0-100). |
(...skipping 28 matching lines...) Expand all Loading... |
101 DECLARE_ENCODER_CREATOR(WEBPImageEncoder); | 112 DECLARE_ENCODER_CREATOR(WEBPImageEncoder); |
102 | 113 |
103 #ifdef SK_BUILD_FOR_IOS | 114 #ifdef SK_BUILD_FOR_IOS |
104 DECLARE_ENCODER_CREATOR(PNGImageEncoder_IOS); | 115 DECLARE_ENCODER_CREATOR(PNGImageEncoder_IOS); |
105 #endif | 116 #endif |
106 | 117 |
107 // Typedef to make registering encoder callback easier | 118 // Typedef to make registering encoder callback easier |
108 // This has to be defined outside SkImageEncoder. :( | 119 // This has to be defined outside SkImageEncoder. :( |
109 typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_Enc
odeReg; | 120 typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_Enc
odeReg; |
110 #endif | 121 #endif |
OLD | NEW |