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.

TransImageGetter.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  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. //
  20. // TransImageGetter - class to perform translation between pixel formats,
  21. // implementing the ImageGetter interface.
  22. //
  23. #ifndef __RFB_TRANSIMAGEGETTER_H__
  24. #define __RFB_TRANSIMAGEGETTER_H__
  25. #include <rfb/Rect.h>
  26. #include <rfb/PixelFormat.h>
  27. #include <rfb/PixelTransformer.h>
  28. #include <rfb/ImageGetter.h>
  29. namespace rfb {
  30. class SMsgWriter;
  31. class ColourMap;
  32. class PixelBuffer;
  33. class ColourCube;
  34. class TransImageGetter : public ImageGetter,
  35. public PixelTransformer {
  36. public:
  37. TransImageGetter(bool econ=false);
  38. virtual ~TransImageGetter();
  39. // init() is called to initialise the translation tables. The PixelBuffer
  40. // argument gives the source data and format details, outPF gives the
  41. // client's pixel format. If the client has a colour map, then the writer
  42. // argument is used to send a SetColourMapEntries message to the client.
  43. void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0,
  44. ColourCube* cube=0);
  45. // setColourMapEntries() is called when the PixelBuffer has a colour map
  46. // which has changed. firstColour and nColours specify which part of the
  47. // colour map has changed. If nColours is 0, this means the rest of the
  48. // colour map. The PixelBuffer previously passed to init() must have a
  49. // valid ColourMap object. If the client also has a colour map, then the
  50. // writer argument is used to send a SetColourMapEntries message to the
  51. // client. If the client is true colour then instead we update the
  52. // internal translation table - in this case the caller should also make
  53. // sure that the client receives an update of the relevant parts of the
  54. // framebuffer (the simplest thing to do is just update the whole
  55. // framebuffer, though it is possible to be smarter than this).
  56. void setColourMapEntries(int firstColour, int nColours);
  57. // getImage() gets the given rectangle of data from the PixelBuffer,
  58. // translates it into the client's pixel format and puts it in the buffer
  59. // pointed to by the outPtr argument. The optional outStride argument can
  60. // be used where padding is required between the output scanlines (the
  61. // padding will be outStride-r.width() pixels).
  62. void getImage(void* outPtr, const Rect& r, int outStride=0);
  63. // getRawBufferR() gets the given rectangle of data directly from the
  64. // underlying PixelBuffer, bypassing the translation logic. Only use
  65. // this when doing something that's independent of the client's pixel
  66. // format.
  67. const rdr::U8 *getRawBufferR(const Rect &r, int *stride);
  68. // setPixelBuffer() changes the pixel buffer to be used. The new pixel
  69. // buffer MUST have the same pixel format as the old one - if not you
  70. // should call init() instead.
  71. void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; }
  72. PixelBuffer *getPixelBuffer(void) { return pb; }
  73. // setOffset() sets an offset which is subtracted from the coordinates of
  74. // the rectangle given to getImage().
  75. void setOffset(const Point& offset_) { offset = offset_; }
  76. private:
  77. static void cmCallback(int firstColour, int nColours,
  78. ColourMap* cm, void* data);
  79. private:
  80. bool economic;
  81. PixelBuffer* pb;
  82. PixelFormat outPF;
  83. SMsgWriter* writer;
  84. rdr::U8* table;
  85. transFnType transFn;
  86. ColourCube* cube;
  87. Point offset;
  88. };
  89. }
  90. #endif