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.

121 lines
2.3KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LGPL.txt file
  15. */
  16. #include "../Image.hpp"
  17. START_NAMESPACE_DISTRHO
  18. // -------------------------------------------------
  19. Image::Image()
  20. : fRawData(nullptr),
  21. fSize(0, 0),
  22. fFormat(0),
  23. fType(0)
  24. {
  25. }
  26. Image::Image(const char* rawData, const Size<int>& size, GLenum format, GLenum type)
  27. : fRawData(rawData),
  28. fSize(size),
  29. fFormat(format),
  30. fType(type)
  31. {
  32. }
  33. Image::Image(const Image& image)
  34. : fRawData(image.fRawData),
  35. fSize(image.fSize),
  36. fFormat(image.fFormat),
  37. fType(image.fType)
  38. {
  39. }
  40. void Image::loadFromMemory(const char* rawData, const Size<int>& size, GLenum format, GLenum type)
  41. {
  42. fRawData = rawData;
  43. fSize = size;
  44. fFormat = format;
  45. fType = type;
  46. }
  47. bool Image::isValid() const
  48. {
  49. return (fRawData != nullptr && getWidth() > 0 && getHeight() > 0);
  50. }
  51. int Image::getWidth() const
  52. {
  53. return fSize.getWidth();
  54. }
  55. int Image::getHeight() const
  56. {
  57. return fSize.getHeight();
  58. }
  59. const Size<int>& Image::getSize() const
  60. {
  61. return fSize;
  62. }
  63. const char* Image::getRawData() const
  64. {
  65. return fRawData;
  66. }
  67. GLenum Image::getFormat() const
  68. {
  69. return fFormat;
  70. }
  71. GLenum Image::getType() const
  72. {
  73. return fType;
  74. }
  75. void Image::draw()
  76. {
  77. draw(0, 0);
  78. }
  79. void Image::draw(int x, int y)
  80. {
  81. if (! isValid())
  82. return;
  83. glRasterPos2i(x, fSize.getHeight()+y);
  84. glDrawPixels(fSize.getWidth(), fSize.getHeight(), fFormat, fType, fRawData);
  85. }
  86. void Image::draw(const Point<int>& pos)
  87. {
  88. draw(pos.getX(), pos.getY());
  89. }
  90. Image& Image::operator=(const Image& image)
  91. {
  92. fRawData = image.fRawData;
  93. fSize = image.fSize;
  94. fFormat = image.fFormat;
  95. fType = image.fType;
  96. return *this;
  97. }
  98. // -------------------------------------------------
  99. END_NAMESPACE_DISTRHO