epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 8 | #ifndef SkImageEncoder_DEFINED |
| 9 | #define SkImageEncoder_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
| 12 | |
| 13 | class SkBitmap; |
| 14 | class SkWStream; |
| 15 | |
| 16 | class SkImageEncoder { |
| 17 | public: |
| 18 | enum Type { |
| 19 | kJPEG_Type, |
| 20 | kPNG_Type |
| 21 | }; |
| 22 | static SkImageEncoder* Create(Type); |
| 23 | |
| 24 | virtual ~SkImageEncoder(); |
| 25 | |
| 26 | /* Quality ranges from 0..100 */ |
| 27 | enum { |
| 28 | kDefaultQuality = 80 |
| 29 | }; |
| 30 | |
| 31 | bool encodeFile(const char file[], const SkBitmap&, int quality); |
| 32 | bool encodeStream(SkWStream*, const SkBitmap&, int quality); |
| 33 | |
| 34 | static bool EncodeFile(const char file[], const SkBitmap&, Type, |
| 35 | int quality); |
| 36 | static bool EncodeStream(SkWStream*, const SkBitmap&, Type, |
| 37 | int quality); |
| 38 | |
| 39 | protected: |
| 40 | virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0; |
| 41 | }; |
| 42 | |
robertphillips@google.com | ec51cb8 | 2012-03-23 18:13:47 +0000 | [diff] [blame] | 43 | // This macro declares a global (i.e., non-class owned) creation entry point |
| 44 | // for each encoder (e.g., CreateJPEGImageEncoder) |
| 45 | #define DECLARE_ENCODER_CREATOR(codec) \ |
| 46 | SkImageEncoder *Create ## codec (); |
| 47 | |
| 48 | // This macro defines the global creation entry point for each encoder. Each |
| 49 | // encoder implementation that registers with the encoder factory must call it. |
| 50 | #define DEFINE_ENCODER_CREATOR(codec) \ |
| 51 | SkImageEncoder *Create ## codec () { \ |
| 52 | return SkNEW( Sk ## codec ); \ |
| 53 | } |
| 54 | |
| 55 | // All the encoders known by Skia. Note that, depending on the compiler settings, |
| 56 | // not all of these will be available |
| 57 | DECLARE_ENCODER_CREATOR(JPEGImageEncoder); |
| 58 | DECLARE_ENCODER_CREATOR(PNGImageEncoder); |
| 59 | |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 60 | #endif |