aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-02-26 14:43:21 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-26 14:43:21 -0800
commit27c3fddaac722086b80a7725f42c14fb694ec4a6 (patch)
treec6b6450032178f67335b8455e85a2c1d97e09977 /dm
parentde11ee41b39d7c382e11636a47c39470426c9325 (diff)
DM: support --config {f16,srgb}
Will need to follow up with enabling f16 and srgb configs. They're still assert-y. The GMs 'gamma' and 'gradients' look reassuringly good on f16 and srgb backends. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1711143002 Review URL: https://codereview.chromium.org/1711143002
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp72
-rw-r--r--dm/DMSrcSink.cpp7
-rw-r--r--dm/DMSrcSink.h5
3 files changed, 69 insertions, 15 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 9021f3c789..59c7def4d6 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -14,13 +14,16 @@
#include "SkBBHFactory.h"
#include "SkChecksum.h"
#include "SkCodec.h"
+#include "SkColorPriv.h"
#include "SkCommonFlags.h"
#include "SkCommonFlagsConfig.h"
#include "SkFontMgr.h"
#include "SkGraphics.h"
+#include "SkHalf.h"
#include "SkMD5.h"
#include "SkMutex.h"
#include "SkOSFile.h"
+#include "SkPM4fPriv.h"
#include "SkSpinlock.h"
#include "SkTHash.h"
#include "SkTaskGroup.h"
@@ -700,6 +703,8 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
if (FLAGS_cpu) {
SINK("565", RasterSink, kRGB_565_SkColorType);
SINK("8888", RasterSink, kN32_SkColorType);
+ SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType);
+ SINK("f16", RasterSink, kRGBA_F16_SkColorType);
SINK("pdf", PDFSink, "Pdfium");
SINK("pdf_poppler", PDFSink, "Poppler");
SINK("skp", SKPSink);
@@ -777,21 +782,66 @@ static void gather_sinks() {
static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
const int w = bitmap.width(),
h = bitmap.height();
+ // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too).
+ // We leave the gamma of these bytes unspecified, to continue the status quo,
+ // which we think generally is to interpret them as sRGB.
- // First get the bitmap into N32 color format. The next step will work only there.
- if (bitmap.colorType() != kN32_SkColorType) {
- SkBitmap n32;
- if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
+ SkAutoTMalloc<uint32_t> rgba(w*h);
+
+ if (bitmap. colorType() == kN32_SkColorType &&
+ bitmap.profileType() == kSRGB_SkColorProfileType) {
+ // These are premul sRGB 8-bit pixels in SkPMColor order.
+ // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats.
+ bitmap.lockPixels();
+ auto px = (const uint32_t*)bitmap.getPixels();
+ if (!px) {
return false;
}
- bitmap = n32;
- }
+ for (int i = 0; i < w*h; i++) {
+ Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear floats.
+ #if defined(SK_PMCOLOR_IS_BGRA)
+ fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not there already.
+ #endif
+ float invA = 1.0f / fs[3];
+ fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
+ rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
+ }
- // Convert our N32 bitmap into unpremul RGBA for libpng.
- SkAutoTMalloc<uint32_t> rgba(w*h);
- if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
- rgba, 4*w, 0,0)) {
- return false;
+ } else if (bitmap.colorType() == kRGBA_F16_SkColorType) {
+ // These are premul linear half-float pixels in RGBA order.
+ // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats.
+ bitmap.lockPixels();
+ auto px = (const uint64_t*)bitmap.getPixels();
+ if (!px) {
+ return false;
+ }
+ for (int i = 0; i < w*h; i++) {
+ Sk4f fs = SkHalfToFloat_01(px[i]); // Convert up to linear floats.
+ float invA = 1.0f / fs[3];
+ fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
+ rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
+ }
+
+
+ } else {
+ // We "should" gamma correct in here but we don't.
+ // We want Gold to show exactly what our clients are seeing, broken gamma.
+
+ // Convert smaller formats up to premul linear 8-bit (in SkPMColor order).
+ if (bitmap.colorType() != kN32_SkColorType) {
+ SkBitmap n32;
+ if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
+ return false;
+ }
+ bitmap = n32;
+ }
+
+ // Convert premul linear 8-bit to unpremul linear 8-bit RGBA.
+ if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType,
+ kUnpremul_SkAlphaType),
+ rgba, 4*w, 0,0)) {
+ return false;
+ }
}
// We don't need bitmap anymore. Might as well drop our ref.
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index ea21d7a695..2d2a455e7b 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1033,7 +1033,9 @@ Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
+RasterSink::RasterSink(SkColorType colorType, SkColorProfileType profileType)
+ : fColorType(colorType)
+ , fProfileType(profileType) {}
Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
const SkISize size = src.size();
@@ -1042,7 +1044,8 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
(void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
SkMallocPixelRef::ZeroedPRFactory factory;
- dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType),
+ dst->allocPixels(SkImageInfo::Make(size.width(), size.height(),
+ fColorType, alphaType, fProfileType),
&factory,
nullptr/*colortable*/);
SkCanvas canvas(*dst);
diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h
index 3190576c68..bbf47cffd8 100644
--- a/dm/DMSrcSink.h
+++ b/dm/DMSrcSink.h
@@ -249,13 +249,14 @@ public:
class RasterSink : public Sink {
public:
- explicit RasterSink(SkColorType);
+ explicit RasterSink(SkColorType, SkColorProfileType=kLinear_SkColorProfileType);
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "png"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
private:
- SkColorType fColorType;
+ SkColorType fColorType;
+ SkColorProfileType fProfileType;
};
class SKPSink : public Sink {