Ignore:
Timestamp:
Apr 13, 2006, 7:54:07 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Redisplay the output bitmap using libcaca. Eh ouais mon gars.
Location:
libcaca/trunk/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/test/Makefile.am

    r750 r767  
    2121
    2222font_SOURCES = font.c
    23 font_LDADD = ../cucul/libcucul.la @CUCUL_LIBS@
     23font_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@
    2424
    2525gamma_SOURCES = gamma.c
  • libcaca/trunk/test/font.c

    r763 r767  
    2222#endif
    2323
     24#if defined(HAVE_ENDIAN_H)
     25#   include <endian.h>
     26#endif
     27
    2428#include <stdio.h>
    2529#include <stdlib.h>
     
    2731
    2832#include "cucul.h"
     33#include "caca.h"
    2934
    3035int main(int argc, char *argv[])
    3136{
    3237    cucul_t *qq;
     38    caca_t *kk;
    3339    struct cucul_font *f;
     40    struct cucul_dither *d;
     41    struct caca_event ev;
    3442    unsigned char *buf;
    35     unsigned int x, y, w, h;
     43    unsigned int w, h;
    3644    char const * const * fonts;
    3745
     
    4149    /* Draw stuff on our canvas */
    4250    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    43     cucul_putstr(qq, 0, 0, "ABcde\\o/");
    44     cucul_putstr(qq, 0, 1, "&$âøÿ░▒█");
     51    cucul_putstr(qq, 0, 0, "ABcde");
     52    cucul_set_color(qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
     53    cucul_putstr(qq, 5, 0, "\\o/");
     54    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
     55    cucul_putstr(qq, 0, 1, "&$âøÿØ?!");
    4556
    4657    /* Load a libcucul internal font */
     
    5263    }
    5364    f = cucul_load_font(fonts[0], 0);
     65    if(f == NULL)
     66    {
     67        fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
     68        return -1;
     69    }
    5470
    5571    /* Create our bitmap buffer (32-bit ARGB) */
     
    6177    cucul_render_canvas(qq, f, buf, w, h, 4 * w);
    6278
    63     /* Just for fun, output the image on the terminal using ASCII art */
    64     for(y = 0; y < h; y++)
    65     {
    66         for(x = 0; x < w; x++)
    67         {
    68             static const char list[] = {
    69                 ' ', '.', ':', 't', 'S', 'R', '#', '@'
    70             };
     79    /* Just for fun, render the image using libcaca */
     80    cucul_set_size(qq, 80, 32);
     81    kk = caca_attach(qq);
    7182
    72             printf("%c", list[buf[4 * (y * w + x) + 3] / 0x20]);
    73         }
    74         printf("\n");
    75     }
     83#if defined(HAVE_ENDIAN_H)
     84    if(__BYTE_ORDER == __BIG_ENDIAN)
     85#else
     86    /* This is compile-time optimised with at least -O1 or -Os */
     87    uint32_t const rmask = 0x12345678;
     88    if(*(uint8_t const *)&rmask == 0x12)
     89#endif
     90        d = cucul_create_dither(32, w, h, 4 * w,
     91                                0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
     92    else
     93        d = cucul_create_dither(32, w, h, 4 * w,
     94                                0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);
     95
     96    cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1,
     97                                  cucul_get_height(qq) - 1, d, buf);
     98    caca_display(kk);
     99
     100    caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
    76101
    77102    /* Free everything */
     103    caca_detach(kk);
    78104    free(buf);
     105    cucul_free_dither(d);
    79106    cucul_free_font(f);
    80107    cucul_free(qq);
Note: See TracChangeset for help on using the changeset viewer.