gallium/util: added debug_dump_texture() and ppm output
Now we can get dump debug images on Linux too.
This commit is contained in:
parent
dfd6e762e7
commit
4f5675e94b
|
@ -631,6 +631,14 @@ const char *u_prim_name( unsigned prim )
|
|||
|
||||
|
||||
#ifdef DEBUG
|
||||
/**
|
||||
* Dump an image to a .raw or .ppm file (depends on OS).
|
||||
* \param format PIPE_FORMAT_x
|
||||
* \param cpp bytes per pixel
|
||||
* \param width width in pixels
|
||||
* \param height height in pixels
|
||||
* \param stride row stride in bytes
|
||||
*/
|
||||
void debug_dump_image(const char *prefix,
|
||||
unsigned format, unsigned cpp,
|
||||
unsigned width, unsigned height,
|
||||
|
@ -672,6 +680,52 @@ void debug_dump_image(const char *prefix,
|
|||
}
|
||||
|
||||
EngUnmapFile(iFile);
|
||||
#elif defined(PIPE_OS_UNIX)
|
||||
/* write a ppm file */
|
||||
char filename[256];
|
||||
FILE *f;
|
||||
|
||||
util_snprintf(filename, sizeof(filename), "%s.ppm", prefix);
|
||||
|
||||
f = fopen(filename, "w");
|
||||
if (f) {
|
||||
int i, x, y;
|
||||
int r, g, b;
|
||||
const uint8_t *ptr = (uint8_t *) data;
|
||||
|
||||
/* XXX this is a hack */
|
||||
switch (format) {
|
||||
case PIPE_FORMAT_A8R8G8B8_UNORM:
|
||||
r = 2;
|
||||
g = 1;
|
||||
b = 0;
|
||||
break;
|
||||
default:
|
||||
r = 0;
|
||||
g = 1;
|
||||
b = 1;
|
||||
}
|
||||
|
||||
fprintf(f, "P6\n");
|
||||
fprintf(f, "# ppm-file created by osdemo.c\n");
|
||||
fprintf(f, "%i %i\n", width, height);
|
||||
fprintf(f, "255\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen(filename, "ab"); /* reopen in binary append mode */
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
i = y * stride + x * cpp;
|
||||
fputc(ptr[i + r], f); /* write red */
|
||||
fputc(ptr[i + g], f); /* write green */
|
||||
fputc(ptr[i + b], f); /* write blue */
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Can't open %s for writing\n", filename);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -712,6 +766,27 @@ error:
|
|||
}
|
||||
|
||||
|
||||
void debug_dump_texture(const char *prefix,
|
||||
struct pipe_texture *texture)
|
||||
{
|
||||
struct pipe_surface *surface;
|
||||
struct pipe_screen *screen;
|
||||
|
||||
if (!texture)
|
||||
return;
|
||||
|
||||
screen = texture->screen;
|
||||
|
||||
/* XXX for now, just dump image for face=0, level=0 */
|
||||
surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
|
||||
PIPE_TEXTURE_USAGE_SAMPLER);
|
||||
if (surface) {
|
||||
debug_dump_surface(prefix, surface);
|
||||
screen->tex_surface_destroy(surface);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma pack(push,2)
|
||||
struct bmp_file_header {
|
||||
uint16_t bfType;
|
||||
|
|
|
@ -354,6 +354,8 @@ debug_memory_end(unsigned long beginning);
|
|||
#ifdef DEBUG
|
||||
struct pipe_surface;
|
||||
struct pipe_transfer;
|
||||
struct pipe_texture;
|
||||
|
||||
void debug_dump_image(const char *prefix,
|
||||
unsigned format, unsigned cpp,
|
||||
unsigned width, unsigned height,
|
||||
|
@ -361,6 +363,8 @@ void debug_dump_image(const char *prefix,
|
|||
const void *data);
|
||||
void debug_dump_surface(const char *prefix,
|
||||
struct pipe_surface *surface);
|
||||
void debug_dump_texture(const char *prefix,
|
||||
struct pipe_texture *texture);
|
||||
void debug_dump_surface_bmp(const char *filename,
|
||||
struct pipe_surface *surface);
|
||||
void debug_dump_transfer_bmp(const char *filename,
|
||||
|
|
Loading…
Reference in New Issue