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

Last change on this file since 1255 was 1049, checked in by Sam Hocevar, 14 years ago
  • A few coding style fixes.
  • Property svn:keywords set to Id
File size: 1.7 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 1049 2006-09-17 12:58:12Z 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#if !defined(__KERNEL__)
18#   include <stdio.h>
19#   include <string.h>
20#   include <stdlib.h>
21#endif
22
23#include "cucul.h"
24#include "common-image.h"
25
26int main(int argc, char **argv)
27{
28    /* libcucul context */
29    cucul_canvas_t *cv;
30    cucul_buffer_t *export;
31    struct image *i;
32    int cols = 56, lines;
33
34    if(argc != 2)
35    {
36        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
37        return 1;
38    }
39
40    cv = cucul_create_canvas(0, 0);
41    if(!cv)
42    {
43        fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
44        return 1;
45    }
46
47    i = load_image(argv[1]);
48    if(!i)
49    {
50        fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
51        cucul_free_canvas(cv);
52        return 1;
53    }
54
55    /* Assume a 6×10 font */
56    lines = cols * i->h * 6 / i->w / 10;
57
58    cucul_set_canvas_size(cv, cols, lines);
59    cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT);
60    cucul_clear_canvas(cv);
61    cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);
62
63    unload_image(i);
64
65    export = cucul_export_canvas(cv, "irc");
66    fwrite(cucul_get_buffer_data(export),
67           cucul_get_buffer_size(export), 1, stdout);
68    cucul_free_buffer(export);
69
70    cucul_free_canvas(cv);
71
72    return 0;
73}
74
Note: See TracBrowser for help on using the repository browser.