michael@0: michael@0: /* michael@0: * Copyright 2013 Google, Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkDebugUtils_DEFINED michael@0: #define SkDebugUtils_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: // These functions dump 0, 1, and 2d arrays of data in a format that's michael@0: // compatible with Mathematica for quick visualization michael@0: michael@0: michael@0: template michael@0: inline void SkDebugDumpMathematica( const T val ) { michael@0: SkDEBUGFAIL("Need to specialize SkDebugDumpMathematica for your type, sorry."); michael@0: } michael@0: michael@0: template michael@0: inline void SkDebugDumpMathematica(const char *name, const T *array, int size) { michael@0: SkDebugf(name); michael@0: SkDebugf(" = {"); michael@0: for (int i=0 ; i < size ; i++) { michael@0: SkDebugDumpMathematica(array[i]); michael@0: if (i != size-1) SkDebugf(", "); michael@0: } michael@0: SkDebugf("};\n"); michael@0: } michael@0: michael@0: template michael@0: inline void SkDebugDumpMathematica(const char *name, const T *array, int width, int height) { michael@0: SkDebugf(name); michael@0: SkDebugf(" = {\n"); michael@0: for (int i=0 ; i < height ; i++) { michael@0: SkDebugf(" {"); michael@0: for (int j = 0 ; j < width ; j++) { michael@0: SkDebugDumpMathematica(array[i*width + j]); michael@0: if (j != width-1) { michael@0: SkDebugf(", "); michael@0: } michael@0: } michael@0: SkDebugf("}"); michael@0: if (i != height-1) { michael@0: SkDebugf(", \n"); michael@0: } michael@0: } michael@0: SkDebugf("\n};\n"); michael@0: } michael@0: michael@0: template michael@0: inline void SkDebugDumpMathematica( const char *name, const T val ) { michael@0: SkDebugf(name); michael@0: SkDebugf(" = "); michael@0: SkDebugDumpMathematica(val); michael@0: SkDebugf(";\n"); michael@0: } michael@0: michael@0: template<> michael@0: inline void SkDebugDumpMathematica( const uint8_t val ) { michael@0: SkDebugf("%u", val); michael@0: } michael@0: michael@0: template<> michael@0: inline void SkDebugDumpMathematica( const unsigned int val ) { michael@0: SkDebugf("%u", val); michael@0: } michael@0: michael@0: template<> michael@0: inline void SkDebugDumpMathematica( const int val ) { michael@0: SkDebugf("%d", val); michael@0: } michael@0: michael@0: template<> michael@0: inline void SkDebugDumpMathematica( const size_t val ) { michael@0: SkDebugf("%u", val); michael@0: } michael@0: michael@0: template<> michael@0: void SkDebugDumpMathematica( const char * val ) { michael@0: SkDebugf("%s", val); michael@0: } michael@0: michael@0: template<> michael@0: inline void SkDebugDumpMathematica( float val ) { michael@0: SkDebugf("%f", val); michael@0: } michael@0: michael@0: michael@0: #endif