aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-14 15:33:20 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-14 15:33:20 +0000
commit2bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7 (patch)
tree67d590a01f682d9a821edc8f457dcaa696c7e6d5 /bench
parent99e0d08113738dd8ea8f52af0cdd04c971ff074a (diff)
Add an option to create unpremultiplied bitmaps.
Currently they cannot be used directly by Skia, but the pixels can be used elsewhere. SkImageDecoder: Add functions to require unpremultiplied output and query the presence of the requirement SkImageDecoder_libpng: SkImageDecoder_libwebp: SkImageDecoder_WIC: Respect the requirement for unpremultiplied output. TODO: Fix SkImageDecoder_CG. SkScaledBitmapSampler: Add procs to skip premultiplication and a boolean parameter to use those procs. ImageDecodingTest: Test unpremultiplied bitmap decoding. SampleUnpremul: Add a sample which allows visually comparing between the unpremultiplied version (copied into a premultiplied bitmap, since drawing unpremultiplied is not currently supported) and a premultiplied version of image files. gm.h: Add a getter for the resource path, so Samples can use it. As of patch set 13, https://codereview.chromium.org/16816016/ and https://codereview.chromium.org/16983004/, which were approved separately. R=reed@google.com Review URL: https://codereview.chromium.org/16410009 git-svn-id: http://skia.googlecode.com/svn/trunk@9612 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r--bench/ImageDecodeBench.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/bench/ImageDecodeBench.cpp b/bench/ImageDecodeBench.cpp
new file mode 100644
index 0000000000..1cb29b1f1e
--- /dev/null
+++ b/bench/ImageDecodeBench.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBenchmark.h"
+#include "SkBitmap.h"
+#include "SkData.h"
+#include "SkForceLinking.h"
+#include "SkImageDecoder.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+#include "SkString.h"
+
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
+class SkCanvas;
+
+class ImageDecodeBench : public SkBenchmark {
+public:
+ ImageDecodeBench(void* p, const char* filename)
+ : INHERITED(p)
+ , fName("image_decode_")
+ , fFilename(filename)
+ , fStream()
+ , fValid(false) {
+ fName.append(SkOSPath::SkBasename(filename));
+ fIsRendering = false;
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return fName.c_str();
+ }
+
+ virtual void onPreDraw() SK_OVERRIDE {
+ SkFILEStream fileStream(fFilename.c_str());
+ fValid = fileStream.isValid() && fileStream.getLength() > 0;
+ if (fValid) {
+ const size_t size = fileStream.getLength();
+ void* data = sk_malloc_throw(size);
+ if (fileStream.read(data, size) < size) {
+ fValid = false;
+ } else {
+ SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size));
+ fStream.setData(skdata.get());
+ }
+ }
+ }
+
+ virtual void onDraw(SkCanvas*) SK_OVERRIDE {
+#ifdef SK_DEBUG
+ if (!fValid) {
+ SkDebugf("stream was invalid: %s\n", fName.c_str());
+ return;
+ }
+#endif
+ // Decode a bunch of times
+ SkBitmap bm;
+ for (int i = 0; i < SkBENCHLOOP(1000); ++i) {
+ SkDEBUGCODE(bool success =) SkImageDecoder::DecodeStream(&fStream, &bm);
+#ifdef SK_DEBUG
+ if (!success) {
+ SkDebugf("failed to decode %s\n", fName.c_str());
+ return;
+ }
+#endif
+ SkDEBUGCODE(success =) fStream.rewind();
+#ifdef SK_DEBUG
+ if (!success) {
+ SkDebugf("failed to rewind %s\n", fName.c_str());
+ return;
+ }
+#endif
+ }
+ }
+
+private:
+ SkString fName;
+ const SkString fFilename;
+ SkMemoryStream fStream;
+ bool fValid;
+
+ typedef SkBenchmark INHERITED;
+};
+
+// These are files which call decodePalette
+//DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, (p, "/usr/local/google/home/scroggo/Downloads/images/hal_163x90.png")); )
+//DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, (p, "/usr/local/google/home/scroggo/Downloads/images/box_19_top-left.png")); )