Audio plugin host https://kx.studio/carla
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.

Image.hpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_IMAGE_HPP_INCLUDED
  17. #define DGL_IMAGE_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. /**
  22. Base DGL Image class.
  23. This is an Image class that handles raw image data in pixels.
  24. You can init the image data on the contructor or later on by calling loadFromMemory().
  25. To generate raw data useful for this class see the utils/png2rgba.py script.
  26. Be careful when using a PNG without alpha channel, for those the format is 'GL_BGR'
  27. instead of the default 'GL_BGRA'.
  28. Images are drawn on screen via 2D textures.
  29. */
  30. class Image
  31. {
  32. public:
  33. /**
  34. Constructor for a null Image.
  35. */
  36. Image();
  37. /**
  38. Constructor using raw image data.
  39. @note: @a rawData must remain valid for the lifetime of this Image.
  40. */
  41. Image(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
  42. /**
  43. Constructor using raw image data.
  44. @note: @a rawData must remain valid for the lifetime of this Image.
  45. */
  46. Image(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
  47. /**
  48. Constructor using another image data.
  49. */
  50. Image(const Image& image);
  51. /**
  52. Destructor.
  53. */
  54. ~Image();
  55. /**
  56. Load image data from memory.
  57. @note: @a rawData must remain valid for the lifetime of this Image.
  58. */
  59. void loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
  60. /**
  61. Load image data from memory.
  62. @note: @a rawData must remain valid for the lifetime of this Image.
  63. */
  64. void loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
  65. /**
  66. Check if this image is valid.
  67. */
  68. bool isValid() const noexcept;
  69. /**
  70. Get width.
  71. */
  72. uint getWidth() const noexcept;
  73. /**
  74. Get height.
  75. */
  76. uint getHeight() const noexcept;
  77. /**
  78. Get size.
  79. */
  80. const Size<uint>& getSize() const noexcept;
  81. /**
  82. Get the raw image data.
  83. */
  84. const char* getRawData() const noexcept;
  85. /**
  86. Get the image format.
  87. */
  88. GLenum getFormat() const noexcept;
  89. /**
  90. Get the image type.
  91. */
  92. GLenum getType() const noexcept;
  93. /**
  94. Draw this image at (0, 0) point.
  95. */
  96. void draw();
  97. /**
  98. Draw this image at (x, y) point.
  99. */
  100. void drawAt(const int x, const int y);
  101. /**
  102. Draw this image at position @a pos.
  103. */
  104. void drawAt(const Point<int>& pos);
  105. Image& operator=(const Image& image) noexcept;
  106. bool operator==(const Image& image) const noexcept;
  107. bool operator!=(const Image& image) const noexcept;
  108. private:
  109. const char* fRawData;
  110. Size<uint> fSize;
  111. GLenum fFormat;
  112. GLenum fType;
  113. GLuint fTextureId;
  114. bool fIsReady;
  115. };
  116. // -----------------------------------------------------------------------
  117. END_NAMESPACE_DGL
  118. #endif // DGL_IMAGE_HPP_INCLUDED