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

Last change on this file since 1302 was 1302, checked in by Sam Hocevar, 13 years ago
  • Deprecate buffer management. We're back to standard void* memory areas.
  • Property svn:keywords set to Id
File size: 3.1 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 1302 2006-11-08 12:11:07Z sam $
7 *
8 *  This library 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/*
15 *  This file contains legacy functions that we keep around until all
16 *  applications are ported.
17 */
18
19#include "config.h"
20#include "common.h"
21
22#if !defined(__KERNEL__)
23#   if defined(HAVE_ERRNO_H)
24#       include <errno.h>
25#   endif
26#   include <stdio.h>
27#   include <stdlib.h>
28#   include <string.h>
29#endif
30
31#include "cucul.h"
32#include "cucul_internals.h"
33
34/*
35 * Functions from color.c
36 */
37
38int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
39{
40    return cucul_set_color_ansi(cv, fg, bg);
41}
42
43int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
44{
45    return cucul_set_color_argb(cv, fg, bg);
46}
47
48/*
49 * Functions from import.c
50 */
51
52cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
53{
54    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
55    int ret = cucul_import(cv, (unsigned char const *)buf->data,
56                           buf->size, format);
57    if(ret < 0)
58    {
59        cucul_free_canvas(cv);
60        return NULL;
61    }
62
63    return cv;
64}
65
66/*
67 * Functions from export.c
68 */
69
70cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
71{
72    cucul_buffer_t *ex;
73
74    ex = malloc(sizeof(cucul_buffer_t));
75    if(!ex)
76    {
77#if defined(HAVE_ERRNO_H)
78        errno = ENOMEM;
79#endif
80        return NULL;
81    }
82
83    ex->data = cucul_export(cv, format, &ex->size);
84    if(!ex->data)
85    {
86        free(ex);
87        return NULL;
88    }
89
90    ex->user_data = 0;
91
92    return ex;
93}
94
95/*
96 * Functions from buffer.c
97 */
98
99cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
100{
101    cucul_buffer_t *buf;
102
103    buf = malloc(sizeof(cucul_buffer_t));
104    if(!buf)
105        return NULL;
106
107    buf->data = data;
108    buf->size = size;
109    buf->user_data = 1;
110
111    return buf;
112}
113
114#if !defined(__KERNEL__)
115cucul_buffer_t *cucul_load_file(char const *file)
116{
117    cucul_buffer_t *buf;
118    FILE *fp;
119    long int size;
120
121    fp = fopen(file, "rb");
122    if(!fp)
123        return NULL;
124
125    buf = malloc(sizeof(cucul_buffer_t));
126    if(!buf)
127    {
128        fclose(fp);
129        return NULL;
130    }
131
132    fseek(fp, 0, SEEK_END);
133    size = ftell(fp);
134
135    buf->data = malloc(size);
136    if(!buf->data)
137    {
138        free(buf);
139        fclose(fp);
140        return NULL;
141    }
142    buf->size = size;
143    buf->user_data = 0;
144
145    fseek(fp, 0, SEEK_SET);
146    fread(buf->data, buf->size, 1, fp);
147    fclose(fp);
148
149    return buf;
150}
151#endif
152
153unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
154{
155    return buf->size;
156}
157
158void * cucul_get_buffer_data(cucul_buffer_t *buf)
159{
160    return buf->data;
161}
162
163int cucul_free_buffer(cucul_buffer_t *buf)
164{
165    if(!buf->user_data)
166        free(buf->data);
167
168    free(buf);
169
170    return 0;
171}
172
Note: See TracBrowser for help on using the repository browser.