vnc-enc-hextile.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 32
  33. #include "vnc-enc-hextile-template.h"
  34. #undef BPP
  35. #define GENERIC
  36. #define BPP 32
  37. #include "vnc-enc-hextile-template.h"
  38. #undef BPP
  39. #undef GENERIC
  40. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  41. int y, int w, int h)
  42. {
  43. int i, j;
  44. int has_fg, has_bg;
  45. uint8_t *last_fg, *last_bg;
  46. last_fg = (uint8_t *) g_malloc(VNC_SERVER_FB_BYTES);
  47. last_bg = (uint8_t *) g_malloc(VNC_SERVER_FB_BYTES);
  48. has_fg = has_bg = 0;
  49. for (j = y; j < (y + h); j += 16) {
  50. for (i = x; i < (x + w); i += 16) {
  51. vs->hextile.send_tile(vs, i, j,
  52. MIN(16, x + w - i), MIN(16, y + h - j),
  53. last_bg, last_fg, &has_bg, &has_fg);
  54. }
  55. }
  56. g_free(last_fg);
  57. g_free(last_bg);
  58. return 1;
  59. }
  60. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic)
  61. {
  62. if (!generic) {
  63. switch (VNC_SERVER_FB_BITS) {
  64. case 32:
  65. vs->hextile.send_tile = send_hextile_tile_32;
  66. break;
  67. }
  68. } else {
  69. switch (VNC_SERVER_FB_BITS) {
  70. case 32:
  71. vs->hextile.send_tile = send_hextile_tile_generic_32;
  72. break;
  73. }
  74. }
  75. }