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

Last change on this file since 1870 was 1870, checked in by Sam Hocevar, 12 years ago
  • Add cucul_get_dither_brightness(), _gamma() and _contrast(). There is no reason to keep a copy of them in the calling program.
  • Deprecate cucul_set_dither_invert(). Inverting a dither's colours is now done by setting a negative gamma value.
  • Property svn:keywords set to Id
File size: 4.2 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 1870 2007-11-03 22:59:53Z 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
78/*
79 * Functions from import.c
80 */
81
82cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
83{
84    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
85    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
86                                  buf->size, format);
87    if(ret < 0)
88    {
89        cucul_free_canvas(cv);
90        return NULL;
91    }
92
93    return cv;
94}
95
96/*
97 * Functions from export.c
98 */
99
100cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
101{
102    cucul_buffer_t *ex;
103
104    ex = malloc(sizeof(cucul_buffer_t));
105    if(!ex)
106    {
107        seterrno(ENOMEM);
108        return NULL;
109    }
110
111    ex->data = cucul_export_memory(cv, format, &ex->size);
112    if(!ex->data)
113    {
114        free(ex);
115        return NULL;
116    }
117
118    ex->user_data = 0;
119
120    return ex;
121}
122
123/*
124 * Functions from frame.c
125 */
126
127unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
128{
129    return cucul_get_frame_count(cv);
130}
131
132int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
133{
134    return cucul_set_frame(cv, id);
135}
136
137int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
138{
139    return cucul_create_frame(cv, id);
140}
141
142int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
143{
144    return cucul_free_frame(cv, id);
145}
146
147/*
148 * Functions from buffer.c
149 */
150
151cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
152{
153    cucul_buffer_t *buf;
154
155    buf = malloc(sizeof(cucul_buffer_t));
156    if(!buf)
157        return NULL;
158
159    buf->data = data;
160    buf->size = size;
161    buf->user_data = 1;
162
163    return buf;
164}
165
166#if !defined(__KERNEL__)
167cucul_buffer_t *cucul_load_file(char const *file)
168{
169    cucul_buffer_t *buf;
170    FILE *fp;
171    long int size;
172
173    fp = fopen(file, "rb");
174    if(!fp)
175        return NULL;
176
177    buf = malloc(sizeof(cucul_buffer_t));
178    if(!buf)
179    {
180        fclose(fp);
181        return NULL;
182    }
183
184    fseek(fp, 0, SEEK_END);
185    size = ftell(fp);
186
187    buf->data = malloc(size);
188    if(!buf->data)
189    {
190        free(buf);
191        fclose(fp);
192        return NULL;
193    }
194    buf->size = size;
195    buf->user_data = 0;
196
197    fseek(fp, 0, SEEK_SET);
198    fread(buf->data, buf->size, 1, fp);
199    fclose(fp);
200
201    return buf;
202}
203#endif
204
205unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
206{
207    return buf->size;
208}
209
210void * cucul_get_buffer_data(cucul_buffer_t *buf)
211{
212    return buf->data;
213}
214
215int cucul_free_buffer(cucul_buffer_t *buf)
216{
217    if(!buf->user_data)
218        free(buf->data);
219
220    free(buf);
221
222    return 0;
223}
224
225/*
226 * Functions from transform.c
227 */
228
229int cucul_rotate(cucul_canvas_t *cv)
230{
231    return cucul_rotate_180(cv);
232}
233
Note: See TracBrowser for help on using the repository browser.