remove colorprofiletype from imageinfo

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2075853002

Review-Url: https://codereview.chromium.org/2075853002
This commit is contained in:
reed 2016-06-17 09:26:41 -07:00 committed by Commit bot
parent 7d2f607ac1
commit 960b2d69bb
6 changed files with 156 additions and 81 deletions

View File

@ -86,7 +86,9 @@ public:
SkColorType colorType() const { return fInfo.colorType(); }
SkAlphaType alphaType() const { return fInfo.alphaType(); }
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
SkColorProfileType profileType() const { return fInfo.profileType(); }
#endif
/**
* Return the number of bytes per pixel based on the colortype. If the colortype is

View File

@ -79,6 +79,8 @@ protected:
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named);
friend Named sk_deduce_named_from_colorspace(SkColorSpace*);
const GammaNamed fGammaNamed;
const SkMatrix44 fToXYZD50;
const Named fNamed;

View File

@ -13,6 +13,8 @@
#include "SkRect.h"
#include "SkSize.h"
#define SK_SUPPORT_LEGACY_COLORPROFILETYPE
class SkReadBuffer;
class SkWriteBuffer;
@ -169,12 +171,14 @@ enum SkYUVColorSpace {
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
enum SkColorProfileType {
kLinear_SkColorProfileType,
kSRGB_SkColorProfileType,
kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType
};
#endif
enum class SkSourceGammaTreatment {
kRespect,
@ -193,45 +197,19 @@ public:
, fHeight(0)
, fColorType(kUnknown_SkColorType)
, fAlphaType(kUnknown_SkAlphaType)
, fProfileType(kLinear_SkColorProfileType)
{}
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
SkColorProfileType pt = kLinear_SkColorProfileType) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return SkImageInfo(width, height, ct, at, pt, cs);
sk_sp<SkColorSpace> cs = nullptr) {
return SkImageInfo(width, height, ct, at, std::move(cs));
}
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs);
/**
* Sets colortype to the native ARGB32 type.
*/
static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
SkColorProfileType pt = kLinear_SkColorProfileType) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return SkImageInfo(width, height, kN32_SkColorType, at, pt, cs);
}
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(int width, int height,
SkColorProfileType pt = kLinear_SkColorProfileType) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, pt, cs);
}
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(const SkISize& size,
SkColorProfileType pt = kLinear_SkColorProfileType) {
return MakeN32Premul(size.width(), size.height(), pt);
sk_sp<SkColorSpace> cs = nullptr) {
return Make(width, height, kN32_SkColorType, at, cs);
}
/**
@ -239,19 +217,63 @@ public:
*/
static SkImageInfo MakeS32(int width, int height, SkAlphaType at);
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(int width, int height) {
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, nullptr);
}
static SkImageInfo MakeN32Premul(const SkISize& size) {
return MakeN32Premul(size.width(), size.height());
}
static SkImageInfo MakeA8(int width, int height) {
return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType,
kLinear_SkColorProfileType, nullptr);
return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr);
}
static SkImageInfo MakeUnknown(int width, int height) {
return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType,
kLinear_SkColorProfileType, nullptr);
return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, nullptr);
}
static SkImageInfo MakeUnknown() {
return SkImageInfo();
return MakeUnknown(0, 0);
}
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
SkColorProfileType pt) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return Make(width, height, ct, at, cs);
}
static SkImageInfo MakeN32(int width, int height, SkAlphaType at, SkColorProfileType pt) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return SkImageInfo(width, height, kN32_SkColorType, at, cs);
}
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(int width, int height, SkColorProfileType pt) {
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs);
}
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(const SkISize& size, SkColorProfileType pt) {
return MakeN32Premul(size.width(), size.height(), pt);
}
SkColorProfileType profileType() const;
bool isLinear() const { return kLinear_SkColorProfileType == this->profileType(); }
bool isSRGB() const { return kSRGB_SkColorProfileType == this->profileType(); }
#endif
int width() const { return fWidth; }
int height() const { return fHeight; }
@ -259,40 +281,37 @@ public:
SkAlphaType alphaType() const { return fAlphaType; }
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
// Deprecated
SkColorProfileType profileType() const { return fProfileType; }
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
bool isOpaque() const {
return SkAlphaTypeIsOpaque(fAlphaType);
}
// Deprecated
bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; }
bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; }
SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
bool gammaCloseToSRGB() const {
return fColorSpace && fColorSpace->gammaCloseToSRGB();
}
/**
* Return a new ImageInfo with the same colortype and alphatype as this info,
* but with the specified width and height.
*/
SkImageInfo makeWH(int newWidth, int newHeight) const {
return SkImageInfo(newWidth, newHeight, fColorType, fAlphaType, fProfileType, fColorSpace);
return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace);
}
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const {
return SkImageInfo(fWidth, fHeight, fColorType, newAlphaType, fProfileType, fColorSpace);
return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace);
}
SkImageInfo makeColorType(SkColorType newColorType) const {
return SkImageInfo(fWidth, fHeight, newColorType, fAlphaType, fProfileType, fColorSpace);
return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace);
}
SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const {
return SkImageInfo::Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
}
int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
@ -316,12 +335,12 @@ public:
bool operator==(const SkImageInfo& other) const {
return fWidth == other.fWidth && fHeight == other.fHeight &&
fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
fProfileType == other.fProfileType && fColorSpace == other.fColorSpace;
fColorSpace == other.fColorSpace;
}
bool operator!=(const SkImageInfo& other) const {
return fWidth != other.fWidth || fHeight != other.fHeight ||
fColorType != other.fColorType || fAlphaType != other.fAlphaType ||
fProfileType != other.fProfileType || fColorSpace != other.fColorSpace;
fColorSpace != other.fColorSpace;
}
void unflatten(SkReadBuffer&);
@ -348,12 +367,11 @@ public:
}
void reset() {
fColorSpace = nullptr;
fWidth = 0;
fHeight = 0;
fColorType = kUnknown_SkColorType;
fAlphaType = kUnknown_SkAlphaType;
fProfileType = kLinear_SkColorProfileType;
fColorSpace = nullptr;
}
SkDEBUGCODE(void validate() const;)
@ -364,16 +382,13 @@ private:
int fHeight;
SkColorType fColorType;
SkAlphaType fAlphaType;
SkColorProfileType fProfileType;
SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt,
sk_sp<SkColorSpace> cs)
SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
: fColorSpace(std::move(cs))
, fWidth(width)
, fHeight(height)
, fColorType(ct)
, fAlphaType(at)
, fProfileType(pt)
{}
};

View File

@ -252,8 +252,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM
SkBitmap result;
// Note: pass along the profile information even thought this is no the right answer because
// this could be scaling in sRGB.
result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight,
source.alphaType(), source.info().profileType()));
result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, source.alphaType(),
sk_ref_sp(source.info().colorSpace())));
result.allocPixels(allocator, nullptr);
SkPixmap resultPM;

View File

@ -788,7 +788,7 @@ SkShader::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo&
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
return SkShader::ContextRec::kPM4f_DstType;
#else
return (dstInfo.isSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType)
return (dstInfo.gammaCloseToSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType)
? SkShader::ContextRec::kPM4f_DstType
: SkShader::ContextRec::kPMColor_DstType;
#endif
@ -922,7 +922,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
if (true)
#else
if (device.info().isSRGB())
if (device.info().gammaCloseToSRGB())
#endif
{
blitter = SkBlitter_ARGB32_Create(device, *paint, shaderContext, allocator);

View File

@ -10,6 +10,57 @@
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
/*
* We store this as a byte in the ImageInfo flatten buffer.
*/
enum class SkFlattenColorSpaceEnum {
kUnspecified,
kSRGB,
kAdobe1998,
// ... add more here
kLastEnum = kAdobe1998,
// final value means the actual profile data follows the info
kICCProfile = 0xFF,
};
static sk_sp<SkColorSpace> make_from_enum(SkFlattenColorSpaceEnum value) {
switch (value) {
case SkFlattenColorSpaceEnum::kSRGB:
return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
case SkFlattenColorSpaceEnum::kAdobe1998:
return SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named);
default:
return nullptr;
}
}
SkColorSpace::Named sk_deduce_named_from_colorspace(SkColorSpace* cs) {
return cs->fNamed;
}
static SkFlattenColorSpaceEnum deduce_from_colorspace(SkColorSpace* cs) {
if (!cs) {
return SkFlattenColorSpaceEnum::kUnspecified;
}
switch (sk_deduce_named_from_colorspace(cs)) {
case SkColorSpace::kSRGB_Named:
return SkFlattenColorSpaceEnum::kSRGB;
case SkColorSpace::kAdobeRGB_Named:
return SkFlattenColorSpaceEnum::kAdobe1998;
default:
return SkFlattenColorSpaceEnum::kICCProfile;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
SkColorProfileType SkImageInfo::profileType() const {
return fColorSpace && fColorSpace->gammaCloseToSRGB()
? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
}
#endif
// Indicate how images and gradients should interpret colors by default.
bool gDefaultProfileIsSRGB;
@ -18,10 +69,6 @@ SkColorProfileType SkDefaultColorProfile() {
: kLinear_SkColorProfileType;
}
static bool profile_type_is_valid(SkColorProfileType profileType) {
return (profileType >= 0) && (profileType <= kLastEnum_SkColorProfileType);
}
static bool alpha_type_is_valid(SkAlphaType alphaType) {
return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
}
@ -30,19 +77,8 @@ static bool color_type_is_valid(SkColorType colorType) {
return (colorType >= 0) && (colorType <= kLastEnum_SkColorType);
}
SkImageInfo SkImageInfo::Make(int width, int height, SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs) {
SkColorProfileType pt = SkDefaultColorProfile();
// try to keep the enum and the colorspace in sync.
// TODO: eliminate the enum entirely, now that we have colorspace objects
if (cs && (SkColorSpace::kLinear_GammaNamed != cs->gammaNamed())) {
pt = kSRGB_SkColorProfileType;
}
return SkImageInfo(width, height, ct, at, pt, std::move(cs));
}
SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
return SkImageInfo(width, height, kN32_SkColorType, at, kSRGB_SkColorProfileType,
return SkImageInfo(width, height, kN32_SkColorType, at,
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
}
@ -52,23 +88,43 @@ void SkImageInfo::unflatten(SkReadBuffer& buffer) {
uint32_t packed = buffer.read32();
SkASSERT(0 == (packed >> 24));
fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF);
fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
fColorType = (SkColorType)((packed >> 0) & 0xFF);
buffer.validate(profile_type_is_valid(fProfileType) &&
alpha_type_is_valid(fAlphaType) &&
color_type_is_valid(fColorType));
fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
SkFlattenColorSpaceEnum csenum = (SkFlattenColorSpaceEnum)((packed >> 16) & 0xFF);
buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType));
if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
SkASSERT(false); // we shouldn't hit this yet, as we don't write these yet
fColorSpace.reset();
} else {
if (csenum > SkFlattenColorSpaceEnum::kLastEnum) {
csenum = SkFlattenColorSpaceEnum::kUnspecified;
}
fColorSpace = make_from_enum(csenum);
}
}
void SkImageInfo::flatten(SkWriteBuffer& buffer) const {
buffer.write32(fWidth);
buffer.write32(fHeight);
SkASSERT(0 == (fProfileType & ~0xFF));
SkFlattenColorSpaceEnum csenum = deduce_from_colorspace(fColorSpace.get());
// TODO: when we actually support flattening the colorspace to a profile blob, remove this
// hack (and write the blob after we write packed.
if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
csenum = SkFlattenColorSpaceEnum::kUnspecified;
}
SkASSERT(0 == ((int)csenum & ~0xFF));
SkASSERT(0 == (fAlphaType & ~0xFF));
SkASSERT(0 == (fColorType & ~0xFF));
uint32_t packed = (fProfileType << 16) | (fAlphaType << 8) | fColorType;
uint32_t packed = ((int)csenum << 16) | (fAlphaType << 8) | fColorType;
buffer.write32(packed);
if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
// TODO: write the ICCProfile blob
}
}
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,