skia2/include/core/SkImageEncoder.h

71 lines
2.3 KiB
C
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
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.
*/
#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.
*
Reland "Treat kWEBP encode with quality=100 as lossless" This reverts commit 22170b317800325408310e144194d6c024d571bc. It was reverted due to the test breaking Google3. This includes a workaround. Original change's description: > Treat kWEBP encode with quality=100 as lossless > > In SkEncodeImage and friends, treat quality of 100 as a lossless encode > when using kWEBP. This seems a good fit for the intent - which is > presumably to save the highest quality image. This also matches > Chromium's blink::ImageEncoder::ComputeWebpOptions, which treats a > quality of 1 (on a float scale from 0 to 1) as a lossless encode. > > FWIW, Chromium has had this behavior since > https://codereview.chromium.org/1937433002, in response to > crbug.com/523098. The goal is to "maintain sharpness to > match the JPEG encoder behavior (use WEBP lossless encoding)". > > Add a test to verify the new behavior. This requires making tests > depend on libwebp to use WebPGetFeatures, since the Skia API does not > provide a way to determine whether an encoded webp file was encoded > lossless-ly or lossily. > > Bug: skia:8586 > Change-Id: Ie9e09c2f7414ab701d696c4ad9edf405868a716f > Reviewed-on: https://skia-review.googlesource.com/c/175823 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Reviewed-by: Mike Reed <reed@google.com> TBR=reed@google.com, based on prior approval Bug: skia:8586 Change-Id: I09c73f71996422f797fd9456fef5dfad9af36839 Reviewed-on: https://skia-review.googlesource.com/c/194194 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com> Auto-Submit: Leon Scroggins <scroggo@google.com>
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.
*
* For examples of encoding an image to a file or to a block of memory,
* see tools/ToolUtils.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.
*
Reland "Treat kWEBP encode with quality=100 as lossless" This reverts commit 22170b317800325408310e144194d6c024d571bc. It was reverted due to the test breaking Google3. This includes a workaround. Original change's description: > Treat kWEBP encode with quality=100 as lossless > > In SkEncodeImage and friends, treat quality of 100 as a lossless encode > when using kWEBP. This seems a good fit for the intent - which is > presumably to save the highest quality image. This also matches > Chromium's blink::ImageEncoder::ComputeWebpOptions, which treats a > quality of 1 (on a float scale from 0 to 1) as a lossless encode. > > FWIW, Chromium has had this behavior since > https://codereview.chromium.org/1937433002, in response to > crbug.com/523098. The goal is to "maintain sharpness to > match the JPEG encoder behavior (use WEBP lossless encoding)". > > Add a test to verify the new behavior. This requires making tests > depend on libwebp to use WebPGetFeatures, since the Skia API does not > provide a way to determine whether an encoded webp file was encoded > lossless-ly or lossily. > > Bug: skia:8586 > Change-Id: Ie9e09c2f7414ab701d696c4ad9edf405868a716f > Reviewed-on: https://skia-review.googlesource.com/c/175823 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Reviewed-by: Mike Reed <reed@google.com> TBR=reed@google.com, based on prior approval Bug: skia:8586 Change-Id: I09c73f71996422f797fd9456fef5dfad9af36839 Reviewed-on: https://skia-review.googlesource.com/c/194194 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com> Auto-Submit: Leon Scroggins <scroggo@google.com>
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.
*/
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