pixel_buffer.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  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 General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "pixel_buffer.hpp"
  17. #include <QImage>
  18. #include <iostream>
  19. #include <assert.h>
  20. class PixelBufferImpl
  21. {
  22. public:
  23. QImage image;
  24. };
  25. PixelBuffer
  26. PixelBuffer::from_file(const std::string& filename)
  27. {
  28. PixelBuffer buffer;
  29. buffer.m_impl.reset(new PixelBufferImpl);
  30. buffer.m_impl->image = QImage(filename.c_str());
  31. std::cout << "loading: " << filename << " -> " << buffer.m_impl->image.isNull() << std::endl;
  32. if (buffer.m_impl->image.isNull())
  33. {
  34. assert(!"Failed to load image, fatal");
  35. }
  36. return buffer;
  37. }
  38. PixelBuffer::PixelBuffer()
  39. {}
  40. PixelBuffer::PixelBuffer(int width, int height) :
  41. m_impl(new PixelBufferImpl)
  42. {
  43. m_impl->image = QImage(QSize(width, height),QImage::Format_ARGB32);
  44. }
  45. #ifdef GRUMBEL
  46. CL_PixelFormat get_format() const { return m_pixelbuffer.get_format(); }
  47. CL_Palette get_palette() const { return m_pixelbuffer.get_palette(); }
  48. #endif
  49. QImage&
  50. PixelBuffer::get_qimage()
  51. {
  52. assert(m_impl);
  53. return m_impl->image;
  54. }
  55. void
  56. PixelBuffer::lock()
  57. {
  58. }
  59. void
  60. PixelBuffer::unlock()
  61. {
  62. }
  63. int
  64. PixelBuffer::get_width() const
  65. {
  66. assert(m_impl);
  67. return m_impl->image.width();
  68. }
  69. int
  70. PixelBuffer::get_height() const
  71. {
  72. assert(m_impl);
  73. return m_impl->image.height();
  74. }
  75. int
  76. PixelBuffer::get_pitch() const
  77. {
  78. assert(m_impl);
  79. return m_impl->image.bytesPerLine();
  80. }
  81. int
  82. PixelBuffer::get_depth() const
  83. {
  84. assert(m_impl);
  85. return m_impl->image.depth();
  86. }
  87. void*
  88. PixelBuffer::get_data()
  89. {
  90. assert(m_impl);
  91. return m_impl->image.bits();
  92. }
  93. /* EOF */