libcaca  0.99.beta19
About: libcaca is a graphics library that outputs text instead of pixels, so that it can work on older video cards or text terminals (something like an advanced AAlib library).
  Fossies Dox: libcaca-0.99.beta19.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

legacy.c
Go to the documentation of this file.
1 /*
2  * libcaca Colour ASCII-Art library
3  * Copyright (c) 2002-2012 Sam Hocevar <sam@hocevar.net>
4  * All Rights Reserved
5  *
6  * This library is free software. It comes without any warranty, to
7  * the extent permitted by applicable law. You can redistribute it
8  * and/or modify it under the terms of the Do What the Fuck You Want
9  * to Public License, Version 2, as published by Sam Hocevar. See
10  * http://www.wtfpl.net/ for more details.
11  */
12 
13 /*
14  * This file contains legacy functions that we keep around until all
15  * applications are ported.
16  */
17 
18 #include "config.h"
19 
20 #if !defined(__KERNEL__)
21 # include <stdio.h>
22 # include <stdlib.h>
23 # include <string.h>
24 #endif
25 
26 #include "caca.h"
27 #include "caca_internals.h"
28 
30 {
31  size_t size;
32  char *data;
33  int user_data;
34 };
35 
36 /*
37  * Functions from canvas.c
38  */
39 
40 int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
41 {
42  return caca_put_char(cv, x, y, ch);
43 }
44 
45 unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
46 {
47  return caca_get_char(cv, x, y);
48 }
49 
50 int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
51 {
52  return caca_put_str(cv, x, y, s);
53 }
54 
55 /*
56  * Functions from color.c
57  */
58 
59 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
60 {
61  return caca_set_color_ansi(cv, fg, bg);
62 }
63 
64 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
65 {
66  return caca_set_color_argb(cv, fg, bg);
67 }
68 
69 /*
70  * Functions from dither.c
71  */
73 {
74  float gamma = caca_get_dither_gamma(d);
75 
76  if(gamma * (value ? -1 : 1) < 0)
77  caca_set_dither_gamma(d, -gamma);
78 
79  return 0;
80 }
81 
82 int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
83 {
84  return caca_set_dither_algorithm(d, s);
85 }
86 
87 char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
88 {
90 }
91 
92 /*
93  * Functions from import.c
94  */
95 
97 {
100  (unsigned char const *)buf->data,
101  buf->size, format);
102  if(ret < 0)
103  {
105  return NULL;
106  }
107 
108  return cv;
109 }
110 
111 /*
112  * Functions from export.c
113  */
114 
116 {
117  cucul_buffer_t *ex;
118 
119  ex = malloc(sizeof(cucul_buffer_t));
120  if(!ex)
121  {
122  seterrno(ENOMEM);
123  return NULL;
124  }
125 
126  ex->data = caca_export_canvas_to_memory(cv, format, &ex->size);
127  if(!ex->data)
128  {
129  free(ex);
130  return NULL;
131  }
132 
133  ex->user_data = 0;
134 
135  return ex;
136 }
137 
138 /*
139  * Functions from frame.c
140  */
141 
143 {
144  return caca_get_frame_count(cv);
145 }
146 
148 {
149  return caca_set_frame(cv, id);
150 }
151 
153 {
154  return caca_create_frame(cv, id);
155 }
156 
158 {
159  return caca_free_frame(cv, id);
160 }
161 
162 /*
163  * Functions from buffer.c
164  */
165 
166 cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
167 {
168  cucul_buffer_t *buf;
169 
170  buf = malloc(sizeof(cucul_buffer_t));
171  if(!buf)
172  return NULL;
173 
174  buf->data = data;
175  buf->size = size;
176  buf->user_data = 1;
177 
178  return buf;
179 }
180 
181 cucul_buffer_t *cucul_load_file(char const *file)
182 {
183  cucul_buffer_t *buf;
184  caca_file_t *f;
185  int ret;
186 
187  f = caca_file_open(file, "rb");
188  if(!f)
189  return NULL;
190 
191  buf = malloc(sizeof(cucul_buffer_t));
192  if(!buf)
193  {
194  caca_file_close(f);
195  return NULL;
196  }
197 
198  buf->data = NULL;
199  buf->size = 0;
200 
201  while(!caca_file_eof(f))
202  {
203  buf->data = realloc(buf->data, buf->size + 1024);
204  if(!buf->data)
205  {
206  int saved_errno = geterrno();
207  free(buf);
208  caca_file_close(f);
209  seterrno(saved_errno);
210  return NULL;
211  }
212 
213  ret = caca_file_read(f, buf->data + buf->size, 1024);
214  if(ret >= 0)
215  buf->size += ret;
216  }
217  caca_file_close(f);
218 
219  return buf;
220 }
221 
222 unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
223 {
224  return buf->size;
225 }
226 
228 {
229  return buf->data;
230 }
231 
233 {
234  if(!buf->user_data)
235  free(buf->data);
236 
237  free(buf);
238 
239  return 0;
240 }
241 
242 /*
243  * Functions from transform.c
244  */
245 
247 {
248  return caca_rotate_180(cv);
249 }
250 
cucul_buffer
Definition: legacy.c:29
caca_file
Definition: file.c:38
cucul_buffer::size
size_t size
Definition: legacy.c:31
caca_export_canvas_to_memory
void * caca_export_canvas_to_memory(caca_canvas_t const *, char const *, size_t *)
Export a canvas into a foreign format.
Definition: export.c:83
cucul_set_color
int cucul_set_color(caca_canvas_t *cv, unsigned char fg, unsigned char bg)
Definition: legacy.c:59
caca_free_frame
int caca_free_frame(caca_canvas_t *, int)
Remove a frame from a canvas.
Definition: frame.c:205
caca_get_dither_gamma
float caca_get_dither_gamma(caca_dither_t const *)
Get the gamma of a dither object.
Definition: dither.c:490
cucul_get_buffer_size
unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
Definition: legacy.c:222
cucul_load_file
cucul_buffer_t * cucul_load_file(char const *file)
Definition: legacy.c:181
y
static int y
Definition: cacadraw.c:27
cucul_set_dither_invert
int cucul_set_dither_invert(caca_dither_t *d, int value)
Definition: legacy.c:72
cucul_getchar
unsigned long int cucul_getchar(caca_canvas_t *, int, int)
caca_set_dither_algorithm
int caca_set_dither_algorithm(caca_dither_t *, char const *)
Set dithering algorithm.
Definition: dither.c:828
cucul_get_dither_mode_list
const char *const * cucul_get_dither_mode_list(caca_dither_t const *d)
Definition: legacy.c:87
caca_create_frame
int caca_create_frame(caca_canvas_t *, int)
Add a frame to a canvas.
Definition: frame.c:145
cucul_load_memory
cucul_buffer_t * cucul_load_memory(void *data, unsigned long int size)
Definition: legacy.c:166
caca_file_eof
int caca_file_eof(caca_file_t *)
Tell whether a file handle reached end of file.
Definition: file.c:298
caca_create_canvas
caca_canvas_t * caca_create_canvas(int, int)
Initialise a libcaca canvas.
Definition: canvas.c:54
caca_free_canvas
int caca_free_canvas(caca_canvas_t *)
Free a libcaca canvas.
Definition: canvas.c:308
caca_set_dither_gamma
int caca_set_dither_gamma(caca_dither_t *, float)
Set the gamma of a dither object.
Definition: dither.c:455
caca_put_str
int caca_put_str(caca_canvas_t *, int, int, char const *)
Print a string.
Definition: string.c:254
seterrno
#define seterrno(x)
Definition: caca_stubs.h:27
caca_rotate_180
int caca_rotate_180(caca_canvas_t *)
Rotate a canvas.
Definition: transform.c:184
geterrno
#define geterrno(x)
Definition: caca_stubs.h:28
cucul_canvas_t
#define cucul_canvas_t
Definition: caca.h:763
cucul_putstr
int cucul_putstr(caca_canvas_t *cv, int x, int y, char const *s)
Definition: legacy.c:50
cv
caca_canvas_t * cv
Definition: cacaview.c:45
caca_file_close
int caca_file_close(caca_file_t *)
Close a file handle.
Definition: file.c:151
cucul_export_canvas
cucul_buffer_t * cucul_export_canvas(caca_canvas_t *cv, char const *format)
Definition: legacy.c:115
cucul_get_buffer_data
void * cucul_get_buffer_data(cucul_buffer_t *buf)
Definition: legacy.c:227
caca_import_canvas_from_memory
ssize_t caca_import_canvas_from_memory(caca_canvas_t *, void const *, size_t, char const *)
Import a memory buffer into a canvas.
Definition: import.c:73
caca_put_char
int caca_put_char(caca_canvas_t *, int, int, uint32_t)
Print an ASCII or Unicode character.
Definition: string.c:120
caca_internals.h
caca_get_dither_algorithm_list
const char *const * caca_get_dither_algorithm_list(caca_dither_t const *)
Get dithering algorithms.
Definition: dither.c:894
cucul_putchar
int cucul_putchar(caca_canvas_t *, int, int, unsigned long int)
cucul_create_canvas_frame
int cucul_create_canvas_frame(caca_canvas_t *cv, unsigned int id)
Definition: legacy.c:152
cucul_set_dither_mode
int cucul_set_dither_mode(caca_dither_t *d, char const *s)
Definition: legacy.c:82
cucul_buffer::user_data
int user_data
Definition: legacy.c:33
cucul_get_canvas_frame_count
unsigned int cucul_get_canvas_frame_count(caca_canvas_t *cv)
Definition: legacy.c:142
cucul_set_canvas_frame
int cucul_set_canvas_frame(caca_canvas_t *cv, unsigned int id)
Definition: legacy.c:147
cucul_rotate
int cucul_rotate(caca_canvas_t *cv)
Definition: legacy.c:246
caca_file_open
caca_file_t * caca_file_open(char const *, const char *)
Open a file for reading or writing.
Definition: file.c:64
cucul_free_canvas_frame
int cucul_free_canvas_frame(caca_canvas_t *cv, unsigned int id)
Definition: legacy.c:157
caca_set_color_ansi
int caca_set_color_ansi(caca_canvas_t *cv, uint8_t fg, uint8_t bg)
Set the default colour pair for text (ANSI version).
Definition: attr.c:234
caca.h
The libcaca public header.
cucul_dither_t
#define cucul_dither_t
Definition: caca.h:764
config.h
caca_get_char
uint32_t caca_get_char(caca_canvas_t const *, int, int)
Get the Unicode character at the given coordinates.
Definition: string.c:224
cucul_set_truecolor
int cucul_set_truecolor(caca_canvas_t *cv, unsigned int fg, unsigned int bg)
Definition: legacy.c:64
caca_set_frame
int caca_set_frame(caca_canvas_t *, int)
Activate a given canvas frame.
Definition: frame.c:57
caca_set_color_argb
int caca_set_color_argb(caca_canvas_t *cv, uint16_t fg, uint16_t bg)
Set the default colour pair for text (truecolor version).
Definition: attr.c:267
cucul_free_buffer
int cucul_free_buffer(cucul_buffer_t *buf)
Definition: legacy.c:232
cucul_import_canvas
caca_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
Definition: legacy.c:96
caca_file_read
size_t caca_file_read(caca_file_t *, void *, size_t)
Read data from a file handle.
Definition: file.c:199
cucul_buffer::data
char * data
Definition: legacy.c:32
caca_canvas
Definition: caca_internals.h:47
x
static int x
Definition: cacadraw.c:27
caca_get_frame_count
int caca_get_frame_count(caca_canvas_t const *)
Get the number of frames in a canvas.
Definition: frame.c:37