25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

774 satır
20 KiB

  1. /*
  2. * cacaview image viewer for libcaca
  3. * Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program 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. #include "config.h"
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #if defined(HAVE_IMLIB2_H)
  18. # include <Imlib2.h>
  19. #else
  20. # include <stdio.h>
  21. #endif
  22. #if defined(HAVE_SLEEP)
  23. # include <windows.h>
  24. #endif
  25. #include "cucul.h"
  26. #include "caca.h"
  27. /* Local macros */
  28. #define MODE_IMAGE 1
  29. #define MODE_FILES 2
  30. #define STATUS_DITHERING 1
  31. #define STATUS_ANTIALIASING 2
  32. #define STATUS_BACKGROUND 3
  33. #define ZOOM_FACTOR 1.08f
  34. #define ZOOM_MAX 50
  35. #define GAMMA_FACTOR 1.04f
  36. #define GAMMA_MAX 100
  37. #define GAMMA(g) (((g) < 0) ? 1.0 / gammatab[-(g)] : gammatab[(g)])
  38. #define PAD_STEP 0.15
  39. /* libcucul/libcaca contexts */
  40. cucul_t *qq; caca_t *kk;
  41. /* Local functions */
  42. static void print_status(void);
  43. static void print_help(int, int);
  44. static void set_zoom(int);
  45. static void set_gamma(int);
  46. static void load_image(char const *);
  47. static void unload_image(void);
  48. static void draw_checkers(int, int, int, int);
  49. #if !defined(HAVE_IMLIB2_H)
  50. static int freadint(FILE *);
  51. static int freadshort(FILE *);
  52. static int freadchar(FILE *);
  53. #endif
  54. /* Local variables */
  55. #if defined(HAVE_IMLIB2_H)
  56. Imlib_Image image = NULL;
  57. #endif
  58. char *pixels = NULL;
  59. struct cucul_bitmap *bitmap = NULL;
  60. unsigned int w, h, depth, bpp, rmask, gmask, bmask, amask;
  61. #if !defined(HAVE_IMLIB2_H)
  62. unsigned int red[256], green[256], blue[256], alpha[256];
  63. #endif
  64. float zoomtab[ZOOM_MAX + 1];
  65. float gammatab[GAMMA_MAX + 1];
  66. float xfactor = 1.0, yfactor = 1.0, dx = 0.5, dy = 0.5;
  67. int zoom = 0, g = 0, fullscreen = 0, mode, ww, wh;
  68. int main(int argc, char **argv)
  69. {
  70. int quit = 0, update = 1, help = 0, status = 0;
  71. int reload = 0;
  72. char **list = NULL;
  73. int current = 0, items = 0, opts = 1;
  74. int i;
  75. /* Initialise libcucul */
  76. qq = cucul_create(0, 0);
  77. if(!qq)
  78. {
  79. fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
  80. return 1;
  81. }
  82. kk = caca_attach(qq);
  83. if(!kk)
  84. {
  85. fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
  86. return 1;
  87. }
  88. /* Set the window title */
  89. caca_set_window_title(kk, "cacaview");
  90. ww = cucul_get_width(qq);
  91. wh = cucul_get_height(qq);
  92. /* Fill the zoom table */
  93. zoomtab[0] = 1.0;
  94. for(i = 0; i < ZOOM_MAX; i++)
  95. zoomtab[i + 1] = zoomtab[i] * ZOOM_FACTOR;
  96. /* Fill the gamma table */
  97. gammatab[0] = 1.0;
  98. for(i = 0; i < GAMMA_MAX; i++)
  99. gammatab[i + 1] = gammatab[i] * GAMMA_FACTOR;
  100. /* Load items into playlist */
  101. for(i = 1; i < argc; i++)
  102. {
  103. /* Skip options except after `--' */
  104. if(opts && argv[i][0] == '-')
  105. {
  106. if(argv[i][1] == '-' && argv[i][2] == '\0')
  107. opts = 0;
  108. continue;
  109. }
  110. /* Add argv[i] to the list */
  111. if(items)
  112. list = realloc(list, (items + 1) * sizeof(char *));
  113. else
  114. list = malloc(sizeof(char *));
  115. list[items] = argv[i];
  116. items++;
  117. reload = 1;
  118. }
  119. /* Go ! */
  120. while(!quit)
  121. {
  122. struct caca_event ev;
  123. unsigned int const event_mask = CACA_EVENT_KEY_PRESS
  124. | CACA_EVENT_RESIZE
  125. | CACA_EVENT_MOUSE_PRESS;
  126. unsigned int new_status = 0, new_help = 0;
  127. int event;
  128. if(update)
  129. event = caca_get_event(kk, event_mask, &ev, 0);
  130. else
  131. event = caca_get_event(kk, event_mask, &ev, -1);
  132. while(event)
  133. {
  134. if(ev.type & CACA_EVENT_MOUSE_PRESS)
  135. {
  136. if(ev.data.mouse.button == 1)
  137. {
  138. if(items) current = (current + 1) % items;
  139. reload = 1;
  140. }
  141. else if(ev.data.mouse.button == 2)
  142. {
  143. if(items) current = (items + current - 1) % items;
  144. reload = 1;
  145. }
  146. }
  147. else if(ev.type & CACA_EVENT_KEY_PRESS) switch(ev.data.key.c)
  148. {
  149. case 'n':
  150. case 'N':
  151. if(items) current = (current + 1) % items;
  152. reload = 1;
  153. break;
  154. case 'p':
  155. case 'P':
  156. if(items) current = (items + current - 1) % items;
  157. reload = 1;
  158. break;
  159. case 'f':
  160. case 'F':
  161. fullscreen = ~fullscreen;
  162. update = 1;
  163. set_zoom(zoom);
  164. break;
  165. case 'b':
  166. i = 1 + cucul_get_feature(qq, CUCUL_BACKGROUND);
  167. if(i > CUCUL_BACKGROUND_MAX) i = CUCUL_BACKGROUND_MIN;
  168. cucul_set_feature(qq, i);
  169. new_status = STATUS_BACKGROUND;
  170. update = 1;
  171. break;
  172. case 'B':
  173. i = -1 + cucul_get_feature(qq, CUCUL_BACKGROUND);
  174. if(i < CUCUL_BACKGROUND_MIN) i = CUCUL_BACKGROUND_MAX;
  175. cucul_set_feature(qq, i);
  176. new_status = STATUS_BACKGROUND;
  177. update = 1;
  178. break;
  179. case 'a':
  180. i = 1 + cucul_get_feature(qq, CUCUL_ANTIALIASING);
  181. if(i > CUCUL_ANTIALIASING_MAX) i = CUCUL_ANTIALIASING_MIN;
  182. cucul_set_feature(qq, i);
  183. new_status = STATUS_ANTIALIASING;
  184. update = 1;
  185. break;
  186. case 'A':
  187. i = -1 + cucul_get_feature(qq, CUCUL_ANTIALIASING);
  188. if(i < CUCUL_ANTIALIASING_MIN) i = CUCUL_ANTIALIASING_MAX;
  189. cucul_set_feature(qq, i);
  190. new_status = STATUS_ANTIALIASING;
  191. update = 1;
  192. break;
  193. case 'd':
  194. i = 1 + cucul_get_feature(qq, CUCUL_DITHERING);
  195. if(i > CUCUL_DITHERING_MAX) i = CUCUL_DITHERING_MIN;
  196. cucul_set_feature(qq, i);
  197. new_status = STATUS_DITHERING;
  198. update = 1;
  199. break;
  200. case 'D':
  201. i = -1 + cucul_get_feature(qq, CUCUL_DITHERING);
  202. if(i < CUCUL_DITHERING_MIN) i = CUCUL_DITHERING_MAX;
  203. cucul_set_feature(qq, i);
  204. new_status = STATUS_DITHERING;
  205. update = 1;
  206. break;
  207. case '+':
  208. update = 1;
  209. set_zoom(zoom + 1);
  210. break;
  211. case '-':
  212. update = 1;
  213. set_zoom(zoom - 1);
  214. break;
  215. case 'G':
  216. update = 1;
  217. set_gamma(g + 1);
  218. break;
  219. case 'g':
  220. update = 1;
  221. set_gamma(g - 1);
  222. break;
  223. case 'x':
  224. case 'X':
  225. update = 1;
  226. set_zoom(0);
  227. set_gamma(0);
  228. break;
  229. case 'k':
  230. case 'K':
  231. case CACA_KEY_UP:
  232. if(yfactor > 1.0) dy -= PAD_STEP / yfactor;
  233. if(dy < 0.0) dy = 0.0;
  234. update = 1;
  235. break;
  236. case 'j':
  237. case 'J':
  238. case CACA_KEY_DOWN:
  239. if(yfactor > 1.0) dy += PAD_STEP / yfactor;
  240. if(dy > 1.0) dy = 1.0;
  241. update = 1;
  242. break;
  243. case 'h':
  244. case 'H':
  245. case CACA_KEY_LEFT:
  246. if(xfactor > 1.0) dx -= PAD_STEP / xfactor;
  247. if(dx < 0.0) dx = 0.0;
  248. update = 1;
  249. break;
  250. case 'l':
  251. case 'L':
  252. case CACA_KEY_RIGHT:
  253. if(xfactor > 1.0) dx += PAD_STEP / xfactor;
  254. if(dx > 1.0) dx = 1.0;
  255. update = 1;
  256. break;
  257. case '?':
  258. new_help = !help;
  259. update = 1;
  260. break;
  261. case 'q':
  262. case 'Q':
  263. quit = 1;
  264. break;
  265. }
  266. else if(ev.type == CACA_EVENT_RESIZE)
  267. {
  268. caca_display(kk);
  269. ww = ev.data.resize.w;
  270. wh = ev.data.resize.h;
  271. update = 1;
  272. set_zoom(zoom);
  273. }
  274. if(status || new_status)
  275. status = new_status;
  276. if(help || new_help)
  277. help = new_help;
  278. event = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0);
  279. }
  280. if(items && reload)
  281. {
  282. char *buffer;
  283. int len = strlen(" Loading `%s'... ") + strlen(list[current]);
  284. if(len < ww + 1)
  285. len = ww + 1;
  286. buffer = malloc(len);
  287. sprintf(buffer, " Loading `%s'... ", list[current]);
  288. buffer[ww] = '\0';
  289. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  290. cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer);
  291. caca_display(kk);
  292. ww = cucul_get_width(qq);
  293. wh = cucul_get_height(qq);
  294. unload_image();
  295. load_image(list[current]);
  296. reload = 0;
  297. /* Reset image-specific runtime variables */
  298. dx = dy = 0.5;
  299. update = 1;
  300. set_zoom(0);
  301. set_gamma(0);
  302. free(buffer);
  303. }
  304. cucul_clear(qq);
  305. if(!items)
  306. {
  307. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  308. cucul_printf(qq, ww / 2 - 5, wh / 2, " No image. ");
  309. }
  310. else if(!pixels)
  311. {
  312. #if defined(HAVE_IMLIB2_H)
  313. # define ERROR_STRING " Error loading `%s'. "
  314. #else
  315. # define ERROR_STRING " Error loading `%s'. Only BMP is supported. "
  316. #endif
  317. char *buffer;
  318. int len = strlen(ERROR_STRING) + strlen(list[current]);
  319. if(len < ww + 1)
  320. len = ww + 1;
  321. buffer = malloc(len);
  322. sprintf(buffer, ERROR_STRING, list[current]);
  323. buffer[ww] = '\0';
  324. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  325. cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer);
  326. free(buffer);
  327. }
  328. else
  329. {
  330. float xdelta, ydelta;
  331. int y, height;
  332. y = fullscreen ? 0 : 1;
  333. height = fullscreen ? wh : wh - 3;
  334. xdelta = (xfactor > 1.0) ? dx : 0.5;
  335. ydelta = (yfactor > 1.0) ? dy : 0.5;
  336. draw_checkers(ww * (1.0 - xfactor) / 2,
  337. y + height * (1.0 - yfactor) / 2,
  338. ww * (1.0 + xfactor) / 2,
  339. y + height * (1.0 + yfactor) / 2);
  340. cucul_draw_bitmap(qq, ww * (1.0 - xfactor) * xdelta,
  341. y + height * (1.0 - yfactor) * ydelta,
  342. ww * (xdelta + (1.0 - xdelta) * xfactor),
  343. y + height * (ydelta + (1.0 - ydelta) * yfactor),
  344. bitmap, pixels);
  345. }
  346. if(!fullscreen)
  347. {
  348. print_status();
  349. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  350. switch(status)
  351. {
  352. case STATUS_ANTIALIASING:
  353. cucul_printf(qq, 0, wh - 1, "Antialiasing: %s",
  354. cucul_get_feature_name(cucul_get_feature(qq, CUCUL_ANTIALIASING)));
  355. break;
  356. case STATUS_DITHERING:
  357. cucul_printf(qq, 0, wh - 1, "Dithering: %s",
  358. cucul_get_feature_name(cucul_get_feature(qq, CUCUL_DITHERING)));
  359. break;
  360. case STATUS_BACKGROUND:
  361. cucul_printf(qq, 0, wh - 1, "Background: %s",
  362. cucul_get_feature_name(cucul_get_feature(qq, CUCUL_BACKGROUND)));
  363. break;
  364. }
  365. }
  366. if(help)
  367. {
  368. print_help(ww - 26, 2);
  369. }
  370. caca_display(kk);
  371. update = 0;
  372. }
  373. /* Clean up */
  374. unload_image();
  375. caca_detach(kk);
  376. cucul_free(qq);
  377. return 0;
  378. }
  379. static void print_status(void)
  380. {
  381. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  382. cucul_draw_line(qq, 0, 0, ww - 1, 0, " ");
  383. cucul_draw_line(qq, 0, wh - 2, ww - 1, wh - 2, "-");
  384. cucul_putstr(qq, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma "
  385. "hjkl:Move d:Dither a:Antialias");
  386. cucul_putstr(qq, ww - strlen("?:Help"), 0, "?:Help");
  387. cucul_printf(qq, 3, wh - 2, "cacaview %s", VERSION);
  388. cucul_printf(qq, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g));
  389. cucul_printf(qq, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);
  390. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  391. cucul_draw_line(qq, 0, wh - 1, ww - 1, wh - 1, " ");
  392. }
  393. static void print_help(int x, int y)
  394. {
  395. static char const *help[] =
  396. {
  397. " +: zoom in ",
  398. " -: zoom out ",
  399. " g: decrease gamma ",
  400. " G: increase gamma ",
  401. " x: reset zoom and gamma ",
  402. " ----------------------- ",
  403. " hjkl: move view ",
  404. " arrows: move view ",
  405. " ----------------------- ",
  406. " a: antialiasing method ",
  407. " d: dithering method ",
  408. " b: background mode ",
  409. " ----------------------- ",
  410. " ?: help ",
  411. " q: quit ",
  412. NULL
  413. };
  414. int i;
  415. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  416. for(i = 0; help[i]; i++)
  417. cucul_putstr(qq, x, y + i, help[i]);
  418. }
  419. static void set_zoom(int new_zoom)
  420. {
  421. int height;
  422. zoom = new_zoom;
  423. if(zoom > ZOOM_MAX) zoom = ZOOM_MAX;
  424. if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX;
  425. ww = cucul_get_width(qq);
  426. height = fullscreen ? wh : wh - 3;
  427. xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom];
  428. yfactor = xfactor * ww / height * h / w
  429. * cucul_get_height(qq) / cucul_get_width(qq)
  430. * caca_get_window_width(kk) / caca_get_window_height(kk);
  431. if(yfactor > xfactor)
  432. {
  433. float tmp = xfactor;
  434. xfactor = tmp * tmp / yfactor;
  435. yfactor = tmp;
  436. }
  437. }
  438. static void set_gamma(int new_gamma)
  439. {
  440. g = new_gamma;
  441. if(g > GAMMA_MAX) g = GAMMA_MAX;
  442. if(g < -GAMMA_MAX) g = -GAMMA_MAX;
  443. cucul_set_bitmap_gamma(bitmap, (g < 0) ? 1.0 / gammatab[-g] : gammatab[g]);
  444. }
  445. static void unload_image(void)
  446. {
  447. #if defined(HAVE_IMLIB2_H)
  448. if(image)
  449. imlib_free_image();
  450. image = NULL;
  451. pixels = NULL;
  452. #else
  453. if(pixels)
  454. free(pixels);
  455. pixels = NULL;
  456. #endif
  457. if(bitmap)
  458. cucul_free_bitmap(bitmap);
  459. bitmap = NULL;
  460. }
  461. static void load_image(char const *name)
  462. {
  463. #if defined(HAVE_IMLIB2_H)
  464. /* Load the new image */
  465. image = imlib_load_image(name);
  466. if(!image)
  467. return;
  468. imlib_context_set_image(image);
  469. pixels = (char *)imlib_image_get_data_for_reading_only();
  470. w = imlib_image_get_width();
  471. h = imlib_image_get_height();
  472. rmask = 0x00ff0000;
  473. gmask = 0x0000ff00;
  474. bmask = 0x000000ff;
  475. amask = 0xff000000;
  476. bpp = 32;
  477. depth = 4;
  478. /* Create the libcucul bitmap */
  479. bitmap = cucul_create_bitmap(bpp, w, h, depth * w,
  480. rmask, gmask, bmask, amask);
  481. if(!bitmap)
  482. {
  483. imlib_free_image();
  484. image = NULL;
  485. }
  486. #else
  487. /* Try to load a BMP file */
  488. FILE *fp;
  489. unsigned int i, colors, offset, tmp, planes;
  490. fp = fopen(name, "rb");
  491. if(!fp)
  492. return;
  493. if(freadshort(fp) != 0x4d42)
  494. {
  495. fclose(fp);
  496. return;
  497. }
  498. freadint(fp); /* size */
  499. freadshort(fp); /* reserved 1 */
  500. freadshort(fp); /* reserved 2 */
  501. offset = freadint(fp);
  502. tmp = freadint(fp); /* header size */
  503. if(tmp == 40)
  504. {
  505. w = freadint(fp);
  506. h = freadint(fp);
  507. planes = freadshort(fp);
  508. bpp = freadshort(fp);
  509. tmp = freadint(fp); /* compression */
  510. if(tmp != 0)
  511. {
  512. fclose(fp);
  513. return;
  514. }
  515. freadint(fp); /* sizeimage */
  516. freadint(fp); /* xpelspermeter */
  517. freadint(fp); /* ypelspermeter */
  518. freadint(fp); /* biclrused */
  519. freadint(fp); /* biclrimportantn */
  520. colors = (offset - 54) / 4;
  521. for(i = 0; i < colors && i < 256; i++)
  522. {
  523. blue[i] = freadchar(fp) * 16;
  524. green[i] = freadchar(fp) * 16;
  525. red[i] = freadchar(fp) * 16;
  526. alpha[i] = 0;
  527. freadchar(fp);
  528. }
  529. }
  530. else if(tmp == 12)
  531. {
  532. w = freadint(fp);
  533. h = freadint(fp);
  534. planes = freadshort(fp);
  535. bpp = freadshort(fp);
  536. colors = (offset - 26) / 3;
  537. for(i = 0; i < colors && i < 256; i++)
  538. {
  539. blue[i] = freadchar(fp);
  540. green[i] = freadchar(fp);
  541. red[i] = freadchar(fp);
  542. alpha[i] = 0;
  543. }
  544. }
  545. else
  546. {
  547. fclose(fp);
  548. return;
  549. }
  550. /* Fill the rest of the palette */
  551. for(i = colors; i < 256; i++)
  552. blue[i] = green[i] = red[i] = alpha[i] = 0;
  553. depth = (bpp + 7) / 8;
  554. /* Sanity check */
  555. if(!w || w > 0x10000 || !h || h > 0x10000 || planes != 1 /*|| bpp != 24*/)
  556. {
  557. fclose(fp);
  558. return;
  559. }
  560. /* Allocate the pixel buffer */
  561. pixels = malloc(w * h * depth);
  562. if(!pixels)
  563. {
  564. fclose(fp);
  565. return;
  566. }
  567. memset(pixels, 0, w * h * depth);
  568. /* Read the bitmap data */
  569. for(i = h; i--; )
  570. {
  571. unsigned int j, k, bits = 0;
  572. switch(bpp)
  573. {
  574. case 1:
  575. for(j = 0; j < w; j++)
  576. {
  577. k = j % 32;
  578. if(k == 0)
  579. bits = freadint(fp);
  580. pixels[w * i * depth + j] =
  581. (bits >> ((k & ~0xf) + 0xf - (k & 0xf))) & 0x1;
  582. }
  583. break;
  584. case 4:
  585. for(j = 0; j < w; j++)
  586. {
  587. k = j % 8;
  588. if(k == 0)
  589. bits = freadint(fp);
  590. pixels[w * i * depth + j] =
  591. (bits >> (4 * ((k & ~0x1) + 0x1 - (k & 0x1)))) & 0xf;
  592. }
  593. break;
  594. default:
  595. /* Works for 8bpp, but also for 16, 24 etc. */
  596. fread(pixels + w * i * depth, w * depth, 1, fp);
  597. /* Pad reads to 4 bytes */
  598. tmp = (w * depth) % 4;
  599. tmp = (4 - tmp) % 4;
  600. while(tmp--)
  601. freadchar(fp);
  602. break;
  603. }
  604. }
  605. switch(depth)
  606. {
  607. case 3:
  608. rmask = 0xff0000;
  609. gmask = 0x00ff00;
  610. bmask = 0x0000ff;
  611. amask = 0x000000;
  612. break;
  613. case 2: /* XXX: those are the 16 bits values */
  614. rmask = 0x7c00;
  615. gmask = 0x03e0;
  616. bmask = 0x001f;
  617. amask = 0x0000;
  618. break;
  619. case 1:
  620. default:
  621. bpp = 8;
  622. rmask = gmask = bmask = amask = 0;
  623. break;
  624. }
  625. fclose(fp);
  626. /* Create the libcucul bitmap */
  627. bitmap = cucul_create_bitmap(bpp, w, h, depth * w,
  628. rmask, gmask, bmask, amask);
  629. if(!bitmap)
  630. {
  631. free(pixels);
  632. pixels = NULL;
  633. return;
  634. }
  635. if(bpp == 8)
  636. cucul_set_bitmap_palette(bitmap, red, green, blue, alpha);
  637. #endif
  638. }
  639. static void draw_checkers(int x1, int y1, int x2, int y2)
  640. {
  641. int xn, yn;
  642. if(x2 + 1 > (int)cucul_get_width(qq)) x2 = cucul_get_width(qq) - 1;
  643. if(y2 + 1 > (int)cucul_get_height(qq)) y2 = cucul_get_height(qq) - 1;
  644. for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++)
  645. for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++)
  646. {
  647. if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1)
  648. cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY);
  649. else
  650. cucul_set_color(qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY);
  651. cucul_putchar(qq, xn, yn, ' ');
  652. }
  653. }
  654. #if !defined(HAVE_IMLIB2_H)
  655. static int freadint(FILE *fp)
  656. {
  657. unsigned char buffer[4];
  658. fread(buffer, 4, 1, fp);
  659. return ((int)buffer[3] << 24) | ((int)buffer[2] << 16)
  660. | ((int)buffer[1] << 8) | ((int)buffer[0]);
  661. }
  662. static int freadshort(FILE *fp)
  663. {
  664. unsigned char buffer[2];
  665. fread(buffer, 2, 1, fp);
  666. return ((int)buffer[1] << 8) | ((int)buffer[0]);
  667. }
  668. static int freadchar(FILE *fp)
  669. {
  670. unsigned char buffer;
  671. fread(&buffer, 1, 1, fp);
  672. return (int)buffer;
  673. }
  674. #endif