Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

678 рядки
20 KiB

  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the Do What The Fuck You Want To
  11. * Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains various export functions
  16. */
  17. #include "config.h"
  18. #if !defined(__KERNEL__)
  19. # include <stdlib.h>
  20. # include <stdio.h>
  21. # include <string.h>
  22. #endif
  23. #include "cucul.h"
  24. #include "cucul_internals.h"
  25. static void export_ansi(cucul_t *, cucul_buffer_t *);
  26. static void export_html(cucul_t *, cucul_buffer_t *);
  27. static void export_html3(cucul_t *, cucul_buffer_t *);
  28. static void export_irc(cucul_t *, cucul_buffer_t *);
  29. static void export_ps(cucul_t *, cucul_buffer_t *);
  30. static void export_svg(cucul_t *, cucul_buffer_t *);
  31. static void export_tga(cucul_t *, cucul_buffer_t *);
  32. /** \brief Export a canvas into a foreign format.
  33. *
  34. * This function exports a libcucul canvas into various foreign formats such
  35. * as ANSI art, HTML, IRC colours, etc. One should use cucul_get_buffer_data()
  36. * and cucul_get_buffer_size() to access the buffer contents. The allocated
  37. * data is valid until cucul_free_buffer() is called.
  38. *
  39. * Valid values for \e format are:
  40. *
  41. * \li \e "ansi": export ANSI art (CP437 charset with ANSI colour codes).
  42. *
  43. * \li \e "html": export an HTML page with CSS information.
  44. *
  45. * \li \e "html3": export an HTML table that should be compatible with
  46. * most navigators, including textmode ones.
  47. *
  48. * \li \e "irc": export UTF-8 text with mIRC colour codes.
  49. *
  50. * \li \e "ps": export a PostScript document.
  51. *
  52. * \li \e "svg": export an SVG vector image.
  53. *
  54. * \li \e "tga": export a TGA image.
  55. *
  56. * \param qq A libcucul canvas
  57. * \param format A string describing the requested output format.
  58. */
  59. cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format)
  60. {
  61. cucul_buffer_t *ex;
  62. ex = malloc(sizeof(cucul_buffer_t));
  63. ex->size = 0;
  64. ex->data = NULL;
  65. if(!strcasecmp("ansi", format))
  66. export_ansi(qq, ex);
  67. else if(!strcasecmp("html", format))
  68. export_html(qq, ex);
  69. else if(!strcasecmp("html3", format))
  70. export_html3(qq, ex);
  71. else if(!strcasecmp("irc", format))
  72. export_irc(qq, ex);
  73. else if(!strcasecmp("ps", format))
  74. export_ps(qq, ex);
  75. else if(!strcasecmp("svg", format))
  76. export_svg(qq, ex);
  77. else if(!strcasecmp("tga", format))
  78. export_tga(qq, ex);
  79. if(ex->size == 0)
  80. {
  81. free(ex);
  82. return NULL;
  83. }
  84. return ex;
  85. }
  86. /** \brief Get available export formats
  87. *
  88. * Return a list of available export formats. The list is a NULL-terminated
  89. * array of strings, interleaving a string containing the internal value for
  90. * the export format, to be used with \e cucul_create_export(), and a string
  91. * containing the natural language description for that export format.
  92. *
  93. * \return An array of strings.
  94. */
  95. char const * const * cucul_get_export_list(void)
  96. {
  97. static char const * const list[] =
  98. {
  99. "ansi", "ANSI",
  100. "html", "HTML",
  101. "html3", "backwards-compatible HTML",
  102. "irc", "IRC with mIRC colours",
  103. "ps", "PostScript document",
  104. "svg", "SVG vector image",
  105. "tga", "TGA image",
  106. NULL, NULL
  107. };
  108. return list;
  109. }
  110. /*
  111. * XXX: the following functions are local.
  112. */
  113. /* Generate ANSI representation of current canvas. */
  114. static void export_ansi(cucul_t *qq, cucul_buffer_t *ex)
  115. {
  116. static uint8_t const palette[] =
  117. {
  118. 0, 4, 2, 6, 1, 5, 3, 7,
  119. 8, 12, 10, 14, 9, 13, 11, 15
  120. };
  121. char *cur;
  122. unsigned int x, y;
  123. /* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus
  124. * 4 max bytes for a UTF-8 character).
  125. * Add height*9 to that (zeroes color at the end and jump to next line) */
  126. ex->size = (qq->height * 9) + (qq->width * qq->height * 23);
  127. ex->data = malloc(ex->size);
  128. cur = ex->data;
  129. for(y = 0; y < qq->height; y++)
  130. {
  131. uint32_t *lineattr = qq->attr + y * qq->width;
  132. uint32_t *linechar = qq->chars + y * qq->width;
  133. uint8_t prevfg = -1;
  134. uint8_t prevbg = -1;
  135. for(x = 0; x < qq->width; x++)
  136. {
  137. uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])];
  138. uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])];
  139. uint32_t c = linechar[x];
  140. if(fg != prevfg || bg != prevbg)
  141. {
  142. cur += sprintf(cur, "\033[0;");
  143. if(fg < 8)
  144. if(bg < 8)
  145. cur += sprintf(cur, "3%d;4%dm", fg, bg);
  146. else
  147. cur += sprintf(cur, "5;3%d;4%d;10%dm",
  148. fg, bg - 8, bg - 8);
  149. else
  150. if(bg < 8)
  151. cur += sprintf(cur, "1;3%d;4%d;9%dm",
  152. fg - 8, bg, fg - 8);
  153. else
  154. cur += sprintf(cur, "5;1;3%d;4%d;9%d;10%dm",
  155. fg - 8, bg - 8, fg - 8, bg - 8);
  156. }
  157. *cur++ = c & 0x7f;
  158. prevfg = fg;
  159. prevbg = bg;
  160. }
  161. cur += sprintf(cur, "\033[0m\r\n");
  162. }
  163. /* Crop to really used size */
  164. ex->size = (uintptr_t)(cur - ex->data);
  165. ex->data = realloc(ex->data, ex->size);
  166. }
  167. /* Generate HTML representation of current canvas. */
  168. static void export_html(cucul_t *qq, cucul_buffer_t *ex)
  169. {
  170. static uint16_t const palette[] =
  171. {
  172. 0x000, 0x008, 0x080, 0x088, 0x800, 0x808, 0x880, 0x888,
  173. 0x444, 0x44f, 0x4f4, 0x4ff, 0xf44, 0xf4f, 0xff4, 0xfff,
  174. };
  175. char *cur;
  176. unsigned int x, y, len;
  177. /* The CSS palette: roughly 13000 bytes
  178. * A line: 7 chars for "<br />\n"
  179. * A glyph: 18 chars for "<span class='bxx'>"
  180. * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
  181. * 7 chars for "</span>" */
  182. ex->size = 13000 + qq->height * (7 + qq->width * (18 + 9 + 7));
  183. ex->data = malloc(ex->size);
  184. cur = ex->data;
  185. /* HTML header */
  186. cur += sprintf(cur, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION);
  187. /* CSS */
  188. cur += sprintf(cur, "<style>\n");
  189. cur += sprintf(cur, ".caca { font-family: monospace, fixed; font-weight: bold; }");
  190. for(x = 0; x < 0x100; x++)
  191. {
  192. cur += sprintf(cur, ".b%02x { color:#%03x; background-color:#%03x; }\n",
  193. x, palette[x & 0xf ], palette[x >> 4]);
  194. }
  195. cur += sprintf(cur, "</style>\n</head>\n<body>\n");
  196. cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
  197. "font-family: monospace, fixed; font-weight: bold;");
  198. for(y = 0; y < qq->height; y++)
  199. {
  200. uint32_t *lineattr = qq->attr + y * qq->width;
  201. uint32_t *linechar = qq->chars + y * qq->width;
  202. for(x = 0; x < qq->width; x += len)
  203. {
  204. cur += sprintf(cur, "<span class='b%02x'>",
  205. _cucul_argb32_to_ansi8(lineattr[x]));
  206. for(len = 0;
  207. x + len < qq->width && lineattr[x + len] == lineattr[x];
  208. len++)
  209. {
  210. if(linechar[x + len] <= 0x00000020)
  211. cur += sprintf(cur, "&nbsp;");
  212. else if(linechar[x + len] < 0x00000080)
  213. cur += sprintf(cur, "%c", linechar[x + len]);
  214. else
  215. cur += sprintf(cur, "&#%i;", linechar[x + len]);
  216. }
  217. cur += sprintf(cur, "</span>");
  218. }
  219. /* New line */
  220. cur += sprintf(cur, "<br />\n");
  221. }
  222. cur += sprintf(cur, "</div></body></html>\n");
  223. /* Crop to really used size */
  224. ex->size = strlen(ex->data) + 1;
  225. ex->data = realloc(ex->data, ex->size);
  226. }
  227. /* Export an HTML3 document. This function is way bigger than export_html(),
  228. * but permits viewing in old browsers (or limited ones such as links). It
  229. * will not work under gecko (mozilla rendering engine) unless you set a
  230. * correct header. */
  231. static void export_html3(cucul_t *qq, cucul_buffer_t *ex)
  232. {
  233. static uint32_t const palette[] =
  234. {
  235. 0x000000, 0x000088, 0x008800, 0x008888,
  236. 0x880000, 0x880088, 0x888800, 0x888888,
  237. 0x444444, 0x4444ff, 0x44ff44, 0x44ffff,
  238. 0xff4444, 0xff44ff, 0xffff44, 0xffffff,
  239. };
  240. char *cur;
  241. unsigned int x, y, len;
  242. /* The CSS palette: roughly 13000 bytes
  243. * A line: 10 chars for "<tr></tr>\n"
  244. * A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>"
  245. * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
  246. * 12 chars for "</font></td>" */
  247. ex->size = 13000 + qq->height * (10 + qq->width * (40 + 9 + 12));
  248. ex->data = malloc(ex->size);
  249. cur = ex->data;
  250. /* Table */
  251. cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n",
  252. qq->height);
  253. for(y = 0; y < qq->height; y++)
  254. {
  255. uint32_t *lineattr = qq->attr + y * qq->width;
  256. uint32_t *linechar = qq->chars + y * qq->width;
  257. cur += sprintf(cur, "<tr>");
  258. for(x = 0; x < qq->width; x += len)
  259. {
  260. unsigned int i;
  261. /* Use colspan option to factorize cells with same attributes
  262. * (see below) */
  263. len = 1;
  264. while(x + len < qq->width && lineattr[x + len] == lineattr[x])
  265. len++;
  266. cur += sprintf(cur, "<td bgcolor=#%06x",
  267. palette[_cucul_argb32_to_ansi4bg(lineattr[x])]);
  268. if(len > 1)
  269. cur += sprintf(cur, " colspan=%d", len);
  270. cur += sprintf(cur, "><font color=#%06x>",
  271. palette[_cucul_argb32_to_ansi4fg(lineattr[x])]);
  272. for(i = 0; i < len; i++)
  273. {
  274. if(linechar[x + i] <= 0x00000020)
  275. cur += sprintf(cur, "&nbsp;");
  276. else if(linechar[x + i] < 0x00000080)
  277. cur += sprintf(cur, "%c", linechar[x + i]);
  278. else
  279. cur += sprintf(cur, "&#%i;", linechar[x + i]);
  280. }
  281. cur += sprintf(cur, "</font></td>");
  282. }
  283. cur += sprintf(cur, "</tr>\n");
  284. }
  285. /* Footer */
  286. cur += sprintf(cur, "</table>\n");
  287. /* Crop to really used size */
  288. ex->size = (uintptr_t)(cur - ex->data);
  289. ex->data = realloc(ex->data, ex->size);
  290. }
  291. /* Export a text file with IRC colours */
  292. static void export_irc(cucul_t *qq, cucul_buffer_t *ex)
  293. {
  294. static uint8_t const palette[] =
  295. {
  296. 1, 2, 3, 10, 5, 6, 7, 15, /* Dark */
  297. 14, 12, 9, 11, 4, 13, 8, 0, /* Light */
  298. };
  299. char *cur;
  300. unsigned int x, y;
  301. /* 11 bytes assumed for max length per pixel. Worst case scenario:
  302. * ^Cxx,yy 6 bytes
  303. * ^B^B 2 bytes
  304. * c 1 byte
  305. * \r\n 2 bytes
  306. * In real life, the average bytes per pixel value will be around 5.
  307. */
  308. ex->size = 2 + (qq->width * qq->height * 11);
  309. ex->data = malloc(ex->size);
  310. cur = ex->data;
  311. for(y = 0; y < qq->height; y++)
  312. {
  313. uint32_t *lineattr = qq->attr + y * qq->width;
  314. uint32_t *linechar = qq->chars + y * qq->width;
  315. uint8_t prevfg = -1;
  316. uint8_t prevbg = -1;
  317. for(x = 0; x < qq->width; x++)
  318. {
  319. uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])];
  320. uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])];
  321. uint32_t c = linechar[x];
  322. if(bg == prevbg)
  323. {
  324. if(fg == prevfg)
  325. ; /* Same fg/bg, do nothing */
  326. else if(c == (uint32_t)' ')
  327. fg = prevfg; /* Hackety hack */
  328. else
  329. {
  330. cur += sprintf(cur, "\x03%d", fg);
  331. if(c >= (uint32_t)'0' && c <= (uint32_t)'9')
  332. cur += sprintf(cur, "\x02\x02");
  333. }
  334. }
  335. else
  336. {
  337. if(fg == prevfg)
  338. cur += sprintf(cur, "\x03,%d", bg);
  339. else
  340. cur += sprintf(cur, "\x03%d,%d", fg, bg);
  341. if(c >= (uint32_t)'0' && c <= (uint32_t)'9')
  342. cur += sprintf(cur, "\x02\x02");
  343. }
  344. *cur++ = c & 0x7f;
  345. prevfg = fg;
  346. prevbg = bg;
  347. }
  348. *cur++ = '\r';
  349. *cur++ = '\n';
  350. }
  351. /* Crop to really used size */
  352. ex->size = (uintptr_t)(cur - ex->data);
  353. ex->data = realloc(ex->data, ex->size);
  354. }
  355. /* Export a PostScript document. */
  356. static void export_ps(cucul_t *qq, cucul_buffer_t *ex)
  357. {
  358. static char const *ps_header =
  359. "%!\n"
  360. "%% libcaca PDF export\n"
  361. "%%LanguageLevel: 2\n"
  362. "%%Pages: 1\n"
  363. "%%DocumentData: Clean7Bit\n"
  364. "/csquare {\n"
  365. " newpath\n"
  366. " 0 0 moveto\n"
  367. " 0 1 rlineto\n"
  368. " 1 0 rlineto\n"
  369. " 0 -1 rlineto\n"
  370. " closepath\n"
  371. " setrgbcolor\n"
  372. " fill\n"
  373. "} def\n"
  374. "/S {\n"
  375. " Show\n"
  376. "} bind def\n"
  377. "/Courier-Bold findfont\n"
  378. "8 scalefont\n"
  379. "setfont\n"
  380. "gsave\n"
  381. "6 10 scale\n";
  382. char *cur;
  383. unsigned int x, y;
  384. /* 200 is arbitrary but should be ok */
  385. ex->size = strlen(ps_header) + (qq->width * qq->height * 200);
  386. ex->data = malloc(ex->size);
  387. cur = ex->data;
  388. /* Header */
  389. cur += sprintf(cur, "%s", ps_header);
  390. /* Background, drawn using csquare macro defined in header */
  391. for(y = qq->height; y--; )
  392. {
  393. uint32_t *lineattr = qq->attr + y * qq->width;
  394. for(x = 0; x < qq->width; x++)
  395. {
  396. uint8_t argb[8];
  397. _cucul_argb32_to_argb4(*lineattr++, argb);
  398. cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n",
  399. (float)argb[1] * (1.0 / 0xf),
  400. (float)argb[2] * (1.0 / 0xf),
  401. (float)argb[3] * (1.0 / 0xf));
  402. }
  403. /* Return to beginning of the line, and jump to the next one */
  404. cur += sprintf(cur, "-%d 1 translate\n", qq->width);
  405. }
  406. cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */
  407. for(y = qq->height; y--; )
  408. {
  409. uint32_t *lineattr = qq->attr + (qq->height - y - 1) * qq->width;
  410. uint32_t *linechar = qq->chars + (qq->height - y - 1) * qq->width;
  411. for(x = 0; x < qq->width; x++)
  412. {
  413. uint8_t argb[8];
  414. uint32_t c = *linechar++;
  415. _cucul_argb32_to_argb4(*lineattr++, argb);
  416. cur += sprintf(cur, "newpath\n");
  417. cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10 + 2);
  418. cur += sprintf(cur, "%f %f %f setrgbcolor\n",
  419. (float)argb[5] * (1.0 / 0xf),
  420. (float)argb[6] * (1.0 / 0xf),
  421. (float)argb[7] * (1.0 / 0xf));
  422. if(c < 0x00000020)
  423. cur += sprintf(cur, "(?) show\n");
  424. else if(c >= 0x00000080)
  425. cur += sprintf(cur, "(?) show\n");
  426. else switch((uint8_t)(c & 0x7f))
  427. {
  428. case '\\':
  429. case '(':
  430. case ')':
  431. cur += sprintf(cur, "(\\%c) show\n", c);
  432. break;
  433. default:
  434. cur += sprintf(cur, "(%c) show\n", c);
  435. break;
  436. }
  437. }
  438. }
  439. cur += sprintf(cur, "showpage\n");
  440. /* Crop to really used size */
  441. ex->size = (uintptr_t)(cur - ex->data);
  442. ex->data = realloc(ex->data, ex->size);
  443. }
  444. /* Export an SVG vector image */
  445. static void export_svg(cucul_t *qq, cucul_buffer_t *ex)
  446. {
  447. static char const svg_header[] =
  448. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  449. "<svg width=\"%d\" height=\"%d\" viewBox=\"0 0 %d %d\""
  450. " xmlns=\"http://www.w3.org/2000/svg\""
  451. " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
  452. " xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n";
  453. char *cur;
  454. unsigned int x, y;
  455. /* 200 is arbitrary but should be ok */
  456. ex->size = strlen(svg_header) + (qq->width * qq->height * 200);
  457. ex->data = malloc(ex->size);
  458. cur = ex->data;
  459. /* Header */
  460. cur += sprintf(cur, svg_header, qq->width * 6, qq->height * 10,
  461. qq->width * 6, qq->height * 10);
  462. cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\n");
  463. /* Background */
  464. for(y = 0; y < qq->height; y++)
  465. {
  466. uint32_t *lineattr = qq->attr + y * qq->width;
  467. for(x = 0; x < qq->width; x++)
  468. {
  469. cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\""
  470. " width=\"6\" height=\"10\"/>\n",
  471. _cucul_argb32_to_rgb12bg(*lineattr++),
  472. x * 6, y * 10);
  473. }
  474. }
  475. /* Text */
  476. for(y = 0; y < qq->height; y++)
  477. {
  478. uint32_t *lineattr = qq->attr + y * qq->width;
  479. uint32_t *linechar = qq->chars + y * qq->width;
  480. for(x = 0; x < qq->width; x++)
  481. {
  482. uint32_t c = *linechar++;
  483. cur += sprintf(cur, "<text style=\"fill:#%.03x\" "
  484. "x=\"%d\" y=\"%d\">",
  485. _cucul_argb32_to_rgb12fg(*lineattr++),
  486. x * 6, (y * 10) + 10);
  487. if(c < 0x00000020)
  488. cur += sprintf(cur, "?");
  489. else if(c > 0x0000007f)
  490. {
  491. static const uint8_t mark[7] =
  492. {
  493. 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
  494. };
  495. char buf[10], *parser;
  496. int bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4;
  497. buf[bytes] = '\0';
  498. parser = buf + bytes;
  499. switch(bytes)
  500. {
  501. case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6;
  502. case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6;
  503. case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6;
  504. }
  505. *--parser = c | mark[bytes];
  506. cur += sprintf(cur, "%s", buf);
  507. }
  508. else switch((uint8_t)c)
  509. {
  510. case '>': cur += sprintf(cur, "&gt;"); break;
  511. case '<': cur += sprintf(cur, "&lt;"); break;
  512. case '&': cur += sprintf(cur, "&amp;"); break;
  513. default: cur += sprintf(cur, "%c", c); break;
  514. }
  515. cur += sprintf(cur, "</text>\n");
  516. }
  517. }
  518. cur += sprintf(cur, " </g>\n");
  519. cur += sprintf(cur, "</svg>\n");
  520. /* Crop to really used size */
  521. ex->size = (uintptr_t)(cur - ex->data);
  522. ex->data = realloc(ex->data, ex->size);
  523. }
  524. /* Export a TGA image */
  525. static void export_tga(cucul_t *qq, cucul_buffer_t *ex)
  526. {
  527. char const * const * fontlist;
  528. char * cur;
  529. cucul_font_t *f;
  530. unsigned int i, w, h;
  531. fontlist = cucul_get_font_list();
  532. if(!fontlist[0])
  533. return;
  534. f = cucul_load_font(fontlist[0], 0);
  535. w = cucul_get_width(qq) * cucul_get_font_width(f);
  536. h = cucul_get_height(qq) * cucul_get_font_height(f);
  537. ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */
  538. ex->data = malloc(ex->size);
  539. cur = ex->data;
  540. /* ID Length */
  541. cur += sprintf(cur, "%c", 0);
  542. /* Color Map Type: no colormap */
  543. cur += sprintf(cur, "%c", 0);
  544. /* Image Type: uncompressed truecolor */
  545. cur += sprintf(cur, "%c", 2);
  546. /* Color Map Specification: no color map */
  547. memset(cur, 0, 5); cur += 5;
  548. /* Image Specification */
  549. cur += sprintf(cur, "%c%c", 0, 0); /* X Origin */
  550. cur += sprintf(cur, "%c%c", 0, 0); /* Y Origin */
  551. cur += sprintf(cur, "%c%c", w & 0xff, w >> 8); /* Width */
  552. cur += sprintf(cur, "%c%c", h & 0xff, h >> 8); /* Height */
  553. cur += sprintf(cur, "%c", 32); /* Pixel Depth */
  554. cur += sprintf(cur, "%c", 40); /* Image Descriptor */
  555. /* Image ID: no ID */
  556. /* Color Map Data: no colormap */
  557. /* Image Data */
  558. cucul_render_canvas(qq, f, cur, w, h, 4 * w);
  559. /* Swap bytes. What a waste of time. */
  560. for(i = 0; i < w * h * 4; i += 4)
  561. {
  562. char w;
  563. w = cur[i]; cur[i] = cur[i + 3]; cur[i + 3] = w;
  564. w = cur[i + 1]; cur[i + 1] = cur[i + 2]; cur[i + 2] = w;
  565. }
  566. cucul_free_font(f);
  567. }