gfx/skia/trunk/include/core/SkImageEncoder.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8 #ifndef SkImageEncoder_DEFINED
michael@0 9 #define SkImageEncoder_DEFINED
michael@0 10
michael@0 11 #include "SkTypes.h"
michael@0 12 #include "SkTRegistry.h"
michael@0 13
michael@0 14 class SkBitmap;
michael@0 15 class SkData;
michael@0 16 class SkWStream;
michael@0 17
michael@0 18 class SkImageEncoder {
michael@0 19 public:
michael@0 20 enum Type {
michael@0 21 kUnknown_Type,
michael@0 22 kBMP_Type,
michael@0 23 kGIF_Type,
michael@0 24 kICO_Type,
michael@0 25 kJPEG_Type,
michael@0 26 kPNG_Type,
michael@0 27 kWBMP_Type,
michael@0 28 kWEBP_Type,
michael@0 29 };
michael@0 30 static SkImageEncoder* Create(Type);
michael@0 31
michael@0 32 virtual ~SkImageEncoder();
michael@0 33
michael@0 34 /* Quality ranges from 0..100 */
michael@0 35 enum {
michael@0 36 kDefaultQuality = 80
michael@0 37 };
michael@0 38
michael@0 39 /**
michael@0 40 * Encode bitmap 'bm', returning the results in an SkData, at quality level
michael@0 41 * 'quality' (which can be in range 0-100). If the bitmap cannot be
michael@0 42 * encoded, return null. On success, the caller is responsible for
michael@0 43 * calling unref() on the data when they are finished.
michael@0 44 */
michael@0 45 SkData* encodeData(const SkBitmap&, int quality);
michael@0 46
michael@0 47 /**
michael@0 48 * Encode bitmap 'bm' in the desired format, writing results to
michael@0 49 * file 'file', at quality level 'quality' (which can be in range
michael@0 50 * 0-100). Returns false on failure.
michael@0 51 */
michael@0 52 bool encodeFile(const char file[], const SkBitmap& bm, int quality);
michael@0 53
michael@0 54 /**
michael@0 55 * Encode bitmap 'bm' in the desired format, writing results to
michael@0 56 * stream 'stream', at quality level 'quality' (which can be in
michael@0 57 * range 0-100). Returns false on failure.
michael@0 58 */
michael@0 59 bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality);
michael@0 60
michael@0 61 static SkData* EncodeData(const SkBitmap&, Type, int quality);
michael@0 62 static bool EncodeFile(const char file[], const SkBitmap&, Type,
michael@0 63 int quality);
michael@0 64 static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
michael@0 65 int quality);
michael@0 66
michael@0 67 protected:
michael@0 68 /**
michael@0 69 * Encode bitmap 'bm' in the desired format, writing results to
michael@0 70 * stream 'stream', at quality level 'quality' (which can be in
michael@0 71 * range 0-100).
michael@0 72 *
michael@0 73 * This must be overridden by each SkImageEncoder implementation.
michael@0 74 */
michael@0 75 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) = 0;
michael@0 76 };
michael@0 77
michael@0 78 // This macro declares a global (i.e., non-class owned) creation entry point
michael@0 79 // for each encoder (e.g., CreateJPEGImageEncoder)
michael@0 80 #define DECLARE_ENCODER_CREATOR(codec) \
michael@0 81 SkImageEncoder *Create ## codec ();
michael@0 82
michael@0 83 // This macro defines the global creation entry point for each encoder. Each
michael@0 84 // encoder implementation that registers with the encoder factory must call it.
michael@0 85 #define DEFINE_ENCODER_CREATOR(codec) \
michael@0 86 SkImageEncoder *Create ## codec () { \
michael@0 87 return SkNEW( Sk ## codec ); \
michael@0 88 }
michael@0 89
michael@0 90 // All the encoders known by Skia. Note that, depending on the compiler settings,
michael@0 91 // not all of these will be available
michael@0 92 /** An ARGBImageEncoder will always write out
michael@0 93 * bitmap.width() * bitmap.height() * 4
michael@0 94 * bytes.
michael@0 95 */
michael@0 96 DECLARE_ENCODER_CREATOR(ARGBImageEncoder);
michael@0 97 DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
michael@0 98 DECLARE_ENCODER_CREATOR(PNGImageEncoder);
michael@0 99 DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
michael@0 100
michael@0 101 // Typedef to make registering encoder callback easier
michael@0 102 // This has to be defined outside SkImageEncoder. :(
michael@0 103 typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
michael@0 104 #endif

mercurial