vnc-enc-hextile.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * QEMU VNC display driver: hextile encoding
  3. *
  4. * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
  5. * Copyright (C) 2006 Fabrice Bellard
  6. * Copyright (C) 2009 Red Hat, Inc
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "vnc.h"
  27. static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h)
  28. {
  29. ptr[0] = ((x & 0x0F) << 4) | (y & 0x0F);
  30. ptr[1] = (((w - 1) & 0x0F) << 4) | ((h - 1) & 0x0F);
  31. }
  32. #define BPP 8
  33. #include "vnc-enc-hextile-template.h"
  34. #undef BPP
  35. #define BPP 16
  36. #include "vnc-enc-hextile-template.h"
  37. #undef BPP
  38. #define BPP 32
  39. #include "vnc-enc-hextile-template.h"
  40. #undef BPP
  41. #define GENERIC
  42. #define BPP 8
  43. #include "vnc-enc-hextile-template.h"
  44. #undef BPP
  45. #undef GENERIC
  46. #define GENERIC
  47. #define BPP 16
  48. #include "vnc-enc-hextile-template.h"
  49. #undef BPP
  50. #undef GENERIC
  51. #define GENERIC
  52. #define BPP 32
  53. #include "vnc-enc-hextile-template.h"
  54. #undef BPP
  55. #undef GENERIC
  56. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  57. int y, int w, int h)
  58. {
  59. int i, j;
  60. int has_fg, has_bg;
  61. uint8_t *last_fg, *last_bg;
  62. VncDisplay *vd = vs->vd;
  63. last_fg = (uint8_t *) g_malloc(vd->server->pf.bytes_per_pixel);
  64. last_bg = (uint8_t *) g_malloc(vd->server->pf.bytes_per_pixel);
  65. has_fg = has_bg = 0;
  66. for (j = y; j < (y + h); j += 16) {
  67. for (i = x; i < (x + w); i += 16) {
  68. vs->hextile.send_tile(vs, i, j,
  69. MIN(16, x + w - i), MIN(16, y + h - j),
  70. last_bg, last_fg, &has_bg, &has_fg);
  71. }
  72. }
  73. g_free(last_fg);
  74. g_free(last_bg);
  75. return 1;
  76. }
  77. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic)
  78. {
  79. if (!generic) {
  80. switch (vs->ds->surface->pf.bits_per_pixel) {
  81. case 8:
  82. vs->hextile.send_tile = send_hextile_tile_8;
  83. break;
  84. case 16:
  85. vs->hextile.send_tile = send_hextile_tile_16;
  86. break;
  87. case 32:
  88. vs->hextile.send_tile = send_hextile_tile_32;
  89. break;
  90. }
  91. } else {
  92. switch (vs->ds->surface->pf.bits_per_pixel) {
  93. case 8:
  94. vs->hextile.send_tile = send_hextile_tile_generic_8;
  95. break;
  96. case 16:
  97. vs->hextile.send_tile = send_hextile_tile_generic_16;
  98. break;
  99. case 32:
  100. vs->hextile.send_tile = send_hextile_tile_generic_32;
  101. break;
  102. }
  103. }
  104. }