diff options
author | humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-02-14 18:57:59 +0000 |
---|---|---|
committer | humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-02-14 18:57:59 +0000 |
commit | 5d0a7692da32ae50d639b9ef3cf99724e3b112ac (patch) | |
tree | 2d49f502057c9a28f354387404acad109a17c18b /include/utils | |
parent | cfb7b91b57aa37714f914c86e84928f88c7ad2d7 (diff) |
debug dump functions for mathematica visualization
BUG=
Review URL: https://codereview.appspot.com/7322078
git-svn-id: http://skia.googlecode.com/svn/trunk@7743 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/utils')
-rw-r--r-- | include/utils/SkDebugUtils.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/include/utils/SkDebugUtils.h b/include/utils/SkDebugUtils.h new file mode 100644 index 0000000000..64e2935d76 --- /dev/null +++ b/include/utils/SkDebugUtils.h @@ -0,0 +1,94 @@ + +/* + * Copyright 2013 Google, Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SkDebugUtils_DEFINED +#define SkDebugUtils_DEFINED + +#include "SkTypes.h" + +// These functions dump 0, 1, and 2d arrays of data in a format that's +// compatible with Mathematica for quick visualization + + +template<class T> +inline void SkDebugDumpMathematica( const T val ) { + SkDEBUGFAIL("Need to specialize SkDebugDumpMathematica for your type, sorry."); +} + +template<class T> +inline void SkDebugDumpMathematica(const char *name, const T *array, int size) { + SkDebugf(name); + SkDebugf(" = {"); + for (int i=0 ; i < size ; i++) { + SkDebugDumpMathematica<T>(array[i]); + if (i != size-1) SkDebugf(", "); + } + SkDebugf("};\n"); +} + +template<class T> +inline void SkDebugDumpMathematica(const char *name, const T *array, int width, int height) { + SkDebugf(name); + SkDebugf(" = {\n"); + for (int i=0 ; i < height ; i++) { + SkDebugf(" {"); + for (int j = 0 ; j < width ; j++) { + SkDebugDumpMathematica<T>(array[i*width + j]); + if (j != width-1) { + SkDebugf(", "); + } + } + SkDebugf("}"); + if (i != height-1) { + SkDebugf(", \n"); + } + } + SkDebugf("\n};\n"); +} + +template<class T> +inline void SkDebugDumpMathematica( const char *name, const T val ) { + SkDebugf(name); + SkDebugf(" = "); + SkDebugDumpMathematica<T>(val); + SkDebugf(";\n"); +} + +template<> +inline void SkDebugDumpMathematica<uint8_t>( const uint8_t val ) { + SkDebugf("%u", val); +} + +template<> +inline void SkDebugDumpMathematica<unsigned int>( const unsigned int val ) { + SkDebugf("%u", val); +} + +template<> +inline void SkDebugDumpMathematica<int>( const int val ) { + SkDebugf("%d", val); +} + +template<> +inline void SkDebugDumpMathematica<size_t>( const size_t val ) { + SkDebugf("%u", val); +} + +template<> +void SkDebugDumpMathematica<const char *>( const char * val ) { + SkDebugf("%s", val); +} + +template<> +inline void SkDebugDumpMathematica<float>( float val ) { + SkDebugf("%f", val); +} + + +#endif |