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 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) { | 90 DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) { |
91 sk_sp<SkImage> limg = make(nullptr); | 91 sk_sp<SkImage> limg = make(nullptr); |
92 sk_sp<SkImage> simg = make(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
); | 92 sk_sp<SkImage> simg = make(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
); |
93 | 93 |
94 canvas->translate(10, 10); | 94 canvas->translate(10, 10); |
95 show_mips(canvas, limg.get()); | 95 show_mips(canvas, limg.get()); |
96 canvas->translate(0, limg->height() + 10.0f); | 96 canvas->translate(0, limg->height() + 10.0f); |
97 show_mips(canvas, simg.get()); | 97 show_mips(canvas, simg.get()); |
98 } | 98 } |
99 | 99 |
| 100 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 101 |
| 102 // create a gradient image computed raw, so we can wrap it as a linear or srgb i
mage |
| 103 static sk_sp<SkImage> make_g8_gradient(sk_sp<SkColorSpace> cs) { |
| 104 const int N = 100; |
| 105 SkImageInfo info = SkImageInfo::Make(N, N, kGray_8_SkColorType, kOpaque_SkAl
phaType, cs); |
| 106 SkBitmap bm; |
| 107 bm.allocPixels(info); |
| 108 |
| 109 for (int y = 0; y < N; ++y) { |
| 110 for (int x = 0; x < N; ++x) { |
| 111 *bm.getAddr8(x, y) = static_cast<uint8_t>(255.0f * ((x + y) / (2.0f
* (N - 1)))); |
| 112 } |
| 113 } |
| 114 bm.setImmutable(); |
| 115 return SkImage::MakeFromBitmap(bm); |
| 116 } |
| 117 |
| 118 static void show_mips_only(SkCanvas* canvas, SkImage* img) { |
| 119 SkPaint paint; |
| 120 paint.setFilterQuality(kMedium_SkFilterQuality); |
| 121 |
| 122 // Want to ensure we never draw fractional pixels, so we use an IRect |
| 123 SkIRect dst = SkIRect::MakeWH(img->width() / 2, img->height() / 2); |
| 124 while (dst.width() > 5) { |
| 125 canvas->drawImageRect(img, SkRect::Make(dst), &paint); |
| 126 dst.offset(dst.width() + 10, 0); |
| 127 dst.fRight = dst.fLeft + dst.width() / 2; |
| 128 dst.fBottom = dst.fTop + dst.height() / 2; |
| 129 } |
| 130 } |
| 131 |
| 132 /* |
| 133 * Ensure that in L32 drawing mode, both images/mips look the same as each othe
r, and |
| 134 * their mips are darker than the original (since the mips should ignore the ga
mma in L32). |
| 135 * |
| 136 * Ensure that in S32 drawing mode, all images/mips look the same, and look cor
rect (i.e. |
| 137 * the mip levels match the original in brightness). |
| 138 * |
| 139 * This test also verifies handling of Gray_8 data in Ganesh, which is not done
natively. |
| 140 */ |
| 141 DEF_SIMPLE_GM(mipmap_gray8_srgb, canvas, 260, 230) { |
| 142 sk_sp<SkImage> limg = make_g8_gradient(nullptr); |
| 143 sk_sp<SkImage> simg = make_g8_gradient(SkColorSpace::NewNamed(SkColorSpace::
kSRGB_Named)); |
| 144 |
| 145 canvas->translate(10, 10); |
| 146 show_mips_only(canvas, limg.get()); |
| 147 canvas->translate(0, limg->height() + 10.0f); |
| 148 show_mips_only(canvas, simg.get()); |
| 149 } |
OLD | NEW |