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:
Brian Osman 2018-06-04 09:21:17 -04:00 committed by Skia Commit-Bot
parent 7258e97e8e
commit e1adc3a955
9 changed files with 14 additions and 70 deletions

View File

@ -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,
* the caller should choose one of the two versions below.
* Returns true if |info| contains a valid combination of width, height, colorType, and alphaType.
*/
static inline bool SkImageInfoIsValidCommon(const SkImageInfo& info) {
static inline bool SkImageInfoIsValid(const SkImageInfo& info) {
if (info.width() <= 0 || info.height() <= 0) {
return false;
}
@ -113,53 +112,9 @@ static inline bool SkImageInfoIsValidCommon(const SkImageInfo& info) {
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 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 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.
@ -174,7 +129,7 @@ static inline bool SkImageInfoIsValid(const SkImageInfo& info) {
* conversion is not well-defined.
*/
static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) {
if (!SkImageInfoIsValidAllowNumericalCS(dst) || !SkImageInfoIsValidAllowNumericalCS(src)) {
if (!SkImageInfoIsValid(dst) || !SkImageInfoIsValid(src)) {
return false;
}

View File

@ -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
// create a fake image info here.
SkImageInfo info = SkImageInfo::Make(1, 1, ct, at, cs);
if (!SkImageInfoIsValidAllowNumericalCS(info)) {
if (!SkImageInfoIsValid(info)) {
return false;
}
@ -697,7 +697,7 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
}
SkImageInfo info = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace);
if (!SkImageInfoIsValidAllowNumericalCS(info)) {
if (!SkImageInfoIsValid(info)) {
return nullptr;
}
GrPixelConfig config = kUnknown_GrPixelConfig;

View File

@ -315,7 +315,7 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmapPriv(const SkBitmap& bm, SkCopyPixelsM
}
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;
}

View File

@ -38,10 +38,7 @@ private:
///////////////////////////////////////////////////////////////////////////////
bool SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes) {
if (!SkImageInfoIsValidCommon(info)) {
return false;
}
if (info.isEmpty()) {
if (!SkImageInfoIsValid(info)) {
return false;
}

View File

@ -11,17 +11,9 @@
#include "SkImageEncoder.h"
#include "SkImageInfoPriv.h"
static inline bool SkPixmapIsValid(const SkPixmap& src,
SkTransferFunctionBehavior unpremulBehavior)
{
if (SkTransferFunctionBehavior::kRespect == unpremulBehavior) {
if (!SkImageInfoIsValidRenderingCS(src.info())) {
return false;
}
} else {
if (!SkImageInfoIsValidAllowNumericalCS(src.info())) {
return false;
}
static inline bool SkPixmapIsValid(const SkPixmap& src) {
if (!SkImageInfoIsValid(src.info())) {
return false;
}
if (!src.addr() || src.rowBytes() < src.info().minRowBytes()) {

View File

@ -181,7 +181,7 @@ bool SkJpegEncoderMgr::setParams(const SkImageInfo& srcInfo, const SkJpegEncoder
std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src,
const Options& options) {
if (!SkPixmapIsValid(src, options.fBlendBehavior)) {
if (!SkPixmapIsValid(src)) {
return nullptr;
}

View File

@ -364,7 +364,7 @@ void SkPngEncoderMgr::chooseProc(const SkImageInfo& srcInfo,
std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src,
const Options& options) {
if (!SkPixmapIsValid(src, options.fUnpremulBehavior)) {
if (!SkPixmapIsValid(src)) {
return nullptr;
}

View File

@ -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) {
if (!SkPixmapIsValid(pixmap, opts.fUnpremulBehavior)) {
if (!SkPixmapIsValid(pixmap)) {
return false;
}

View File

@ -610,7 +610,7 @@ static const void* five_reference_pixels(SkColorType colorType) {
static void test_conversion(skiatest::Reporter* r, const SkImageInfo& dstInfo,
const SkImageInfo& srcInfo) {
if (!SkImageInfoIsValidRenderingCS(srcInfo)) {
if (!SkImageInfoIsValid(srcInfo)) {
return;
}