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.

63 lines
1.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. //
  11. // The Image class
  12. // ---------------
  13. //
  14. #if !defined __LOL_IMAGE_IMAGE_H__
  15. #define __LOL_IMAGE_IMAGE_H__
  16. #include <lol/math/vector.h>
  17. namespace lol
  18. {
  19. /* FIXME: is it possible to avoid the cast to int here? */
  20. template <PixelFormat T> struct PixelType { typedef void type; };
  21. template<> struct PixelType<PixelFormat::Y_8> { typedef uint8_t type; };
  22. template<> struct PixelType<PixelFormat::RGB_8> { typedef u8vec3 type; };
  23. template<> struct PixelType<PixelFormat::RGBA_8> { typedef u8vec4 type; };
  24. class Image
  25. {
  26. friend class ImageBank;
  27. friend class ImageCodec;
  28. public:
  29. Image();
  30. ~Image();
  31. static Image *Create(char const *path);
  32. bool Save(char const *path);
  33. void Destroy();
  34. PixelFormat GetFormat() const;
  35. void *LockGeneric();
  36. template<PixelFormat T> typename PixelType<T>::type *Lock();
  37. void Unlock();
  38. ivec2 GetSize() const;
  39. void SetSize(ivec2);
  40. bool RetrieveTiles(Array<ivec2, ivec2>& tiles) const;
  41. private:
  42. class ImageData *m_data;
  43. String m_path;
  44. };
  45. } /* namespace lol */
  46. #endif // __LOL_IMAGE_IMAGE_H__