Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: include/core/SkImageInfo.h

Issue 532583002: Revert of Revert of Add gamma/sRGB tag to SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | src/core/SkImageInfo.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkImageInfo.h
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 3d82dc805c7998084986878283da43ef9f35b7b8..7a56fb4557ce349394a8b44335b21d16a672fbda 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -135,37 +135,50 @@
/**
* Describe an image's dimensions and pixel type.
*/
-struct SkImageInfo {
+struct SK_API SkImageInfo {
+public:
+ SkImageInfo() {}
+
int fWidth;
int fHeight;
SkColorType fColorType;
SkAlphaType fAlphaType;
+ /*
+ * Return an info with the specified attributes, tagged as sRGB. Note that if the requested
+ * color type does not make sense with sRGB (e.g. kAlpha_8) then the sRGB request is ignored.
+ *
+ * You can call isSRGB() on the returned info to determine if the request was fulfilled.
+ */
+ static SkImageInfo MakeSRGB(int width, int height, SkColorType ct, SkAlphaType at);
+
+ /*
+ * Return an info with the specified attributes, tagged with a specific gamma.
+ * Note that if the requested gamma is unsupported for the requested color type, then the gamma
+ * value will be set to 1.0 (the default).
+ *
+ * You can call gamma() to query the resulting gamma value.
+ */
+ static SkImageInfo MakeWithGamma(int width, int height, SkColorType ct, SkAlphaType at,
+ float gamma);
+
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) {
- SkImageInfo info = {
- width, height, ct, at
- };
- return info;
+ return MakeWithGamma(width, height, ct, at, 1);
}
/**
* Sets colortype to the native ARGB32 type.
*/
static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
- SkImageInfo info = {
- width, height, kN32_SkColorType, at
- };
- return info;
+ return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Profile, 1);
}
/**
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
*/
static SkImageInfo MakeN32Premul(int width, int height) {
- SkImageInfo info = {
- width, height, kN32_SkColorType, kPremul_SkAlphaType
- };
- return info;
+ return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType,
+ kExponential_Profile, 1);
}
/**
@@ -176,24 +189,17 @@
}
static SkImageInfo MakeA8(int width, int height) {
- SkImageInfo info = {
- width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
- };
- return info;
+ return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType,
+ kUnknown_Profile, 0);
}
static SkImageInfo MakeUnknown(int width, int height) {
- SkImageInfo info = {
- width, height, kUnknown_SkColorType, kIgnore_SkAlphaType
- };
- return info;
+ return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaType,
+ kUnknown_Profile, 0);
}
static SkImageInfo MakeUnknown() {
- SkImageInfo info = {
- 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType
- };
- return info;
+ return SkImageInfo(0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType, kUnknown_Profile, 0);
}
int width() const { return fWidth; }
@@ -236,8 +242,11 @@
return 0 != memcmp(this, &other, sizeof(other));
}
+ // DEPRECATED : use the static Unflatten
void unflatten(SkReadBuffer&);
void flatten(SkWriteBuffer&) const;
+
+ static SkImageInfo Unflatten(SkReadBuffer&);
int64_t getSafeSize64(size_t rowBytes) const {
if (0 == fHeight) {
@@ -256,6 +265,36 @@
}
SkDEBUGCODE(void validate() const;)
+
+ /**
+ * If the Info was tagged to be sRGB, return true, else return false.
+ */
+ bool isSRGB() const { return kSRGB_Profile == fProfile; }
+
+ /**
+ * If this was tagged with an explicit gamma value, return that value, else return 0.
+ * If this was tagged as sRGB, return 0.
+ */
+ float gamma() const { return fGamma; }
+
+private:
+ enum Profile {
+ kUnknown_Profile,
+ kSRGB_Profile,
+ kExponential_Profile,
+ };
+
+ uint32_t fProfile;
+ float fGamma;
+
+ SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, Profile p, float g)
+ : fWidth(width)
+ , fHeight(height)
+ , fColorType(ct)
+ , fAlphaType(at)
+ , fProfile(p)
+ , fGamma(g)
+ {}
};
#endif
« no previous file with comments | « gyp/tests.gypi ('k') | src/core/SkImageInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698