Flutter Engine
The Flutter Engine
Functions | Variables
colorspace.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkSurface.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

static void draw_colorspace_gm (Strategy strategy, SkCanvas *canvas)
 
 DEF_SIMPLE_GM (colorspace, canvas, W *std::size(gTFs), H *std::size(gGamuts))
 
 DEF_SIMPLE_GM (colorspace2, canvas, W *std::size(gTFs), H *std::size(gGamuts))
 

Variables

static const skcms_TransferFunction gTFs []
 
static const skcms_Matrix3x3 gGamuts []
 
static const int W = 128
 
static const int H = 128
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( colorspace  ,
canvas  ,
W std::sizegTFs,
H std::sizegGamuts 
)

Definition at line 118 of file colorspace.cpp.

118 {
119 draw_colorspace_gm(SkImage_makeColorSpace, canvas);
120}
static void draw_colorspace_gm(Strategy strategy, SkCanvas *canvas)
Definition: colorspace.cpp:69

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( colorspace2  ,
canvas  ,
W std::sizegTFs,
H std::sizegGamuts 
)

Definition at line 122 of file colorspace.cpp.

122 {
123 draw_colorspace_gm(SkCanvas_makeSurface, canvas);
124}

◆ draw_colorspace_gm()

static void draw_colorspace_gm ( Strategy  strategy,
SkCanvas canvas 
)
static

Definition at line 69 of file colorspace.cpp.

69 {
71 if (!canvas->imageInfo().colorSpace()) {
72 canvas->drawString("This GM only makes sense with color-managed drawing.",
73 W,H, font, SkPaint{});
74 return;
75 }
76
77 sk_sp<SkImage> img = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
78 if (!img) {
79 canvas->drawString("Could not load our test image!",
80 W,H, font, SkPaint{});
81 return;
82 }
83
84 SkASSERT(img->width() == W);
85 SkASSERT(img->height() == H);
86 SkASSERT(img->colorSpace());
87
88 for (skcms_Matrix3x3 gamut : gGamuts) {
89 canvas->save();
90 for (skcms_TransferFunction tf : gTFs) {
92
93 switch (strategy) {
94 case SkImage_makeColorSpace: {
95 canvas->drawImage(img->makeColorSpace(nullptr, midCS), 0,0);
96 } break;
97
98 case SkCanvas_makeSurface: {
99 sk_sp<SkSurface> offscreen =
100 canvas->makeSurface(canvas->imageInfo().makeColorSpace(midCS));
101 if (!offscreen) {
102 canvas->drawString("Could not allocate offscreen surface!",
103 W,H, font, SkPaint{});
104 return;
105 }
106 offscreen->getCanvas()->drawImage(img, 0,0);
107 canvas->drawImage(offscreen->makeImageSnapshot(), 0,0);
108 } break;
109 }
110
111 canvas->translate(W, 0);
112 }
113 canvas->restore();
114 canvas->translate(0, H);
115 }
116}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
Definition: SkFont.h:35
virtual sk_sp< SkImage > makeColorSpace(GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
SkColorSpace * colorSpace() const
Definition: SkImage.cpp:156
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90
static const skcms_Matrix3x3 gGamuts[]
Definition: colorspace.cpp:27
static const skcms_TransferFunction gTFs[]
Definition: colorspace.cpp:17
static const int W
Definition: colorspace.cpp:35
SkFont DefaultPortableFont()
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
font
Font Metadata and Metrics.
Definition: SkMD5.cpp:130
SkColorSpace * colorSpace() const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const

Variable Documentation

◆ gGamuts

const skcms_Matrix3x3 gGamuts[]
static
Initial value:
= {
}
static constexpr skcms_Matrix3x3 kSRGB
Definition: SkColorSpace.h:67
static constexpr skcms_Matrix3x3 kAdobeRGB
Definition: SkColorSpace.h:77
static constexpr skcms_Matrix3x3 kXYZ
Definition: SkColorSpace.h:99
static constexpr skcms_Matrix3x3 kRec2020
Definition: SkColorSpace.h:93
static constexpr skcms_Matrix3x3 kDisplayP3
Definition: SkColorSpace.h:87

Definition at line 27 of file colorspace.cpp.

◆ gTFs

const skcms_TransferFunction gTFs[]
static
Initial value:
= {
{-3.0f, 2.0f, 2.0f, 1/0.17883277f, 0.28466892f, 0.55991073f, 3.0f },
}
static constexpr skcms_TransferFunction kRec2020
Definition: SkColorSpace.h:54
static constexpr skcms_TransferFunction k2Dot2
Definition: SkColorSpace.h:48
static constexpr skcms_TransferFunction kSRGB
Definition: SkColorSpace.h:45
static constexpr skcms_TransferFunction kHLG
Definition: SkColorSpace.h:60
static constexpr skcms_TransferFunction kPQ
Definition: SkColorSpace.h:57
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51

Definition at line 17 of file colorspace.cpp.

◆ H

const int H = 128
static

Definition at line 36 of file colorspace.cpp.

◆ W

const int W = 128
static

Definition at line 35 of file colorspace.cpp.