/*
- * Copyright 2013 Google Inc.
+ * Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#include "gm.h"
#include "SkColor.h"
+#include "SkColorSpace_Base.h"
#include "SkColorSpaceXform.h"
#include "SkRect.h"
SkMatrix44 wideGamut(SkMatrix44::kUninitialized_Constructor);
wideGamut.set3x3RowMajorf(kWideGamutRGB_toXYZD50);
+ // Test BGRA input.
sk_sp<SkColorSpace> srcSpace = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> dstSpace =
SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut);
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace.get(),
dstSpace.get());
-
- xform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, fWideGamutColors,
+ xform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, fWideGamutColors0,
SkColorSpaceXform::kBGRA_8888_ColorFormat, colors, kNumColors,
kOpaque_SkAlphaType);
+
+ // Test F32 input.
+ srcSpace = as_CSB(srcSpace)->makeLinearGamma();
+ xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
+ xform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, fWideGamutColors1,
+ SkColorSpaceXform::kRGBA_F32_ColorFormat, fSRGBColors, kNumColors,
+ kOpaque_SkAlphaType);
}
SkString onShortName() override {
}
SkISize onISize() override {
- return SkISize::Make(500, 200);
+ return SkISize::Make(500, 300);
}
void onDraw(SkCanvas* canvas) override {
// Wide gamut colors should appear darker - we are simulating a more intense display.
drawColors(fSRGBColors);
canvas->translate(0.0f, 100.0f);
- drawColors(fWideGamutColors);
+ drawColors(fWideGamutColors0);
+ canvas->translate(0.0f, 100.0f);
+ drawColors(fWideGamutColors1);
}
private:
static constexpr int kNumColors = 10;
SkColor4f fSRGBColors[kNumColors];
- SkColor4f fWideGamutColors[kNumColors];
+ SkColor4f fWideGamutColors0[kNumColors];
+ SkColor4f fWideGamutColors1[kNumColors];
typedef skiagm::GM INHERITED;
};
kRGBA_U16_BE_ColorFormat, // Src only
kRGBA_F16_ColorFormat,
- kRGBA_F32_ColorFormat, // Dst only
+ kRGBA_F32_ColorFormat,
};
/**
* Apply the color conversion to a |src| buffer, storing the output in the |dst| buffer.
*
- * F32 is only supported as a dst color format. F16 and F32 are only supported when the color
- * space is linear. This function will return false in unsupported cases.
+ * F16 and F32 are only supported when the color space is linear. This function will return
+ * false in unsupported cases.
*
* @param dst Stored in the format described by |dstColorFormat|
* @param src Stored in the format described by |srcColorFormat|
}
if (kRGBA_F32_ColorFormat == dstColorFormat ||
+ kRGBA_F32_ColorFormat == srcColorFormat ||
kRGBA_F16_ColorFormat == srcColorFormat ||
kRGBA_U16_BE_ColorFormat == srcColorFormat ||
kRGB_U16_BE_ColorFormat == srcColorFormat ||
}
pipeline.append(SkRasterPipeline::load_f16, &src);
break;
+ case kRGBA_F32_ColorFormat:
+ if (kLinear_SrcGamma != fSrcGamma) {
+ return false;
+ }
+ pipeline.append(SkRasterPipeline::load_f32, &src);
+ break;
case kRGBA_U16_BE_ColorFormat:
switch (fSrcGamma) {
case kLinear_SrcGamma:
break;
}
break;
- default:
- return false;
}
if (kNone_ColorSpaceMatch == kCSM) {
M(set_rgb) M(swap_rb) \
M(from_srgb) M(to_srgb) \
M(from_2dot2) M(to_2dot2) \
- M(constant_color) M(seed_shader) M(store_f32) \
+ M(constant_color) M(seed_shader) \
M(load_a8) M(store_a8) \
M(load_g8) \
M(load_565) M(store_565) \
M(load_4444) M(store_4444) \
M(load_f16) M(store_f16) \
+ M(load_f32) M(store_f32) \
M(load_8888) M(store_8888) \
M(load_u16_be) M(load_rgb_u16_be) M(store_u16_be) \
M(load_tables_u16_be) M(load_tables_rgb_u16_be) \
template <typename T>
SI SkNx<N,T> load(size_t tail, const T* src) {
if (tail) {
- T buf[8] = {0};
+ T buf[8];
+ memset(buf, 0, 8*sizeof(T));
switch (tail & (N-1)) {
case 7: buf[6] = src[6];
case 6: buf[5] = src[5];
}
}
+STAGE_CTX(load_f32, const SkPM4f**) {
+ auto ptr = *ctx + x;
+
+ const void* src = ptr;
+ SkNx<N, SkPM4f> px;
+ if (tail) {
+ px = load(tail, ptr);
+ src = &px;
+ }
+ SkNf::Load4(src, &r, &g, &b, &a);
+}
STAGE_CTX(store_f32, SkPM4f**) {
auto ptr = *ctx + x;