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.

133 lines
3.6KB

  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. #include "../ImageBase.hpp"
  17. START_NAMESPACE_DGL
  18. // --------------------------------------------------------------------------------------------------------------------
  19. // protected constructors
  20. ImageBase::ImageBase()
  21. : rawData(nullptr),
  22. size(0, 0),
  23. format(kImageFormatNull) {}
  24. ImageBase::ImageBase(const char* const rdata, const uint width, const uint height, const ImageFormat fmt)
  25. : rawData(rdata),
  26. size(width, height),
  27. format(fmt) {}
  28. ImageBase::ImageBase(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
  29. : rawData(rdata),
  30. size(s),
  31. format(fmt) {}
  32. ImageBase::ImageBase(const ImageBase& image)
  33. : rawData(image.rawData),
  34. size(image.size),
  35. format(image.format) {}
  36. // --------------------------------------------------------------------------------------------------------------------
  37. // public methods
  38. ImageBase::~ImageBase() {}
  39. bool ImageBase::isValid() const noexcept
  40. {
  41. return (rawData != nullptr && size.isValid());
  42. }
  43. bool ImageBase::isInvalid() const noexcept
  44. {
  45. return (rawData == nullptr || size.isInvalid());
  46. }
  47. uint ImageBase::getWidth() const noexcept
  48. {
  49. return size.getWidth();
  50. }
  51. uint ImageBase::getHeight() const noexcept
  52. {
  53. return size.getHeight();
  54. }
  55. const Size<uint>& ImageBase::getSize() const noexcept
  56. {
  57. return size;
  58. }
  59. const char* ImageBase::getRawData() const noexcept
  60. {
  61. return rawData;
  62. }
  63. ImageFormat ImageBase::getFormat() const noexcept
  64. {
  65. return format;
  66. }
  67. void ImageBase::loadFromMemory(const char* const rdata,
  68. const uint width,
  69. const uint height,
  70. const ImageFormat fmt) noexcept
  71. {
  72. loadFromMemory(rdata, Size<uint>(width, height), fmt);
  73. }
  74. void ImageBase::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
  75. {
  76. rawData = rdata;
  77. size = s;
  78. format = fmt;
  79. }
  80. void ImageBase::draw(const GraphicsContext& context)
  81. {
  82. drawAt(context, Point<int>(0, 0));
  83. }
  84. void ImageBase::drawAt(const GraphicsContext& context, const int x, const int y)
  85. {
  86. drawAt(context, Point<int>(x, y));
  87. }
  88. // --------------------------------------------------------------------------------------------------------------------
  89. // public operators
  90. ImageBase& ImageBase::operator=(const ImageBase& image) noexcept
  91. {
  92. rawData = image.rawData;
  93. size = image.size;
  94. format = image.format;
  95. return *this;
  96. }
  97. bool ImageBase::operator==(const ImageBase& image) const noexcept
  98. {
  99. return (rawData == image.rawData && size == image.size && format == image.format);
  100. }
  101. bool ImageBase::operator!=(const ImageBase& image) const noexcept
  102. {
  103. return !operator==(image);
  104. }
  105. // --------------------------------------------------------------------------------------------------------------------
  106. END_NAMESPACE_DGL