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.

157 lines
4.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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_BASE_HPP_INCLUDED
  17. #define DGL_IMAGE_BASE_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. START_NAMESPACE_DGL
  20. // --------------------------------------------------------------------------------------------------------------------
  21. enum ImageFormat {
  22. kImageFormatNull,
  23. kImageFormatGrayscale,
  24. kImageFormatBGR,
  25. kImageFormatBGRA,
  26. kImageFormatRGB,
  27. kImageFormatRGBA,
  28. };
  29. /**
  30. Base DGL Image class.
  31. This is an Image class that handles raw image data in pixels.
  32. It is an abstract class that provides the common methods to build on top.
  33. Cairo and OpenGL Image classes are based upon this one.
  34. @see CairoImage, OpenGLImage
  35. */
  36. class ImageBase
  37. {
  38. protected:
  39. /**
  40. Constructor for a null Image.
  41. */
  42. ImageBase();
  43. /**
  44. Constructor using raw image data.
  45. @note @a rawData must remain valid for the lifetime of this Image.
  46. */
  47. ImageBase(const char* rawData, uint width, uint height, ImageFormat format);
  48. /**
  49. Constructor using raw image data.
  50. @note @a rawData must remain valid for the lifetime of this Image.
  51. */
  52. ImageBase(const char* rawData, const Size<uint>& size, ImageFormat format);
  53. /**
  54. Constructor using another image data.
  55. */
  56. ImageBase(const ImageBase& image);
  57. public:
  58. /**
  59. Destructor.
  60. */
  61. virtual ~ImageBase();
  62. /**
  63. Check if this image is valid.
  64. */
  65. bool isValid() const noexcept;
  66. /**
  67. Check if this image is not valid.
  68. */
  69. bool isInvalid() const noexcept;
  70. /**
  71. Get width.
  72. */
  73. uint getWidth() const noexcept;
  74. /**
  75. Get height.
  76. */
  77. uint getHeight() const noexcept;
  78. /**
  79. Get size.
  80. */
  81. const Size<uint>& getSize() const noexcept;
  82. /**
  83. Get the raw image data.
  84. */
  85. const char* getRawData() const noexcept;
  86. /**
  87. Get the image format.
  88. */
  89. ImageFormat getFormat() const noexcept;
  90. /**
  91. Load image data from memory.
  92. @note @a rawData must remain valid for the lifetime of this Image.
  93. */
  94. void loadFromMemory(const char* rawData, uint width, uint height, ImageFormat format = kImageFormatBGRA) noexcept;
  95. /**
  96. Load image data from memory.
  97. @note @a rawData must remain valid for the lifetime of this Image.
  98. */
  99. virtual void loadFromMemory(const char* rawData,
  100. const Size<uint>& size,
  101. ImageFormat format = kImageFormatBGRA) noexcept;
  102. /**
  103. Draw this image at (0, 0) point using the current OpenGL context.
  104. */
  105. void draw(const GraphicsContext& context);
  106. /**
  107. Draw this image at (x, y) point using the current OpenGL context.
  108. */
  109. void drawAt(const GraphicsContext& context, int x, int y);
  110. /**
  111. Draw this image at position @a pos using the current OpenGL context.
  112. */
  113. virtual void drawAt(const GraphicsContext& context, const Point<int>& pos) = 0;
  114. /**
  115. TODO document this.
  116. */
  117. ImageBase& operator=(const ImageBase& image) noexcept;
  118. bool operator==(const ImageBase& image) const noexcept;
  119. bool operator!=(const ImageBase& image) const noexcept;
  120. protected:
  121. const char* rawData;
  122. Size<uint> size;
  123. ImageFormat format;
  124. };
  125. // --------------------------------------------------------------------------------------------------------------------
  126. END_NAMESPACE_DGL
  127. #endif // DGL_IMAGE_HPP_INCLUDED