38#include <initializer_list>
49 return 1.055f * powf(
linear, 1.f / 2.4f) - 0.055f;
55 if (srgb <= 0.04045f) {
58 return powf((srgb + 0.055f) / 1.055f, 2.4f);
65 uint32_t expectedColor =
src & 0xff000000;
68 if ((
src & 0xff000000) != (
dst & 0xff000000)) {
76 invScale = 255.0f / alpha;
79 for (
int c = 0; c < 3; ++c) {
80 float srcComponent = ((
src & (0xff << (c * 8))) >> (c * 8)) * invScale;
93 SkASSERT(upper >= 0.f && upper <= 255.f);
94 uint8_t dstComponent = (
dst & (0xff << (c * 8))) >> (c * 8);
100 expectedColor |= expectedComponent << (c * 8);
103 *expected = expectedColor;
108 auto context = ctxInfo.directContext();
109 static constexpr SkISize kBaseSize{256, 256};
110 static const size_t kRowBytes =
sizeof(uint32_t) * kBaseSize.
fWidth;
115 for (
int y = 0;
y < kBaseSize.fHeight; ++
y) {
116 for (
int x = 0;
x < kBaseSize.fWidth; ++
x) {
128 float error = context->priv().caps()->shaderCaps()->fHalfIs32Bits ? 0.5f : 1.2f;
130 for (
auto toSRGB : {
false,
true }) {
134 ERRORF(
reporter,
"Could not create surfaces for copy surface test.");
152 if (!
dst->readPixels(ii,
read.get(), kRowBytes, 0, 0)) {
159 for (
int y = 0;
y < kBaseSize.fHeight && !abort; ++
y) {
160 for (
int x = 0;
x < kBaseSize.fWidth && !abort; ++
x) {
161 uint32_t r =
read.get()[
y * kBaseSize.fWidth +
x];
162 uint32_t
s = srcPixels.
get()[
y * kBaseSize.fWidth +
x];
166 "from src 0x%08x and mode %s. Got %08x",
x,
y, expected,
s,
167 toSRGB ?
"ToSRGB" :
"ToLinear", r);
static float linear_to_srgb(float linear)
static float srgb_to_linear(float srgb)
bool check_gamma(uint32_t src, uint32_t dst, bool toSRGB, float error, uint32_t *expected)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo, CtsEnforcement::kNever)
#define SkGetPackedA32(packed)
SK_API SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
constexpr SkColor SK_ColorRED
static bool read(SkStream *stream, void *buffer, size_t amount)
#define SkScalarRoundToInt(x)
#define SkScalarCeilToInt(x)
#define SkScalarFloorToInt(x)
#define ApplyGamma(table, alpha)
sk_sp< SkImage > asImage() const
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
void clear(SkColor color)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkColorFilter > SRGBToLinearGamma()
static sk_sp< SkColorFilter > LinearToSRGBGamma()
void setBlendMode(SkBlendMode mode)
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
const uint8_t uint32_t uint32_t GError ** error
static float max(float r, float g, float b)
static float min(float r, float g, float b)
void(* memset32)(uint32_t[], uint32_t, int)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)