b62f50cf76
- Encoders and decoders always assume kIgnore. - They are less opinionated about F16 and color space, we just trust the color space that's passed in, and put that directly in the image (no sRGB encoding). - SkBitmap and SkPixmap read/write pixels functions were defaulting to kResepct, those are now always kIgnore. - Many other bits of plumbing are simplified, and I added a default of kIgnore to SkImage::makeColorSpace, so we can phase out that argument entirely. - Still need to add defaults to other public APIs that take SkTransferFunctionBehavior. - This makes gold think that we've dramatically changed the contents of all F16 images, but that's because it doesn't understand the (now linear) color space that's embedded. Once we triage them all once, they will work fine (and they'll look perfect in the browser). Bug: skia: Change-Id: I62fa090f96cae1b67d181ce14bd91f34ff2ed747 Reviewed-on: https://skia-review.googlesource.com/140570 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
/*
|
|
* Copyright 2017 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkColorSpacePriv.h"
|
|
#include "SkImage.h"
|
|
#include "SkPngEncoder.h"
|
|
|
|
#include "Resources.h"
|
|
|
|
/**
|
|
* Create a color space that swaps the red, green, and blue channels.
|
|
*/
|
|
static sk_sp<SkColorSpace> gbr_color_space() {
|
|
return SkColorSpace::MakeSRGB()->makeColorSpin();
|
|
}
|
|
|
|
/**
|
|
* Create a color space with a steep transfer function.
|
|
*/
|
|
static sk_sp<SkColorSpace> tf_color_space() {
|
|
SkColorSpaceTransferFn fn;
|
|
fn.fA = 1.f; fn.fB = 0.f; fn.fC = 0.f; fn.fD = 0.f; fn.fE = 0.f; fn.fF = 0.f; fn.fG = 50.f;
|
|
return SkColorSpace::MakeRGB(fn, SkColorSpace::kSRGB_Gamut);
|
|
}
|
|
|
|
/**
|
|
* Create a wide gamut color space.
|
|
*/
|
|
static sk_sp<SkColorSpace> wide_gamut_color_space() {
|
|
return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
|
SkColorSpace::kRec2020_Gamut);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
sk_sp<SkImage> image = GetResourceAsImage("images/flutter_logo.jpg");
|
|
if (!image) {
|
|
SkDebugf("Cannot find flutter_logo.jpg in resources.\n");
|
|
return 1;
|
|
}
|
|
|
|
// Encode an image with a gbr color space.
|
|
SkImageInfo info = SkImageInfo::MakeN32(image->width(), image->height(), kOpaque_SkAlphaType,
|
|
gbr_color_space());
|
|
size_t rowBytes = info.minRowBytes();
|
|
SkAutoTMalloc<uint8_t> storage(rowBytes * image->height());
|
|
SkPixmap src(info, storage.get(), rowBytes);
|
|
image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
|
|
SkFILEWStream dst0("gbr.png");
|
|
SkPngEncoder::Options opts;
|
|
SkAssertResult(SkPngEncoder::Encode(&dst0, src, opts));
|
|
|
|
// Encode an image with steep transfer function.
|
|
src.setColorSpace(tf_color_space());
|
|
image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
|
|
SkFILEWStream dst1("tf.png");
|
|
SkAssertResult(SkPngEncoder::Encode(&dst1, src, opts));
|
|
|
|
// Encode a wide gamut image.
|
|
src.setColorSpace(wide_gamut_color_space());
|
|
image->readPixels(src, 0, 0, SkImage::kDisallow_CachingHint);
|
|
SkFILEWStream dst2("wide-gamut.png");
|
|
SkAssertResult(SkPngEncoder::Encode(&dst2, src, opts));
|
|
|
|
return 0;
|
|
}
|