Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: include/core/SkImageEncoder.h

Issue 1373683003: change pixel-serializer to support reencoding existing data Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: I hate this warning Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/core.gypi ('k') | include/core/SkPixelSerializer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | include/core/SkPixelSerializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698