source: libcaca/trunk/cucul/legacy.c @ 1881

Last change on this file since 1881 was 1881, checked in by Sam Hocevar, 12 years ago
  • Renamed cucul_set_dither_mode() into cucul_set_dither_algorithm(). It’s a longer name but "mode" really wasn’t appropriate here.
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/*
2 *  libcucul      Canvas for ultrafast compositing of Unicode letters
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: legacy.c 1881 2007-11-04 12:00:00Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  This file contains legacy functions that we keep around until all
17 *  applications are ported.
18 */
19
20#include "config.h"
21#include "common.h"
22
23#if !defined(__KERNEL__)
24#   include <stdio.h>
25#   include <stdlib.h>
26#   include <string.h>
27#endif
28
29#include "cucul.h"
30#include "cucul_internals.h"
31
32/*
33 * Functions from canvas.c
34 */
35
36int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
37{
38    return cucul_put_char(cv, x, y, ch);
39}
40
41unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
42{
43    return cucul_get_char(cv, x, y);
44}
45
46int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
47{
48    return cucul_put_str(cv, x, y, s);
49}
50
51/*
52 * Functions from color.c
53 */
54
55int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
56{
57    return cucul_set_color_ansi(cv, fg, bg);
58}
59
60int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
61{
62    return cucul_set_color_argb(cv, fg, bg);
63}
64
65/*
66 * Functions from dither.c
67 */
68int cucul_set_dither_invert(cucul_dither_t *d, int value)
69{
70    float gamma = cucul_get_dither_gamma(d);
71
72    if(gamma * (value ? -1 : 1) < 0)
73        cucul_set_dither_gamma(d, -gamma);
74
75    return 0;
76}
77
78int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
79{
80    return cucul_set_dither_algorithm(d, s);
81}
82
83char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
84{
85    return cucul_get_dither_algorithm_list(d);
86}
87
88/*
89 * Functions from import.c
90 */
91
92cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
93{
94    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
95    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
96                                  buf->size, format);
97    if(ret < 0)
98    {
99        cucul_free_canvas(cv);
100        return NULL;
101    }
102
103    return cv;
104}
105
106/*
107 * Functions from export.c
108 */
109
110cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
111{
112    cucul_buffer_t *ex;
113
114    ex = malloc(sizeof(cucul_buffer_t));
115    if(!ex)
116    {
117        seterrno(ENOMEM);
118        return NULL;
119    }
120
121    ex->data = cucul_export_memory(cv, format, &ex->size);
122    if(!ex->data)
123    {
124        free(ex);
125        return NULL;
126    }
127
128    ex->user_data = 0;
129
130    return ex;
131}
132
133/*
134 * Functions from frame.c
135 */
136
137unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
138{
139    return cucul_get_frame_count(cv);
140}
141
142int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
143{
144    return cucul_set_frame(cv, id);
145}
146
147int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
148{
149    return cucul_create_frame(cv, id);
150}
151
152int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
153{
154    return cucul_free_frame(cv, id);
155}
156
157/*
158 * Functions from buffer.c
159 */
160
161cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
162{
163    cucul_buffer_t *buf;
164
165    buf = malloc(sizeof(cucul_buffer_t));
166    if(!buf)
167        return NULL;
168
169    buf->data = data;
170    buf->size = size;
171    buf->user_data = 1;
172
173    return buf;
174}
175
176#if !defined(__KERNEL__)
177cucul_buffer_t *cucul_load_file(char const *file)
178{
179    cucul_buffer_t *buf;
180    FILE *fp;
181    long int size;
182
183    fp = fopen(file, "rb");
184    if(!fp)
185        return NULL;
186
187    buf = malloc(sizeof(cucul_buffer_t));
188    if(!buf)
189    {
190        fclose(fp);
191        return NULL;
192    }
193
194    fseek(fp, 0, SEEK_END);
195    size = ftell(fp);
196
197    buf->data = malloc(size);
198    if(!buf->data)
199    {
200        free(buf);
201        fclose(fp);
202        return NULL;
203    }
204    buf->size = size;
205    buf->user_data = 0;
206
207    fseek(fp, 0, SEEK_SET);
208    fread(buf->data, buf->size, 1, fp);
209    fclose(fp);
210
211    return buf;
212}
213#endif
214
215unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
216{
217    return buf->size;
218}
219
220void * cucul_get_buffer_data(cucul_buffer_t *buf)
221{
222    return buf->data;
223}
224
225int cucul_free_buffer(cucul_buffer_t *buf)
226{
227    if(!buf->user_data)
228        free(buf->data);
229
230    free(buf);
231
232    return 0;
233}
234
235/*
236 * Functions from transform.c
237 */
238
239int cucul_rotate(cucul_canvas_t *cv)
240{
241    return cucul_rotate_180(cv);
242}
243
Note: See TracBrowser for help on using the repository browser.