humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google, Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef SkDebugUtils_DEFINED |
| 11 | #define SkDebugUtils_DEFINED |
| 12 | |
| 13 | #include "SkTypes.h" |
| 14 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 15 | // These functions dump 0, 1, and 2d arrays of data in a format that's |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 16 | // compatible with Mathematica for quick visualization |
| 17 | |
| 18 | |
| 19 | template<class T> |
| 20 | inline void SkDebugDumpMathematica( const T val ) { |
| 21 | SkDEBUGFAIL("Need to specialize SkDebugDumpMathematica for your type, sorry."); |
| 22 | } |
| 23 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 24 | template<class T> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 25 | inline void SkDebugDumpMathematica(const char *name, const T *array, int size) { |
| 26 | SkDebugf(name); |
| 27 | SkDebugf(" = {"); |
| 28 | for (int i=0 ; i < size ; i++) { |
| 29 | SkDebugDumpMathematica<T>(array[i]); |
| 30 | if (i != size-1) SkDebugf(", "); |
| 31 | } |
| 32 | SkDebugf("};\n"); |
| 33 | } |
| 34 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 35 | template<class T> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 36 | inline void SkDebugDumpMathematica(const char *name, const T *array, int width, int height) { |
| 37 | SkDebugf(name); |
| 38 | SkDebugf(" = {\n"); |
| 39 | for (int i=0 ; i < height ; i++) { |
| 40 | SkDebugf(" {"); |
| 41 | for (int j = 0 ; j < width ; j++) { |
| 42 | SkDebugDumpMathematica<T>(array[i*width + j]); |
| 43 | if (j != width-1) { |
| 44 | SkDebugf(", "); |
| 45 | } |
| 46 | } |
| 47 | SkDebugf("}"); |
| 48 | if (i != height-1) { |
| 49 | SkDebugf(", \n"); |
| 50 | } |
| 51 | } |
| 52 | SkDebugf("\n};\n"); |
| 53 | } |
| 54 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 55 | template<class T> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 56 | inline void SkDebugDumpMathematica( const char *name, const T val ) { |
| 57 | SkDebugf(name); |
| 58 | SkDebugf(" = "); |
| 59 | SkDebugDumpMathematica<T>(val); |
| 60 | SkDebugf(";\n"); |
| 61 | } |
| 62 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 63 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 64 | inline void SkDebugDumpMathematica<uint8_t>( const uint8_t val ) { |
| 65 | SkDebugf("%u", val); |
| 66 | } |
| 67 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 68 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 69 | inline void SkDebugDumpMathematica<unsigned int>( const unsigned int val ) { |
| 70 | SkDebugf("%u", val); |
| 71 | } |
| 72 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 73 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 74 | inline void SkDebugDumpMathematica<int>( const int val ) { |
| 75 | SkDebugf("%d", val); |
| 76 | } |
| 77 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 78 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 79 | inline void SkDebugDumpMathematica<size_t>( const size_t val ) { |
| 80 | SkDebugf("%u", val); |
| 81 | } |
| 82 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 83 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 84 | void SkDebugDumpMathematica<const char *>( const char * val ) { |
| 85 | SkDebugf("%s", val); |
| 86 | } |
| 87 | |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 88 | template<> |
humper@google.com | 5d0a769 | 2013-02-14 18:57:59 +0000 | [diff] [blame] | 89 | inline void SkDebugDumpMathematica<float>( float val ) { |
| 90 | SkDebugf("%f", val); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | #endif |