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 813 2006-04-18 15:54:33Z 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 | |
---|
16 | #include <stdio.h> |
---|
17 | #include <string.h> |
---|
18 | #include <stdlib.h> |
---|
19 | |
---|
20 | #include "cucul.h" |
---|
21 | #include "common-image.h" |
---|
22 | |
---|
23 | int main(int argc, char **argv) |
---|
24 | { |
---|
25 | /* libcucul context */ |
---|
26 | cucul_canvas_t *cv; |
---|
27 | cucul_buffer_t *export; |
---|
28 | struct image *i; |
---|
29 | int cols = 56, lines; |
---|
30 | |
---|
31 | if(argc != 2) |
---|
32 | { |
---|
33 | fprintf(stderr, "%s: wrong argument count\n", argv[0]); |
---|
34 | return 1; |
---|
35 | } |
---|
36 | |
---|
37 | cv = cucul_create_canvas(0, 0); |
---|
38 | if(!cv) |
---|
39 | { |
---|
40 | fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); |
---|
41 | return 1; |
---|
42 | } |
---|
43 | |
---|
44 | i = load_image(argv[1]); |
---|
45 | if(!i) |
---|
46 | { |
---|
47 | fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]); |
---|
48 | cucul_free_canvas(cv); |
---|
49 | return 1; |
---|
50 | } |
---|
51 | |
---|
52 | /* Assume a 6×10 font */ |
---|
53 | lines = cols * i->h * 6 / i->w / 10; |
---|
54 | |
---|
55 | cucul_set_canvas_size(cv, cols, lines); |
---|
56 | cucul_clear(cv); |
---|
57 | cucul_dither_bitmap(cv, 0, 0, cols - 1, lines - 1, i->dither, i->pixels); |
---|
58 | |
---|
59 | unload_image(i); |
---|
60 | |
---|
61 | export = cucul_create_export(cv, "irc"); |
---|
62 | fwrite(cucul_get_buffer_data(export), |
---|
63 | cucul_get_buffer_size(export), 1, stdout); |
---|
64 | cucul_free_buffer(export); |
---|
65 | |
---|
66 | cucul_free_canvas(cv); |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|