aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/jpg_color_cube.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-09-12 16:04:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-13 14:10:50 +0000
commitb433c5691b0d130697a89e7362c76ec6ae74a254 (patch)
tree01a11ab79e68fca774977f9e33e9b89d73d5d71f /gm/jpg_color_cube.cpp
parent489bef054ee912992195a905c1035b5059dc9c57 (diff)
Adjust GPU YUV -> RGB (JPG) conversion
All of the published coefficients assume math is being done on bytes, and that 128 is the encoding of 0 (in the biased Cb and Cr values). When sampling an A8 texture, though, GPUs typically decode as byte/255. Thus, 128 ends up slightly larger than 0.5. To fix this, just adjust the bias terms to be scaled by 128/255, rather than 0.5. I also changed some of the other coefficients to be higher precision, based on the values in ITU-T T.871. This originally surfaced as a Chromium bug where an all-black JPG decoded to (1/255, 0, 1/255) on GPU. I've added a GM that encodes a color cube to JPG, then draws from the encoded data. GPU and CPU (libjpeg) still disagree in many cases, but the newer version performs much better (diffing gl and 8888 configs): Previously: 95.2% of pixels differ, max diff of 2, avg diff of 1 Now : 65.4% of pixels differ, max diff of 1, avg diff of 0 Bug: skia:7038 chromium:763605 Change-Id: I4801db9f6e2fc4d4109eb5e27c9499f214084d38 Reviewed-on: https://skia-review.googlesource.com/45842 Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'gm/jpg_color_cube.cpp')
-rw-r--r--gm/jpg_color_cube.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/gm/jpg_color_cube.cpp b/gm/jpg_color_cube.cpp
new file mode 100644
index 0000000000..408cc90ea2
--- /dev/null
+++ b/gm/jpg_color_cube.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "gm.h"
+#include "sk_tool_utils.h"
+#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkImage.h"
+#include "SkImageEncoder.h"
+
+namespace skiagm {
+
+class ColorCubeGM : public GM {
+public:
+ ColorCubeGM() {}
+
+protected:
+ SkString onShortName() override {
+ return SkString("jpg-color-cube");
+ }
+
+ SkISize onISize() override {
+ return SkISize::Make(512, 512);
+ }
+
+ void onOnceBeforeDraw() override {
+ SkBitmap bmp;
+ bmp.allocN32Pixels(512, 512, true);
+ int bX = 0, bY = 0;
+ for (int b = 0; b < 64; ++b) {
+ for (int r = 0; r < 64; ++r) {
+ for (int g = 0; g < 64; ++g) {
+ *bmp.getAddr32(bX + r, bY + g) = SkPackARGB32(255,
+ SkTPin(r * 4, 0, 255),
+ SkTPin(g * 4, 0, 255),
+ SkTPin(b * 4, 0, 255));
+ }
+ }
+ bX += 64;
+ if (bX >= 512) {
+ bX = 0;
+ bY += 64;
+ }
+ }
+ auto jpegData(sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kJPEG, 100));
+ fImage = SkImage::MakeFromEncoded(jpegData);
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ canvas->drawImage(fImage, 0, 0);
+ }
+
+private:
+ sk_sp<SkImage> fImage;
+
+ typedef GM INHERITED;
+};
+
+DEF_GM( return new ColorCubeGM; )
+}