blob: 907e28b9de95bdf1e5b44db4fa89d94672acf66b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.comb08eb2b2009-01-06 20:16:26 +00008#ifndef SkImageEncoder_DEFINED
9#define SkImageEncoder_DEFINED
10
11#include "SkTypes.h"
12
13class SkBitmap;
14class SkWStream;
15
16class SkImageEncoder {
17public:
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
39protected:
40 virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0;
41};
42
robertphillips@google.comec51cb82012-03-23 18:13:47 +000043// 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
57DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
58DECLARE_ENCODER_CREATOR(PNGImageEncoder);
59
reed@android.comb08eb2b2009-01-06 20:16:26 +000060#endif