選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PixelBuffer.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2014 Pierre Ossman for Cendio AB
  3. *
  4. * This 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 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software 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 software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. // -=- PixelBuffer.h
  20. //
  21. // The PixelBuffer class encapsulates the PixelFormat and dimensions
  22. // of a block of pixel data.
  23. #ifndef __RFB_PIXEL_BUFFER_H__
  24. #define __RFB_PIXEL_BUFFER_H__
  25. #include <rfb/PixelFormat.h>
  26. #include <rfb/Rect.h>
  27. namespace rfb {
  28. class Region;
  29. class PixelBuffer {
  30. public:
  31. PixelBuffer(const PixelFormat& pf, int width, int height);
  32. virtual ~PixelBuffer();
  33. ///////////////////////////////////////////////
  34. // Format / Layout
  35. //
  36. public:
  37. // Get pixel format
  38. const PixelFormat &getPF() const { return format; }
  39. // Get width, height and number of pixels
  40. int width() const { return width_; }
  41. int height() const { return height_; }
  42. int area() const { return width_ * height_; }
  43. // Get rectangle encompassing this buffer
  44. // Top-left of rectangle is either at (0,0), or the specified point.
  45. Rect getRect() const { return Rect(0, 0, width_, height_); }
  46. Rect getRect(const Point& pos) const {
  47. return Rect(pos, pos.translate(Point(width_, height_)));
  48. }
  49. ///////////////////////////////////////////////
  50. // Access to pixel data
  51. //
  52. // Get a pointer into the buffer
  53. // The pointer is to the top-left pixel of the specified Rect.
  54. // The buffer stride (in pixels) is returned.
  55. virtual const uint8_t* getBuffer(const Rect& r, int* stride) const = 0;
  56. // Get pixel data for a given part of the buffer
  57. // Data is copied into the supplied buffer, with the specified
  58. // stride. Try to avoid using this though as getBuffer() will in
  59. // most cases avoid the extra memory copy.
  60. void getImage(void* imageBuf, const Rect& r, int stride=0) const;
  61. // Get pixel data in a given format
  62. // Works just the same as getImage(), but guaranteed to be in a
  63. // specific format.
  64. void getImage(const PixelFormat& pf, void* imageBuf,
  65. const Rect& r, int stride=0) const;
  66. ///////////////////////////////////////////////
  67. // Framebuffer update methods
  68. //
  69. // Ensure that the specified rectangle of buffer is up to date.
  70. // Overridden by derived classes implementing framebuffer access
  71. // to copy the required display data into place.
  72. virtual void grabRegion(const Region& /*region*/) {}
  73. protected:
  74. PixelBuffer();
  75. virtual void setSize(int width, int height);
  76. protected:
  77. PixelFormat format;
  78. private:
  79. int width_, height_;
  80. };
  81. // ModifiablePixelBuffer
  82. class ModifiablePixelBuffer : public PixelBuffer {
  83. public:
  84. ModifiablePixelBuffer(const PixelFormat& pf, int width, int height);
  85. virtual ~ModifiablePixelBuffer();
  86. ///////////////////////////////////////////////
  87. // Access to pixel data
  88. //
  89. // Get a writeable pointer into the buffer
  90. // Like getBuffer(), the pointer is to the top-left pixel of the
  91. // specified Rect and the stride in pixels is returned.
  92. virtual uint8_t* getBufferRW(const Rect& r, int* stride) = 0;
  93. // Commit the modified contents
  94. // Ensures that the changes to the specified Rect is properly
  95. // stored away and any temporary buffers are freed. The Rect given
  96. // here needs to match the Rect given to the earlier call to
  97. // getBufferRW().
  98. virtual void commitBufferRW(const Rect& r) = 0;
  99. ///////////////////////////////////////////////
  100. // Basic rendering operations
  101. // These operations DO NOT clip to the pixelbuffer area, or trap overruns.
  102. // Fill a rectangle
  103. void fillRect(const Rect &dest, const void* pix);
  104. // Copy pixel data to the buffer
  105. void imageRect(const Rect &dest, const void* pixels, int stride=0);
  106. // Copy pixel data from one PixelBuffer location to another
  107. void copyRect(const Rect &dest, const Point& move_by_delta);
  108. // Render in a specific format
  109. // Does the exact same thing as the above methods, but the given
  110. // pixel values are defined by the given PixelFormat.
  111. void fillRect(const PixelFormat& pf, const Rect &dest, const void* pix);
  112. void imageRect(const PixelFormat& pf, const Rect &dest,
  113. const void* pixels, int stride=0);
  114. protected:
  115. ModifiablePixelBuffer();
  116. };
  117. // FullFramePixelBuffer
  118. class FullFramePixelBuffer : public ModifiablePixelBuffer {
  119. public:
  120. FullFramePixelBuffer(const PixelFormat& pf, int width, int height,
  121. uint8_t* data_, int stride);
  122. virtual ~FullFramePixelBuffer();
  123. public:
  124. virtual const uint8_t* getBuffer(const Rect& r, int* stride) const;
  125. virtual uint8_t* getBufferRW(const Rect& r, int* stride);
  126. virtual void commitBufferRW(const Rect& r);
  127. protected:
  128. FullFramePixelBuffer();
  129. virtual void setBuffer(int width, int height, uint8_t* data, int stride);
  130. private:
  131. virtual void setSize(int w, int h);
  132. private:
  133. uint8_t* data;
  134. int stride;
  135. };
  136. // -=- Managed pixel buffer class
  137. // Automatically allocates enough space for the specified format & area
  138. class ManagedPixelBuffer : public FullFramePixelBuffer {
  139. public:
  140. ManagedPixelBuffer();
  141. ManagedPixelBuffer(const PixelFormat& pf, int width, int height);
  142. virtual ~ManagedPixelBuffer();
  143. // Manage the pixel buffer layout
  144. virtual void setPF(const PixelFormat &pf);
  145. virtual void setSize(int w, int h);
  146. private:
  147. uint8_t* data_; // Mirrors FullFramePixelBuffer::data
  148. unsigned long datasize;
  149. };
  150. };
  151. #endif // __RFB_PIXEL_BUFFER_H__