-
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#ifndef SkImageEncoder_DEFINED
#define SkImageEncoder_DEFINED
-#include "SkTypes.h"
+#include "SkImageInfo.h"
#include "SkTRegistry.h"
class SkBitmap;
*/
bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality);
+ static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t rowBytes,
+ Type, int quality);
static SkData* EncodeData(const SkBitmap&, Type, int quality);
+
static bool EncodeFile(const char file[], const SkBitmap&, Type,
int quality);
static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
* Call to get the client's version of encoding these pixels. If it
* returns NULL, serialize the raw pixels.
*/
- SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
+ SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes) {
return this->onEncodePixels(info, pixels, rowBytes);
}
* If you want to encode these pixels, return the encoded data as an SkData
* Return null if you want to serialize the raw pixels.
*/
- virtual SkData* onEncodePixels(const SkImageInfo&, void* pixels, size_t rowBytes) = 0;
+ virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_t rowBytes) = 0;
};
#endif // SkPixelSerializer_DEFINED
SkASSERT(fEncoder);
}
- virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+ bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
- virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
+ SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
size_t rowBytes) SK_OVERRIDE {
// Required by signature of EncodeBitmap.
size_t unused;
SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
return enc.get() ? enc.get()->encodeData(bm, quality) : NULL;
}
+
+SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes,
+ Type t, int quality) {
+ SkBitmap bm;
+ if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
+ return NULL;
+ }
+ SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
+ return enc.get() ? enc.get()->encodeData(bm, quality) : NULL;
+}
// FIXME: Share with PictureRenderer.cpp?
class PngPixelSerializer : public SkPixelSerializer {
public:
- virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
- virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
- size_t rowBytes) SK_OVERRIDE {
- SkBitmap bm;
- if (!bm.installPixels(info, pixels, rowBytes)) {
- return NULL;
- }
- return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
+ bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+ SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+ size_t rowBytes) SK_OVERRIDE {
+ return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
}
};
class PngPixelSerializer : public SkPixelSerializer {
public:
- virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
- virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
- size_t rowBytes) SK_OVERRIDE {
- SkBitmap bm;
- if (!bm.installPixels(info, pixels, rowBytes)) {
- return NULL;
- }
- return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
+ bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+ SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+ size_t rowBytes) SK_OVERRIDE {
+ return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
}
};