1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright (c) 2008 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 #include "pipe/p_config.h"
32 #include "pipe/p_compiler.h"
33 #include "os/os_stream.h"
34 #include "util/u_debug.h"
35 #include "pipe/p_format.h"
36 #include "pipe/p_state.h"
37 #include "util/u_inlines.h"
38 #include "util/u_format.h"
39 #include "util/u_memory.h"
40 #include "util/u_string.h"
41 #include "util/u_math.h"
42 #include "util/u_tile.h"
43 #include "util/u_prim.h"
46 void _debug_vprintf(const char *format
, va_list ap
)
48 /* We buffer until we find a newline. */
49 static char buf
[4096] = {'\0'};
50 size_t len
= strlen(buf
);
51 int ret
= util_vsnprintf(buf
+ len
, sizeof(buf
) - len
, format
, ap
);
52 if(ret
> (int)(sizeof(buf
) - len
- 1) || util_strchr(buf
+ len
, '\n')) {
60 void debug_print_blob( const char *name
,
64 const unsigned *ublob
= (const unsigned *)blob
;
67 debug_printf("%s (%d dwords%s)\n", name
, size
/4,
68 size
%4 ? "... plus a few bytes" : "");
70 for (i
= 0; i
< size
/4; i
++) {
71 debug_printf("%d:\t%08x\n", i
, ublob
[i
]);
78 debug_get_option(const char *name
, const char *dfault
)
82 result
= os_get_option(name
);
86 debug_printf("%s: %s = %s\n", __FUNCTION__
, name
, result
? result
: "(null)");
92 debug_get_bool_option(const char *name
, boolean dfault
)
94 const char *str
= os_get_option(name
);
99 else if(!util_strcmp(str
, "n"))
101 else if(!util_strcmp(str
, "no"))
103 else if(!util_strcmp(str
, "0"))
105 else if(!util_strcmp(str
, "f"))
107 else if(!util_strcmp(str
, "false"))
112 debug_printf("%s: %s = %s\n", __FUNCTION__
, name
, result
? "TRUE" : "FALSE");
119 debug_get_num_option(const char *name
, long dfault
)
124 str
= os_get_option(name
);
139 while('0' <= c
&& c
<= '9') {
140 result
= result
*10 + (c
- '0');
146 debug_printf("%s: %s = %li\n", __FUNCTION__
, name
, result
);
153 debug_get_flags_option(const char *name
,
154 const struct debug_named_value
*flags
,
155 unsigned long dfault
)
157 unsigned long result
;
160 str
= os_get_option(name
);
163 else if (!util_strcmp(str
, "help")) {
165 while (flags
->name
) {
166 debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__
, name
, flags
->name
, flags
->value
);
172 while( flags
->name
) {
173 if (!util_strcmp(str
, "all") || util_strstr(str
, flags
->name
))
174 result
|= flags
->value
;
180 debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__
, name
, result
, str
);
183 debug_printf("%s: %s = 0x%lx\n", __FUNCTION__
, name
, result
);
190 void _debug_assert_fail(const char *expr
,
193 const char *function
)
195 _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file
, line
, function
, expr
);
196 #if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER)
197 if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE
))
199 if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE
))
203 _debug_printf("continuing...\n");
208 debug_dump_enum(const struct debug_named_value
*names
,
211 static char rest
[64];
214 if(names
->value
== value
)
219 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
225 debug_dump_enum_noprefix(const struct debug_named_value
*names
,
229 static char rest
[64];
232 if(names
->value
== value
) {
233 const char *name
= names
->name
;
234 while (*name
== *prefix
) {
245 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
251 debug_dump_flags(const struct debug_named_value
*names
,
254 static char output
[4096];
255 static char rest
[256];
261 if((names
->value
& value
) == names
->value
) {
263 util_strncat(output
, "|", sizeof(output
));
266 util_strncat(output
, names
->name
, sizeof(output
) - 1);
267 output
[sizeof(output
) - 1] = '\0';
268 value
&= ~names
->value
;
275 util_strncat(output
, "|", sizeof(output
));
279 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
280 util_strncat(output
, rest
, sizeof(output
) - 1);
281 output
[sizeof(output
) - 1] = '\0';
291 static const struct debug_named_value pipe_format_names
[] = {
293 DEBUG_NAMED_VALUE(PIPE_FORMAT_NONE
),
294 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_UNORM
),
295 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_UNORM
),
296 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_UNORM
),
297 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_UNORM
),
298 DEBUG_NAMED_VALUE(PIPE_FORMAT_A1R5G5B5_UNORM
),
299 DEBUG_NAMED_VALUE(PIPE_FORMAT_A4R4G4B4_UNORM
),
300 DEBUG_NAMED_VALUE(PIPE_FORMAT_R5G6B5_UNORM
),
301 DEBUG_NAMED_VALUE(PIPE_FORMAT_A2B10G10R10_UNORM
),
302 DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_UNORM
),
303 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8_UNORM
),
304 DEBUG_NAMED_VALUE(PIPE_FORMAT_I8_UNORM
),
305 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_UNORM
),
306 DEBUG_NAMED_VALUE(PIPE_FORMAT_L16_UNORM
),
307 DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR
),
308 DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR_REV
),
309 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z16_UNORM
),
310 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_UNORM
),
311 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_FLOAT
),
312 DEBUG_NAMED_VALUE(PIPE_FORMAT_S8Z24_UNORM
),
313 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24S8_UNORM
),
314 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8Z24_UNORM
),
315 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24X8_UNORM
),
316 DEBUG_NAMED_VALUE(PIPE_FORMAT_S8_UNORM
),
317 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64_FLOAT
),
318 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64_FLOAT
),
319 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64_FLOAT
),
320 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64A64_FLOAT
),
321 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_FLOAT
),
322 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_FLOAT
),
323 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_FLOAT
),
324 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_FLOAT
),
325 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_UNORM
),
326 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_UNORM
),
327 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_UNORM
),
328 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_UNORM
),
329 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_USCALED
),
330 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_USCALED
),
331 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_USCALED
),
332 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_USCALED
),
333 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SNORM
),
334 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SNORM
),
335 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SNORM
),
336 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SNORM
),
337 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SSCALED
),
338 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SSCALED
),
339 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SSCALED
),
340 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SSCALED
),
341 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_UNORM
),
342 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_UNORM
),
343 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_UNORM
),
344 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_UNORM
),
345 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_USCALED
),
346 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_USCALED
),
347 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_USCALED
),
348 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_USCALED
),
349 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SNORM
),
350 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SNORM
),
351 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SNORM
),
352 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SNORM
),
353 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SSCALED
),
354 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SSCALED
),
355 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SSCALED
),
356 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SSCALED
),
357 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_UNORM
),
358 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_UNORM
),
359 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_UNORM
),
360 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_UNORM
),
361 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_UNORM
),
362 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_USCALED
),
363 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_USCALED
),
364 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_USCALED
),
365 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_USCALED
),
366 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_USCALED
),
367 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SNORM
),
368 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SNORM
),
369 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SNORM
),
370 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SNORM
),
371 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SNORM
),
372 DEBUG_NAMED_VALUE(PIPE_FORMAT_B6G5R5_SNORM
),
373 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8B8G8R8_SNORM
),
374 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8B8G8R8_SNORM
),
375 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SSCALED
),
376 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SSCALED
),
377 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SSCALED
),
378 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SSCALED
),
379 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SSCALED
),
380 DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_SRGB
),
381 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_SRGB
),
382 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SRGB
),
383 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SRGB
),
384 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SRGB
),
385 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_SRGB
),
386 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_SRGB
),
387 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_SRGB
),
388 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_SRGB
),
389 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8UB8UG8SR8S_NORM
),
390 DEBUG_NAMED_VALUE(PIPE_FORMAT_B6UG5SR5S_NORM
),
391 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGB
),
392 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGBA
),
393 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_RGBA
),
394 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_RGBA
),
395 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGB
),
396 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGBA
),
397 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_SRGBA
),
398 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_SRGBA
),
400 DEBUG_NAMED_VALUE_END
404 void debug_print_format(const char *msg
, unsigned fmt
)
406 debug_printf("%s: %s\n", msg
, debug_dump_enum(pipe_format_names
, fmt
));
410 const char *pf_name( enum pipe_format format
)
412 return debug_dump_enum(pipe_format_names
, format
);
417 static const struct debug_named_value pipe_prim_names
[] = {
419 DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS
),
420 DEBUG_NAMED_VALUE(PIPE_PRIM_LINES
),
421 DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_LOOP
),
422 DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP
),
423 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES
),
424 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP
),
425 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_FAN
),
426 DEBUG_NAMED_VALUE(PIPE_PRIM_QUADS
),
427 DEBUG_NAMED_VALUE(PIPE_PRIM_QUAD_STRIP
),
428 DEBUG_NAMED_VALUE(PIPE_PRIM_POLYGON
),
430 DEBUG_NAMED_VALUE_END
434 const char *u_prim_name( unsigned prim
)
436 return debug_dump_enum(pipe_prim_names
, prim
);
444 * Dump an image to a .raw or .ppm file (depends on OS).
445 * \param format PIPE_FORMAT_x
446 * \param cpp bytes per pixel
447 * \param width width in pixels
448 * \param height height in pixels
449 * \param stride row stride in bytes
451 void debug_dump_image(const char *prefix
,
452 unsigned format
, unsigned cpp
,
453 unsigned width
, unsigned height
,
457 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
458 static unsigned no
= 0;
460 WCHAR wfilename
[sizeof(filename
)];
468 unsigned char *pMap
= NULL
;
471 util_snprintf(filename
, sizeof(filename
), "\\??\\c:\\%03u%s.raw", ++no
, prefix
);
472 for(i
= 0; i
< sizeof(filename
); ++i
)
473 wfilename
[i
] = (WCHAR
)filename
[i
];
475 pMap
= (unsigned char *)EngMapFile(wfilename
, sizeof(header
) + height
*width
*cpp
, &iFile
);
479 header
.format
= format
;
481 header
.width
= width
;
482 header
.height
= height
;
483 memcpy(pMap
, &header
, sizeof(header
));
484 pMap
+= sizeof(header
);
486 for(i
= 0; i
< height
; ++i
) {
487 memcpy(pMap
, (unsigned char *)data
+ stride
*i
, cpp
*width
);
492 #elif defined(PIPE_OS_UNIX)
493 /* write a ppm file */
497 util_snprintf(filename
, sizeof(filename
), "%s.ppm", prefix
);
499 f
= fopen(filename
, "w");
503 const uint8_t *ptr
= (uint8_t *) data
;
505 /* XXX this is a hack */
507 case PIPE_FORMAT_A8R8G8B8_UNORM
:
519 fprintf(f
, "# ppm-file created by osdemo.c\n");
520 fprintf(f
, "%i %i\n", width
, height
);
524 f
= fopen(filename
, "ab"); /* reopen in binary append mode */
525 for (y
= 0; y
< height
; y
++) {
526 for (x
= 0; x
< width
; x
++) {
527 i
= y
* stride
+ x
* cpp
;
528 fputc(ptr
[i
+ r
], f
); /* write red */
529 fputc(ptr
[i
+ g
], f
); /* write green */
530 fputc(ptr
[i
+ b
], f
); /* write blue */
536 fprintf(stderr
, "Can't open %s for writing\n", filename
);
541 void debug_dump_surface(const char *prefix
,
542 struct pipe_surface
*surface
)
544 struct pipe_texture
*texture
;
545 struct pipe_screen
*screen
;
546 struct pipe_transfer
*transfer
;
552 texture
= surface
->texture
;
553 screen
= texture
->screen
;
555 transfer
= screen
->get_tex_transfer(screen
, texture
, surface
->face
,
556 surface
->level
, surface
->zslice
,
557 PIPE_TRANSFER_READ
, 0, 0, surface
->width
,
560 data
= screen
->transfer_map(screen
, transfer
);
564 debug_dump_image(prefix
,
566 util_format_get_blocksize(texture
->format
),
567 util_format_get_nblocksx(texture
->format
, transfer
->width
),
568 util_format_get_nblocksy(texture
->format
, transfer
->height
),
572 screen
->transfer_unmap(screen
, transfer
);
574 screen
->tex_transfer_destroy(transfer
);
578 void debug_dump_texture(const char *prefix
,
579 struct pipe_texture
*texture
)
581 struct pipe_surface
*surface
;
582 struct pipe_screen
*screen
;
587 screen
= texture
->screen
;
589 /* XXX for now, just dump image for face=0, level=0 */
590 surface
= screen
->get_tex_surface(screen
, texture
, 0, 0, 0,
591 PIPE_TEXTURE_USAGE_SAMPLER
);
593 debug_dump_surface(prefix
, surface
);
594 screen
->tex_surface_destroy(surface
);
600 struct bmp_file_header
{
603 uint16_t bfReserved1
;
604 uint16_t bfReserved2
;
609 struct bmp_info_header
{
615 uint32_t biCompression
;
616 uint32_t biSizeImage
;
617 int32_t biXPelsPerMeter
;
618 int32_t biYPelsPerMeter
;
620 uint32_t biClrImportant
;
623 struct bmp_rgb_quad
{
631 debug_dump_surface_bmp(const char *filename
,
632 struct pipe_surface
*surface
)
634 #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
635 struct pipe_transfer
*transfer
;
636 struct pipe_texture
*texture
= surface
->texture
;
637 struct pipe_screen
*screen
= texture
->screen
;
639 transfer
= screen
->get_tex_transfer(screen
, texture
, surface
->face
,
640 surface
->level
, surface
->zslice
,
641 PIPE_TRANSFER_READ
, 0, 0, surface
->width
,
644 debug_dump_transfer_bmp(filename
, transfer
);
646 screen
->tex_transfer_destroy(transfer
);
651 debug_dump_transfer_bmp(const char *filename
,
652 struct pipe_transfer
*transfer
)
654 #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
660 rgba
= MALLOC(transfer
->width
*transfer
->height
*4*sizeof(float));
664 pipe_get_tile_rgba(transfer
, 0, 0,
665 transfer
->width
, transfer
->height
,
668 debug_dump_float_rgba_bmp(filename
,
669 transfer
->width
, transfer
->height
,
670 rgba
, transfer
->width
);
679 debug_dump_float_rgba_bmp(const char *filename
,
680 unsigned width
, unsigned height
,
681 float *rgba
, unsigned stride
)
683 #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
684 struct os_stream
*stream
;
685 struct bmp_file_header bmfh
;
686 struct bmp_info_header bmih
;
692 bmfh
.bfType
= 0x4d42;
693 bmfh
.bfSize
= 14 + 40 + height
*width
*4;
694 bmfh
.bfReserved1
= 0;
695 bmfh
.bfReserved2
= 0;
696 bmfh
.bfOffBits
= 14 + 40;
699 bmih
.biWidth
= width
;
700 bmih
.biHeight
= height
;
702 bmih
.biBitCount
= 32;
703 bmih
.biCompression
= 0;
704 bmih
.biSizeImage
= height
*width
*4;
705 bmih
.biXPelsPerMeter
= 0;
706 bmih
.biYPelsPerMeter
= 0;
708 bmih
.biClrImportant
= 0;
710 stream
= os_stream_create(filename
, bmfh
.bfSize
);
714 os_stream_write(stream
, &bmfh
, 14);
715 os_stream_write(stream
, &bmih
, 40);
719 float *ptr
= rgba
+ (stride
* y
* 4);
720 for(x
= 0; x
< width
; ++x
)
722 struct bmp_rgb_quad pixel
;
723 pixel
.rgbRed
= float_to_ubyte(ptr
[x
*4 + 0]);
724 pixel
.rgbGreen
= float_to_ubyte(ptr
[x
*4 + 1]);
725 pixel
.rgbBlue
= float_to_ubyte(ptr
[x
*4 + 2]);
726 pixel
.rgbAlpha
= 255;
727 os_stream_write(stream
, &pixel
, 4);
731 os_stream_close(stream
);