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

Last change on this file since 1308 was 1308, checked in by Sam Hocevar, 16 years ago
  • Convert all programs and tests to the new import/export API.
  • 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 1308 2006-11-08 17:26:57Z 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    void *export;
31    unsigned long int len;
32    struct image *i;
33    int cols = 56, lines;
34
35    if(argc != 2)
36    {
37        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
38        return 1;
39    }
40
41    cv = cucul_create_canvas(0, 0);
42    if(!cv)
43    {
44        fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
45        return 1;
46    }
47
48    i = load_image(argv[1]);
49    if(!i)
50    {
51        fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
52        cucul_free_canvas(cv);
53        return 1;
54    }
55
56    /* Assume a 6×10 font */
57    lines = cols * i->h * 6 / i->w / 10;
58
59    cucul_set_canvas_size(cv, cols, lines);
60    cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
61    cucul_clear_canvas(cv);
62    cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);
63
64    unload_image(i);
65
66    export = cucul_export_memory(cv, "irc", &len);
67    fwrite(export, len, 1, stdout);
68    free(export);
69
70    cucul_free_canvas(cv);
71
72    return 0;
73}
74
Note: See TracBrowser for help on using the repository browser.