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.

ZRLEDecoder.cxx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <rfb/CMsgReader.h>
  19. #include <rfb/CMsgHandler.h>
  20. #include <rfb/ZRLEDecoder.h>
  21. using namespace rfb;
  22. #define EXTRA_ARGS CMsgHandler* handler
  23. #define FILL_RECT(r, p) handler->fillRect(r, p)
  24. #define IMAGE_RECT(r, p) handler->imageRect(r, p)
  25. #define BPP 8
  26. #include <rfb/zrleDecode.h>
  27. #undef BPP
  28. #define BPP 16
  29. #include <rfb/zrleDecode.h>
  30. #undef BPP
  31. #define BPP 32
  32. #include <rfb/zrleDecode.h>
  33. #define CPIXEL 24A
  34. #include <rfb/zrleDecode.h>
  35. #undef CPIXEL
  36. #define CPIXEL 24B
  37. #include <rfb/zrleDecode.h>
  38. #undef CPIXEL
  39. #undef BPP
  40. ZRLEDecoder::ZRLEDecoder(CMsgReader* reader_) : reader(reader_)
  41. {
  42. }
  43. ZRLEDecoder::~ZRLEDecoder()
  44. {
  45. }
  46. void ZRLEDecoder::readRect(const Rect& r, CMsgHandler* handler)
  47. {
  48. rdr::InStream* is = reader->getInStream();
  49. rdr::U8* buf = reader->getImageBuf(64 * 64 * 4);
  50. switch (reader->bpp()) {
  51. case 8: zrleDecode8 (r, is, &zis, (rdr::U8*) buf, handler); break;
  52. case 16: zrleDecode16(r, is, &zis, (rdr::U16*)buf, handler); break;
  53. case 32:
  54. {
  55. const rfb::PixelFormat& pf = handler->cp.pf();
  56. Pixel maxPixel = pf.pixelFromRGB((rdr::U16)-1, (rdr::U16)-1, (rdr::U16)-1);
  57. bool fitsInLS3Bytes = maxPixel < (1<<24);
  58. bool fitsInMS3Bytes = (maxPixel & 0xff) == 0;
  59. if ((fitsInLS3Bytes && pf.isLittleEndian()) ||
  60. (fitsInMS3Bytes && pf.isBigEndian()))
  61. {
  62. zrleDecode24A(r, is, &zis, (rdr::U32*)buf, handler);
  63. }
  64. else if ((fitsInLS3Bytes && pf.isBigEndian()) ||
  65. (fitsInMS3Bytes && pf.isLittleEndian()))
  66. {
  67. zrleDecode24B(r, is, &zis, (rdr::U32*)buf, handler);
  68. }
  69. else
  70. {
  71. zrleDecode32(r, is, &zis, (rdr::U32*)buf, handler);
  72. }
  73. break;
  74. }
  75. }
  76. }