source: libcaca/trunk/src/img2irc.c @ 917

Last change on this file since 917 was 859, checked in by Sam Hocevar, 14 years ago
  • Removed duplicate uint*_t defines from *_internal.h and included common.h in all .c files that needed it.
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1/*
2 *  pic2irc       image to IRC converter
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: img2irc.c 859 2006-04-24 20:35:59Z sam $
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
14#include "config.h"
15#include "common.h"
16
17#include <stdio.h>
18#include <string.h>
19#include <stdlib.h>
20
21#include "cucul.h"
22#include "common-image.h"
23
24int main(int argc, char **argv)
25{
26    /* libcucul context */
27    cucul_canvas_t *cv;
28    cucul_buffer_t *export;
29    struct image *i;
30    int cols = 56, lines;
31
32    if(argc != 2)
33    {
34        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
35        return 1;
36    }
37
38    cv = cucul_create_canvas(0, 0);
39    if(!cv)
40    {
41        fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
42        return 1;
43    }
44
45    i = load_image(argv[1]);
46    if(!i)
47    {
48        fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
49        cucul_free_canvas(cv);
50        return 1;
51    }
52
53    /* Assume a 6×10 font */
54    lines = cols * i->h * 6 / i->w / 10;
55
56    cucul_set_canvas_size(cv, cols, lines);
57    cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT);
58    cucul_clear_canvas(cv);
59    cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);
60
61    unload_image(i);
62
63    export = cucul_export_canvas(cv, "irc");
64    fwrite(cucul_get_buffer_data(export),
65           cucul_get_buffer_size(export), 1, stdout);
66    cucul_free_buffer(export);
67
68    cucul_free_canvas(cv);
69
70    return 0;
71}
72
Note: See TracBrowser for help on using the repository browser.