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

Side by Side Diff: gm/bitmapimage.cpp

Issue 2061783002: Fix SkImage::asLegacyBitmap() to respect color space info (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/image/SkImage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "Resources.h"
10
11 namespace skiagm {
12
13 class BitmapImageGM : public GM {
14 public:
15 BitmapImageGM() {}
16
17 protected:
18
19 SkString onShortName() override {
20 return SkString("bitmap-image-srgb-linear");
21 }
22
23 SkISize onISize() override {
24 return SkISize::Make(2*kSize, 2*kSize);
25 }
26
27 void onDraw(SkCanvas* canvas) override {
28 // Create image.
29 sk_sp<SkImage> image = GetResourceAsImage("mandrill_512_q075.jpg");
30 if (!image) {
31 SkDebugf("Failure: Is the resource path set properly?");
32 return;
33 }
34
35 // Create matching bitmap.
36 SkBitmap bitmap;
37 SkAssertResult(image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapM ode));
38
39 // The GM will be displayed in a 2x2 grid.
40 // The top two squares show an sRGB image, then bitmap, drawn to a linea r canvas.
41 SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_Sk AlphaType);
42 SkBitmap linearBMCanvas;
43 linearBMCanvas.allocPixels(linearInfo);
44 SkCanvas linearCanvas(linearBMCanvas);
45 linearCanvas.drawImage(image, 0.0f, 0.0f, nullptr);
46 linearCanvas.translate(SkScalar(kSize), 0.0f);
47 linearCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
48 canvas->drawBitmap(linearBMCanvas, 0.0f, 0.0f, nullptr);
49 canvas->translate(0.0f, SkScalar(kSize));
50
51 // The bottom two squares show an sRGB image, then bitmap, drawn to a sr gb canvas.
52 SkImageInfo srgbInfo = SkImageInfo::MakeS32(2*kSize, kSize, kOpaque_SkAl phaType);
53 SkBitmap srgbBMCanvas;
54 srgbBMCanvas.allocPixels(srgbInfo);
55 SkCanvas srgbCanvas(srgbBMCanvas);
56 srgbCanvas.drawImage(image, 0.0f, 0.0f, nullptr);
57 srgbCanvas.translate(SkScalar(kSize), 0.0f);
58 srgbCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
59 canvas->drawBitmap(srgbBMCanvas, 0.0f, 0.0f, nullptr);
60 }
61
62 private:
63 static constexpr int kSize = 512;
64
65 typedef GM INHERITED;
66 };
67
68 //////////////////////////////////////////////////////////////////////////////
69
70 static GM* MyFactory(void*) { return new BitmapImageGM; }
71 static GMRegistry reg(MyFactory);
72
73 }
OLDNEW
« no previous file with comments | « no previous file | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698