Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bin_to_bmp.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2009 VMware, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "pipe/p_compiler.h"
  25. #include "pipe/p_format.h"
  26. #include "pipe/p_state.h"
  27. #include "util/u_memory.h"
  28. #include "util/u_debug.h"
  29. #include "util/u_network.h"
  30. #include "util/u_tile.h"
  31. static uint8_t* read(const char *filename, unsigned size);
  32. static void dump(unsigned src_width, unsigned src_height,
  33. unsigned src_stride, enum pipe_format src_format,
  34. uint8_t *data, unsigned src_size);
  35. int main(int argc, char** argv)
  36. {
  37. /* change these */
  38. unsigned width = 64;
  39. unsigned height = 64;
  40. unsigned stride = width * 4;
  41. unsigned size = stride * height;
  42. const char *filename = "mybin.bin";
  43. enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM;
  44. dump(width, height, stride, format, read(filename, size), size);
  45. return 0;
  46. }
  47. static void dump(unsigned width, unsigned height,
  48. unsigned src_stride, enum pipe_format src_format,
  49. uint8_t *data, unsigned src_size)
  50. {
  51. struct pipe_format_block src_block;
  52. enum pipe_format dst_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
  53. struct pipe_format_block dst_block;
  54. unsigned dst_stride;
  55. unsigned dst_size;
  56. float *rgba;
  57. int i;
  58. char filename[512];
  59. {
  60. pf_get_block(src_format, &src_block);
  61. assert(src_stride >= pf_get_stride(&src_block, width));
  62. assert(src_size >= pf_get_2d_size(&src_block, src_stride, width));
  63. }
  64. {
  65. pf_get_block(dst_format, &dst_block);
  66. dst_stride = pf_get_stride(&dst_block, width);
  67. dst_size = pf_get_2d_size(&dst_block, dst_stride, width);
  68. rgba = MALLOC(dst_size);
  69. }
  70. util_snprintf(filename, 512, "%s.bmp", pf_name(src_format));
  71. if (pf_is_compressed(src_format)) {
  72. debug_printf("skipping: %s\n", filename);
  73. return;
  74. }
  75. debug_printf("saving: %s\n", filename);
  76. for (i = 0; i < height; i++) {
  77. pipe_tile_raw_to_rgba(src_format, data + src_stride * i,
  78. width, 1,
  79. &rgba[width*4*i], dst_stride);
  80. }
  81. debug_dump_float_rgba_bmp(filename, width, height, rgba, width);
  82. FREE(rgba);
  83. }
  84. static uint8_t* read(const char *filename, unsigned size)
  85. {
  86. uint8_t *data;
  87. FILE *file = fopen(filename, "rb");
  88. data = MALLOC(size);
  89. fread(data, 1, size, file);
  90. fclose(file);
  91. return data;
  92. }