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

Last change on this file since 2299 was 2299, checked in by Sam Hocevar, 12 years ago
  • Remove #include <stdint.h> etc. from "common.h". Instead, make sure that <cucul.h> will provide the C99 types, even if libcaca has been installed.
  • Rename what's left of "common.h" to "stubs.h".
  • Remove all references to erroneous <inttypes.h> from source files.
  • Property svn:keywords set to Id
File size: 4.4 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 2299 2008-04-19 12:42:50Z 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
22#if !defined(__KERNEL__)
23#   include <stdio.h>
24#   include <stdlib.h>
25#   include <string.h>
26#endif
27
28#include "cucul.h"
29#include "cucul_internals.h"
30
31/*
32 * Functions from canvas.c
33 */
34
35int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
36{
37    return cucul_put_char(cv, x, y, ch);
38}
39
40unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
41{
42    return cucul_get_char(cv, x, y);
43}
44
45int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
46{
47    return cucul_put_str(cv, x, y, s);
48}
49
50/*
51 * Functions from color.c
52 */
53
54int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
55{
56    return cucul_set_color_ansi(cv, fg, bg);
57}
58
59int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
60{
61    return cucul_set_color_argb(cv, fg, bg);
62}
63
64/*
65 * Functions from dither.c
66 */
67int cucul_set_dither_invert(cucul_dither_t *d, int value)
68{
69    float gamma = cucul_get_dither_gamma(d);
70
71    if(gamma * (value ? -1 : 1) < 0)
72        cucul_set_dither_gamma(d, -gamma);
73
74    return 0;
75}
76
77int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
78{
79    return cucul_set_dither_algorithm(d, s);
80}
81
82char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
83{
84    return cucul_get_dither_algorithm_list(d);
85}
86
87/*
88 * Functions from import.c
89 */
90
91cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
92{
93    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
94    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
95                                  buf->size, format);
96    if(ret < 0)
97    {
98        cucul_free_canvas(cv);
99        return NULL;
100    }
101
102    return cv;
103}
104
105/*
106 * Functions from export.c
107 */
108
109cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
110{
111    cucul_buffer_t *ex;
112
113    ex = malloc(sizeof(cucul_buffer_t));
114    if(!ex)
115    {
116        seterrno(ENOMEM);
117        return NULL;
118    }
119
120    ex->data = cucul_export_memory(cv, format, &ex->size);
121    if(!ex->data)
122    {
123        free(ex);
124        return NULL;
125    }
126
127    ex->user_data = 0;
128
129    return ex;
130}
131
132/*
133 * Functions from frame.c
134 */
135
136unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
137{
138    return cucul_get_frame_count(cv);
139}
140
141int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
142{
143    return cucul_set_frame(cv, id);
144}
145
146int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
147{
148    return cucul_create_frame(cv, id);
149}
150
151int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
152{
153    return cucul_free_frame(cv, id);
154}
155
156/*
157 * Functions from buffer.c
158 */
159
160cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
161{
162    cucul_buffer_t *buf;
163
164    buf = malloc(sizeof(cucul_buffer_t));
165    if(!buf)
166        return NULL;
167
168    buf->data = data;
169    buf->size = size;
170    buf->user_data = 1;
171
172    return buf;
173}
174
175#if !defined(__KERNEL__)
176cucul_buffer_t *cucul_load_file(char const *file)
177{
178    cucul_buffer_t *buf;
179    FILE *fp;
180    long int size;
181
182    fp = fopen(file, "rb");
183    if(!fp)
184        return NULL;
185
186    buf = malloc(sizeof(cucul_buffer_t));
187    if(!buf)
188    {
189        fclose(fp);
190        return NULL;
191    }
192
193    fseek(fp, 0, SEEK_END);
194    size = ftell(fp);
195
196    buf->data = malloc(size);
197    if(!buf->data)
198    {
199        free(buf);
200        fclose(fp);
201        return NULL;
202    }
203    buf->size = size;
204    buf->user_data = 0;
205
206    fseek(fp, 0, SEEK_SET);
207    fread(buf->data, buf->size, 1, fp);
208    fclose(fp);
209
210    return buf;
211}
212#endif
213
214unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
215{
216    return buf->size;
217}
218
219void * cucul_get_buffer_data(cucul_buffer_t *buf)
220{
221    return buf->data;
222}
223
224int cucul_free_buffer(cucul_buffer_t *buf)
225{
226    if(!buf->user_data)
227        free(buf->data);
228
229    free(buf);
230
231    return 0;
232}
233
234/*
235 * Functions from transform.c
236 */
237
238int cucul_rotate(cucul_canvas_t *cv)
239{
240    return cucul_rotate_180(cv);
241}
242
Note: See TracBrowser for help on using the repository browser.