util: Add more entry points for dumping to bmp
This commit is contained in:
@@ -721,6 +721,7 @@ void
|
|||||||
debug_dump_surface_bmp(const char *filename,
|
debug_dump_surface_bmp(const char *filename,
|
||||||
struct pipe_surface *surface)
|
struct pipe_surface *surface)
|
||||||
{
|
{
|
||||||
|
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
|
||||||
struct pipe_transfer *transfer;
|
struct pipe_transfer *transfer;
|
||||||
struct pipe_texture *texture = surface->texture;
|
struct pipe_texture *texture = surface->texture;
|
||||||
struct pipe_screen *screen = texture->screen;
|
struct pipe_screen *screen = texture->screen;
|
||||||
@@ -733,6 +734,7 @@ debug_dump_surface_bmp(const char *filename,
|
|||||||
debug_dump_transfer_bmp(filename, transfer);
|
debug_dump_transfer_bmp(filename, transfer);
|
||||||
|
|
||||||
screen->tex_transfer_destroy(transfer);
|
screen->tex_transfer_destroy(transfer);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -740,32 +742,56 @@ debug_dump_transfer_bmp(const char *filename,
|
|||||||
struct pipe_transfer *transfer)
|
struct pipe_transfer *transfer)
|
||||||
{
|
{
|
||||||
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
|
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
|
||||||
struct util_stream *stream;
|
|
||||||
struct bmp_file_header bmfh;
|
|
||||||
struct bmp_info_header bmih;
|
|
||||||
float *rgba;
|
float *rgba;
|
||||||
unsigned x, y;
|
|
||||||
|
|
||||||
if (!transfer)
|
if (!transfer)
|
||||||
goto error1;
|
goto error1;
|
||||||
|
|
||||||
rgba = MALLOC(transfer->width*transfer->height*4*sizeof(float));
|
rgba = MALLOC(transfer->width*transfer->height*4*sizeof(float));
|
||||||
|
if(!rgba)
|
||||||
|
goto error1;
|
||||||
|
|
||||||
|
pipe_get_tile_rgba(transfer, 0, 0,
|
||||||
|
transfer->width, transfer->height,
|
||||||
|
rgba);
|
||||||
|
|
||||||
|
debug_dump_float_rgba_bmp(filename,
|
||||||
|
transfer->width, transfer->height,
|
||||||
|
rgba, transfer->width);
|
||||||
|
|
||||||
|
FREE(rgba);
|
||||||
|
error1:
|
||||||
|
;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
debug_dump_float_rgba_bmp(const char *filename,
|
||||||
|
unsigned width, unsigned height,
|
||||||
|
float *rgba, unsigned stride)
|
||||||
|
{
|
||||||
|
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
|
||||||
|
struct util_stream *stream;
|
||||||
|
struct bmp_file_header bmfh;
|
||||||
|
struct bmp_info_header bmih;
|
||||||
|
unsigned x, y;
|
||||||
|
|
||||||
if(!rgba)
|
if(!rgba)
|
||||||
goto error1;
|
goto error1;
|
||||||
|
|
||||||
bmfh.bfType = 0x4d42;
|
bmfh.bfType = 0x4d42;
|
||||||
bmfh.bfSize = 14 + 40 + transfer->height*transfer->width*4;
|
bmfh.bfSize = 14 + 40 + height*width*4;
|
||||||
bmfh.bfReserved1 = 0;
|
bmfh.bfReserved1 = 0;
|
||||||
bmfh.bfReserved2 = 0;
|
bmfh.bfReserved2 = 0;
|
||||||
bmfh.bfOffBits = 14 + 40;
|
bmfh.bfOffBits = 14 + 40;
|
||||||
|
|
||||||
bmih.biSize = 40;
|
bmih.biSize = 40;
|
||||||
bmih.biWidth = transfer->width;
|
bmih.biWidth = width;
|
||||||
bmih.biHeight = transfer->height;
|
bmih.biHeight = height;
|
||||||
bmih.biPlanes = 1;
|
bmih.biPlanes = 1;
|
||||||
bmih.biBitCount = 32;
|
bmih.biBitCount = 32;
|
||||||
bmih.biCompression = 0;
|
bmih.biCompression = 0;
|
||||||
bmih.biSizeImage = transfer->height*transfer->width*4;
|
bmih.biSizeImage = height*width*4;
|
||||||
bmih.biXPelsPerMeter = 0;
|
bmih.biXPelsPerMeter = 0;
|
||||||
bmih.biYPelsPerMeter = 0;
|
bmih.biYPelsPerMeter = 0;
|
||||||
bmih.biClrUsed = 0;
|
bmih.biClrUsed = 0;
|
||||||
@@ -773,19 +799,15 @@ debug_dump_transfer_bmp(const char *filename,
|
|||||||
|
|
||||||
stream = util_stream_create(filename, bmfh.bfSize);
|
stream = util_stream_create(filename, bmfh.bfSize);
|
||||||
if(!stream)
|
if(!stream)
|
||||||
goto error2;
|
goto error1;
|
||||||
|
|
||||||
util_stream_write(stream, &bmfh, 14);
|
util_stream_write(stream, &bmfh, 14);
|
||||||
util_stream_write(stream, &bmih, 40);
|
util_stream_write(stream, &bmih, 40);
|
||||||
|
|
||||||
pipe_get_tile_rgba(transfer, 0, 0,
|
y = height;
|
||||||
transfer->width, transfer->height,
|
|
||||||
rgba);
|
|
||||||
|
|
||||||
y = transfer->height;
|
|
||||||
while(y--) {
|
while(y--) {
|
||||||
float *ptr = rgba + (transfer->width * y * 4);
|
float *ptr = rgba + (stride * y * 4);
|
||||||
for(x = 0; x < transfer->width; ++x)
|
for(x = 0; x < width; ++x)
|
||||||
{
|
{
|
||||||
struct bmp_rgb_quad pixel;
|
struct bmp_rgb_quad pixel;
|
||||||
pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]);
|
pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]);
|
||||||
@@ -797,8 +819,6 @@ debug_dump_transfer_bmp(const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
util_stream_close(stream);
|
util_stream_close(stream);
|
||||||
error2:
|
|
||||||
FREE(rgba);
|
|
||||||
error1:
|
error1:
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -347,10 +347,15 @@ void debug_dump_surface_bmp(const char *filename,
|
|||||||
struct pipe_surface *surface);
|
struct pipe_surface *surface);
|
||||||
void debug_dump_transfer_bmp(const char *filename,
|
void debug_dump_transfer_bmp(const char *filename,
|
||||||
struct pipe_transfer *transfer);
|
struct pipe_transfer *transfer);
|
||||||
|
void debug_dump_float_rgba_bmp(const char *filename,
|
||||||
|
unsigned width, unsigned height,
|
||||||
|
float *rgba, unsigned stride);
|
||||||
#else
|
#else
|
||||||
#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
|
#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
|
||||||
#define debug_dump_surface(prefix, surface) ((void)0)
|
#define debug_dump_surface(prefix, surface) ((void)0)
|
||||||
#define debug_dump_surface_bmp(filename, surface) ((void)0)
|
#define debug_dump_surface_bmp(filename, surface) ((void)0)
|
||||||
|
#define debug_dump_transfer_bmp(filename, transfer) ((void)0)
|
||||||
|
#define debug_dump_rgba_float_bmp(filename, width, height, rgba, stride) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user