Revert "SkImageEncoder: simplify API"
This reverts commit 248ff02331.
Revert "Fix bug: can't convert nullptr -> bool"
This reverts commit 2cb6cb7218.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5151
NOTRY=true

Change-Id: I5f6414392d6545f74db0b5bb50608d04f053a8ec
Reviewed-on: https://skia-review.googlesource.com/5151
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2016-11-22 14:21:38 -07:00 committed by Skia Commit-Bot
parent 6b77f1cf09
commit a2b4bdce8c
67 changed files with 406 additions and 473 deletions

View File

@ -1243,7 +1243,6 @@ if (skia_enable_tools) {
deps = [
":flags",
":skia",
":tool_utils",
]
testonly = true
}

View File

@ -11,11 +11,9 @@
#include "SkData.h"
#include "SkImageEncoder.h"
#include "sk_tool_utils.h"
class EncodeBench : public Benchmark {
public:
EncodeBench(const char* filename, SkEncodedImageFormat type, int quality)
EncodeBench(const char* filename, SkImageEncoder::Type type, int quality)
: fFilename(filename)
, fType(type)
, fQuality(quality)
@ -25,13 +23,13 @@ public:
name.append(filename);
name.append("_");
switch (type) {
case SkEncodedImageFormat::kJPEG:
case SkImageEncoder::kJPEG_Type:
name.append("JPEG");
break;
case SkEncodedImageFormat::kPNG:
case SkImageEncoder::kPNG_Type:
name.append("PNG");
break;
case SkEncodedImageFormat::kWEBP:
case SkImageEncoder::kWEBP_Type:
name.append("WEBP");
break;
default:
@ -56,14 +54,14 @@ public:
void onDraw(int loops, SkCanvas*) override {
for (int i = 0; i < loops; i++) {
sk_sp<SkData> data(sk_tool_utils::EncodeImageToData(fBitmap, fType, fQuality));
sk_sp<SkData> data(SkImageEncoder::EncodeData(fBitmap, fType, fQuality));
SkASSERT(data);
}
}
private:
const char* fFilename;
const SkEncodedImageFormat fType;
const SkImageEncoder::Type fType;
const int fQuality;
SkString fName;
SkBitmap fBitmap;
@ -71,13 +69,13 @@ private:
// The Android Photos app uses a quality of 90 on JPEG encodes
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkEncodedImageFormat::kJPEG, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkEncodedImageFormat::kJPEG, 90));
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kJPEG_Type, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kJPEG_Type, 90));
// PNG encodes are lossless so quality should be ignored
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkEncodedImageFormat::kPNG, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkEncodedImageFormat::kPNG, 90));
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kPNG_Type, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kPNG_Type, 90));
// TODO: What is the appropriate quality to use to benchmark WEBP encodes?
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkEncodedImageFormat::kWEBP, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkEncodedImageFormat::kWEBP, 90));
DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kWEBP_Type, 90));
DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kWEBP_Type, 90));

View File

@ -15,8 +15,6 @@
#include "SkSLCompiler.h"
#include <stdio.h>
#include "sk_tool_utils.h"
const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
// This bench exclusively tests GL calls directly
if (nullptr == canvas->getGrContext()) {
@ -183,7 +181,7 @@ void GLBench::DumpImage(const GrGLInterface* gl, uint32_t screenWidth, uint32_t
bm.setPixels(readback.get());
if (!sk_tool_utils::EncodeImageToFile(filename, bm, SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
SkDebugf("------ failed to encode %s\n", filename);
remove(filename); // remove any partial file
return;

View File

@ -300,7 +300,7 @@ static bool write_canvas_png(Target* target, const SkString& filename) {
SkDebugf("Can't write %s.\n", filename.c_str());
return false;
}
if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
SkDebugf("Can't encode a PNG.\n");
return false;
}

View File

@ -82,7 +82,7 @@ int main(int, char**) {
// Grab a snapshot of the surface as an immutable SkImage.
sk_sp<SkImage> image = surface->makeImageSnapshot();
// Encode that image as a .png into a blob in memory.
std::shared_ptr<SkData> png = adopt(image->encode(SkEncodedImageFormat::kPNG, 100));
std::shared_ptr<SkData> png = adopt(image->encode(SkImageEncoder::kPNG_Type, 100));
// This code is no longer Skia-specific. We just dump the .png to disk. Any way works.
static const char* path = "example.png";

View File

@ -281,7 +281,8 @@ void SkDebuggerGUI::saveToFile(const SkString& filename) {
SkFILEWStream file(filename.c_str());
sk_sp<SkPicture> copy(fDebugger.copyPicture());
sk_sp<SkPixelSerializer> serializer(sk_tool_utils::MakePixelSerializer());
sk_sp<SkPixelSerializer> serializer(
SkImageEncoder::CreatePixelSerializer());
copy->serialize(&file, serializer.get());
}

View File

@ -524,17 +524,17 @@ static void push_codec_srcs(Path path) {
nativeModes.push_back(CodecSrc::kCodec_Mode);
nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
switch (codec->getEncodedFormat()) {
case SkEncodedImageFormat::kJPEG:
case SkEncodedFormat::kJPEG_SkEncodedFormat:
nativeModes.push_back(CodecSrc::kScanline_Mode);
nativeModes.push_back(CodecSrc::kStripe_Mode);
nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
supportsNativeScaling = true;
break;
case SkEncodedImageFormat::kWEBP:
case SkEncodedFormat::kWEBP_SkEncodedFormat:
nativeModes.push_back(CodecSrc::kSubset_Mode);
supportsNativeScaling = true;
break;
case SkEncodedImageFormat::kDNG:
case SkEncodedFormat::kDNG_SkEncodedFormat:
break;
default:
nativeModes.push_back(CodecSrc::kScanline_Mode);
@ -547,7 +547,7 @@ static void push_codec_srcs(Path path) {
switch (codec->getInfo().colorType()) {
case kGray_8_SkColorType:
colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
if (SkEncodedImageFormat::kWBMP == codec->getEncodedFormat()) {
if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) {
colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
}
break;
@ -640,15 +640,15 @@ static void push_codec_srcs(Path path) {
push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
if (kWEBP_SkEncodedFormat != codec->getEncodedFormat() &&
kWBMP_SkEncodedFormat != codec->getEncodedFormat() &&
kUnpremul_SkAlphaType != alphaType)
{
push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
}
#elif defined(SK_BUILD_FOR_WIN)
if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
if (kWEBP_SkEncodedFormat != codec->getEncodedFormat() &&
kWBMP_SkEncodedFormat != codec->getEncodedFormat())
{
push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
}

View File

@ -23,8 +23,6 @@
#include <signal.h>
#include "sk_tool_utils.h"
DEFINE_string2(bytes, b, "", "A path to a file. This can be the fuzz bytes or a binary to parse.");
DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name.");
@ -124,7 +122,7 @@ int fuzz_api(sk_sp<SkData> bytes) {
static void dump_png(SkBitmap bitmap) {
if (!FLAGS_dump.isEmpty()) {
sk_tool_utils::EncodeImageToFile(FLAGS_dump[0], bitmap, SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(FLAGS_dump[0], bitmap, SkImageEncoder::kPNG_Type, 100);
SkDebugf("Dumped to %s\n", FLAGS_dump[0]);
}
}

View File

@ -6,11 +6,10 @@
*/
#include "gm.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkUnPreMultiply.h"
namespace skiagm {
@ -37,18 +36,18 @@ static void make_unpremul_256(SkBitmap* bitmap) {
bitmap->setAlphaType(kUnpremul_SkAlphaType);
}
static SkImageEncoder* make_encoder(SkEncodedImageFormat type) {
static SkImageEncoder* make_encoder(SkImageEncoder::Type type) {
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
return CreateImageEncoder_CG((SkImageEncoder::Type)type);
return CreateImageEncoder_CG(type);
#elif defined(SK_BUILD_FOR_WIN)
return CreateImageEncoder_WIC((SkImageEncoder::Type)type);
return CreateImageEncoder_WIC(type);
#else
switch (type) {
case SkEncodedImageFormat::kPNG:
case SkImageEncoder::kPNG_Type:
return CreatePNGImageEncoder();
case SkEncodedImageFormat::kJPEG:
case SkImageEncoder::kJPEG_Type:
return CreateJPEGImageEncoder();
case SkEncodedImageFormat::kWEBP:
case SkImageEncoder::kWEBP_Type:
return CreateWEBPImageEncoder();
default:
SkASSERT(false);
@ -58,28 +57,24 @@ static SkImageEncoder* make_encoder(SkEncodedImageFormat type) {
}
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
static SkEncodedImageFormat kTypes[] {
SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kGIF,
SkEncodedImageFormat::kBMP, SkEncodedImageFormat::kICO,
static SkImageEncoder::Type kTypes[] {
SkImageEncoder::kPNG_Type, SkImageEncoder::kJPEG_Type, SkImageEncoder::kGIF_Type,
SkImageEncoder::kBMP_Type, SkImageEncoder::kICO_Type,
};
#elif defined(SK_BUILD_FOR_WIN)
// Use PNG multiple times because our WIC encoder does not support GIF, BMP, or ICO.
static SkEncodedImageFormat kTypes[] {
SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG,
SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kPNG,
static SkImageEncoder::Type kTypes[] {
SkImageEncoder::kPNG_Type, SkImageEncoder::kJPEG_Type, SkImageEncoder::kPNG_Type,
SkImageEncoder::kPNG_Type, SkImageEncoder::kPNG_Type,
};
#else
// Use WEBP in place of GIF. Use PNG two extra times. We don't support GIF, BMP, or ICO.
static SkEncodedImageFormat kTypes[] {
SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kWEBP,
SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kPNG,
static SkImageEncoder::Type kTypes[] {
SkImageEncoder::kPNG_Type, SkImageEncoder::kJPEG_Type, SkImageEncoder::kWEBP_Type,
SkImageEncoder::kPNG_Type, SkImageEncoder::kPNG_Type,
};
#endif
static sk_sp<SkData> encode_data(std::unique_ptr<SkImageEncoder>& encoder, const SkBitmap& src) {
SkDynamicMemoryWStream buffer;
return encoder->encodeStream(&buffer, src, 100) ? buffer.detachAsData() : nullptr;
}
class EncodePlatformGM : public GM {
public:
@ -100,12 +95,15 @@ protected:
make_premul_256(&premulBm);
make_unpremul_256(&unpremulBm);
for (SkEncodedImageFormat type : kTypes) {
for (SkImageEncoder::Type type : kTypes) {
std::unique_ptr<SkImageEncoder> encoder(make_encoder(type));
sk_sp<SkData> opaqueData(encoder->encodeData(opaqueBm, 100));
sk_sp<SkData> premulData(encoder->encodeData(premulBm, 100));
sk_sp<SkData> unpremulData(encoder->encodeData(unpremulBm, 100));
auto opaqueImage = SkImage::MakeFromEncoded(encode_data(encoder, opaqueBm));
auto premulImage = SkImage::MakeFromEncoded(encode_data(encoder, premulBm));
auto unpremulImage = SkImage::MakeFromEncoded(encode_data(encoder, unpremulBm));
sk_sp<SkImage> opaqueImage = SkImage::MakeFromEncoded(opaqueData);
sk_sp<SkImage> premulImage = SkImage::MakeFromEncoded(premulData);
sk_sp<SkImage> unpremulImage = SkImage::MakeFromEncoded(unpremulData);
canvas->drawImage(opaqueImage.get(), 0.0f, 0.0f);
canvas->drawImage(premulImage.get(), 0.0f, 256.0f);

View File

@ -28,8 +28,8 @@ protected:
void onDraw(SkCanvas* canvas) override {
SkBitmap orig;
GetResourceAsBitmap("mandrill_512_q075.jpg", &orig);
sk_sp<SkData> pngData(sk_tool_utils::EncodeImageToData(orig, SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> jpegData(sk_tool_utils::EncodeImageToData(orig, SkEncodedImageFormat::kJPEG, 100));
sk_sp<SkData> pngData(SkImageEncoder::EncodeData(orig, SkImageEncoder::kPNG_Type, 100));
sk_sp<SkData> jpegData(SkImageEncoder::EncodeData(orig, SkImageEncoder::kJPEG_Type, 100));
sk_sp<SkImage> pngImage = SkImage::MakeFromEncoded(pngData);
sk_sp<SkImage> jpegImage = SkImage::MakeFromEncoded(jpegData);

View File

@ -348,13 +348,13 @@ static SkImageGenerator* gen_picture(const SkImageInfo& info) {
static SkImageGenerator* gen_png(const SkImageInfo& info) {
sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents));
sk_sp<SkData> data(image->encode(SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
return SkImageGenerator::NewFromEncoded(data.get());
}
static SkImageGenerator* gen_jpg(const SkImageInfo& info) {
sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents));
sk_sp<SkData> data(image->encode(SkEncodedImageFormat::kJPEG, 100));
sk_sp<SkData> data(image->encode(SkImageEncoder::kJPEG_Type, 100));
return SkImageGenerator::NewFromEncoded(data.get());
}
@ -467,7 +467,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
// Create encoded image.
[bmp] {
sk_sp<SkData> src(
sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kPNG, 100));
SkImageEncoder::EncodeData(bmp, SkImageEncoder::kPNG_Type, 100));
return SkImage::MakeFromEncoded(std::move(src));
},
// Create a picture image.

View File

@ -55,7 +55,7 @@ static sk_sp<SkImage> make_encode_gen(GrContext* ctx, SkPicture* pic, const SkIm
if (!src) {
return nullptr;
}
sk_sp<SkData> encoded(src->encode(SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> encoded(src->encode(SkImageEncoder::kPNG_Type, 100));
if (!encoded) {
return nullptr;
}

View File

@ -14,6 +14,5 @@ android_framework_defines = [
"SK_IGNORE_GPU_DITHER",
"SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT",
"SK_SUPPORT_LEGACY_CLIP_REGIONOPS",
"SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS",
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
]

View File

@ -51,7 +51,7 @@ public:
/**
* Format of the encoded data.
*/
SkEncodedFormat getEncodedFormat() const { return (SkEncodedFormat)fCodec->getEncodedFormat(); }
SkEncodedFormat getEncodedFormat() const { return fCodec->getEncodedFormat(); }
/**
* @param requestedColorType Color type requested by the client
@ -154,7 +154,7 @@ public:
*
* Must be within the bounds returned by getInfo().
*
* If the EncodedFormat is SkEncodedImageFormat::kWEBP, the top and left
* If the EncodedFormat is kWEBP_SkEncodedFormat, the top and left
* values must be even.
*
* The default is NULL, meaning a decode of the entire image.

View File

@ -10,7 +10,7 @@
#include "../private/SkTemplates.h"
#include "SkColor.h"
#include "SkEncodedImageFormat.h"
#include "SkEncodedFormat.h"
#include "SkEncodedInfo.h"
#include "SkImageInfo.h"
#include "SkSize.h"
@ -176,7 +176,7 @@ public:
/**
* Format of the encoded data.
*/
SkEncodedImageFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
/**
* Used to describe the result of a call to getPixels().
@ -255,7 +255,7 @@ public:
/**
* If not NULL, represents a subset of the original image to decode.
* Must be within the bounds returned by getInfo().
* If the EncodedFormat is SkEncodedImageFormat::kWEBP (the only one which
* If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
* currently supports subsets), the top and left values must be even.
*
* In getPixels and incremental decode, we will attempt to decode the
@ -667,7 +667,7 @@ protected:
return false;
}
virtual SkEncodedImageFormat onGetEncodedFormat() const = 0;
virtual SkEncodedFormat onGetEncodedFormat() const = 0;
/**
* @param rowsDecoded When the encoded image stream is incomplete, this function

View File

@ -8,29 +8,21 @@
#ifndef SkEncodedFormat_DEFINED
#define SkEncodedFormat_DEFINED
#include "SkEncodedImageFormat.h"
#include "SkTypes.h"
#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
/**
* Enum describing format of encoded data.
*/
enum SkEncodedFormat {
kBMP_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kBMP,
kGIF_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kGIF,
kICO_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kICO,
kJPEG_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kJPEG,
kPNG_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kPNG,
kWBMP_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kWBMP,
kWEBP_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kWEBP,
kPKM_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kPKM,
kKTX_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kKTX,
kASTC_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kASTC,
kDNG_SkEncodedFormat = (uint8_t)SkEncodedImageFormat::kDNG,
kUnknown_SkEncodedFormat,
kBMP_SkEncodedFormat,
kGIF_SkEncodedFormat,
kICO_SkEncodedFormat,
kJPEG_SkEncodedFormat,
kPNG_SkEncodedFormat,
kWBMP_SkEncodedFormat,
kWEBP_SkEncodedFormat,
kPKM_SkEncodedFormat,
kKTX_SkEncodedFormat,
kASTC_SkEncodedFormat,
kDNG_SkEncodedFormat,
};
#else
typedef SkEncodedImageFormat SkEncodedFormat;
#endif // SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
#endif // SkEncodedFormat_DEFINED

View File

@ -1,33 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkEncodedImageFormat_DEFINED
#define SkEncodedImageFormat_DEFINED
#include <stdint.h>
/**
* Enum describing format of encoded data.
*/
enum class SkEncodedImageFormat {
#ifdef GOOGLE3
kUnknown,
#endif
kBMP,
kGIF,
kICO,
kJPEG,
kPNG,
kWBMP,
kWEBP,
kPKM,
kKTX,
kASTC,
kDNG,
};
#endif // SkEncodedImageFormat_DEFINED

View File

@ -275,12 +275,7 @@ public:
* Note: this will attempt to encode the image's pixels in the specified format,
* even if the image returns a data from refEncoded(). That data will be ignored.
*/
SkData* encode(SkEncodedImageFormat, int quality) const;
#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
SkData* encode(SkImageEncoder::Type t, int quality) const {
return this->encode((SkEncodedImageFormat)t, quality);
}
#endif
SkData* encode(SkImageEncoder::Type, int quality) const;
/**
* Encode the image and return the result as a caller-managed SkData. This will

View File

@ -8,60 +8,32 @@
#ifndef SkImageEncoder_DEFINED
#define SkImageEncoder_DEFINED
#include "SkBitmap.h"
#include "SkEncodedImageFormat.h"
#include "SkPixelSerializer.h"
#include "SkStream.h"
#include "SkImageInfo.h"
#include "SkTRegistry.h"
/**
* Encode SkPixmap in the given binary image format.
*
* @param dst results are written to this stream.
* @param src source pixels.
* @param format image format, not all formats are supported.
* @param quality range from 0-100, not all formats respect quality.
*
* @return false iff input is bad or format is unsupported.
*
* Will always return false if Skia is compiled without image
* encoders.
*
* For examples of encoding an image to a file or to a block of memory,
* see tools/sk_tool_utils.h.
*/
SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
SkEncodedImageFormat format, int quality);
/**
* The following helper function wraps SkEncodeImage().
*/
inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) {
SkAutoLockPixels autoLockPixels(src);
SkPixmap pixmap;
return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q);
}
#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
////////////////////////////////////////////////////////////////////////////////
class SkBitmap;
class SkPixelSerializer;
class SkPixmap;
class SkData;
class SkWStream;
class SkImageEncoder {
public:
// TODO (scroggo): Merge with SkEncodedFormat.
enum Type {
#ifdef GOOGLE3
kUnknown_Type = (uint8_t)SkEncodedImageFormat::kUnknown,
#endif
kBMP_Type = (uint8_t)SkEncodedImageFormat::kBMP,
kGIF_Type = (uint8_t)SkEncodedImageFormat::kGIF,
kICO_Type = (uint8_t)SkEncodedImageFormat::kICO,
kJPEG_Type = (uint8_t)SkEncodedImageFormat::kJPEG,
kPNG_Type = (uint8_t)SkEncodedImageFormat::kPNG,
kWBMP_Type = (uint8_t)SkEncodedImageFormat::kWBMP,
kWEBP_Type = (uint8_t)SkEncodedImageFormat::kWEBP,
kKTX_Type = (uint8_t)SkEncodedImageFormat::kKTX,
kUnknown_Type,
kBMP_Type,
kGIF_Type,
kICO_Type,
kJPEG_Type,
kPNG_Type,
kWBMP_Type,
kWEBP_Type,
kKTX_Type,
};
static SkImageEncoder* Create(Type);
virtual ~SkImageEncoder() {}
virtual ~SkImageEncoder();
/* Quality ranges from 0..100 */
enum {
@ -74,57 +46,36 @@ public:
* encoded, return null. On success, the caller is responsible for
* calling unref() on the data when they are finished.
*/
SkData* encodeData(const SkBitmap& bm, int quality) {
SkDynamicMemoryWStream buffer;
return this->encodeStream(&buffer, bm, quality)
? buffer.detachAsData().release()
: nullptr;
}
SkData* encodeData(const SkBitmap&, int quality);
/**
* Encode bitmap 'bm' in the desired format, writing results to
* file 'file', at quality level 'quality' (which can be in range
* 0-100). Returns false on failure.
*/
bool encodeFile(const char path[], const SkBitmap& bm, int quality) {
SkFILEWStream file(path);
return this->encodeStream(&file, bm, quality);
}
bool encodeFile(const char file[], const SkBitmap& bm, int quality);
/**
* Encode bitmap 'bm' in the desired format, writing results to
* stream 'stream', at quality level 'quality' (which can be in
* range 0-100). Returns false on failure.
*/
bool encodeStream(SkWStream* dst, const SkBitmap& src, int quality) {
return this->onEncode(dst, src, SkMin32(100, SkMax32(0, quality)));
}
bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality);
static SkData* EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes,
Type t, int quality) {
SkPixmap pixmap(info, pixels, rowBytes, nullptr);
return SkImageEncoder::EncodeData(pixmap, t, quality);
}
static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t rowBytes,
Type, int quality);
static SkData* EncodeData(const SkBitmap&, Type, int quality);
static SkData* EncodeData(const SkBitmap& src, Type t, int quality) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, src, (SkEncodedImageFormat)t, quality)
? buf.detachAsData().release() : nullptr;
}
static SkData* EncodeData(const SkPixmap&, Type, int quality);
static SkData* EncodeData(const SkPixmap& pixmap, Type t, int quality) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, pixmap, (SkEncodedImageFormat)t, quality)
? buf.detachAsData().release() : nullptr;
}
static bool EncodeFile(const char file[], const SkBitmap&, Type,
int quality);
static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
int quality);
static bool EncodeFile(const char path[], const SkBitmap& src, Type t, int quality) {
SkFILEWStream file(path);
return SkEncodeImage(&file, src, (SkEncodedImageFormat)t, quality);
}
static bool EncodeStream(SkWStream* dst, const SkBitmap& bm, Type t, int quality) {
return SkEncodeImage(dst, bm, (SkEncodedImageFormat)t, quality);
}
/** Uses SkImageEncoder to serialize images that are not already
encoded as SkImageEncoder::kPNG_Type images. */
static SkPixelSerializer* CreatePixelSerializer();
protected:
/**
@ -137,5 +88,32 @@ protected:
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) = 0;
};
#endif // SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
#endif // SkImageEncoder_DEFINED
// This macro declares a global (i.e., non-class owned) creation entry point
// for each encoder (e.g., CreateJPEGImageEncoder)
#define DECLARE_ENCODER_CREATOR(codec) \
SK_API SkImageEncoder *Create ## codec ();
// This macro defines the global creation entry point for each encoder. Each
// encoder implementation that registers with the encoder factory must call it.
#define DEFINE_ENCODER_CREATOR(codec) \
SkImageEncoder* Create##codec() { return new Sk##codec; }
// All the encoders known by Skia. Note that, depending on the compiler settings,
// not all of these will be available
DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
DECLARE_ENCODER_CREATOR(PNGImageEncoder);
DECLARE_ENCODER_CREATOR(KTXImageEncoder);
DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
SkImageEncoder* CreateImageEncoder_CG(SkImageEncoder::Type type);
#endif
#if defined(SK_BUILD_FOR_WIN)
SkImageEncoder* CreateImageEncoder_WIC(SkImageEncoder::Type type);
#endif
// Typedef to make registering encoder callback easier
// This has to be defined outside SkImageEncoder. :(
typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
#endif

View File

@ -599,7 +599,6 @@ DEFINES_ALL = [
# Staging flags for API changes
"SK_SUPPORT_LEGACY_ACCESSBITMAP",
"SK_SUPPORT_LEGACY_CLIP_REGIONOPS",
"SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS",
"SK_SUPPORT_LEGACY_XFERMODE_IS_PUBLIC",
# Temporarily Disable analytic AA for Google3
"SK_NO_ANALYTIC_AA",

View File

@ -1407,8 +1407,8 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
static int gSampleGrabCounter;
SkString name;
name.printf("sample_grab_%d.png", gSampleGrabCounter++);
sk_tool_utils::EncodeImageToFile(name.c_str(), bmp,
SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(name.c_str(), bmp,
SkImageEncoder::kPNG_Type, 100);
}
this->inval(nullptr);
return;

View File

@ -15,8 +15,6 @@
#include "SkPaint.h"
#include "SkView.h"
#include "sk_tool_utils.h"
#define BG_COLOR 0xFFDDDDDD
typedef void (*SlideProc)(SkCanvas*);
@ -683,7 +681,7 @@ public:
canvas.restore();
SkString str;
str.printf("/skimages/slide_" SK_SIZE_T_SPECIFIER ".png", i);
sk_tool_utils::EncodeImageToFile(str.c_str(), bm, SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type, 100);
}
this->setBGColor(BG_COLOR);
}

View File

@ -26,9 +26,7 @@ public:
bool conversionSupported(SkColorType colorType) override;
SkEncodedFormat getEncodedFormat() override {
return (SkEncodedFormat)fCodec->getEncodedFormat();
}
SkEncodedFormat getEncodedFormat() override { return fCodec->getEncodedFormat(); }
private:

View File

@ -29,10 +29,11 @@ SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
return NULL;
}
switch ((SkEncodedImageFormat)codec->getEncodedFormat()) {
case SkEncodedImageFormat::kJPEG:
case SkEncodedImageFormat::kPNG:
case SkEncodedImageFormat::kWEBP:
SkEncodedFormat format = codec->getEncodedFormat();
switch (format) {
case SkEncodedFormat::kJPEG_SkEncodedFormat:
case SkEncodedFormat::kPNG_SkEncodedFormat:
case SkEncodedFormat::kWEBP_SkEncodedFormat:
break;
default:
return nullptr;

View File

@ -30,7 +30,7 @@ DEFINE_GET_MEMBER(SkSnapshot);
SkSnapshot::SkSnapshot()
{
quality = 100 * SK_Scalar1;
type = (SkEncodedImageFormat) -1;
type = (SkImageEncoder::Type) -1;
sequence = false;
fSeqVal = 0;
}
@ -38,7 +38,7 @@ SkSnapshot::SkSnapshot()
bool SkSnapshot::draw(SkAnimateMaker& maker) {
SkASSERT(type >= 0);
SkASSERT(filename.size() > 0);
SkImageEncoder* encoder = SkImageEncoder::Create((SkEncodedImageFormat) type);
SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type);
if (!encoder) {
return false;
}
@ -54,9 +54,9 @@ bool SkSnapshot::draw(SkAnimateMaker& maker) {
if (++fSeqVal > 999)
sequence = false;
}
if (type == SkEncodedImageFormat::kJPEG)
if (type == SkImageEncoder::kJPEG_Type)
name.append(".jpg");
else if (type == SkEncodedImageFormat::kPNG)
else if (type == SkImageEncoder::kPNG_Type)
name.append(".png");
SkBitmap pixels;

View File

@ -22,7 +22,7 @@ class SkSnapshot: public SkADrawable {
SkString filename;
SkScalar quality;
SkBool sequence;
int /*SkEncodedImageFormat*/ type;
int /*SkImageEncoder::Type*/ type;
int fSeqVal;
};

View File

@ -28,24 +28,24 @@ SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader
return nullptr;
}
switch ((SkEncodedImageFormat)codec->getEncodedFormat()) {
switch (codec->getEncodedFormat()) {
#ifdef SK_HAS_PNG_LIBRARY
case SkEncodedImageFormat::kPNG:
case SkEncodedImageFormat::kICO:
case kPNG_SkEncodedFormat:
case kICO_SkEncodedFormat:
#endif
#ifdef SK_HAS_JPEG_LIBRARY
case SkEncodedImageFormat::kJPEG:
case kJPEG_SkEncodedFormat:
#endif
case SkEncodedImageFormat::kGIF:
case SkEncodedImageFormat::kBMP:
case SkEncodedImageFormat::kWBMP:
case kGIF_SkEncodedFormat:
case kBMP_SkEncodedFormat:
case kWBMP_SkEncodedFormat:
return new SkSampledCodec(codec.release());
#ifdef SK_HAS_WEBP_LIBRARY
case SkEncodedImageFormat::kWEBP:
case kWEBP_SkEncodedFormat:
return new SkWebpAdapterCodec((SkWebpCodec*) codec.release());
#endif
#ifdef SK_CODEC_DECODES_RAW
case SkEncodedImageFormat::kDNG:
case kDNG_SkEncodedFormat:
return new SkRawAdapterCodec((SkRawCodec*)codec.release());
#endif
default:
@ -64,8 +64,8 @@ SkAndroidCodec* SkAndroidCodec::NewFromData(sk_sp<SkData> data, SkPngChunkReader
SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorType) {
// The legacy GIF and WBMP decoders always decode to kIndex_8_SkColorType.
// We will maintain this behavior.
SkEncodedImageFormat format = (SkEncodedImageFormat)this->getEncodedFormat();
if (SkEncodedImageFormat::kGIF == format || SkEncodedImageFormat::kWBMP == format) {
SkEncodedFormat format = this->getEncodedFormat();
if (kGIF_SkEncodedFormat == format || kWBMP_SkEncodedFormat == format) {
return kIndex_8_SkColorType;
}

View File

@ -41,7 +41,7 @@ protected:
SkBmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder);
SkEncodedImageFormat onGetEncodedFormat() const override { return SkEncodedImageFormat::kBMP; }
SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedFormat; }
/*
* Read enough of the stream to initialize the SkBmpCodec. Returns a bool

View File

@ -40,8 +40,8 @@ protected:
Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&,
SkPMColor*, int*, int*) override;
SkEncodedImageFormat onGetEncodedFormat() const override {
return SkEncodedImageFormat::kGIF;
SkEncodedFormat onGetEncodedFormat() const override {
return kGIF_SkEncodedFormat;
}
bool onRewind() override;

View File

@ -39,8 +39,8 @@ protected:
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
SkPMColor*, int*, int*) override;
SkEncodedImageFormat onGetEncodedFormat() const override {
return SkEncodedImageFormat::kICO;
SkEncodedFormat onGetEncodedFormat() const override {
return kICO_SkEncodedFormat;
}
SkScanlineOrder onGetScanlineOrder() const override;

View File

@ -51,8 +51,8 @@ protected:
Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override;
SkEncodedImageFormat onGetEncodedFormat() const override {
return SkEncodedImageFormat::kJPEG;
SkEncodedFormat onGetEncodedFormat() const override {
return kJPEG_SkEncodedFormat;
}
bool onRewind() override;

View File

@ -9,7 +9,7 @@
#include "SkColorSpaceXform.h"
#include "SkColorTable.h"
#include "SkPngChunkReader.h"
#include "SkEncodedImageFormat.h"
#include "SkEncodedFormat.h"
#include "SkImageInfo.h"
#include "SkRefCnt.h"
#include "SkSwizzler.h"
@ -51,7 +51,7 @@ protected:
Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*)
override;
SkEncodedImageFormat onGetEncodedFormat() const override { return SkEncodedImageFormat::kPNG; }
SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedFormat; }
bool onRewind() override;
uint64_t onGetFillValue(const SkImageInfo&) const override;

View File

@ -10,7 +10,7 @@
#include "SkAndroidCodec.h"
#include "SkCodec.h"
#include "SkEncodedImageFormat.h"
#include "SkEncodedFormat.h"
#include "SkRawCodec.h"
#include "SkStream.h"
#include "SkTypes.h"

View File

@ -37,8 +37,8 @@ protected:
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
SkPMColor*, int*, int*) override;
SkEncodedImageFormat onGetEncodedFormat() const override {
return SkEncodedImageFormat::kDNG;
SkEncodedFormat onGetEncodedFormat() const override {
return kDNG_SkEncodedFormat;
}
SkISize onGetScaledDimensions(float desiredScale) const override;

View File

@ -26,7 +26,7 @@ SkISize SkSampledCodec::accountForNativeScaling(int* sampleSizePtr, int* nativeS
}
// Only JPEG supports native downsampling.
if (this->codec()->getEncodedFormat() == SkEncodedImageFormat::kJPEG) {
if (this->codec()->getEncodedFormat() == kJPEG_SkEncodedFormat) {
// See if libjpeg supports this scale directly
switch (sampleSize) {
case 2:

View File

@ -113,8 +113,8 @@ SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info, SkStr
, fColorTable(nullptr)
{}
SkEncodedImageFormat SkWbmpCodec::onGetEncodedFormat() const {
return SkEncodedImageFormat::kWBMP;
SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const {
return kWBMP_SkEncodedFormat;
}
SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,

View File

@ -24,7 +24,7 @@ public:
static SkCodec* NewFromStream(SkStream*);
protected:
SkEncodedImageFormat onGetEncodedFormat() const override;
SkEncodedFormat onGetEncodedFormat() const override;
Result onGetPixels(const SkImageInfo&, void*, size_t,
const Options&, SkPMColor[], int*, int*) override;
bool onRewind() override;

View File

@ -10,7 +10,7 @@
#include "SkCodec.h"
#include "SkColorSpace.h"
#include "SkEncodedImageFormat.h"
#include "SkEncodedFormat.h"
#include "SkImageInfo.h"
#include "SkTypes.h"
@ -30,7 +30,7 @@ public:
protected:
Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*)
override;
SkEncodedImageFormat onGetEncodedFormat() const override { return SkEncodedImageFormat::kWEBP; }
SkEncodedFormat onGetEncodedFormat() const override { return kWEBP_SkEncodedFormat; }
SkISize onGetScaledDimensions(float desiredScale) const override;

View File

@ -165,11 +165,6 @@ bool GrSurface::readPixels(int left, int top, int width, int height,
rowBytes, pixelOpsFlags);
}
static bool encode_image_to_file(const char* path, const SkBitmap& src) {
SkFILEWStream file(path);
return file.isValid() && SkEncodeImage(&file, src, SkEncodedImageFormat::kPNG, 100);
}
// TODO: This should probably be a non-member helper function. It might only be needed in
// debug or developer builds.
bool GrSurface::savePixels(const char* filename) {
@ -188,7 +183,7 @@ bool GrSurface::savePixels(const char* filename) {
// remove any previous version of this file
remove(filename);
if (!encode_image_to_file(filename, bm)) {
if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
SkDebugf("------ failed to encode %s\n", filename);
remove(filename); // remove any partial file
return false;

View File

@ -103,22 +103,27 @@ sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode
return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
}
SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const {
SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
SkBitmap bm;
// TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do,
// we should decode in "color space aware" mode, then re-encode that. For now, work around this
// by asking for a legacy decode (which gives us the raw data in N32).
if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr;
return SkImageEncoder::EncodeData(bm, type, quality);
}
return nullptr;
}
SkData* SkImage::encode(SkPixelSerializer* serializer) const {
sk_sp<SkPixelSerializer> defaultSerializer;
SkPixelSerializer* effectiveSerializer = serializer;
if (!effectiveSerializer) {
defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer());
SkASSERT(defaultSerializer.get());
effectiveSerializer = defaultSerializer.get();
}
sk_sp<SkData> encoded(this->refEncoded());
if (encoded &&
(!serializer || serializer->useEncodedData(encoded->data(), encoded->size()))) {
if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded->size())) {
return encoded.release();
}
@ -129,13 +134,7 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const {
// by asking for a legacy decode (which gives us the raw data in N32).
if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy) &&
bm.requestLock(&apu)) {
if (serializer) {
return serializer->encode(apu.pixmap());
} else {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, apu.pixmap(), SkEncodedImageFormat::kPNG, 100)
? buf.detachAsData().release() : nullptr;
}
return effectiveSerializer->encode(apu.pixmap());
}
return nullptr;
@ -189,7 +188,7 @@ GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO) const {
GrTexture* texture = as_IB(this)->peekTexture();
if (texture) {
GrContext* context = texture->getContext();
if (context) {
if (context) {
if (flushPendingGrContextIO) {
context->prepareSurfaceForExternalIO(texture);
}

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkForceLinking.h"
// This method is required to fool the linker into not discarding the pre-main
@ -30,10 +30,10 @@ int SkForceLinking(bool doNotPassTrue) {
#endif
#if defined (SK_USE_CG_ENCODER)
CreateImageEncoder_CG(SkEncodedImageFormat::kPNG);
CreateImageEncoder_CG(SkImageEncoder::kPNG_Type);
#endif
#if defined (SK_USE_WIC_ENCODER)
CreateImageEncoder_WIC(SkEncodedImageFormat::kPNG);
CreateImageEncoder_WIC(SkImageEncoder::kPNG_Type);
#endif
return -1;
}

View File

@ -5,15 +5,84 @@
* found in the LICENSE file.
*/
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkBitmap.h"
#include "SkPixelSerializer.h"
#include "SkPixmap.h"
#include "SkStream.h"
#include "SkTemplates.h"
bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
SkEncodedImageFormat format, int quality) {
SkImageEncoder::~SkImageEncoder() {}
bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm,
int quality) {
quality = SkMin32(100, SkMax32(0, quality));
return this->onEncode(stream, bm, quality);
}
bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm,
int quality) {
quality = SkMin32(100, SkMax32(0, quality));
SkFILEWStream stream(file);
return this->onEncode(&stream, bm, quality);
}
SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) {
SkDynamicMemoryWStream stream;
quality = SkMin32(100, SkMax32(0, quality));
if (this->onEncode(&stream, bm, quality)) {
return stream.detachAsData().release();
}
return nullptr;
}
bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t,
int quality) {
std::unique_ptr<SkImageEncoder> enc(SkImageEncoder::Create(t));
return enc.get() && enc.get()->encodeFile(file, bm, quality);
}
bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t,
int quality) {
std::unique_ptr<SkImageEncoder> enc(SkImageEncoder::Create(t));
return enc.get() && enc.get()->encodeStream(stream, bm, quality);
}
SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) {
std::unique_ptr<SkImageEncoder> enc(SkImageEncoder::Create(t));
return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr;
}
SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes,
Type t, int quality) {
SkBitmap bm;
if (!bm.installPixels(src)) {
return false;
if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
return nullptr;
}
bm.setImmutable();
std::unique_ptr<SkImageEncoder> enc(SkImageEncoder::Create((SkImageEncoder::Type)format));
return enc && enc->encodeStream(dst, bm, quality);
return SkImageEncoder::EncodeData(bm, t, quality);
}
SkData* SkImageEncoder::EncodeData(const SkPixmap& pixmap,
Type t, int quality) {
SkBitmap bm;
if (!bm.installPixels(pixmap)) {
return nullptr;
}
bm.setImmutable();
return SkImageEncoder::EncodeData(bm, t, quality);
}
namespace {
class ImageEncoderPixelSerializer final : public SkPixelSerializer {
protected:
bool onUseEncodedData(const void*, size_t) override { return true; }
SkData* onEncode(const SkPixmap& pmap) override {
return SkImageEncoder::EncodeData(pmap, SkImageEncoder::kPNG_Type, 100);
}
};
} // namespace
SkPixelSerializer* SkImageEncoder::CreatePixelSerializer() {
return new ImageEncoderPixelSerializer;
}

View File

@ -1,68 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkImageEncoderPriv_DEFINED
#define SkImageEncoderPriv_DEFINED
#include "SkImageEncoder.h"
#include "SkTRegistry.h"
#ifndef SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
// TODO(halcanary): replace this class and registry system with something simpler.
class SkImageEncoder {
public:
typedef SkEncodedImageFormat Type;
static SkImageEncoder* Create(SkEncodedImageFormat);
virtual ~SkImageEncoder() {}
bool encodeStream(SkWStream* dst, const SkBitmap& src, int quality) {
return this->onEncode(dst, src, SkMin32(100, SkMax32(0, quality)));
}
protected:
/**
* Encode bitmap 'bm' in the desired format, writing results to
* stream 'stream', at quality level 'quality' (which can be in
* range 0-100).
*/
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) = 0;
};
#endif // SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS
// This macro declares a global (i.e., non-class owned) creation entry point
// for each encoder (e.g., CreateJPEGImageEncoder)
#define DECLARE_ENCODER_CREATOR(codec) \
SK_API SkImageEncoder *Create ## codec ();
// This macro defines the global creation entry point for each encoder. Each
// encoder implementation that registers with the encoder factory must call it.
#define DEFINE_ENCODER_CREATOR(codec) \
SkImageEncoder* Create##codec() { return new Sk##codec; }
// All the encoders known by Skia. Note that, depending on the compiler settings,
// not all of these will be available
DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
DECLARE_ENCODER_CREATOR(PNGImageEncoder);
DECLARE_ENCODER_CREATOR(KTXImageEncoder);
DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
SkImageEncoder* CreateImageEncoder_CG(SkImageEncoder::Type type);
#endif
#if defined(SK_BUILD_FOR_WIN)
SkImageEncoder* CreateImageEncoder_WIC(SkImageEncoder::Type type);
#endif
// Typedef to make registering encoder callback easier
// This has to be defined outside SkImageEncoder. :(
typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
#endif // SkImageEncoderPriv_DEFINED

View File

@ -5,11 +5,11 @@
* found in the LICENSE file.
*/
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
template SkImageEncoder_EncodeReg* SkImageEncoder_EncodeReg::gHead;
SkImageEncoder* SkImageEncoder::Create(SkImageEncoder::Type t) {
SkImageEncoder* SkImageEncoder::Create(Type t) {
SkImageEncoder* codec = nullptr;
const SkImageEncoder_EncodeReg* curr = SkImageEncoder_EncodeReg::Head();
while (curr) {

View File

@ -5,20 +5,20 @@
* found in the LICENSE file.
*/
#include "SkImageEncoderPriv.h"
#include "SkCanvas.h"
#include "SkImageEncoder.h"
#include "SkColorPriv.h"
#include "SkDither.h"
#include "SkJPEGWriteUtility.h"
#include "SkRect.h"
#include "SkStream.h"
#include "SkTemplates.h"
#include "SkTime.h"
#include "SkUtils.h"
#include "SkRect.h"
#include "SkCanvas.h"
#include <stdio.h>
#include "SkJPEGWriteUtility.h"
extern "C" {
#include "jpeglib.h"
#include "jerror.h"
@ -178,7 +178,7 @@ DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
return (SkEncodedImageFormat::kJPEG == (SkEncodedImageFormat)t) ? new SkJPEGImageEncoder : nullptr;
return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr;
}
static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);

View File

@ -6,7 +6,7 @@
*/
#include "SkColorPriv.h"
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkImageGenerator.h"
#include "SkPixelRef.h"
#include "SkStream.h"
@ -40,7 +40,7 @@ protected:
DEFINE_ENCODER_CREATOR(KTXImageEncoder);
SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
return (SkEncodedImageFormat::kKTX == (SkEncodedImageFormat)t) ? new SkKTXImageEncoder : nullptr;
return (SkImageEncoder::kKTX_Type == t) ? new SkKTXImageEncoder : nullptr;
}
static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory);

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkColor.h"
#include "SkColorPriv.h"
#include "SkDither.h"
@ -356,7 +356,7 @@ DEFINE_ENCODER_CREATOR(PNGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
return (SkEncodedImageFormat::kPNG == (SkEncodedImageFormat)t) ? new SkPNGImageEncoder : nullptr;
return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : nullptr;
}
static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);

View File

@ -15,7 +15,7 @@
*/
#include "SkBitmap.h"
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkColorPriv.h"
#include "SkStream.h"
#include "SkTemplates.h"
@ -241,7 +241,7 @@ DEFINE_ENCODER_CREATOR(WEBPImageEncoder);
///////////////////////////////////////////////////////////////////////////////
static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
return (SkEncodedImageFormat::kWEBP == (SkEncodedImageFormat)t) ? new SkWEBPImageEncoder : nullptr;
return (SkImageEncoder::kWEBP_Type == t) ? new SkWEBPImageEncoder : nullptr;
}
static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory);

View File

@ -12,7 +12,7 @@
#include "SkCGUtils.h"
#include "SkColorPriv.h"
#include "SkData.h"
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkStream.h"
#include "SkStreamPriv.h"
#include "SkTemplates.h"
@ -59,13 +59,13 @@ static CGImageDestinationRef SkStreamToImageDestination(SkWStream* stream,
class SkImageEncoder_CG : public SkImageEncoder {
public:
SkImageEncoder_CG(SkEncodedImageFormat t) : fType(t) {}
SkImageEncoder_CG(Type t) : fType(t) {}
protected:
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality);
private:
SkEncodedImageFormat fType;
Type fType;
};
/* Encode bitmaps via CGImageDestination. We setup a DataConsumer which writes
@ -80,19 +80,19 @@ bool SkImageEncoder_CG::onEncode(SkWStream* stream, const SkBitmap& bm,
CFStringRef type;
switch (fType) {
case SkEncodedImageFormat::kICO:
case kICO_Type:
type = kUTTypeICO;
break;
case SkEncodedImageFormat::kBMP:
case kBMP_Type:
type = kUTTypeBMP;
break;
case SkEncodedImageFormat::kGIF:
case kGIF_Type:
type = kUTTypeGIF;
break;
case SkEncodedImageFormat::kJPEG:
case kJPEG_Type:
type = kUTTypeJPEG;
break;
case SkEncodedImageFormat::kPNG:
case kPNG_Type:
// PNG encoding an ARGB_4444 bitmap gives the following errors in GM:
// <Error>: CGImageDestinationAddImage image could not be converted to destination
// format.
@ -127,13 +127,13 @@ bool SkImageEncoder_CG::onEncode(SkWStream* stream, const SkBitmap& bm,
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_USE_CG_ENCODER
static SkImageEncoder* sk_imageencoder_cg_factory(SkEncodedImageFormat t) {
static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) {
switch (t) {
case SkEncodedImageFormat::kICO:
case SkEncodedImageFormat::kBMP:
case SkEncodedImageFormat::kGIF:
case SkEncodedImageFormat::kJPEG:
case SkEncodedImageFormat::kPNG:
case SkImageEncoder::kICO_Type:
case SkImageEncoder::kBMP_Type:
case SkImageEncoder::kGIF_Type:
case SkImageEncoder::kJPEG_Type:
case SkImageEncoder::kPNG_Type:
break;
default:
return nullptr;
@ -145,7 +145,7 @@ static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_cg_factory);
#endif
SkImageEncoder* CreateImageEncoder_CG(SkImageEncoder::Type type) {
return new SkImageEncoder_CG((SkEncodedImageFormat)type);
return new SkImageEncoder_CG(type);
}
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -31,7 +31,7 @@
#include <wincodec.h>
#include "SkAutoCoInitialize.h"
#include "SkBitmap.h"
#include "SkImageEncoderPriv.h"
#include "SkImageEncoder.h"
#include "SkIStream.h"
#include "SkStream.h"
#include "SkTScopedComPtr.h"
@ -48,13 +48,13 @@
class SkImageEncoder_WIC : public SkImageEncoder {
public:
SkImageEncoder_WIC(SkEncodedImageFormat t) : fType(t) {}
SkImageEncoder_WIC(Type t) : fType(t) {}
protected:
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality);
private:
SkEncodedImageFormat fType;
Type fType;
};
bool SkImageEncoder_WIC::onEncode(SkWStream* stream
@ -63,10 +63,10 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
{
GUID type;
switch (fType) {
case SkEncodedImageFormat::kJPEG:
case kJPEG_Type:
type = GUID_ContainerFormatJpeg;
break;
case SkEncodedImageFormat::kPNG:
case kPNG_Type:
type = GUID_ContainerFormatPng;
break;
default:
@ -97,7 +97,7 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
size_t rowBytes = bitmap.rowBytes();
SkAutoMalloc pixelStorage;
WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA;
if (SkEncodedImageFormat::kJPEG == fType) {
if (kJPEG_Type == fType) {
formatDesired = GUID_WICPixelFormat24bppBGR;
rowBytes = SkAlign4(bitmap.width() * 3);
pixelStorage.reset(rowBytes * bitmap.height());
@ -219,10 +219,10 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_USE_WIC_ENCODER
static SkImageEncoder* sk_imageencoder_wic_factory(SkEncodedImageFormat t) {
static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) {
switch (t) {
case SkEncodedImageFormat::kPNG:
case SkEncodedImageFormat::kJPEG:
case SkImageEncoder::kPNG_Type:
case SkImageEncoder::kJPEG_Type:
break;
default:
return nullptr;
@ -234,7 +234,7 @@ static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_wic_factory);
#endif
SkImageEncoder* CreateImageEncoder_WIC(SkImageEncoder::Type type) {
return new SkImageEncoder_WIC((SkEncodedImageFormat)type);
return new SkImageEncoder_WIC(type);
}
#endif // defined(SK_BUILD_FOR_WIN32)

View File

@ -5,9 +5,63 @@
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "SkImage.h"
#include "SkImageEncoder.h"
#include "SkPixelSerializer.h"
#include "SkStream.h"
bool SkEncodeImage(SkWStream*, const SkPixmap&, SkEncodedImageFormat, int) {
/////////////////////////////////////////////////////////////////////////
// Empty implementations for SkImageEncoder.
SkImageEncoder* SkImageEncoder::Create(Type t) {
return nullptr;
}
bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap&, Type, int quality) {
return false;
}
bool SkImageEncoder::EncodeStream(SkWStream*, const SkBitmap&, SkImageEncoder::Type, int) {
return false;
}
SkData* SkImageEncoder::EncodeData(const SkBitmap&, Type, int quality) {
return nullptr;
}
SkData* SkImageEncoder::EncodeData(const SkImageInfo&, const void* pixels, size_t rowBytes,
Type, int quality) {
return nullptr;
}
SkData* SkImageEncoder::EncodeData(const SkPixmap&, Type, int) {
return nullptr;
}
bool SkImageEncoder::encodeStream(SkWStream*, const SkBitmap&, int) {
return false;
}
SkData* SkImageEncoder::encodeData(const SkBitmap&, int) {
return nullptr;
}
bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm, int quality) {
return false;
}
namespace {
class ImageEncoderPixelSerializer final : public SkPixelSerializer {
protected:
bool onUseEncodedData(const void*, size_t) override { return true; }
SkData* onEncode(const SkPixmap&) override { return nullptr; }
};
} // namespace
SkPixelSerializer* SkImageEncoder::CreatePixelSerializer() {
return new ImageEncoderPixelSerializer;
}
/////////////////////////////////////////////////////////////////////////

View File

@ -659,14 +659,10 @@ void SkSVGDevice::drawPath(const SkDraw& draw, const SkPath& path, const SkPaint
}
}
static sk_sp<SkData> encode(const SkBitmap& src) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, src, SkEncodedImageFormat::kPNG, 80) ? buf.detachAsData() : nullptr;
}
void SkSVGDevice::drawBitmapCommon(const SkDraw& draw, const SkBitmap& bm,
const SkPaint& paint) {
sk_sp<SkData> pngData = encode(bm);
sk_sp<const SkData> pngData(
SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality));
if (!pngData) {
return;
}

View File

@ -658,7 +658,8 @@ HRESULT SkXPSDevice::createXpsImageBrush(
const SkAlpha alpha,
IXpsOMTileBrush** xpsBrush) {
SkDynamicMemoryWStream write;
if (!SkEncodeImage(&write, bitmap, SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeStream(&write, bitmap,
SkImageEncoder::kPNG_Type, 100)) {
HRM(E_FAIL, "Unable to encode bitmap as png.");
}
SkMemoryStream* read = new SkMemoryStream;

View File

@ -12,8 +12,6 @@
#include "SkRect.h"
#include "Test.h"
#include "sk_tool_utils.h"
// these are in the same order as the SkColorType enum
static const char* gColorTypeName[] = {
"None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
@ -180,7 +178,7 @@ struct Mesh {
#include "SkImageEncoder.h"
static void save_bm(const SkBitmap& bm, const char name[]) {
sk_tool_utils::EncodeImageToFile(name, bm, SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(name, bm, SkImageEncoder::kPNG_Type, 100);
}
static bool gOnce;

View File

@ -23,8 +23,6 @@
#include "png.h"
#include "sk_tool_utils.h"
#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 5
// FIXME (scroggo): Google3 needs to be updated to use a newer version of libpng. In
// the meantime, we had to break some pieces of SkPngCodec in order to support Google3.
@ -1104,7 +1102,7 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk
// Encode the image to png.
sk_sp<SkData> data =
sk_sp<SkData>(sk_tool_utils::EncodeImageToData(bm1, SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_Type, 100));
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType()));

View File

@ -26,8 +26,6 @@
#include "SkUtils.h"
#include "Test.h"
#include "sk_tool_utils.h"
#if SK_SUPPORT_GPU
#include "GrGpu.h"
#endif
@ -155,7 +153,7 @@ static sk_sp<SkImage> create_codec_image() {
sk_sp<SkData> data(create_image_data(&info));
SkBitmap bitmap;
bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
sk_sp<SkData> src(sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> src(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
return SkImage::MakeFromEncoded(std::move(src));
}
#if SK_SUPPORT_GPU
@ -1028,7 +1026,7 @@ DEF_TEST(image_roundtrip_encode, reporter) {
make_all_premul(&bm0);
auto img0 = SkImage::MakeFromBitmap(bm0);
sk_sp<SkData> data(img0->encode(SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> data(img0->encode(SkImageEncoder::kPNG_Type, 100));
auto img1 = SkImage::MakeFromEncoded(data);
SkBitmap bm1;

View File

@ -14,8 +14,6 @@
#include "SkStream.h"
#include "SkPixelSerializer.h"
#include "sk_tool_utils.h"
static void test_empty(skiatest::Reporter* reporter) {
SkDynamicMemoryWStream stream;
@ -121,7 +119,14 @@ namespace {
class JPEGSerializer final : public SkPixelSerializer {
bool onUseEncodedData(const void*, size_t) override { return true; }
SkData* onEncode(const SkPixmap& pixmap) override {
return sk_tool_utils::EncodeImageToData(pixmap, SkEncodedImageFormat::kJPEG, 85).release();
SkBitmap bm;
return bm.installPixels(pixmap.info(),
pixmap.writable_addr(),
pixmap.rowBytes(),
pixmap.ctable(),
nullptr, nullptr)
? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85)
: nullptr;
}
};
} // namespace

View File

@ -110,8 +110,8 @@ static void writePng(const SkConic& c, const SkConic ch[2], const char* name) {
canvas.drawPath(path, paint);
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("%s.png", name);
sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap,
SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
SkImageEncoder::kPNG_Type, 100);
}
static void writeDPng(const SkDConic& dC, const char* name) {
@ -152,8 +152,8 @@ static void writeDPng(const SkDConic& dC, const char* name) {
canvas.drawPath(path, paint);
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("%s.png", name);
sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap,
SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
SkImageEncoder::kPNG_Type, 100);
}
#endif
@ -290,7 +290,7 @@ static void writeFrames() {
}
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("f%d.png", index);
sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
}
}
#endif

View File

@ -429,7 +429,7 @@ static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
SkString outFile = get_sum_path(outDir);
outFile.appendf("%s%s", PATH_SLASH, pngName);
if (!sk_tool_utils::EncodeImageToFile(outFile.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) {
SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
bitmap.width(), bitmap.height());
}

View File

@ -368,8 +368,8 @@ static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
SkString outFile = make_filepath(0, outDir, pngName);
if (!sk_tool_utils::EncodeImageToFile(outFile.c_str(), bitmap,
SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap,
SkImageEncoder::kPNG_Type, 100)) {
SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName,
bitmap.width(), bitmap.height());
}

View File

@ -17,8 +17,6 @@
#include "SkMatrix44.h"
#include "SkOSFile.h"
#include "sk_tool_utils.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
DEFINE_string(input, "input.png", "A path to the input image or icc profile.");
@ -221,7 +219,7 @@ int main(int argc, char** argv) {
}
// Finally, encode the result to the output file.
sk_sp<SkData> out = sk_tool_utils::EncodeImageToData(gamut, SkEncodedImageFormat::kPNG, 100);
sk_sp<SkData> out(SkImageEncoder::EncodeData(gamut, SkImageEncoder::kPNG_Type, 100));
if (!out) {
SkDebugf("Failed to encode gamut output.\n");
return -1;
@ -245,7 +243,7 @@ int main(int argc, char** argv) {
SkDebugf("Could not decode input image.\n");
return -1;
}
out = sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100);
out.reset(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
if (!out) {
SkDebugf("Failed to encode uncorrected image.\n");
return -1;

View File

@ -65,14 +65,14 @@ struct Sniffer : public SkPixelSerializer {
}
SkString ext;
switch (codec->getEncodedFormat()) {
case SkEncodedImageFormat::kBMP: ext = "bmp"; break;
case SkEncodedImageFormat::kGIF: ext = "gif"; break;
case SkEncodedImageFormat::kICO: ext = "ico"; break;
case SkEncodedImageFormat::kJPEG: ext = "jpg"; break;
case SkEncodedImageFormat::kPNG: ext = "png"; break;
case SkEncodedImageFormat::kDNG: ext = "dng"; break;
case SkEncodedImageFormat::kWBMP: ext = "wbmp"; break;
case SkEncodedImageFormat::kWEBP: ext = "webp"; break;
case SkEncodedFormat::kBMP_SkEncodedFormat: ext = "bmp"; break;
case SkEncodedFormat::kGIF_SkEncodedFormat: ext = "gif"; break;
case SkEncodedFormat::kICO_SkEncodedFormat: ext = "ico"; break;
case SkEncodedFormat::kJPEG_SkEncodedFormat: ext = "jpg"; break;
case SkEncodedFormat::kPNG_SkEncodedFormat: ext = "png"; break;
case SkEncodedFormat::kDNG_SkEncodedFormat: ext = "dng"; break;
case SkEncodedFormat::kWBMP_SkEncodedFormat: ext = "wbmp"; break;
case SkEncodedFormat::kWEBP_SkEncodedFormat: ext = "webp"; break;
default:
// This should be unreachable because we cannot create a codec if we do not know
// the image type.

View File

@ -66,7 +66,7 @@ int tool_main(int argc, char** argv) {
SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma);
if (!sk_tool_utils::EncodeImageToFile(FLAGS_out[0], dst, SkEncodedImageFormat::kPNG, 100)) {
if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type, 100)) {
if (!FLAGS_quiet) {
SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]);
}

View File

@ -17,8 +17,6 @@
#include "SkStream.h"
#include "SkString.h"
#include "sk_tool_utils.h"
namespace sk_tools {
void force_all_opaque(const SkBitmap& bitmap) {
SkASSERT(kN32_SkColorType == bitmap.colorType());
@ -65,7 +63,7 @@ namespace sk_tools {
partialPath.set(dirPath);
}
SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str());
if (sk_tool_utils::EncodeImageToFile(fullPath.c_str(), bm, SkEncodedImageFormat::kPNG, 100)) {
if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPNG_Type, 100)) {
return true;
} else {
SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str());

View File

@ -225,31 +225,6 @@ namespace sk_tool_utils {
SkTDArray<TopoTestNode*> fDependencies;
};
template <typename T>
inline bool EncodeImageToFile(const char* path, const T& src, SkEncodedImageFormat f, int q) {
SkFILEWStream file(path);
return file.isValid() && SkEncodeImage(&file, src, f, q);
}
template <typename T>
inline sk_sp<SkData> EncodeImageToData(const T& src, SkEncodedImageFormat f, int q) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, src , f, q) ? buf.detachAsData() : nullptr;
}
/**
* Uses SkEncodeImage to serialize images that are not already
* encoded as SkEncodedImageFormat::kPNG images.
*/
inline sk_sp<SkPixelSerializer> MakePixelSerializer() {
struct EncodeImagePixelSerializer final : SkPixelSerializer {
bool onUseEncodedData(const void*, size_t) override { return true; }
SkData* onEncode(const SkPixmap& pmap) override {
return EncodeImageToData(pmap, SkEncodedImageFormat::kPNG, 100).release();
}
};
return sk_make_sp<EncodeImagePixelSerializer>();
}
} // namespace sk_tool_utils
#endif // sk_tool_utils_DEFINED

View File

@ -6,7 +6,6 @@
*/
#include "skdiff.h"
#include "skdiff_utils.h"
#include "sk_tool_utils.h"
#include "SkBitmap.h"
#include "SkCodec.h"
#include "SkData.h"
@ -83,8 +82,8 @@ bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
SkBitmap copy;
bitmap.copyTo(&copy, kN32_SkColorType);
force_all_opaque(copy);
return sk_tool_utils::EncodeImageToFile(path.c_str(), copy,
SkEncodedImageFormat::kPNG, 100);
return SkImageEncoder::EncodeFile(path.c_str(), copy,
SkImageEncoder::kPNG_Type, 100);
}
/// Return a copy of the "input" string, within which we have replaced all instances

View File

@ -11,7 +11,6 @@
#include "SkPixelSerializer.h"
#include "SkPM4fPriv.h"
#include "picture_utils.h"
#include "sk_tool_utils.h"
using namespace sk_gpu_test;
@ -118,7 +117,7 @@ sk_sp<SkData> Request::writeOutSkp() {
SkDynamicMemoryWStream outStream;
sk_sp<SkPixelSerializer> serializer = sk_tool_utils::MakePixelSerializer();
sk_sp<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerializer());
picture->serialize(&outStream, serializer.get());
return outStream.detachAsData();