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:
parent
7d2f607ac1
commit
960b2d69bb
@ -86,7 +86,9 @@ public:
|
|||||||
SkColorType colorType() const { return fInfo.colorType(); }
|
SkColorType colorType() const { return fInfo.colorType(); }
|
||||||
SkAlphaType alphaType() const { return fInfo.alphaType(); }
|
SkAlphaType alphaType() const { return fInfo.alphaType(); }
|
||||||
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
|
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
||||||
SkColorProfileType profileType() const { return fInfo.profileType(); }
|
SkColorProfileType profileType() const { return fInfo.profileType(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of bytes per pixel based on the colortype. If the colortype is
|
* Return the number of bytes per pixel based on the colortype. If the colortype is
|
||||||
|
@ -79,6 +79,8 @@ protected:
|
|||||||
|
|
||||||
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named);
|
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named);
|
||||||
|
|
||||||
|
friend Named sk_deduce_named_from_colorspace(SkColorSpace*);
|
||||||
|
|
||||||
const GammaNamed fGammaNamed;
|
const GammaNamed fGammaNamed;
|
||||||
const SkMatrix44 fToXYZD50;
|
const SkMatrix44 fToXYZD50;
|
||||||
const Named fNamed;
|
const Named fNamed;
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "SkRect.h"
|
#include "SkRect.h"
|
||||||
#include "SkSize.h"
|
#include "SkSize.h"
|
||||||
|
|
||||||
|
#define SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
||||||
|
|
||||||
class SkReadBuffer;
|
class SkReadBuffer;
|
||||||
class SkWriteBuffer;
|
class SkWriteBuffer;
|
||||||
|
|
||||||
@ -169,12 +171,14 @@ enum SkYUVColorSpace {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
||||||
enum SkColorProfileType {
|
enum SkColorProfileType {
|
||||||
kLinear_SkColorProfileType,
|
kLinear_SkColorProfileType,
|
||||||
kSRGB_SkColorProfileType,
|
kSRGB_SkColorProfileType,
|
||||||
|
|
||||||
kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType
|
kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
enum class SkSourceGammaTreatment {
|
enum class SkSourceGammaTreatment {
|
||||||
kRespect,
|
kRespect,
|
||||||
@ -193,45 +197,19 @@ public:
|
|||||||
, fHeight(0)
|
, fHeight(0)
|
||||||
, fColorType(kUnknown_SkColorType)
|
, fColorType(kUnknown_SkColorType)
|
||||||
, fAlphaType(kUnknown_SkAlphaType)
|
, fAlphaType(kUnknown_SkAlphaType)
|
||||||
, fProfileType(kLinear_SkColorProfileType)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
|
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
|
||||||
SkColorProfileType pt = kLinear_SkColorProfileType) {
|
sk_sp<SkColorSpace> cs = nullptr) {
|
||||||
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
|
return SkImageInfo(width, height, ct, at, std::move(cs));
|
||||||
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
|
|
||||||
return SkImageInfo(width, height, ct, at, pt, cs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
|
|
||||||
sk_sp<SkColorSpace> cs);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets colortype to the native ARGB32 type.
|
* Sets colortype to the native ARGB32 type.
|
||||||
*/
|
*/
|
||||||
static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
|
static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
|
||||||
SkColorProfileType pt = kLinear_SkColorProfileType) {
|
sk_sp<SkColorSpace> cs = nullptr) {
|
||||||
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
|
return Make(width, height, kN32_SkColorType, at, cs);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,60 +217,101 @@ public:
|
|||||||
*/
|
*/
|
||||||
static SkImageInfo MakeS32(int width, int height, SkAlphaType at);
|
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) {
|
static SkImageInfo MakeA8(int width, int height) {
|
||||||
return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType,
|
return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr);
|
||||||
kLinear_SkColorProfileType, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkImageInfo MakeUnknown(int width, int height) {
|
static SkImageInfo MakeUnknown(int width, int height) {
|
||||||
return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType,
|
return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, nullptr);
|
||||||
kLinear_SkColorProfileType, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkImageInfo MakeUnknown() {
|
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 width() const { return fWidth; }
|
||||||
int height() const { return fHeight; }
|
int height() const { return fHeight; }
|
||||||
SkColorType colorType() const { return fColorType; }
|
SkColorType colorType() const { return fColorType; }
|
||||||
SkAlphaType alphaType() const { return fAlphaType; }
|
SkAlphaType alphaType() const { return fAlphaType; }
|
||||||
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
|
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
SkColorProfileType profileType() const { return fProfileType; }
|
|
||||||
|
|
||||||
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
||||||
|
|
||||||
bool isOpaque() const {
|
bool isOpaque() const {
|
||||||
return SkAlphaTypeIsOpaque(fAlphaType);
|
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); }
|
SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
|
||||||
SkIRect bounds() const { return SkIRect::MakeWH(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,
|
* Return a new ImageInfo with the same colortype and alphatype as this info,
|
||||||
* but with the specified width and height.
|
* but with the specified width and height.
|
||||||
*/
|
*/
|
||||||
SkImageInfo makeWH(int newWidth, int newHeight) const {
|
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 {
|
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 {
|
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 {
|
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); }
|
int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
|
||||||
@ -316,12 +335,12 @@ public:
|
|||||||
bool operator==(const SkImageInfo& other) const {
|
bool operator==(const SkImageInfo& other) const {
|
||||||
return fWidth == other.fWidth && fHeight == other.fHeight &&
|
return fWidth == other.fWidth && fHeight == other.fHeight &&
|
||||||
fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
|
fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
|
||||||
fProfileType == other.fProfileType && fColorSpace == other.fColorSpace;
|
fColorSpace == other.fColorSpace;
|
||||||
}
|
}
|
||||||
bool operator!=(const SkImageInfo& other) const {
|
bool operator!=(const SkImageInfo& other) const {
|
||||||
return fWidth != other.fWidth || fHeight != other.fHeight ||
|
return fWidth != other.fWidth || fHeight != other.fHeight ||
|
||||||
fColorType != other.fColorType || fAlphaType != other.fAlphaType ||
|
fColorType != other.fColorType || fAlphaType != other.fAlphaType ||
|
||||||
fProfileType != other.fProfileType || fColorSpace != other.fColorSpace;
|
fColorSpace != other.fColorSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unflatten(SkReadBuffer&);
|
void unflatten(SkReadBuffer&);
|
||||||
@ -348,12 +367,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
|
fColorSpace = nullptr;
|
||||||
fWidth = 0;
|
fWidth = 0;
|
||||||
fHeight = 0;
|
fHeight = 0;
|
||||||
fColorType = kUnknown_SkColorType;
|
fColorType = kUnknown_SkColorType;
|
||||||
fAlphaType = kUnknown_SkAlphaType;
|
fAlphaType = kUnknown_SkAlphaType;
|
||||||
fProfileType = kLinear_SkColorProfileType;
|
|
||||||
fColorSpace = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDEBUGCODE(void validate() const;)
|
SkDEBUGCODE(void validate() const;)
|
||||||
@ -364,16 +382,13 @@ private:
|
|||||||
int fHeight;
|
int fHeight;
|
||||||
SkColorType fColorType;
|
SkColorType fColorType;
|
||||||
SkAlphaType fAlphaType;
|
SkAlphaType fAlphaType;
|
||||||
SkColorProfileType fProfileType;
|
|
||||||
|
|
||||||
SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt,
|
SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
|
||||||
sk_sp<SkColorSpace> cs)
|
|
||||||
: fColorSpace(std::move(cs))
|
: fColorSpace(std::move(cs))
|
||||||
, fWidth(width)
|
, fWidth(width)
|
||||||
, fHeight(height)
|
, fHeight(height)
|
||||||
, fColorType(ct)
|
, fColorType(ct)
|
||||||
, fAlphaType(at)
|
, fAlphaType(at)
|
||||||
, fProfileType(pt)
|
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -252,8 +252,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM
|
|||||||
SkBitmap result;
|
SkBitmap result;
|
||||||
// Note: pass along the profile information even thought this is no the right answer because
|
// Note: pass along the profile information even thought this is no the right answer because
|
||||||
// this could be scaling in sRGB.
|
// this could be scaling in sRGB.
|
||||||
result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight,
|
result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, source.alphaType(),
|
||||||
source.alphaType(), source.info().profileType()));
|
sk_ref_sp(source.info().colorSpace())));
|
||||||
result.allocPixels(allocator, nullptr);
|
result.allocPixels(allocator, nullptr);
|
||||||
|
|
||||||
SkPixmap resultPM;
|
SkPixmap resultPM;
|
||||||
|
@ -788,7 +788,7 @@ SkShader::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo&
|
|||||||
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
|
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
|
||||||
return SkShader::ContextRec::kPM4f_DstType;
|
return SkShader::ContextRec::kPM4f_DstType;
|
||||||
#else
|
#else
|
||||||
return (dstInfo.isSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType)
|
return (dstInfo.gammaCloseToSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType)
|
||||||
? SkShader::ContextRec::kPM4f_DstType
|
? SkShader::ContextRec::kPM4f_DstType
|
||||||
: SkShader::ContextRec::kPMColor_DstType;
|
: SkShader::ContextRec::kPMColor_DstType;
|
||||||
#endif
|
#endif
|
||||||
@ -922,7 +922,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
|
|||||||
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
|
#ifdef SK_FORCE_PM4f_FOR_L32_BLITS
|
||||||
if (true)
|
if (true)
|
||||||
#else
|
#else
|
||||||
if (device.info().isSRGB())
|
if (device.info().gammaCloseToSRGB())
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
blitter = SkBlitter_ARGB32_Create(device, *paint, shaderContext, allocator);
|
blitter = SkBlitter_ARGB32_Create(device, *paint, shaderContext, allocator);
|
||||||
|
@ -10,6 +10,57 @@
|
|||||||
#include "SkReadBuffer.h"
|
#include "SkReadBuffer.h"
|
||||||
#include "SkWriteBuffer.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.
|
// Indicate how images and gradients should interpret colors by default.
|
||||||
bool gDefaultProfileIsSRGB;
|
bool gDefaultProfileIsSRGB;
|
||||||
|
|
||||||
@ -18,10 +69,6 @@ SkColorProfileType SkDefaultColorProfile() {
|
|||||||
: kLinear_SkColorProfileType;
|
: kLinear_SkColorProfileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool profile_type_is_valid(SkColorProfileType profileType) {
|
|
||||||
return (profileType >= 0) && (profileType <= kLastEnum_SkColorProfileType);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool alpha_type_is_valid(SkAlphaType alphaType) {
|
static bool alpha_type_is_valid(SkAlphaType alphaType) {
|
||||||
return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
|
return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
|
||||||
}
|
}
|
||||||
@ -30,19 +77,8 @@ static bool color_type_is_valid(SkColorType colorType) {
|
|||||||
return (colorType >= 0) && (colorType <= kLastEnum_SkColorType);
|
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) {
|
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));
|
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,23 +88,43 @@ void SkImageInfo::unflatten(SkReadBuffer& buffer) {
|
|||||||
|
|
||||||
uint32_t packed = buffer.read32();
|
uint32_t packed = buffer.read32();
|
||||||
SkASSERT(0 == (packed >> 24));
|
SkASSERT(0 == (packed >> 24));
|
||||||
fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF);
|
|
||||||
fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
|
|
||||||
fColorType = (SkColorType)((packed >> 0) & 0xFF);
|
fColorType = (SkColorType)((packed >> 0) & 0xFF);
|
||||||
buffer.validate(profile_type_is_valid(fProfileType) &&
|
fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
|
||||||
alpha_type_is_valid(fAlphaType) &&
|
SkFlattenColorSpaceEnum csenum = (SkFlattenColorSpaceEnum)((packed >> 16) & 0xFF);
|
||||||
color_type_is_valid(fColorType));
|
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 {
|
void SkImageInfo::flatten(SkWriteBuffer& buffer) const {
|
||||||
buffer.write32(fWidth);
|
buffer.write32(fWidth);
|
||||||
buffer.write32(fHeight);
|
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 == (fAlphaType & ~0xFF));
|
||||||
SkASSERT(0 == (fColorType & ~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);
|
buffer.write32(packed);
|
||||||
|
|
||||||
|
if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
|
||||||
|
// TODO: write the ICCProfile blob
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
||||||
|
Loading…
Reference in New Issue
Block a user