LoadBitmap.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (c) 2009 Christopher A. Taylor. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. * Neither the name of LibCat nor the names of its contributors may be used
  11. to endorse or promote products derived from this software without
  12. specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  17. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef LOAD_BITMAP_HPP
  26. #define LOAD_BITMAP_HPP
  27. #include <cat/Platform.hpp>
  28. namespace cat {
  29. /*
  30. LoadBitmap() loads a memory-mapped bitmap or a file from disk into RGBA format,
  31. meaning the first byte of every pixel is Red, then Green, Blue, and Alpha.
  32. The output data is useful for creating an OpenGL texture using GL_RGBA format.
  33. The output width and height will be powers of two.
  34. Parameters:
  35. file, bytes : Memory-mapped file pointer and number of bytes in the file
  36. path : Alternatively, the path to the file to load
  37. width, height : The dimensions of the loaded file, in pixels
  38. Returns: Zero on error, or a pointer to the rasterized RGBA pixels.
  39. Free the allocated memory using Aligned::Delete(a);
  40. */
  41. void *LoadBitmap(void *file, u32 bytes, u32 &width, u32 &height);
  42. void *LoadBitmap(const char *path, u32 &width, u32 &height);
  43. class BMPTokenizer
  44. {
  45. u8 trans_red, trans_green, trans_blue;
  46. bool requirePOTS; // Require Power-of-Two Size
  47. void rasterizeImage(u8 *image);
  48. void onImage(u32 *image, u32 newWidth, u32 newHeight);
  49. public:
  50. BMPTokenizer();
  51. ~BMPTokenizer();
  52. public:
  53. bool LoadFile(const char *path);
  54. };
  55. } // namespace cat
  56. #endif // LOAD_BITMAP_HPP
粤ICP备19079148号