Index: /NonGTP/ImageDebugger/include/imdebug.h
===================================================================
--- /NonGTP/ImageDebugger/include/imdebug.h	(revision 856)
+++ /NonGTP/ImageDebugger/include/imdebug.h	(revision 856)
@@ -0,0 +1,148 @@
+/*============================================================================
+ * Image Debugging API
+ *
+ * This API can simplify the debugging of applications that handle 2D data.
+ * It basically allows you to do 'printf' style debugging of images in 
+ * C and C++ applications.
+ *
+ * Basic Usage:
+ *  #include <imdebug.h>
+ *  ...
+ *  imdebug(format_string, ...);
+ *
+ *  The format string describes the type of image(s) to dump to the debug
+ *  window. Here are some examples
+ *
+ *  Show an rgb image with width and height 16:
+ *
+ *     imdebug("rgb w=%d h=%d %p", 16, 16, img);
+ *   
+ * VARIABLE SPEC:
+ *  %d  -  int
+ *  %f  -  float
+ *  %s  -  string
+ *  %p  -  picture (pointer to raw image data)
+ *  
+ * INPUT FORMAT SPEC:
+ *  rgb
+ *  bgr
+ *  abgr
+ *  rgba...   - specify input image channel order
+ *  lum       - 1-channel image: lumninance
+ *  luma      - 2-channel image: lumninance + alpha
+ *  #5        - 5-channel data (default is to use 0,1,2 as RGB, no alpha)
+ *  ---> (default is rgb)
+ *
+ *  b=8       - size of all channels is 8 bits
+ *  b=5,6,5   - size of channels is 5bits(R) 6bits(G) 5bits(B)
+ *  b=32f     - size of all channels is 32 bits, float format
+ *  ---> (default is b=8)
+ *
+ * OUTPUT FORMAT SPEC:
+ *  rgba=rg__ - just display the red and green chanels
+ *  rgba=aaa_ - display alpha as grayscale
+ *  lum=g     - display green as grayscale
+ *  rgb=#A1C  - r:=chan 10, g:=chan 1, b:=chan 12 (use HEX digits!)
+ *  ---> (default is 1-1 mapping with no translation or swizzling)
+ *
+ * ATTRIBUTE SPEC:
+ *  w=23      - width  is 23 (default 0)
+ *  h=17      - height is 17 (default 0)
+ *  rs=1      - skip 1 row after every row  (default 0)
+ *  cs=2      - skip 2 columns after every column (default 0)
+ *
+ * SCALE AND BIAS:
+ *  *1.2      - scale RGB by 1.2
+ *  /1.2      - scale RGB by 1/1.2
+ *  +128      - bias  RGB by 128
+ *  -0.5      - bias  RGB by -0.5
+ *  r*1.2     - scale red by 1.2
+ *  rb/1.2    - scale both red and blue by 1/1.2
+ *  a+128     - bias  alpha by 128
+ *  rgba-0.5  - bias  RGB and alpha by -0.5
+ *  *auto     - automatically scale & bias RGB based on max & min values
+ *  ra*auto   - automatically scale & bias red and alpha
+ *  --> Default is scale=1 and bias=0 for all channels
+ *  --> Output value is computed as  (x*scale)+bias, 
+ *       the same order as with OpenGL glPixelTransfer functions.
+ *
+ *  Order of specifiers is mostly not important, but channel swizzeling
+ *  should come after input format specifier. 
+ *  (i.e. do "rgb bgr=rgb",   not "bgr=rgb  rgb")
+ *
+ *  If no image is specified (with '%p'), then the previous 
+ *  image data is used.
+ *
+ * THOUGHTS FOR THE FUTURE
+ *
+ *  handling raw graphic images in compressed form. e.g.:
+ *  %pj = specify raw jpg image buffer
+ *  %pp = specify raw png image buffer
+ *  %pb = specify raw bmp image buffer
+ *  
+ *  A way to perform math on images in the format specifier,
+ *  or perform other arbitrary transformations on the input.
+ *  Like "%p - 0.5*%p"
+ *
+ *  A way to specify that several images should be tiled,
+ *  or opened in separate display windows.
+ *
+ *  More control over padding and alignment specs.
+ *
+ *  Ooops!  Really should allow specification of endianness!
+ *  That would be handy for data not created in the local endian format.
+ *
+ *  Author:        William Baxter (baxter@cs.unc.edu)
+ *  Created:       Sept 2002
+ *  Last Modified: Jan 2003
+ *============================================================================
+ *  Copyright 2002 
+ *        William Baxter
+ *        The University of North Carolina at Chapel Hill
+ * 
+ *  Permission to use, copy, modify, distribute and sell this software
+ *  and its documentation for any purpose is hereby granted without
+ *  fee, provided that the above copyright notice appear in all copies
+ *  and that both that copyright notice and this permission notice
+ *  appear in supporting documentation.  Binaries may be compiled with
+ *  this software without any royalties or restrictions.
+ * 
+ *  The University of North Carolina at Chapel Hill makes no
+ *  representations about the suitability of this software for any
+ *  purpose. It is provided "as is" without express or implied
+ *  warranty.
+ *============================================================================
+ */
+
+
+#ifndef IMDEBUG_H
+#define IMDEBUG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+
+#ifndef IMDBG_EXPORT
+#define IMDBG_EXPORT __declspec(dllimport)
+#pragma comment (lib, "imdebug.lib")
+#else
+#endif
+
+/*===========================================================================*/
+/*                                                                           */
+/*  This is it. The one function you need to know about:                     */
+
+IMDBG_EXPORT void CALLBACK imdebug(const char *format, ...);
+
+/*===========================================================================*/
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
+
+#endif /* IMDEBUG_H */
Index: /NonGTP/ImageDebugger/include/imdebuggl.h
===================================================================
--- /NonGTP/ImageDebugger/include/imdebuggl.h	(revision 856)
+++ /NonGTP/ImageDebugger/include/imdebuggl.h	(revision 856)
@@ -0,0 +1,254 @@
+#ifndef __IMDEBUGGL_H__
+#define __IMDEBUGGL_H__
+
+#include <imdebug.h>
+#include <gl/gl.h>
+#include <string>
+
+int format2components(GLenum format);
+std::string format2string(GLenum format);
+
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugTexImage
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief Gets a texture level from OpenGL, and displays it using imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
+ * and passed as the imdebug format string.  Otherwise, the correct format
+ * ("rgb", "lum", etc.) is determined from the @a format argument, and 
+ * prepended to the same string and used as the imdebug format string.
+ */ 
+inline void imdebugTexImage(GLenum target, GLuint texture, 
+                            GLenum format = GL_RGB, 
+                            GLint level = 0, char *argstring = NULL)
+{  
+  int w, h;
+  int prevTexBind;
+  glGetIntegerv(target, &prevTexBind);
+
+  glBindTexture(target, texture);
+  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w);
+  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h);
+  GLubyte *p = new GLubyte[w * h * format2components(format)];
+  
+  glGetTexImage(target, level, format, GL_UNSIGNED_BYTE, p);
+ 
+  std::string s = (NULL == argstring) ? format2string(format) : argstring;
+  imdebug(s.append(" w=%d h=%d %p").c_str(), w, h, p);
+  
+  delete [] p;
+
+  glBindTexture(target, prevTexBind);
+}
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugTexImagef
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief Gets a texture level from OpenGL, and displays it as floats using imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
+ * and passed as the imdebug format string.  Otherwise, the correct format
+ * ("rgb", "lum", etc.) is determined from the @a format argument, and 
+ * prepended to the same string and used as the imdebug format string.
+ */ 
+inline void imdebugTexImagef(GLenum target, GLuint texture, 
+                             GLenum format = GL_RGB, 
+                             GLint level = 0, char *argstring = NULL)
+{  
+  int w, h;
+  int prevTexBind;
+  glGetIntegerv(target, &prevTexBind);
+
+  glBindTexture(target, texture);
+  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w);
+  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h);
+  float *p = new float[w * h * format2components(format)];
+  
+  glGetTexImage(target, level, format, GL_FLOAT, p);
+ 
+  std::string s = (NULL == argstring) ? format2string(format) : argstring;
+  imdebug(s.append(" b=32f w=%d h=%d %p").c_str(), w, h, p);
+  
+  delete [] p;
+
+  glBindTexture(target, prevTexBind);
+}
+
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugPixels
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief performs a glReadPixels(), and then displays the results in imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
+ * and passed as the imdebug format string.  Otherwise, the correct format
+ * ("rgb", "lum", etc.) is determined from the @a format argument, and 
+ * prepended to the same string and used as the imdebug format string.
+ */ 
+inline void imdebugPixels(GLint x, GLint y, GLsizei width, GLsizei height, 
+                          GLenum format = GL_RGB, char *argstring = NULL)
+{
+  GLubyte *p = new GLubyte[width * height * format2components(format)];
+  glReadPixels(x, y, width, height, format, GL_UNSIGNED_BYTE, p);
+ 
+  std::string s = (NULL == argstring) ? format2string(format) : argstring;
+  imdebug(s.append(" w=%d h=%d %p").c_str(), width, height, p);
+
+    
+  delete [] p;
+}
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugPixelsf
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief performs a glReadPixels(), and then displays the results in imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
+ * and passed as the imdebug format string.  Otherwise, the correct format
+ * ("rgb", "lum", etc.) is determined from the @a format argument, and 
+ * prepended to the same string and used as the imdebug format string.
+ */ 
+inline void imdebugPixelsf(GLint x, GLint y, GLsizei width, GLsizei height, 
+                           GLenum format = GL_RGB, char *argstring = NULL)
+{
+  float *p = new float[width * height * format2components(format)];
+  glReadPixels(x, y, width, height, format, GL_FLOAT, p);
+ 
+  std::string s = (NULL == argstring) ? format2string(format) : argstring;
+  imdebug(s.append(" b=32f w=%d h=%d %p").c_str(), width, height, p);
+    
+  delete [] p;
+}
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugDepth
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief performs a glReadPixels() on depth, and then displays the results in imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string " w=%d h=%d %p"
+ * and passed as the imdebug format string.
+ */ 
+inline void imdebugDepth(GLint x, GLint y, GLsizei width, GLsizei height, 
+                         char *argstring = NULL)
+{
+  GLuint *p = new GLuint[width * height];
+  glReadPixels(x, y, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, p);
+ 
+  std::string s = (NULL == argstring) ? "" : argstring;
+  imdebug(s.append("lum b=32 w=%d h=%d %p").c_str(), width, height, p);
+    
+  delete [] p;
+}
+
+//-----------------------------------------------------------------------------
+// Function     : imdebugDepthf
+// Description	: 
+//-----------------------------------------------------------------------------
+/**
+ * @brief performs a glReadPixels() on depth, and then displays the results in imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string 
+ * " lum b=32f w=%d h=%d %p"
+ * and passed as the imdebug format string.
+ */ 
+inline void imdebugDepthf(GLint x, GLint y, GLsizei width, GLsizei height, 
+                          char *argstring = NULL)
+{
+  float *p = new float[width * height];
+  glReadPixels(x, y, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, p);
+ 
+  std::string s = (NULL == argstring) ? "" : argstring;
+  imdebug(s.append(" lum b=32f w=%d h=%d %p").c_str(), width, height, p);
+    
+  delete [] p;
+}
+
+//-----------------------------------------------------------------------------
+// Function    : imdebugStencil
+// Description : 
+//-----------------------------------------------------------------------------
+/**
+ * @brief performs a glReadPixels() on stencil, and then displays the results in imdebug.
+ * 
+ * If argstring is non-NULL, then it is prepended to the string 
+ *  " lum w=%d h=%d %p"
+ * and passed as the imdebug format string.
+ */ 
+inline void imdebugStencil(GLint x, GLint y, GLsizei width, GLsizei height, 
+                           char *argstring = NULL)
+{
+  GLubyte *p = new GLubyte[width * height];
+  glReadPixels(x, y, width, height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, p);
+ 
+  std::string s = (NULL == argstring) ? "" : argstring;
+  imdebug(s.append(" lum w=%d h=%d %p").c_str(), width, height, p);
+    
+  delete [] p;
+}
+
+
+inline int format2components(GLenum format)
+{
+  switch(format) 
+  {
+  case GL_LUMINANCE:
+  case GL_INTENSITY:
+  case GL_ALPHA:
+    return 1;
+  	break;
+  case GL_LUMINANCE_ALPHA:
+    return 2;
+  	break;
+  case GL_RGB:
+  case GL_BGR:
+    return 3;
+    break;
+  case GL_RGBA:
+  case GL_BGRA:
+  case GL_ABGR_EXT:
+    return 4;
+    break;
+  default:
+    return 4;
+    break;
+  }
+}
+
+inline std::string format2string(GLenum format)
+{
+  switch(format) 
+  {
+  case GL_LUMINANCE:
+  case GL_INTENSITY:
+  case GL_ALPHA:
+    return "lum";
+  	break;
+  case GL_LUMINANCE_ALPHA:
+    return "luma";
+  	break;
+  case GL_RGB:
+  case GL_BGR:
+    return "rgb";
+    break;
+  case GL_RGBA:
+  case GL_BGRA:
+  case GL_ABGR_EXT:
+    return "rgba";
+    break;
+  default:
+    return "rgb";
+    break;
+  }
+}
+#endif //__IMDEBUGGL_H__
Index: /NonGTP/ImageDebugger/include/imdebugd3d9.h
===================================================================
--- /NonGTP/ImageDebugger/include/imdebugd3d9.h	(revision 856)
+++ /NonGTP/ImageDebugger/include/imdebugd3d9.h	(revision 856)
@@ -0,0 +1,104 @@
+#ifndef __IMDEBUGD3D_H__
+#define __IMDEBUGD3D_H__
+
+#include <imdebug.h>
+#include <d3d9.h>
+#include <string>
+
+using namespace std;
+
+string format2string(D3DFORMAT format);
+
+inline HRESULT
+imdebugRenderTarget(IDirect3DSurface9 *pRenderTarget, IDirect3DDevice9 *pd3dDevice, char *argstring = NULL)
+{
+    HRESULT hr = S_OK;
+    IDirect3DTexture9 *pTempTex;
+    IDirect3DSurface9 *pData;
+    D3DSURFACE_DESC desc;
+    V( pRenderTarget->GetDesc(&desc) );
+
+    V( D3DXCreateTexture(pd3dDevice, desc.Width, desc.Height, 0, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pTempTex) );
+    V( pTempTex->GetSurfaceLevel(0, &pData) );
+    V( pd3dDevice->GetRenderTargetData(pRenderTarget, pData));
+
+    D3DLOCKED_RECT lockedRect;
+    V( pData->LockRect(&lockedRect, NULL, D3DLOCK_READONLY) );
+
+    string s = (NULL == argstring) ? format2string(desc.Format) : argstring;
+
+    imdebug(s.append(" w=%d h=%d %p").c_str(), desc.Width, desc.Height, lockedRect.pBits);
+
+    pData->UnlockRect();
+
+    SAFE_RELEASE(pTempTex);
+    SAFE_RELEASE(pData);
+
+    return hr;
+}
+
+
+inline string format2string(D3DFORMAT format)
+{
+    switch(format) 
+    {
+    case D3DFMT_R16F:
+    case D3DFMT_R32F:
+        return "lum b=32f";
+        break;
+    case D3DFMT_A8:
+    case D3DFMT_P8:
+    case D3DFMT_L8:
+    case D3DFMT_L16:
+    case D3DFMT_D16_LOCKABLE:
+    case D3DFMT_D32F_LOCKABLE:
+        return "lum";
+        break;
+    case D3DFMT_G16R16F:
+        return "luma b=32f";
+        break;
+    case D3DFMT_V8U8:
+    case D3DFMT_V16U16:
+    case D3DFMT_G16R16:
+    case D3DFMT_A8P8:
+    case D3DFMT_A8L8:
+    case D3DFMT_A4L4:
+        return "luma";
+        break;
+    case D3DFMT_R3G3B2:
+    case D3DFMT_R5G6B5:
+    case D3DFMT_R8G8B8:
+    case D3DFMT_CxV8U8:
+    case D3DFMT_L6V5U5:
+        return "rgb";
+        break;
+    case D3DFMT_X4R4G4B4:
+    case D3DFMT_A8R3G3B2:
+    case D3DFMT_A4R4G4B4:
+    case D3DFMT_A1R5G5B5:
+    case D3DFMT_X1R5G5B5:
+    case D3DFMT_X8R8G8B8:
+    case D3DFMT_A8R8G8B8:
+    case D3DFMT_Q16W16V16U16:
+    case D3DFMT_Q8W8V8U8:
+    case D3DFMT_A2W10V10U10:
+    case D3DFMT_X8L8V8U8:
+        return "rgba";
+        break;
+    case D3DFMT_X8B8G8R8:
+    case D3DFMT_A8B8G8R8:
+    case D3DFMT_A16B16G16R16:
+    case D3DFMT_A2R10G10B10:
+    case D3DFMT_A2B10G10R10:
+        return "abgr";
+        break;
+    case D3DFMT_A16B16G16R16F:
+    case D3DFMT_A32B32G32R32F:
+        return "abgr b=32f";
+        break;
+    default:
+        return "rgba";
+        break;
+    }
+}
+#endif
