aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ImageIsOpaqueTest.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-11-10 08:57:21 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-10 08:57:21 -0800
commit7c74885e017a2473383fed72bd629cc07c773942 (patch)
treeea55901c52a56a80c46e42cf8ef0aab5f11ba3a3 /tests/ImageIsOpaqueTest.cpp
parent6beeb8f3cc323dabed0905920a336ed77aa5c46d (diff)
flag imageinfo as srgb
intended uses: - flag a SkSurface as sRGB (only supported by Ganesh for now) - flag images (e.g. png or jpeg) as sRGB if the codec tells us that wins: - faster gamma-correct text (esp. w/ distance-fields) when we can use sRGB for text - better color fidelity when the screen really is sRGB Review URL: https://codereview.chromium.org/676883003
Diffstat (limited to 'tests/ImageIsOpaqueTest.cpp')
-rw-r--r--tests/ImageIsOpaqueTest.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp
index 3fe5b3db0c..6fdbc8127a 100644
--- a/tests/ImageIsOpaqueTest.cpp
+++ b/tests/ImageIsOpaqueTest.cpp
@@ -6,13 +6,47 @@
*/
#include "SkTypes.h"
+#include "Test.h"
+
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
#endif
#include "SkImage.h"
#include "SkSurface.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
-#include "Test.h"
+static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info) {
+ // just need a safe amount of storage
+ char storage[sizeof(SkImageInfo)*2];
+ SkWriteBuffer wb(storage, sizeof(storage));
+ info.flatten(wb);
+ SkASSERT(wb.bytesWritten() < sizeof(storage));
+
+ SkReadBuffer rb(storage, wb.bytesWritten());
+ SkImageInfo info2;
+
+ // pick a noisy byte pattern, so we ensure that unflatten sets all of our fields
+ memset(&info2, 0xB8, sizeof(info2));
+
+ info2.unflatten(rb);
+ REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten());
+ REPORTER_ASSERT(reporter, info == info2);
+}
+
+DEF_TEST(ImageInfo_flattening, reporter) {
+ for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
+ for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) {
+ for (int pt = 0; pt <= kLastEnum_SkColorProfileType; ++pt) {
+ SkImageInfo info = SkImageInfo::Make(100, 200,
+ static_cast<SkColorType>(ct),
+ static_cast<SkAlphaType>(at),
+ static_cast<SkColorProfileType>(pt));
+ test_flatten(reporter, info);
+ }
+ }
+ }
+}
static void check_isopaque(skiatest::Reporter* reporter, SkSurface* surface, bool expectedOpaque) {
SkAutoTUnref<SkImage> image(surface->newImageSnapshot());