2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-12-19 20:26:07 +00:00
|
|
|
|
2009-01-06 20:16:26 +00:00
|
|
|
#ifndef SkImageEncoder_DEFINED
|
|
|
|
#define SkImageEncoder_DEFINED
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
// TODO: update clients so we can remove this include, they should IWYU
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2020-12-23 15:11:33 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkEncodedImageFormat.h"
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkPixmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkStream.h"
|
2009-01-06 20:16:26 +00:00
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
class SkBitmap;
|
|
|
|
|
2016-11-23 15:55:18 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2017-05-16 21:06:52 +00:00
|
|
|
* @param quality range from 0-100, this is supported by jpeg and webp.
|
|
|
|
* higher values correspond to improved visual quality, but less compression.
|
2016-11-23 15:55:18 +00:00
|
|
|
*
|
|
|
|
* @return false iff input is bad or format is unsupported.
|
|
|
|
*
|
|
|
|
* Will always return false if Skia is compiled without image
|
|
|
|
* encoders.
|
|
|
|
*
|
2019-02-22 17:32:16 +00:00
|
|
|
* For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise
|
|
|
|
* it will use lossy.
|
2017-05-16 21:06:52 +00:00
|
|
|
*
|
2016-11-23 15:55:18 +00:00
|
|
|
* For examples of encoding an image to a file or to a block of memory,
|
2019-03-20 16:12:10 +00:00
|
|
|
* see tools/ToolUtils.h.
|
2016-11-23 15:55:18 +00:00
|
|
|
*/
|
|
|
|
SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
|
|
|
|
SkEncodedImageFormat format, int quality);
|
2017-12-08 21:20:58 +00:00
|
|
|
|
2016-11-23 15:55:18 +00:00
|
|
|
/**
|
|
|
|
* The following helper function wraps SkEncodeImage().
|
|
|
|
*/
|
2020-12-23 15:11:33 +00:00
|
|
|
SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q);
|
2016-11-23 15:55:18 +00:00
|
|
|
|
2017-12-08 21:20:58 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2019-02-22 17:32:16 +00:00
|
|
|
* For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise
|
|
|
|
* it will use lossy.
|
2017-12-08 21:20:58 +00:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
2016-11-23 15:55:18 +00:00
|
|
|
#endif // SkImageEncoder_DEFINED
|