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" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 | 13 |
14 static sk_sp<SkImage> make_image() { | 14 static sk_sp<SkImage> make_image(bool useSRGB) { |
15 const SkImageInfo info = SkImageInfo::MakeN32Premul(319, 52); | 15 const SkImageInfo info = SkImageInfo::MakeS32(319, 52, kPremul_SkAlphaType); |
16 auto surface(SkSurface::MakeRaster(info)); | 16 auto surface(SkSurface::MakeRaster(info)); |
17 SkCanvas* canvas = surface->getCanvas(); | 17 SkCanvas* canvas = surface->getCanvas(); |
18 canvas->drawColor(sk_tool_utils::color_to_565(0xFFF8F8F8)); | 18 canvas->drawColor(sk_tool_utils::color_to_565(0xFFF8F8F8)); |
19 | 19 |
20 SkPaint paint; | 20 SkPaint paint; |
21 paint.setAntiAlias(true); | 21 paint.setAntiAlias(true); |
22 | 22 |
23 paint.setStyle(SkPaint::kStroke_Style); | 23 paint.setStyle(SkPaint::kStroke_Style); |
| 24 paint.setStrokeWidth(2); |
24 for (int i = 0; i < 20; ++i) { | 25 for (int i = 0; i < 20; ++i) { |
25 canvas->drawCircle(-4, 25, 20, paint); | 26 canvas->drawCircle(-4, 25, 20, paint); |
26 canvas->translate(25, 0); | 27 canvas->translate(25, 0); |
27 } | 28 } |
28 return surface->makeImageSnapshot(); | 29 auto img = surface->makeImageSnapshot(); |
| 30 if (useSRGB) { |
| 31 return img; |
| 32 } else { |
| 33 SkBitmap bm; |
| 34 bm.allocN32Pixels(info.width(), info.height()); |
| 35 img->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0, 0); |
| 36 bm.setImmutable(); |
| 37 return SkImage::MakeFromBitmap(bm); |
| 38 } |
29 } | 39 } |
30 | 40 |
31 DEF_SIMPLE_GM(mipmap, canvas, 400, 200) { | 41 DEF_SIMPLE_GM(mipmap, canvas, 420, 200) { |
32 sk_sp<SkImage> img(make_image());//SkImage::NewFromEncoded(data)); | |
33 | |
34 SkPaint paint; | 42 SkPaint paint; |
35 const SkRect dst = SkRect::MakeWH(177, 15); | 43 const SkRect dst = SkRect::MakeWH(177, 15); |
| 44 const SkRect clip = SkRect::MakeWH(200, 200); |
36 | 45 |
37 paint.setTextSize(30); | 46 paint.setTextSize(30); |
38 SkString str; | |
39 str.printf("scale %g %g", dst.width() / img->width(), dst.height() / img->he
ight()); | |
40 // canvas->drawText(str.c_str(), str.size(), 300, 100, paint); | |
41 | 47 |
42 canvas->translate(20, 20); | 48 for (bool useSRGB : { false, true }) { |
43 for (int i = 0; i < 4; ++i) { | 49 sk_sp<SkImage> img(make_image(useSRGB)); |
44 paint.setFilterQuality(SkFilterQuality(i)); | 50 canvas->save(); |
45 canvas->drawImageRect(img.get(), dst, &paint); | 51 canvas->clipRect(clip); |
46 canvas->translate(0, 20); | 52 canvas->translate(20, 20); |
| 53 for (int i = 0; i < 4; ++i) { |
| 54 paint.setFilterQuality(SkFilterQuality(i)); |
| 55 canvas->drawImageRect(img.get(), dst, &paint); |
| 56 canvas->translate(0, 20); |
| 57 } |
| 58 canvas->drawImage(img.get(), 0, 20, nullptr); |
| 59 canvas->restore(); |
| 60 canvas->translate(200, 0); |
47 } | 61 } |
48 canvas->drawImage(img.get(), 20, 20, nullptr); | |
49 } | 62 } |
OLD | NEW |