PNGImage.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PNGIMAGE_H_
  23. #define _PNGIMAGE_H_
  24. #ifndef _CONSOLEINTERNAL_H_
  25. #include "console/consoleInternal.h"
  26. #endif
  27. #include <png.h>
  28. #include "platform/types.h"
  29. #include "console/console.h"
  30. #include "console/consoleTypes.h"
  31. enum PNGImageType { PNGTYPE_UNKNOWN = 0, PNGTYPE_RGB, PNGTYPE_RGBA };
  32. class PNGImage : public SimObject
  33. {
  34. typedef SimObject Parent;
  35. protected:
  36. U32 mWidth, mHeight;
  37. png_byte mColorType;
  38. png_byte mBitDepth;
  39. png_structp mPng;
  40. png_infop mInfo;
  41. png_bytep* mRowPointers;
  42. PNGImageType mPNGImageType;
  43. char mReadFilePath[256];
  44. bool mRead;
  45. bool mWrite;
  46. public:
  47. PNGImage();
  48. ~PNGImage();
  49. DECLARE_CONOBJECT(PNGImage);
  50. /// Construct the png information from the .png file path provided.
  51. bool Read(const char* filePath);
  52. bool Create(U32 width, U32 height, PNGImageType imageType);
  53. /// Write the .png file read from Read and save it to the file path provided.
  54. bool Write(const char* filePath);
  55. // Will "merge" the incoming image onto the current image on to an x, y position.
  56. bool MergeOn(U32 x, U32 y, const PNGImage* inc);
  57. // Will clean up any allocated memory from the PNGImage. This must be called or there may be a memory leak.
  58. bool CleanMemoryUsage();
  59. bool ClearImageData();
  60. U32 GetWidth() const { return mWidth; }
  61. U32 GetHeight() const { return mHeight; }
  62. const png_bytep* GetRowPointers() const { return mRowPointers; }
  63. const png_structp GetPng() const { return mPng; }
  64. const png_infop GetInfo() const { return mInfo; }
  65. const char* GetReadFilePath() { return mReadFilePath; }
  66. PNGImageType GetPNGImageType() const { return mPNGImageType; }
  67. };
  68. #endif