Remove color space restrictions from image infos
What makes an info valid (or invalid)? Nothing to do with color space. Bug: skia: Change-Id: I6795efa9aa74ab0d65935c5ddccc1058f8e0b112 Reviewed-on: https://skia-review.googlesource.com/131780 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
7258e97e8e
commit
e1adc3a955
@ -88,10 +88,9 @@ static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This contains shared checks on SkImageInfo. Depending on the desired color space behavior,
|
* Returns true if |info| contains a valid combination of width, height, colorType, and alphaType.
|
||||||
* the caller should choose one of the two versions below.
|
|
||||||
*/
|
*/
|
||||||
static inline bool SkImageInfoIsValidCommon(const SkImageInfo& info) {
|
static inline bool SkImageInfoIsValid(const SkImageInfo& info) {
|
||||||
if (info.width() <= 0 || info.height() <= 0) {
|
if (info.width() <= 0 || info.height() <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -113,53 +112,9 @@ static inline bool SkImageInfoIsValidCommon(const SkImageInfo& info) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
|
|
||||||
* colorSpace. Allows numerical color spaces. Returns false otherwise.
|
|
||||||
*/
|
|
||||||
static inline bool SkImageInfoIsValidAllowNumericalCS(const SkImageInfo& info) {
|
|
||||||
if (!SkImageInfoIsValidCommon(info)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkColorSpaceTransferFn fn;
|
|
||||||
if (info.colorSpace() && !info.colorSpace()->isNumericalTransferFn(&fn)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
|
|
||||||
* colorSpace. Only supports rendering color spaces. Returns false otherwise.
|
|
||||||
*/
|
|
||||||
static inline bool SkImageInfoIsValidRenderingCS(const SkImageInfo& info) {
|
|
||||||
if (!SkImageInfoIsValidCommon(info)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info.colorSpace() &&
|
|
||||||
(!info.colorSpace()->gammaCloseToSRGB() && !info.colorSpace()->gammaIsLinear())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
|
|
||||||
* colorSpace.
|
|
||||||
*/
|
|
||||||
static inline bool SkImageInfoIsValid(const SkImageInfo& info) {
|
|
||||||
return SkImageInfoIsValidAllowNumericalCS(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if Skia has defined a pixel conversion from the |src| to the |dst|.
|
* Returns true if Skia has defined a pixel conversion from the |src| to the |dst|.
|
||||||
* Returns false otherwise. Some discussion of false cases:
|
* Returns false otherwise. Some discussion of false cases:
|
||||||
* We will not convert to kIndex8 unless it exactly matches the src, since color tables
|
|
||||||
* are immutable.
|
|
||||||
* We do not convert to kGray8 when the |src| is not kGray8 in the same color space.
|
* We do not convert to kGray8 when the |src| is not kGray8 in the same color space.
|
||||||
* We may add this feature - it just requires some work to convert to luminance while
|
* We may add this feature - it just requires some work to convert to luminance while
|
||||||
* handling color spaces correctly. Currently no one is asking for this.
|
* handling color spaces correctly. Currently no one is asking for this.
|
||||||
@ -174,7 +129,7 @@ static inline bool SkImageInfoIsValid(const SkImageInfo& info) {
|
|||||||
* conversion is not well-defined.
|
* conversion is not well-defined.
|
||||||
*/
|
*/
|
||||||
static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) {
|
static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) {
|
||||||
if (!SkImageInfoIsValidAllowNumericalCS(dst) || !SkImageInfoIsValidAllowNumericalCS(src)) {
|
if (!SkImageInfoIsValid(dst) || !SkImageInfoIsValid(src)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ bool validate_backend_texture(GrContext* ctx, const GrBackendTexture& tex, GrPix
|
|||||||
// TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to
|
// TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to
|
||||||
// create a fake image info here.
|
// create a fake image info here.
|
||||||
SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs);
|
SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs);
|
||||||
if (!SkImageInfoIsValidAllowNumericalCS(info)) {
|
if (!SkImageInfoIsValid(info)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -697,7 +697,7 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkImageInfo info = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace);
|
SkImageInfo info = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace);
|
||||||
if (!SkImageInfoIsValidAllowNumericalCS(info)) {
|
if (!SkImageInfoIsValid(info)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
GrPixelConfig config = kUnknown_GrPixelConfig;
|
GrPixelConfig config = kUnknown_GrPixelConfig;
|
||||||
|
@ -315,7 +315,7 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmapPriv(const SkBitmap& bm, SkCopyPixelsM
|
|||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm) {
|
sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm) {
|
||||||
if (!SkImageInfoIsValidAllowNumericalCS(bm.info()) || bm.rowBytes() < bm.info().minRowBytes()) {
|
if (!SkImageInfoIsValid(bm.info()) || bm.rowBytes() < bm.info().minRowBytes()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,7 @@ private:
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes) {
|
bool SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes) {
|
||||||
if (!SkImageInfoIsValidCommon(info)) {
|
if (!SkImageInfoIsValid(info)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (info.isEmpty()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,17 +11,9 @@
|
|||||||
#include "SkImageEncoder.h"
|
#include "SkImageEncoder.h"
|
||||||
#include "SkImageInfoPriv.h"
|
#include "SkImageInfoPriv.h"
|
||||||
|
|
||||||
static inline bool SkPixmapIsValid(const SkPixmap& src,
|
static inline bool SkPixmapIsValid(const SkPixmap& src) {
|
||||||
SkTransferFunctionBehavior unpremulBehavior)
|
if (!SkImageInfoIsValid(src.info())) {
|
||||||
{
|
return false;
|
||||||
if (SkTransferFunctionBehavior::kRespect == unpremulBehavior) {
|
|
||||||
if (!SkImageInfoIsValidRenderingCS(src.info())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!SkImageInfoIsValidAllowNumericalCS(src.info())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!src.addr() || src.rowBytes() < src.info().minRowBytes()) {
|
if (!src.addr() || src.rowBytes() < src.info().minRowBytes()) {
|
||||||
|
@ -181,7 +181,7 @@ bool SkJpegEncoderMgr::setParams(const SkImageInfo& srcInfo, const SkJpegEncoder
|
|||||||
|
|
||||||
std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src,
|
std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src,
|
||||||
const Options& options) {
|
const Options& options) {
|
||||||
if (!SkPixmapIsValid(src, options.fBlendBehavior)) {
|
if (!SkPixmapIsValid(src)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ void SkPngEncoderMgr::chooseProc(const SkImageInfo& srcInfo,
|
|||||||
|
|
||||||
std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src,
|
std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src,
|
||||||
const Options& options) {
|
const Options& options) {
|
||||||
if (!SkPixmapIsValid(src, options.fUnpremulBehavior)) {
|
if (!SkPixmapIsValid(src)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ static int stream_writer(const uint8_t* data, size_t data_size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Options& opts) {
|
bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Options& opts) {
|
||||||
if (!SkPixmapIsValid(pixmap, opts.fUnpremulBehavior)) {
|
if (!SkPixmapIsValid(pixmap)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ static const void* five_reference_pixels(SkColorType colorType) {
|
|||||||
|
|
||||||
static void test_conversion(skiatest::Reporter* r, const SkImageInfo& dstInfo,
|
static void test_conversion(skiatest::Reporter* r, const SkImageInfo& dstInfo,
|
||||||
const SkImageInfo& srcInfo) {
|
const SkImageInfo& srcInfo) {
|
||||||
if (!SkImageInfoIsValidRenderingCS(srcInfo)) {
|
if (!SkImageInfoIsValid(srcInfo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user