Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

export_bitmap.c 2.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains export functions for bitmap formats
  15. */
  16. #include "config.h"
  17. #if !defined(__KERNEL__)
  18. # include <stdlib.h>
  19. # include <stdio.h>
  20. # include <string.h>
  21. #endif
  22. #include "cucul.h"
  23. #include "cucul_internals.h"
  24. void _cucul_get_tga(cucul_t *qq, cucul_buffer_t *ex)
  25. {
  26. char const * const * fonts;
  27. char * cur;
  28. cucul_font_t *f;
  29. unsigned int i, w, h;
  30. fonts = cucul_get_font_list();
  31. if(!fonts[0])
  32. return;
  33. f = cucul_load_font(fonts[0], 0);
  34. w = cucul_get_width(qq) * cucul_get_font_width(f);
  35. h = cucul_get_height(qq) * cucul_get_font_height(f);
  36. ex->size = w * h * 4 + 18;
  37. ex->data = malloc(ex->size);
  38. cur = ex->data;
  39. /* ID Length */
  40. cur += sprintf(cur, "%c", 0);
  41. /* Color Map Type: no colormap */
  42. cur += sprintf(cur, "%c", 0);
  43. /* Image Type: uncompressed truecolor */
  44. cur += sprintf(cur, "%c", 2);
  45. /* Color Map Specification: no color map */
  46. memset(cur, 0, 5); cur += 5;
  47. /* Image Specification */
  48. cur += sprintf(cur, "%c%c", 0, 0); /* X Origin */
  49. cur += sprintf(cur, "%c%c", 0, 0); /* Y Origin */
  50. cur += sprintf(cur, "%c%c", w & 0xff, w >> 8); /* Width */
  51. cur += sprintf(cur, "%c%c", h & 0xff, h >> 8); /* Height */
  52. cur += sprintf(cur, "%c", 32); /* Pixel Depth */
  53. cur += sprintf(cur, "%c", 40); /* Image Descriptor */
  54. /* Image ID: no ID */
  55. /* Color Map Data: no colormap */
  56. /* Image Data */
  57. cucul_render_canvas(qq, f, cur, w, h, 4 * w);
  58. /* Swap bytes. What a waste of time. */
  59. for(i = 0; i < w * h * 4; i += 4)
  60. {
  61. char w;
  62. w = cur[i]; cur[i] = cur[i + 3]; cur[i + 3] = w;
  63. w = cur[i + 1]; cur[i + 1] = cur[i + 2]; cur[i + 2] = w;
  64. }
  65. cucul_free_font(f);
  66. }