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.cxx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <assert.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <rfb/PixelFormat.h>
  24. #include <rfb/Exception.h>
  25. #include <rfb/ConnParams.h>
  26. #include <rfb/SMsgWriter.h>
  27. #include <rfb/ColourMap.h>
  28. #include <rfb/TrueColourMap.h>
  29. #include <rfb/PixelBuffer.h>
  30. #include <rfb/ColourCube.h>
  31. #include <rfb/TransImageGetter.h>
  32. using namespace rfb;
  33. TransImageGetter::TransImageGetter(bool econ)
  34. : PixelTransformer(econ), pb(0)
  35. {
  36. }
  37. TransImageGetter::~TransImageGetter()
  38. {
  39. }
  40. void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out,
  41. SMsgWriter* writer_, ColourCube* cube_)
  42. {
  43. pb = pb_;
  44. writer = writer_;
  45. PixelTransformer::init(pb->getPF(), pb->getColourMap(), out, cube_,
  46. cmCallback, this);
  47. }
  48. void TransImageGetter::setColourMapEntries(int firstCol, int nCols)
  49. {
  50. PixelTransformer::setColourMapEntries(firstCol, nCols);
  51. }
  52. const rdr::U8 *TransImageGetter::getRawBufferR(const Rect &r, int *stride)
  53. {
  54. if (!offset.equals(Point(0, 0)))
  55. return pb->getBuffer(r.translate(offset.negate()), stride);
  56. else
  57. return pb->getBuffer(r, stride);
  58. }
  59. void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride)
  60. {
  61. int inStride;
  62. const rdr::U8* inPtr = pb->getBuffer(r.translate(offset.negate()), &inStride);
  63. if (!outStride) outStride = r.width();
  64. translateRect((void*)inPtr, inStride, Rect(0, 0, r.width(), r.height()),
  65. outPtr, outStride, Point(0, 0));
  66. }
  67. void TransImageGetter::cmCallback(int firstColour, int nColours,
  68. ColourMap* cm, void* data)
  69. {
  70. TransImageGetter *self;
  71. assert(data);
  72. self = (TransImageGetter*)data;
  73. if (self->writer)
  74. self->writer->writeSetColourMapEntries(firstColour, nColours, cm);
  75. }