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 "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 | 12 |
13 DEF_SIMPLE_GM(gamma, canvas, 500, 200) { | 13 DEF_SIMPLE_GM(gamma, canvas, 560, 200) { |
14 SkPaint p; | 14 SkPaint p; |
15 const SkScalar sz = 50.0f; | 15 const SkScalar sz = 50.0f; |
16 const int szInt = SkScalarTruncToInt(sz); | 16 const int szInt = SkScalarTruncToInt(sz); |
17 const SkScalar tx = sz + 5.0f; | 17 const SkScalar tx = sz + 5.0f; |
18 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); | 18 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); |
19 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; | 19 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; |
20 | 20 |
21 SkBitmap ditherBmp; | 21 SkBitmap ditherBmp; |
22 ditherBmp.allocN32Pixels(2, 2); | 22 ditherBmp.allocN32Pixels(2, 2); |
23 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(ditherBmp.getPixels()); | 23 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(ditherBmp.getPixels()); |
24 pixels[0] = pixels[3] = SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF); | 24 pixels[0] = pixels[3] = SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF); |
25 pixels[1] = pixels[2] = SkPackARGB32(0xFF, 0, 0, 0); | 25 pixels[1] = pixels[2] = SkPackARGB32(0xFF, 0, 0, 0); |
26 | 26 |
27 SkBitmap linearGreyBmp; | 27 SkBitmap linearGreyBmp; |
28 SkImageInfo linearGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAl
phaType, | 28 SkImageInfo linearGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAl
phaType, |
29 kLinear_SkColorProfileType
); | 29 kLinear_SkColorProfileType
); |
30 linearGreyBmp.allocPixels(linearGreyInfo); | 30 linearGreyBmp.allocPixels(linearGreyInfo); |
31 linearGreyBmp.eraseARGB(0xFF, 0x7F, 0x7F, 0x7F); | 31 linearGreyBmp.eraseARGB(0xFF, 0x7F, 0x7F, 0x7F); |
32 | 32 |
33 SkBitmap srgbGreyBmp; | 33 SkBitmap srgbGreyBmp; |
34 SkImageInfo srgbGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlph
aType, | 34 SkImageInfo srgbGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlph
aType, |
35 kSRGB_SkColorProfileType); | 35 kSRGB_SkColorProfileType); |
36 srgbGreyBmp.allocPixels(srgbGreyInfo); | 36 srgbGreyBmp.allocPixels(srgbGreyInfo); |
| 37 // 0xBC = 255 * linear_to_srgb(0.5f) |
37 srgbGreyBmp.eraseARGB(0xFF, 0xBC, 0xBC, 0xBC); | 38 srgbGreyBmp.eraseARGB(0xFF, 0xBC, 0xBC, 0xBC); |
38 | 39 |
| 40 SkBitmap mipmapBmp; |
| 41 SkImageInfo mipmapInfo = SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType, |
| 42 kSRGB_SkColorProfileType); |
| 43 mipmapBmp.allocPixels(mipmapInfo); |
| 44 SkPMColor* mipmapPixels = reinterpret_cast<SkPMColor*>(mipmapBmp.getPixels()
); |
| 45 // 0x89 = 255 * linear_to_srgb(0.25f) |
| 46 mipmapPixels[0] = mipmapPixels[3] = SkPackARGB32(0xFF, 0x89, 0x89, 0x89); |
| 47 // 0xE1 = 255 * linear_to_srgb(0.75f) |
| 48 mipmapPixels[1] = mipmapPixels[2] = SkPackARGB32(0xFF, 0xE1, 0xE1, 0xE1); |
| 49 |
39 SkPaint textPaint; | 50 SkPaint textPaint; |
40 textPaint.setColor(SK_ColorWHITE); | 51 textPaint.setColor(SK_ColorWHITE); |
41 | 52 |
42 // Helpers: | 53 // Helpers: |
43 auto advance = [&]() { | 54 auto advance = [&]() { |
44 canvas->translate(tx, 0); | 55 canvas->translate(tx, 0); |
45 p.reset(); | 56 p.reset(); |
46 }; | 57 }; |
47 | 58 |
48 auto nextRect = [&](const char* label, const char* label2) { | 59 auto nextRect = [&](const char* label, const char* label2) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix)); | 111 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix)); |
101 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 112 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
102 nextRect("Dither", "Bilerp"); | 113 nextRect("Dither", "Bilerp"); |
103 | 114 |
104 // Black/white dither, scaled down by 2x. Tests minification. | 115 // Black/white dither, scaled down by 2x. Tests minification. |
105 SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f); | 116 SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f); |
106 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix)); | 117 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix)); |
107 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 118 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
108 nextRect("Dither", "Scale"); | 119 nextRect("Dither", "Scale"); |
109 | 120 |
| 121 // 25%/75% dither, scaled down by 2x. Tests ALL aspects of minification. Spe
cifically, are |
| 122 // sRGB sources decoded to linear before computing mipmaps? |
| 123 p.setShader(SkShader::MakeBitmapShader(mipmapBmp, rpt, rpt, &scaleMatrix)); |
| 124 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 125 nextRect("MipMaps", 0); |
| 126 |
110 // 50% grey via paint color. | 127 // 50% grey via paint color. |
111 p.setColor(0xff7f7f7f); | 128 p.setColor(0xff7f7f7f); |
112 nextRect("Color", 0); | 129 nextRect("Color", 0); |
113 | 130 |
114 // Black -> White gradient, scaled to sample just the middle. | 131 // Black -> White gradient, scaled to sample just the middle. |
115 // Tests gradient interpolation. | 132 // Tests gradient interpolation. |
116 SkPoint points[2] = { | 133 SkPoint points[2] = { |
117 SkPoint::Make(0 - (sz * 10), 0), | 134 SkPoint::Make(0 - (sz * 10), 0), |
118 SkPoint::Make(sz + (sz * 10), 0) | 135 SkPoint::Make(sz + (sz * 10), 0) |
119 }; | 136 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); | 174 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); |
158 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); | 175 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); |
159 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); | 176 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); |
160 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); | 177 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); |
161 | 178 |
162 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); | 179 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); |
163 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); | 180 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); |
164 | 181 |
165 canvas->restore(); | 182 canvas->restore(); |
166 } | 183 } |
OLD | NEW |