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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/CConnection.h>
  20. #include <rfb/PixelBuffer.h>
  21. #include <rfb/ZRLEDecoder.h>
  22. using namespace rfb;
  23. static inline rdr::U32 readOpaque24A(rdr::InStream* is)
  24. {
  25. is->check(3);
  26. rdr::U32 r=0;
  27. ((rdr::U8*)&r)[0] = is->readU8();
  28. ((rdr::U8*)&r)[1] = is->readU8();
  29. ((rdr::U8*)&r)[2] = is->readU8();
  30. return r;
  31. }
  32. static inline rdr::U32 readOpaque24B(rdr::InStream* is)
  33. {
  34. is->check(3);
  35. rdr::U32 r=0;
  36. ((rdr::U8*)&r)[1] = is->readU8();
  37. ((rdr::U8*)&r)[2] = is->readU8();
  38. ((rdr::U8*)&r)[3] = is->readU8();
  39. return r;
  40. }
  41. #define BPP 8
  42. #include <rfb/zrleDecode.h>
  43. #undef BPP
  44. #define BPP 16
  45. #include <rfb/zrleDecode.h>
  46. #undef BPP
  47. #define BPP 32
  48. #include <rfb/zrleDecode.h>
  49. #define CPIXEL 24A
  50. #include <rfb/zrleDecode.h>
  51. #undef CPIXEL
  52. #define CPIXEL 24B
  53. #include <rfb/zrleDecode.h>
  54. #undef CPIXEL
  55. #undef BPP
  56. ZRLEDecoder::ZRLEDecoder(CConnection* conn) : Decoder(conn)
  57. {
  58. }
  59. ZRLEDecoder::~ZRLEDecoder()
  60. {
  61. }
  62. void ZRLEDecoder::readRect(const Rect& r, ModifiablePixelBuffer* pb)
  63. {
  64. rdr::InStream* is = conn->getInStream();
  65. rdr::U8* buf = conn->reader()->getImageBuf(64 * 64 * 4);
  66. const rfb::PixelFormat& pf = conn->cp.pf();
  67. switch (pf.bpp) {
  68. case 8: zrleDecode8 (r, is, &zis, (rdr::U8*) buf, pf, pb); break;
  69. case 16: zrleDecode16(r, is, &zis, (rdr::U16*)buf, pf, pb); break;
  70. case 32:
  71. {
  72. Pixel maxPixel = pf.pixelFromRGB((rdr::U16)-1, (rdr::U16)-1, (rdr::U16)-1);
  73. bool fitsInLS3Bytes = maxPixel < (1<<24);
  74. bool fitsInMS3Bytes = (maxPixel & 0xff) == 0;
  75. if ((fitsInLS3Bytes && pf.isLittleEndian()) ||
  76. (fitsInMS3Bytes && pf.isBigEndian()))
  77. {
  78. zrleDecode24A(r, is, &zis, (rdr::U32*)buf, pf, pb);
  79. }
  80. else if ((fitsInLS3Bytes && pf.isBigEndian()) ||
  81. (fitsInMS3Bytes && pf.isLittleEndian()))
  82. {
  83. zrleDecode24B(r, is, &zis, (rdr::U32*)buf, pf, pb);
  84. }
  85. else
  86. {
  87. zrleDecode32(r, is, &zis, (rdr::U32*)buf, pf, pb);
  88. }
  89. break;
  90. }
  91. }
  92. }