skia2/include/core/SkImageEncoder.h
Mike Reed 25eef6b342 centralize encoding to SkData
Bug: skia:
Change-Id: If3a9a6de54cf76d03e4d159b54b07a4ea6d5cda9
Reviewed-on: https://skia-review.googlesource.com/83020
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-12-09 01:36:48 +00:00

69 lines
2.2 KiB
C

/*
* 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 "SkBitmap.h"
#include "SkData.h"
#include "SkEncodedImageFormat.h"
#include "SkStream.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, this is supported by jpeg and webp.
* higher values correspond to improved visual quality, but less compression.
*
* @return false iff input is bad or format is unsupported.
*
* Will always return false if Skia is compiled without image
* encoders.
*
* Note that webp encodes will use webp lossy compression.
*
* 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) {
SkPixmap pixmap;
return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q);
}
/**
* Encode SkPixmap in the given binary image format.
*
* @param src source pixels.
* @param format image format, not all formats are supported.
* @param quality range from 0-100, this is supported by jpeg and webp.
* higher values correspond to improved visual quality, but less compression.
*
* @return encoded data or nullptr if input is bad or format is unsupported.
*
* Will always return nullptr if Skia is compiled without image
* encoders.
*
* Note that webp encodes will use webp lossy compression.
*/
SK_API sk_sp<SkData> SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality);
/**
* Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap()
*/
SK_API sk_sp<SkData> SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality);
#endif // SkImageEncoder_DEFINED