debug: Add function for writing transfers to files
authorJakob Bornecrantz <jakob@vmware.com>
Sat, 21 Mar 2009 13:23:04 +0000 (14:23 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Sun, 22 Mar 2009 03:59:09 +0000 (04:59 +0100)
src/gallium/auxiliary/util/u_debug.c
src/gallium/auxiliary/util/u_debug.h

index f96e27e09fd130e1399fb35aa9135fd6a367ff08..0af69d8c8f04f4a56b20eca95e822133ca87c156 100644 (file)
@@ -715,78 +715,85 @@ struct bmp_rgb_quad {
    uint8_t rgbAlpha;
 };
 
-void 
+void
 debug_dump_surface_bmp(const char *filename,
                        struct pipe_surface *surface)
 {
-#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
+   struct pipe_transfer *transfer;
    struct pipe_texture *texture;
    struct pipe_screen *screen;
+
+   transfer = screen->get_tex_transfer(screen, texture, surface->face,
+                                       surface->level, surface->zslice,
+                                       PIPE_TRANSFER_READ, 0, 0, surface->width,
+                                       surface->height);
+
+   debug_dump_transfer_bmp(filename, transfer);
+
+   screen->tex_transfer_destroy(transfer);
+}
+
+void
+debug_dump_transfer_bmp(const char *filename,
+                        struct pipe_transfer *transfer)
+{
+#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
    struct util_stream *stream;
-   struct pipe_transfer *transfer;
    struct bmp_file_header bmfh;
    struct bmp_info_header bmih;
    float *rgba;
    unsigned x, y;
 
-   if (!surface)
+   if (!transfer)
       goto error1;
 
-   rgba = MALLOC(surface->width*4*sizeof(float));
+   rgba = MALLOC(transfer->width*transfer->height*4*sizeof(float));
    if(!rgba)
       goto error1;
-   
+
    bmfh.bfType = 0x4d42;
-   bmfh.bfSize = 14 + 40 + surface->height*surface->width*4;
+   bmfh.bfSize = 14 + 40 + transfer->height*transfer->width*4;
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;
    bmfh.bfOffBits = 14 + 40;
-   
+
    bmih.biSize = 40;
-   bmih.biWidth = surface->width;
-   bmih.biHeight = surface->height;
+   bmih.biWidth = transfer->width;
+   bmih.biHeight = transfer->height;
    bmih.biPlanes = 1;
    bmih.biBitCount = 32;
    bmih.biCompression = 0;
-   bmih.biSizeImage = surface->height*surface->width*4;
+   bmih.biSizeImage = transfer->height*transfer->width*4;
    bmih.biXPelsPerMeter = 0;
    bmih.biYPelsPerMeter = 0;
    bmih.biClrUsed = 0;
    bmih.biClrImportant = 0;
-   
+
    stream = util_stream_create(filename, bmfh.bfSize);
    if(!stream)
       goto error2;
-   
+
    util_stream_write(stream, &bmfh, 14);
    util_stream_write(stream, &bmih, 40);
 
-   texture = surface->texture;
-   screen = texture->screen;
-   
-   transfer = screen->get_tex_transfer(screen, texture, surface->face,
-                                       surface->level, surface->zslice,
-                                       PIPE_TRANSFER_READ, 0, 0, surface->width,
-                                       surface->height);
+   pipe_get_tile_rgba(transfer, 0, 0,
+                      transfer->width, transfer->height,
+                      rgba);
 
-   y = surface->height;
+   y = transfer->height;
    while(y--) {
-      pipe_get_tile_rgba(transfer,
-                         0, y, surface->width, 1,
-                         rgba);
-      for(x = 0; x < surface->width; ++x)
+      float *ptr = rgba + (transfer->width * y * 4);
+      for(x = 0; x < transfer->width; ++x)
       {
          struct bmp_rgb_quad pixel;
-         pixel.rgbRed   = float_to_ubyte(rgba[x*4 + 0]);
-         pixel.rgbGreen = float_to_ubyte(rgba[x*4 + 1]);
-         pixel.rgbBlue  = float_to_ubyte(rgba[x*4 + 2]);
-         pixel.rgbAlpha = float_to_ubyte(rgba[x*4 + 3]);
+         pixel.rgbRed   = float_to_ubyte(ptr[x*4 + 0]);
+         pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]);
+         pixel.rgbBlue  = float_to_ubyte(ptr[x*4 + 2]);
+         pixel.rgbAlpha = 255;
          util_stream_write(stream, &pixel, 4);
-      }  
+      }
    }
 
-   screen->tex_transfer_destroy(transfer);
-   
    util_stream_close(stream);
 error2:
    FREE(rgba);
index 7c829707b2011d29eeecfd75759b36bec7e13213..33e7cb3419ecd23349a662c2fdc6dfded962ef18 100644 (file)
@@ -338,6 +338,7 @@ debug_profile_stop(void);
 
 #ifdef DEBUG
 struct pipe_surface;
+struct pipe_transfer;
 void debug_dump_image(const char *prefix,
                       unsigned format, unsigned cpp,
                       unsigned width, unsigned height,
@@ -347,6 +348,8 @@ void debug_dump_surface(const char *prefix,
                         struct pipe_surface *surface);   
 void debug_dump_surface_bmp(const char *filename,
                             struct pipe_surface *surface);
+void debug_dump_transfer_bmp(const char *filename,
+                             struct pipe_transfer *transfer);
 #else
 #define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
 #define debug_dump_surface(prefix, surface) ((void)0)