OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include <vector> | 10 #include <vector> |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 otherContextInfo.grContext(), buffer, budgeted)); | 931 otherContextInfo.grContext(), buffer, budgeted)); |
932 REPORTER_ASSERT(reporter, !newImage2); | 932 REPORTER_ASSERT(reporter, !newImage2); |
933 testContext->makeCurrent(); | 933 testContext->makeCurrent(); |
934 } | 934 } |
935 } | 935 } |
936 sk_free(buffer); | 936 sk_free(buffer); |
937 } | 937 } |
938 } | 938 } |
939 } | 939 } |
940 #endif | 940 #endif |
| 941 |
| 942 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 943 |
| 944 static void make_all_premul(SkBitmap* bm) { |
| 945 bm->allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); |
| 946 for (int a = 0; a < 256; ++a) { |
| 947 for (int r = 0; r < 256; ++r) { |
| 948 // make all valid premul combinations |
| 949 int c = SkTMin(a, r); |
| 950 *bm->getAddr32(a, r) = SkPackARGB32(a, c, c, c); |
| 951 } |
| 952 } |
| 953 } |
| 954 |
| 955 static bool equal(const SkBitmap& a, const SkBitmap& b) { |
| 956 SkASSERT(a.width() == b.width()); |
| 957 SkASSERT(a.height() == b.height()); |
| 958 for (int y = 0; y < a.height(); ++y) { |
| 959 if (0 != memcmp(a.getAddr32(0, y), b.getAddr32(0, y), a.width() * sizeof
(SkPMColor))) { |
| 960 return false; |
| 961 } |
| 962 } |
| 963 return true; |
| 964 } |
| 965 |
| 966 DEF_TEST(image_roundtrip_encode, reporter) { |
| 967 SkBitmap bm0; |
| 968 make_all_premul(&bm0); |
| 969 |
| 970 auto img0 = SkImage::MakeFromBitmap(bm0); |
| 971 sk_sp<SkData> data(img0->encode(SkImageEncoder::kPNG_Type, 100)); |
| 972 auto img1 = SkImage::MakeFromEncoded(data); |
| 973 |
| 974 SkBitmap bm1; |
| 975 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); |
| 976 img1->readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); |
| 977 |
| 978 REPORTER_ASSERT(reporter, equal(bm0, bm1)); |
| 979 } |
| 980 |
| 981 DEF_TEST(image_roundtrip_premul, reporter) { |
| 982 SkBitmap bm0; |
| 983 make_all_premul(&bm0); |
| 984 |
| 985 SkBitmap bm1; |
| 986 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); |
| 987 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); |
| 988 |
| 989 SkBitmap bm2; |
| 990 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); |
| 991 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); |
| 992 |
| 993 REPORTER_ASSERT(reporter, equal(bm0, bm2)); |
| 994 } |
OLD | NEW |