Image.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef IMAGE_H__
  2. #define IMAGE_H__
  3. namespace gameplay
  4. {
  5. /**
  6. * Represents an image (currently only supports PNG files).
  7. */
  8. class Image
  9. {
  10. public:
  11. /**
  12. * Defines the set of supported image formats.
  13. */
  14. enum Format
  15. {
  16. LUMINANCE,
  17. RGB,
  18. RGBA
  19. };
  20. /**
  21. * Destructor.
  22. */
  23. ~Image();
  24. /**
  25. * Creates an image from the image file at the given path.
  26. *
  27. * @param path The path to the image file.
  28. * @return The newly created image.
  29. */
  30. static Image* create(const char* path);
  31. /**
  32. * Creates a new empty image of the given format and size.
  33. *
  34. * @param format Image format.
  35. * @param width Image width.
  36. * @param height Image height.
  37. * @return The newly created image.
  38. */
  39. static Image* create(Format format, unsigned int width, unsigned int height);
  40. /**
  41. * Gets the image's raw pixel data.
  42. *
  43. * @return The image's pixel data.
  44. */
  45. void* getData() const;
  46. /**
  47. * Sets the image's raw pixel data.
  48. *
  49. * The passed in data MUST be at least width*height*bpp
  50. * bytes of data.
  51. */
  52. void setData(void* data);
  53. /**
  54. * Gets the image's format.
  55. *
  56. * @return The image's format.
  57. */
  58. Format getFormat() const;
  59. /**
  60. * Gets the height of the image.
  61. *
  62. * @return The height of the image.
  63. */
  64. unsigned int getHeight() const;
  65. /**
  66. * Gets the width of the image.
  67. *
  68. * @return The width of the image.
  69. */
  70. unsigned int getWidth() const;
  71. /**
  72. * Returns the number of bytes per pixel for this image.
  73. *
  74. * @return The number of bytes per pixel.
  75. */
  76. unsigned int getBpp() const;
  77. /**
  78. * Saves the contents of the image as a PNG to the specified location.
  79. *
  80. * @param path Path to save to.
  81. */
  82. void save(const char* path);
  83. private:
  84. /**
  85. * Hidden constructor.
  86. */
  87. Image();
  88. /**
  89. * Hidden copy constructor.
  90. */
  91. Image(const Image&);
  92. /**
  93. * Hidden copy assignment operator.
  94. */
  95. Image& operator=(const Image&);
  96. unsigned char* _data;
  97. Format _format;
  98. unsigned int _height;
  99. unsigned int _width;
  100. unsigned int _bpp;
  101. };
  102. }
  103. #endif