glbmp.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef GLBMP_BASIC_USE
  2. #define GLBMP_BASIC_USE
  3. /*
  4. * Basic external API of glbmp. If you're using this for an OpenGL project,
  5. * you don't need to do anything.
  6. */
  7. /* loads pixel data from specified BMP file into a big buffer of unsigned chars */
  8. unsigned char *
  9. GLBMP_load_pixel_data(const char *filepath, int *width, int *height, int *channels, int force_channels);
  10. /* convenience function to dispose of pixel data buffer after use */
  11. void
  12. GLBMP_free_pixel_data(unsigned char *image);
  13. /* print information contained in bmp headers */
  14. void
  15. GLBMP_print_headers(const char *fpath);
  16. #endif /* GLIMG_BASIC_USE */
  17. #ifndef GLBMP_INTERNAL_USED
  18. #ifdef GLBMP_INTERNAL
  19. /*
  20. * NOTE: You will not need to use the following macro unless writing you
  21. * are working on an implementation of glbmp.h
  22. *
  23. * Structure definitions and function declaractions used internally by a
  24. * glbmp.h implementation.
  25. */
  26. #include <inttypes.h>
  27. struct GLBMP_file_header
  28. {
  29. char bfType[2]; /* identifying characters 'BM' */
  30. uint32_t bfSize; /* size of the file */
  31. int16_t bfReserved1; /* two reserved variables at 2 bytes each */
  32. int16_t bfReserved2;
  33. uint32_t bfOffBits; /* the offset to the pixeldata section */
  34. };
  35. struct GLBMP_image_header
  36. {
  37. uint32_t biSize; /* header size - minimum of 40 */
  38. int32_t biWidth; /* image width in pixels */
  39. int32_t biHeight; /* image height in pixels */
  40. uint16_t biPlanes; /* must be 1 */
  41. uint16_t biBitCount; /* bits per pixel (1/4/8/16/24/32) */
  42. uint32_t biCompression; /* compression type (0 = uncompressed) */
  43. uint32_t biSizeImage; /* size of image - uncompressed images can be zero */
  44. uint32_t biXPelsPerMeter; /* preferred resolution in pixels per meter for (X/Y) */
  45. uint32_t biYPelsPerMeter;
  46. uint32_t biClrUsed; /* number of color map entries used */
  47. uint32_t biClrImportant; /* number of significant colors */
  48. };
  49. /*
  50. * A struct describing the layout of compliant BMP files
  51. */
  52. typedef struct GLBMP_bmp_headers
  53. {
  54. struct GLBMP_file_header fhead;
  55. struct GLBMP_image_header ihead;
  56. } GLBMP_bmp_headers;
  57. #endif /* GLBMP_INTERNAL */
  58. #endif /* GLBMP_INTERNAL_USED */