Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
115
float Float16ToFloat(const uint16_t& f16) {
union FloatUIntUnion {
uint32_t fUInt;
float fFloat;
};
FloatUIntUnion magic = {126 << 23};
FloatUIntUnion o;
if (((f16 >> 10) & 0x001f) == 0) {
o.fUInt = magic.fUInt + (f16 & 0x03ff);
o.fFloat -= magic.fFloat;
} else {
o.fUInt = (f16 & 0x03ff) << 13;
if (((f16 >> 10) & 0x001f) == 0x1f)
o.fUInt |= (255 << 23);
else
o.fUInt |= ((127 - 15 + ((f16 >> 10) & 0x001f)) << 23);
}
o.fUInt |= ((f16 >> 15) << 31);
return o.fFloat;
}
SkString printSkImage(sk_sp<SkImage> input) {
// find out the color space
SkColorSpace* color_space = input->colorSpace();
SkString str;
if (input->alphaType() == kPremul_SkAlphaType)
str.append("Premul");
else
str.append("Unpremul");
SkColorType color_type = kRGBA_8888_SkColorType;
SkImageInfo info =
SkImageInfo::Make(input->width(), input->height(), color_type,
input->alphaType(), input->refColorSpace());
if (info.bytesPerPixel() == 4) {
std::unique_ptr<uint8_t[]> read_pixels(
new uint8_t[input->width() * input->height() * info.bytesPerPixel()]());
input->readPixels(info, read_pixels.get(),
input->width() * info.bytesPerPixel(), 0, 0);
for (int i = 0; i < input->width() * input->height(); i++) {
if (i > 0 && i % input->width() == 0)
str.append("\n");
str.append("[");
for (int j = 0; j < info.bytesPerPixel(); j++)
str.appendf(" %3d", (int)(read_pixels[i * info.bytesPerPixel() + j]));
str.append(" ]");
}
} else {
std::unique_ptr<uint16_t[]> read_pixels(
new uint16_t[input->width() * input->height() * 4]());
input->readPixels(info, read_pixels.get(),
input->width() * info.bytesPerPixel(), 0, 0);
for (int i = 0; i < input->width() * input->height(); i++) {
str.append("\n");
str.append("[");
for (int j = 0; j < 4; j++)
str.appendf("%1.5f%s", Float16ToFloat(read_pixels[i * 4 + j]), j == 3 ? "" : ", ");
str.append("]");
}
}
return str;
}
void draw(SkCanvas* canvas) {
SkImageInfo info = SkImageInfo::Make(
4, 4, SkColorType::kN32_SkColorType, SkAlphaType::kUnpremul_SkAlphaType,
SkColorSpace::MakeSRGB());
sk_sp<SkSurface> offscreen = SkSurface::MakeRaster(info);
DRAW(0, 0, SkPackARGB32(255, 50, 100, 150));
/*
DRAW(1, 0, SkPackARGB32(255, 0, 255, 0));
DRAW(2, 0, SkPackARGB32(255, 0, 0, 255));
DRAW(3, 0, SkPackARGB32(255, 0, 0, 0));
DRAW(0, 1, SkPackARGB32(255, 155, 27, 27));
DRAW(1, 1, SkPackARGB32(255, 27, 155, 27));
DRAW(2, 1, SkPackARGB32(255, 27, 27, 155));
DRAW(3, 1, SkPackARGB32(255, 27, 27, 27));
DRAW(0, 2, SkPackARGB32(128, 155, 27, 27));
DRAW(1, 2, SkPackARGB32(128, 27, 155, 27));
DRAW(2, 2, SkPackARGB32(128, 27, 27, 155));
DRAW(3, 2, SkPackARGB32(128, 27, 27, 27));
DRAW(0, 3, SkPackARGB32(128, 226, 31, 31));
DRAW(1, 3, SkPackARGB32(128, 31, 226, 31));
DRAW(2, 3, SkPackARGB32(128, 31, 31, 226));
DRAW(3, 3, SkPackARGB32(128, 31, 31, 31));
*/
sk_sp<SkImage> img1 = offscreen->makeImageSnapshot();
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(
SkNamedTransferFn::kSRGB,
SkNamedGamut::kDisplayP3);
static constexpr skcms_TransferFunction k2Dot4 =
{ 2.4f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
sk_sp<SkColorSpace> rec2020 = SkColorSpace::MakeRGB(
k2Dot4,
SkNamedGamut::kRec2020);
SkDebugf("Input: \n%s\n", printSkImage(img1).c_str());
SkDebugf("srgb: \n%s\n", printSkImage(img1->makeColorSpace(srgb)).c_str());
SkDebugf("p3: \n%s\n", printSkImage(img1->makeColorSpace(p3)).c_str());
SkDebugf("rec2020:\n%s\n", printSkImage(img1->makeColorSpace(rec2020)).c_str());
}