Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ZRLEEncoderBPP.cxx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #define CONCAT2(a,b) a##b
  19. #define CONCAT2E(a,b) CONCAT2(a,b)
  20. #define UBPP CONCAT2E(U,BPP)
  21. void ZRLEEncoder::writePaletteTile(int width, int height,
  22. const rdr::UBPP* buffer, int stride,
  23. const PixelFormat& pf,
  24. const Palette& palette)
  25. {
  26. const int bitsPerPackedPixel[] = {
  27. 0, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
  28. };
  29. int bppp;
  30. int pad;
  31. assert(palette.size() > 1);
  32. assert(palette.size() <= 16);
  33. zos.writeU8(palette.size());
  34. writePalette(pf, palette);
  35. bppp = bitsPerPackedPixel[palette.size()-1];
  36. pad = stride - width;
  37. for (int i = 0; i < height; i++) {
  38. int w;
  39. rdr::U8 nbits = 0;
  40. rdr::U8 byte = 0;
  41. w = width;
  42. while (w--) {
  43. rdr::UBPP pix = *buffer++;
  44. rdr::U8 index = palette.lookup(pix);
  45. byte = (byte << bppp) | index;
  46. nbits += bppp;
  47. if (nbits >= 8) {
  48. zos.writeU8(byte);
  49. nbits = 0;
  50. }
  51. }
  52. if (nbits > 0) {
  53. byte <<= 8 - nbits;
  54. zos.writeU8(byte);
  55. }
  56. buffer += pad;
  57. }
  58. }
  59. void ZRLEEncoder::writePaletteRLETile(int width, int height,
  60. const rdr::UBPP* buffer, int stride,
  61. const PixelFormat& pf,
  62. const Palette& palette)
  63. {
  64. int pad;
  65. rdr::UBPP prevColour;
  66. int runLength;
  67. assert(palette.size() > 1);
  68. assert(palette.size() <= 127);
  69. zos.writeU8(palette.size() | 0x80);
  70. writePalette(pf, palette);
  71. pad = stride - width;
  72. prevColour = *buffer;
  73. runLength = 0;
  74. while (height--) {
  75. int w = width;
  76. while (w--) {
  77. if (prevColour != *buffer) {
  78. if (runLength == 1)
  79. zos.writeU8(palette.lookup(prevColour));
  80. else {
  81. zos.writeU8(palette.lookup(prevColour) | 0x80);
  82. while (runLength > 255) {
  83. zos.writeU8(255);
  84. runLength -= 255;
  85. }
  86. zos.writeU8(runLength - 1);
  87. }
  88. prevColour = *buffer;
  89. runLength = 0;
  90. }
  91. runLength++;
  92. buffer++;
  93. }
  94. buffer += pad;
  95. }
  96. if (runLength == 1)
  97. zos.writeU8(palette.lookup(prevColour));
  98. else {
  99. zos.writeU8(palette.lookup(prevColour) | 0x80);
  100. while (runLength > 255) {
  101. zos.writeU8(255);
  102. runLength -= 255;
  103. }
  104. zos.writeU8(runLength - 1);
  105. }
  106. }