Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: gm/mipmap.cpp

Issue 2029373004: respect srgb gamma when building mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gm/mipmap.cpp
diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp
index ae73a8de9db19259bd4114cfa50b54acd552333f..1ce8d0b263cd0ec7e85def54fa52602c531dafca 100644
--- a/gm/mipmap.cpp
+++ b/gm/mipmap.cpp
@@ -11,8 +11,8 @@
#include "SkRandom.h"
#include "SkSurface.h"
-static sk_sp<SkImage> make_image() {
- const SkImageInfo info = SkImageInfo::MakeN32Premul(319, 52);
+static sk_sp<SkImage> make_image(bool useSRGB) {
Brian Osman 2016/06/10 13:37:14 Want to make sure I understand the changes to this
reed1 2016/06/10 14:26:04 reverted
+ const SkImageInfo info = SkImageInfo::MakeS32(319, 52, kPremul_SkAlphaType);
auto surface(SkSurface::MakeRaster(info));
SkCanvas* canvas = surface->getCanvas();
canvas->drawColor(sk_tool_utils::color_to_565(0xFFF8F8F8));
@@ -21,29 +21,42 @@ static sk_sp<SkImage> make_image() {
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(2);
for (int i = 0; i < 20; ++i) {
canvas->drawCircle(-4, 25, 20, paint);
canvas->translate(25, 0);
}
- return surface->makeImageSnapshot();
+ auto img = surface->makeImageSnapshot();
+ if (useSRGB) {
+ return img;
+ } else {
+ SkBitmap bm;
+ bm.allocN32Pixels(info.width(), info.height());
+ img->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0, 0);
+ bm.setImmutable();
+ return SkImage::MakeFromBitmap(bm);
+ }
}
-DEF_SIMPLE_GM(mipmap, canvas, 400, 200) {
- sk_sp<SkImage> img(make_image());//SkImage::NewFromEncoded(data));
-
+DEF_SIMPLE_GM(mipmap, canvas, 420, 200) {
SkPaint paint;
const SkRect dst = SkRect::MakeWH(177, 15);
+ const SkRect clip = SkRect::MakeWH(200, 200);
paint.setTextSize(30);
- SkString str;
- str.printf("scale %g %g", dst.width() / img->width(), dst.height() / img->height());
-// canvas->drawText(str.c_str(), str.size(), 300, 100, paint);
- canvas->translate(20, 20);
- for (int i = 0; i < 4; ++i) {
- paint.setFilterQuality(SkFilterQuality(i));
- canvas->drawImageRect(img.get(), dst, &paint);
- canvas->translate(0, 20);
+ for (bool useSRGB : { false, true }) {
+ sk_sp<SkImage> img(make_image(useSRGB));
+ canvas->save();
+ canvas->clipRect(clip);
+ canvas->translate(20, 20);
+ for (int i = 0; i < 4; ++i) {
+ paint.setFilterQuality(SkFilterQuality(i));
+ canvas->drawImageRect(img.get(), dst, &paint);
+ canvas->translate(0, 20);
+ }
+ canvas->drawImage(img.get(), 0, 20, nullptr);
+ canvas->restore();
+ canvas->translate(200, 0);
}
- canvas->drawImage(img.get(), 20, 20, nullptr);
}

Powered by Google App Engine
This is Rietveld 408576698