encode F16/F32 .pngs as Rec2020

This lets us see more of the range of configs like esrgb.

Change-Id: Id8fe3d6d7545b139d905e4a0e587228c85159043
Reviewed-on: https://skia-review.googlesource.com/154380
Auto-Submit: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2018-09-13 11:13:15 -04:00 committed by Skia Commit-Bot
parent 1a0f189049
commit ae4b1f484c

View File

@ -828,6 +828,23 @@ static bool gather_srcs() {
return true;
}
static sk_sp<SkColorSpace> rec2020() {
// See https://en.wikipedia.org/wiki/Rec._2020
float alpha = 1.09929682680944f,
beta = 0.018053968510807f,
gamma = 0.45f;
SkColorSpaceTransferFn rec2020_TF = SkColorSpaceTransferFn{
gamma,
powf(alpha, 1/gamma),
0.0f,
4.5f,
beta,
1 - alpha,
0.0f,
}.invert();
return SkColorSpace::MakeRGB(rec2020_TF, SkColorSpace::kRec2020_Gamut);
}
static void push_sink(const SkCommandLineConfig& config, Sink* s) {
std::unique_ptr<Sink> sink(s);
@ -921,26 +938,11 @@ static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLi
SkMatrix44 narrow_gamut(SkMatrix44::kUninitialized_Constructor);
narrow_gamut.set3x3RowMajorf(gNarrow_toXYZD50);
// See https://en.wikipedia.org/wiki/Rec._2020
float alpha = 1.09929682680944f,
beta = 0.018053968510807f,
gamma = 0.45f;
SkColorSpaceTransferFn rec2020_TF = SkColorSpaceTransferFn{
gamma,
powf(alpha, 1/gamma),
0.0f,
4.5f,
beta,
1 - alpha,
0.0f,
}.invert();
auto narrow = SkColorSpace::MakeRGB(k2Dot2Curve_SkGammaNamed, narrow_gamut),
srgb = SkColorSpace::MakeSRGB(),
srgbLinear = SkColorSpace::MakeSRGBLinear(),
p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
SkColorSpace::kDCIP3_D65_Gamut),
rec2020 = SkColorSpace::MakeRGB(rec2020_TF, SkColorSpace::kRec2020_Gamut);
SkColorSpace::kDCIP3_D65_Gamut);
SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
@ -949,8 +951,8 @@ static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLi
SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020 );
SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020 );
SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
}
@ -1066,6 +1068,15 @@ static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
strlen(comments[2])+1, strlen(comments[3])+1,
};
// PNGs can't hold out-of-gamut values, so if we're likely to be holding them,
// convert to a wide gamut, giving us the best chance to have the PNG look like our colors.
SkBitmap wide;
if (pm.colorType() >= kRGBA_F16_SkColorType) {
wide.allocPixels(pm.info().makeColorSpace(rec2020()));
SkAssertResult(wide.writePixels(pm, 0,0));
SkAssertResult(wide.peekPixels(&pm));
}
SkPngEncoder::Options options;
options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;