far better for error checking.tags/v0.99.beta14
@@ -27,7 +27,8 @@ | |||||
#include <cucul.h> | #include <cucul.h> | ||||
#undef __extern | #undef __extern | ||||
#if defined(_WIN32) && defined(__LIBCACA__) | |||||
#if defined(_DOXYGEN_SKIP_ME) | |||||
#elif defined(_WIN32) && defined(__LIBCACA__) | |||||
# define __extern extern __declspec(dllexport) | # define __extern extern __declspec(dllexport) | ||||
#else | #else | ||||
# define __extern extern | # define __extern extern | ||||
@@ -79,9 +80,9 @@ struct caca_event | |||||
enum caca_event_type type; | enum caca_event_type type; | ||||
union | union | ||||
{ | { | ||||
struct { unsigned int x, y, button; } mouse; | |||||
struct { unsigned int w, h; } resize; | |||||
struct { unsigned int ch; uint32_t utf32; char utf8[8]; } key; | |||||
struct { int x, y, button; } mouse; | |||||
struct { int w, h; } resize; | |||||
struct { int ch; uint32_t utf32; char utf8[8]; } key; | |||||
} data; | } data; | ||||
uint8_t padding[16]; | uint8_t padding[16]; | ||||
}; | }; | ||||
@@ -170,10 +171,10 @@ __extern int caca_set_display_driver(caca_display_t *, char const *); | |||||
__extern int caca_free_display(caca_display_t *); | __extern int caca_free_display(caca_display_t *); | ||||
__extern cucul_canvas_t * caca_get_canvas(caca_display_t *); | __extern cucul_canvas_t * caca_get_canvas(caca_display_t *); | ||||
__extern int caca_refresh_display(caca_display_t *); | __extern int caca_refresh_display(caca_display_t *); | ||||
__extern int caca_set_display_time(caca_display_t *, unsigned int); | |||||
__extern unsigned int caca_get_display_time(caca_display_t const *); | |||||
__extern unsigned int caca_get_display_width(caca_display_t const *); | |||||
__extern unsigned int caca_get_display_height(caca_display_t const *); | |||||
__extern int caca_set_display_time(caca_display_t *, int); | |||||
__extern int caca_get_display_time(caca_display_t const *); | |||||
__extern int caca_get_display_width(caca_display_t const *); | |||||
__extern int caca_get_display_height(caca_display_t const *); | |||||
__extern int caca_set_display_title(caca_display_t *, char const *); | __extern int caca_set_display_title(caca_display_t *, char const *); | ||||
__extern int caca_set_mouse(caca_display_t *, int); | __extern int caca_set_mouse(caca_display_t *, int); | ||||
__extern int caca_set_cursor(caca_display_t *, int); | __extern int caca_set_cursor(caca_display_t *, int); | ||||
@@ -186,27 +187,24 @@ __extern char const * caca_get_version(void); | |||||
* clicks. | * clicks. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
__extern int caca_get_event(caca_display_t *, unsigned int, | |||||
caca_event_t *, int); | |||||
__extern unsigned int caca_get_mouse_x(caca_display_t const *); | |||||
__extern unsigned int caca_get_mouse_y(caca_display_t const *); | |||||
__extern int caca_get_event(caca_display_t *, int, caca_event_t *, int); | |||||
__extern int caca_get_mouse_x(caca_display_t const *); | |||||
__extern int caca_get_mouse_y(caca_display_t const *); | |||||
__extern enum caca_event_type caca_get_event_type(caca_event_t const *); | __extern enum caca_event_type caca_get_event_type(caca_event_t const *); | ||||
__extern unsigned int caca_get_event_key_ch(caca_event_t const *); | |||||
__extern int caca_get_event_key_ch(caca_event_t const *); | |||||
__extern uint32_t caca_get_event_key_utf32(caca_event_t const *); | __extern uint32_t caca_get_event_key_utf32(caca_event_t const *); | ||||
__extern int caca_get_event_key_utf8(caca_event_t const *, char *); | __extern int caca_get_event_key_utf8(caca_event_t const *, char *); | ||||
__extern unsigned int caca_get_event_mouse_button(caca_event_t const *); | |||||
__extern unsigned int caca_get_event_mouse_x(caca_event_t const *); | |||||
__extern unsigned int caca_get_event_mouse_y(caca_event_t const *); | |||||
__extern unsigned int caca_get_event_resize_width(caca_event_t const *); | |||||
__extern unsigned int caca_get_event_resize_height(caca_event_t const *); | |||||
__extern int caca_get_event_mouse_button(caca_event_t const *); | |||||
__extern int caca_get_event_mouse_x(caca_event_t const *); | |||||
__extern int caca_get_event_mouse_y(caca_event_t const *); | |||||
__extern int caca_get_event_resize_width(caca_event_t const *); | |||||
__extern int caca_get_event_resize_height(caca_event_t const *); | |||||
/* @} */ | /* @} */ | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
#if !defined(_DOXYGEN_SKIP_ME) | |||||
# undef __extern | |||||
#endif | |||||
#undef __extern | |||||
#endif /* __CACA_H__ */ | #endif /* __CACA_H__ */ |
@@ -95,9 +95,9 @@ struct caca_privevent | |||||
union | union | ||||
{ | { | ||||
struct { unsigned int x, y, button; } mouse; | |||||
struct { unsigned int w, h; } resize; | |||||
struct { unsigned int ch; unsigned long int utf32; char utf8[8]; } key; | |||||
struct { int x, y, button; } mouse; | |||||
struct { int w, h; } resize; | |||||
struct { int ch; uint32_t utf32; char utf8[8]; } key; | |||||
} data; | } data; | ||||
}; | }; | ||||
@@ -122,8 +122,8 @@ struct caca_display | |||||
int (* init_graphics) (caca_display_t *); | int (* init_graphics) (caca_display_t *); | ||||
int (* end_graphics) (caca_display_t *); | int (* end_graphics) (caca_display_t *); | ||||
int (* set_display_title) (caca_display_t *, char const *); | int (* set_display_title) (caca_display_t *, char const *); | ||||
unsigned int (* get_display_width) (caca_display_t const *); | |||||
unsigned int (* get_display_height) (caca_display_t const *); | |||||
int (* get_display_width) (caca_display_t const *); | |||||
int (* get_display_height) (caca_display_t const *); | |||||
void (* display) (caca_display_t *); | void (* display) (caca_display_t *); | ||||
void (* handle_resize) (caca_display_t *); | void (* handle_resize) (caca_display_t *); | ||||
int (* get_event) (caca_display_t *, caca_privevent_t *); | int (* get_event) (caca_display_t *, caca_privevent_t *); | ||||
@@ -134,7 +134,7 @@ struct caca_display | |||||
/* Mouse position */ | /* Mouse position */ | ||||
struct mouse | struct mouse | ||||
{ | { | ||||
unsigned int x, y; | |||||
int x, y; | |||||
} mouse; | } mouse; | ||||
/* Window resize handling */ | /* Window resize handling */ | ||||
@@ -142,11 +142,11 @@ struct caca_display | |||||
{ | { | ||||
int resized; /* A resize event was requested */ | int resized; /* A resize event was requested */ | ||||
int allow; /* The display driver allows resizing */ | int allow; /* The display driver allows resizing */ | ||||
unsigned w, h; /* Requested width and height */ | |||||
int w, h; /* Requested width and height */ | |||||
} resize; | } resize; | ||||
/* Framerate handling */ | /* Framerate handling */ | ||||
unsigned int delay, rendertime; | |||||
int delay, rendertime; | |||||
caca_timer_t timer; | caca_timer_t timer; | ||||
int lastticks; | int lastticks; | ||||
@@ -158,19 +158,19 @@ struct caca_display | |||||
#endif | #endif | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) | #if defined(USE_SLANG) || defined(USE_NCURSES) | ||||
caca_timer_t key_timer; | caca_timer_t key_timer; | ||||
unsigned int last_key_ticks; | |||||
unsigned int autorepeat_ticks; | |||||
int last_key_ticks; | |||||
int autorepeat_ticks; | |||||
caca_privevent_t last_key_event; | caca_privevent_t last_key_event; | ||||
#endif | #endif | ||||
#if defined(USE_WIN32) | #if defined(USE_WIN32) | ||||
unsigned char not_empty_struct; | |||||
uint8_t not_empty_struct; | |||||
#endif | #endif | ||||
} events; | } events; | ||||
}; | }; | ||||
/* Internal timer functions */ | /* Internal timer functions */ | ||||
extern void _caca_sleep(unsigned int); | |||||
extern unsigned int _caca_getticks(caca_timer_t *); | |||||
extern void _caca_sleep(int); | |||||
extern int _caca_getticks(caca_timer_t *); | |||||
/* Internal event functions */ | /* Internal event functions */ | ||||
extern void _caca_handle_resize(caca_display_t *); | extern void _caca_handle_resize(caca_display_t *); | ||||
@@ -62,7 +62,7 @@ static BOOL s_quitting = NO; | |||||
{ | { | ||||
//NSFont* _font; | //NSFont* _font; | ||||
NSRect _font_rect; | NSRect _font_rect; | ||||
unsigned int _h, _w; | |||||
int _h, _w; | |||||
uint32_t* _attrs; | uint32_t* _attrs; | ||||
uint32_t* _chars; | uint32_t* _chars; | ||||
NSRect* _bkg_rects; | NSRect* _bkg_rects; | ||||
@@ -99,7 +99,7 @@ static BOOL s_quitting = NO; | |||||
[[self window] makeFirstResponder:self]; | [[self window] makeFirstResponder:self]; | ||||
#ifdef PRECACHE_WHOLE_COLOR_TABLE | #ifdef PRECACHE_WHOLE_COLOR_TABLE | ||||
unsigned int i; | |||||
int i; | |||||
for(i = 0; i < NCOLORS; i++) | for(i = 0; i < NCOLORS; i++) | ||||
_colorCache[i] = [[NSColor colorFromRgb12:i] retain]; | _colorCache[i] = [[NSColor colorFromRgb12:i] retain]; | ||||
#else | #else | ||||
@@ -125,7 +125,7 @@ static BOOL s_quitting = NO; | |||||
{ | { | ||||
//[_font release]; | //[_font release]; | ||||
#ifdef PRECACHE_WHOLE_COLOR_TABLE | #ifdef PRECACHE_WHOLE_COLOR_TABLE | ||||
unsigned short i; | |||||
short i; | |||||
for(i = 0; i < NCOLORS; i++) | for(i = 0; i < NCOLORS; i++) | ||||
[_colorCache[i] release]; | [_colorCache[i] release]; | ||||
#else | #else | ||||
@@ -248,7 +248,7 @@ static BOOL s_quitting = NO; | |||||
return; | return; | ||||
} | } | ||||
unsigned int x, y; | |||||
int x, y; | |||||
float fw = _font_rect.size.width; | float fw = _font_rect.size.width; | ||||
float fh = _font_rect.size.height; | float fh = _font_rect.size.height; | ||||
uint32_t* attrs; | uint32_t* attrs; | ||||
@@ -258,10 +258,10 @@ static BOOL s_quitting = NO; | |||||
[[NSColor blackColor] set]; | [[NSColor blackColor] set]; | ||||
NSRectFill(rect); | NSRectFill(rect); | ||||
unsigned int arrayLength = 0; | |||||
int arrayLength = 0; | |||||
for(y = 0; y < _h; y++) | for(y = 0; y < _h; y++) | ||||
{ | { | ||||
unsigned int yoff = y * fh; | |||||
int yoff = y * fh; | |||||
for(x = 0; x < _w; x++) | for(x = 0; x < _w; x++) | ||||
{ | { | ||||
NSRect r = NSMakeRect(x * fw, yoff, fw, fh); | NSRect r = NSMakeRect(x * fw, yoff, fw, fh); | ||||
@@ -307,7 +307,7 @@ static BOOL s_quitting = NO; | |||||
/* Then print the foreground characters */ | /* Then print the foreground characters */ | ||||
for(y = 0; y < _h; y++) | for(y = 0; y < _h; y++) | ||||
{ | { | ||||
unsigned int yoff = y * fh; | |||||
int yoff = y * fh; | |||||
for(x = 0; x < _w; x++, chars++) | for(x = 0; x < _w; x++, chars++) | ||||
{ | { | ||||
attrs = _attrs + x + y * _w; | attrs = _attrs + x + y * _w; | ||||
@@ -597,9 +597,9 @@ static void create_first_window(caca_display_t *dp) | |||||
dp->drv.p->view = view; | dp->drv.p->view = view; | ||||
} | } | ||||
static unsigned int get_caca_keycode(NSEvent* event) | |||||
static int get_caca_keycode(NSEvent* event) | |||||
{ | { | ||||
unsigned int caca_keycode = 0; | |||||
int caca_keycode = 0; | |||||
/* | /* | ||||
unsigned short mac_keycode = [event keyCode]; | unsigned short mac_keycode = [event keyCode]; | ||||
debug_log(@"keycode %u (%x)", mac_keycode, mac_keycode); | debug_log(@"keycode %u (%x)", mac_keycode, mac_keycode); | ||||
@@ -747,7 +747,7 @@ static BOOL handle_key_event(caca_privevent_t *ev, NSEvent* event) | |||||
; | ; | ||||
} | } | ||||
unsigned int caca_keycode = get_caca_keycode(event); | |||||
int caca_keycode = get_caca_keycode(event); | |||||
if(caca_keycode) | if(caca_keycode) | ||||
{ | { | ||||
ev->data.key.ch = caca_keycode; | ev->data.key.ch = caca_keycode; | ||||
@@ -800,8 +800,8 @@ static BOOL handle_mouse_event(caca_display_t *dp, caca_privevent_t *ev, | |||||
case NSMouseMoved: | case NSMouseMoved: | ||||
{ | { | ||||
NSPoint mouseLoc = [NSEvent mouseLocation]; | NSPoint mouseLoc = [NSEvent mouseLocation]; | ||||
unsigned int mouse_x = round(mouseLoc.x); | |||||
unsigned int mouse_y = round(mouseLoc.y); | |||||
int mouse_x = round(mouseLoc.x); | |||||
int mouse_y = round(mouseLoc.y); | |||||
if(dp->mouse.x == mouse_x && dp->mouse.y == mouse_y) | if(dp->mouse.x == mouse_x && dp->mouse.y == mouse_y) | ||||
break; | break; | ||||
@@ -826,8 +826,8 @@ static BOOL handle_mouse_event(caca_display_t *dp, caca_privevent_t *ev, | |||||
static int cocoa_init_graphics(caca_display_t *dp) | static int cocoa_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, width, height); | debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, width, height); | ||||
@@ -970,12 +970,12 @@ static int cocoa_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int cocoa_get_display_width(caca_display_t const *dp) | |||||
static int cocoa_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
return [dp->drv.p->window frame].size.width; | return [dp->drv.p->window frame].size.width; | ||||
} | } | ||||
static unsigned int cocoa_get_display_height(caca_display_t const *dp) | |||||
static int cocoa_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
return [dp->drv.p->window frame].size.height; | return [dp->drv.p->window frame].size.height; | ||||
} | } | ||||
@@ -84,13 +84,13 @@ static int conio_set_display_title(caca_display_t *dp, char const *title) | |||||
return -1; | return -1; | ||||
} | } | ||||
static unsigned int conio_get_display_width(caca_display_t const *dp) | |||||
static int conio_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_width(dp->cv) * 6; | return cucul_get_canvas_width(dp->cv) * 6; | ||||
} | } | ||||
static unsigned int conio_get_display_height(caca_display_t const *dp) | |||||
static int conio_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_height(dp->cv) * 10; | return cucul_get_canvas_height(dp->cv) * 10; | ||||
@@ -101,9 +101,9 @@ static void conio_display(caca_display_t *dp) | |||||
char *screen = dp->drv.p->screen; | char *screen = dp->drv.p->screen; | ||||
uint32_t const *chars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *chars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *attrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *attrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int n; | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int n; | |||||
for(n = height * width; n--; ) | for(n = height * width; n--; ) | ||||
{ | { | ||||
@@ -63,8 +63,8 @@ static void gl_compute_font(caca_display_t *); | |||||
struct driver_private | struct driver_private | ||||
{ | { | ||||
int window; | int window; | ||||
unsigned int width, height; | |||||
unsigned int new_width, new_height; | |||||
int width, height; | |||||
int new_width, new_height; | |||||
cucul_font_t *f; | cucul_font_t *f; | ||||
float font_width, font_height; | float font_width, font_height; | ||||
float incx, incy; | float incx, incy; | ||||
@@ -73,8 +73,8 @@ struct driver_private | |||||
uint8_t close; | uint8_t close; | ||||
uint8_t bit; | uint8_t bit; | ||||
uint8_t mouse_changed, mouse_clicked; | uint8_t mouse_changed, mouse_clicked; | ||||
unsigned int mouse_x, mouse_y; | |||||
unsigned int mouse_button, mouse_state; | |||||
int mouse_x, mouse_y; | |||||
int mouse_button, mouse_state; | |||||
uint8_t key; | uint8_t key; | ||||
int special_key; | int special_key; | ||||
@@ -87,8 +87,8 @@ static int gl_init_graphics(caca_display_t *dp) | |||||
char const *geometry; | char const *geometry; | ||||
char *argv[2] = { "", NULL }; | char *argv[2] = { "", NULL }; | ||||
char const * const * fonts; | char const * const * fonts; | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int argc = 1; | int argc = 1; | ||||
dp->drv.p = malloc(sizeof(struct driver_private)); | dp->drv.p = malloc(sizeof(struct driver_private)); | ||||
@@ -204,12 +204,12 @@ static int gl_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int gl_get_display_width(caca_display_t const *dp) | |||||
static int gl_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
return dp->drv.p->width; | return dp->drv.p->width; | ||||
} | } | ||||
static unsigned int gl_get_display_height(caca_display_t const *dp) | |||||
static int gl_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
return dp->drv.p->height; | return dp->drv.p->height; | ||||
} | } | ||||
@@ -218,8 +218,8 @@ static void gl_display(caca_display_t *dp) | |||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int x, y, line; | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int x, y, line; | |||||
glClear(GL_COLOR_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT); | ||||
glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
@@ -332,13 +332,13 @@ static int ncurses_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int ncurses_get_display_width(caca_display_t const *dp) | |||||
static int ncurses_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_width(dp->cv) * 6; | return cucul_get_canvas_width(dp->cv) * 6; | ||||
} | } | ||||
static unsigned int ncurses_get_display_height(caca_display_t const *dp) | |||||
static int ncurses_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_height(dp->cv) * 10; | return cucul_get_canvas_height(dp->cv) * 10; | ||||
@@ -348,8 +348,8 @@ static void ncurses_display(caca_display_t *dp) | |||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int x, y; | int x, y; | ||||
for(y = 0; y < (int)height; y++) | for(y = 0; y < (int)height; y++) | ||||
@@ -420,8 +420,7 @@ static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
int keys[7]; /* Necessary for ungetch(); */ | int keys[7]; /* Necessary for ungetch(); */ | ||||
char utf8[7]; | char utf8[7]; | ||||
uint32_t utf32; | uint32_t utf32; | ||||
unsigned int i; | |||||
size_t bytes = 0; | |||||
size_t i, bytes = 0; | |||||
keys[0] = intkey; | keys[0] = intkey; | ||||
utf8[0] = intkey; | utf8[0] = intkey; | ||||
@@ -495,8 +494,7 @@ static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
#undef CLICK | #undef CLICK | ||||
} | } | ||||
if(dp->mouse.x == (unsigned int)mevent.x && | |||||
dp->mouse.y == (unsigned int)mevent.y) | |||||
if(dp->mouse.x == mevent.x && dp->mouse.y == mevent.y) | |||||
return _pop_event(dp, ev); | return _pop_event(dp, ev); | ||||
dp->mouse.x = mevent.x; | dp->mouse.x = mevent.x; | ||||
@@ -29,8 +29,8 @@ | |||||
static int raw_init_graphics(caca_display_t *dp) | static int raw_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
char const *geometry; | char const *geometry; | ||||
#if defined(HAVE_GETENV) | #if defined(HAVE_GETENV) | ||||
@@ -56,12 +56,12 @@ static int raw_set_display_title(caca_display_t *dp, char const *title) | |||||
return -1; | return -1; | ||||
} | } | ||||
static unsigned int raw_get_display_width(caca_display_t const *dp) | |||||
static int raw_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int raw_get_display_height(caca_display_t const *dp) | |||||
static int raw_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
return 0; | return 0; | ||||
} | } | ||||
@@ -69,7 +69,7 @@ static unsigned int raw_get_display_height(caca_display_t const *dp) | |||||
static void raw_display(caca_display_t *dp) | static void raw_display(caca_display_t *dp) | ||||
{ | { | ||||
void *buffer; | void *buffer; | ||||
unsigned long int len; | |||||
size_t len; | |||||
buffer = cucul_export_memory(dp->cv, "caca", &len); | buffer = cucul_export_memory(dp->cv, "caca", &len); | ||||
if(!buffer) | if(!buffer) | ||||
@@ -207,13 +207,13 @@ static int slang_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int slang_get_display_width(caca_display_t const *dp) | |||||
static int slang_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_width(dp->cv) * 6; | return cucul_get_canvas_width(dp->cv) * 6; | ||||
} | } | ||||
static unsigned int slang_get_display_height(caca_display_t const *dp) | |||||
static int slang_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return cucul_get_canvas_height(dp->cv) * 10; | return cucul_get_canvas_height(dp->cv) * 10; | ||||
@@ -223,8 +223,8 @@ static void slang_display(caca_display_t *dp) | |||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int x, y; | int x, y; | ||||
for(y = 0; y < (int)height; y++) | for(y = 0; y < (int)height; y++) | ||||
@@ -328,8 +328,7 @@ static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
int keys[7]; /* Necessary for ungetkey(); */ | int keys[7]; /* Necessary for ungetkey(); */ | ||||
char utf8[7]; | char utf8[7]; | ||||
uint32_t utf32; | uint32_t utf32; | ||||
unsigned int i; | |||||
size_t bytes = 0; | |||||
size_t i, bytes = 0; | |||||
keys[0] = intkey; | keys[0] = intkey; | ||||
utf8[0] = intkey; | utf8[0] = intkey; | ||||
@@ -361,8 +360,8 @@ static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
if(intkey == 0x3e9) | if(intkey == 0x3e9) | ||||
{ | { | ||||
int button = (SLang_getkey() - ' ' + 1) & 0xf; | int button = (SLang_getkey() - ' ' + 1) & 0xf; | ||||
unsigned int x = SLang_getkey() - '!'; | |||||
unsigned int y = SLang_getkey() - '!'; | |||||
int x = SLang_getkey() - '!'; | |||||
int y = SLang_getkey() - '!'; | |||||
ev->data.mouse.button = button; | ev->data.mouse.button = button; | ||||
ev->type = CACA_EVENT_MOUSE_PRESS; | ev->type = CACA_EVENT_MOUSE_PRESS; | ||||
@@ -101,13 +101,13 @@ static int vga_set_display_title(caca_display_t *dp, char const *title) | |||||
return -1; | return -1; | ||||
} | } | ||||
static unsigned int vga_get_display_width(caca_display_t const *dp) | |||||
static int vga_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 320x200 screen */ | /* Fallback to a 320x200 screen */ | ||||
return 320; | return 320; | ||||
} | } | ||||
static unsigned int vga_get_display_height(caca_display_t const *dp) | |||||
static int vga_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
/* Fallback to a 320x200 screen */ | /* Fallback to a 320x200 screen */ | ||||
return 200; | return 200; | ||||
@@ -118,8 +118,8 @@ static void vga_display(caca_display_t *dp) | |||||
char *screen = (char *)(intptr_t)0x000b8000; | char *screen = (char *)(intptr_t)0x000b8000; | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int n; | int n; | ||||
for(n = height * width; n--; ) | for(n = height * width; n--; ) | ||||
@@ -82,8 +82,8 @@ struct driver_private | |||||
static int win32_init_graphics(caca_display_t *dp) | static int win32_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
CONSOLE_SCREEN_BUFFER_INFO csbi; | CONSOLE_SCREEN_BUFFER_INFO csbi; | ||||
SMALL_RECT rect; | SMALL_RECT rect; | ||||
COORD size; | COORD size; | ||||
@@ -175,7 +175,7 @@ static int win32_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int win32_get_display_width(caca_display_t const *dp) | |||||
static int win32_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
/* FIXME */ | /* FIXME */ | ||||
@@ -183,7 +183,7 @@ static unsigned int win32_get_display_width(caca_display_t const *dp) | |||||
return cucul_get_canvas_width(dp->cv) * 6; | return cucul_get_canvas_width(dp->cv) * 6; | ||||
} | } | ||||
static unsigned int win32_get_display_height(caca_display_t const *dp) | |||||
static int win32_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
/* FIXME */ | /* FIXME */ | ||||
@@ -198,9 +198,9 @@ static void win32_display(caca_display_t *dp) | |||||
CHAR_INFO *buffer = dp->drv.p->buffer; | CHAR_INFO *buffer = dp->drv.p->buffer; | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int n; | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int n; | |||||
/* Render everything to our screen buffer */ | /* Render everything to our screen buffer */ | ||||
for(n = height * width; n--; ) | for(n = height * width; n--; ) | ||||
@@ -302,8 +302,7 @@ static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
{ | { | ||||
COORD pos = rec.Event.MouseEvent.dwMousePosition; | COORD pos = rec.Event.MouseEvent.dwMousePosition; | ||||
if(dp->mouse.x == (unsigned int)pos.X && | |||||
dp->mouse.y == (unsigned int)pos.Y) | |||||
if(dp->mouse.x == pos.X && dp->mouse.y == pos.Y) | |||||
continue; | continue; | ||||
dp->mouse.x = pos.X; | dp->mouse.x = pos.X; | ||||
@@ -75,8 +75,8 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
int (*old_error_handler)(Display *, XErrorEvent *); | int (*old_error_handler)(Display *, XErrorEvent *); | ||||
char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; | char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; | ||||
char const *geometry; | char const *geometry; | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int i; | int i; | ||||
dp->drv.p = malloc(sizeof(struct driver_private)); | dp->drv.p = malloc(sizeof(struct driver_private)); | ||||
@@ -111,7 +111,7 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
/* Parse our font list */ | /* Parse our font list */ | ||||
for( ; ; parser++) | for( ; ; parser++) | ||||
{ | { | ||||
unsigned int font_max_char; | |||||
uint32_t font_max_char; | |||||
if(!*parser) | if(!*parser) | ||||
{ | { | ||||
@@ -143,7 +143,7 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
dp->drv.p->max_char = 0x7f; | dp->drv.p->max_char = 0x7f; | ||||
font_max_char = | font_max_char = | ||||
(((unsigned int)dp->drv.p->font_struct->max_byte1) << 8) | |||||
(dp->drv.p->font_struct->max_byte1 << 8) | |||||
| dp->drv.p->font_struct->max_char_or_byte2; | | dp->drv.p->font_struct->max_char_or_byte2; | ||||
if(font_max_char && (font_max_char < dp->drv.p->max_char)) | if(font_max_char && (font_max_char < dp->drv.p->max_char)) | ||||
dp->drv.p->max_char = font_max_char; | dp->drv.p->max_char = font_max_char; | ||||
@@ -277,12 +277,12 @@ static int x11_set_display_title(caca_display_t *dp, char const *title) | |||||
return 0; | return 0; | ||||
} | } | ||||
static unsigned int x11_get_display_width(caca_display_t const *dp) | |||||
static int x11_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
return cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width; | return cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width; | ||||
} | } | ||||
static unsigned int x11_get_display_height(caca_display_t const *dp) | |||||
static int x11_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
return cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height; | return cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height; | ||||
} | } | ||||
@@ -291,9 +291,9 @@ static void x11_display(caca_display_t *dp) | |||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | ||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int x, y, len; | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
int x, y, len; | |||||
/* First draw the background colours. Splitting the process in two | /* First draw the background colours. Splitting the process in two | ||||
* loops like this is actually slightly faster. */ | * loops like this is actually slightly faster. */ | ||||
@@ -322,7 +322,7 @@ static void x11_display(caca_display_t *dp) | |||||
/* Then print the foreground characters */ | /* Then print the foreground characters */ | ||||
for(y = 0; y < height; y++) | for(y = 0; y < height; y++) | ||||
{ | { | ||||
unsigned int yoff = (y + 1) * dp->drv.p->font_height | |||||
int yoff = (y + 1) * dp->drv.p->font_height | |||||
- dp->drv.p->font_offset; | - dp->drv.p->font_offset; | ||||
uint32_t const *chars = cvchars + y * width; | uint32_t const *chars = cvchars + y * width; | ||||
uint32_t const *attrs = cvattrs + y * width; | uint32_t const *attrs = cvattrs + y * width; | ||||
@@ -378,8 +378,8 @@ static void x11_handle_resize(caca_display_t *dp) | |||||
static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
XEvent xevent; | XEvent xevent; | ||||
char key; | char key; | ||||
@@ -401,7 +401,7 @@ static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
/* Resize event */ | /* Resize event */ | ||||
if(xevent.type == ConfigureNotify) | if(xevent.type == ConfigureNotify) | ||||
{ | { | ||||
unsigned int w, h; | |||||
int w, h; | |||||
w = (xevent.xconfigure.width + dp->drv.p->font_width / 3) | w = (xevent.xconfigure.width + dp->drv.p->font_width / 3) | ||||
/ dp->drv.p->font_width; | / dp->drv.p->font_width; | ||||
@@ -421,8 +421,8 @@ static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
/* Check for mouse motion events */ | /* Check for mouse motion events */ | ||||
if(xevent.type == MotionNotify) | if(xevent.type == MotionNotify) | ||||
{ | { | ||||
unsigned int newx = xevent.xmotion.x / dp->drv.p->font_width; | |||||
unsigned int newy = xevent.xmotion.y / dp->drv.p->font_height; | |||||
int newx = xevent.xmotion.x / dp->drv.p->font_width; | |||||
int newy = xevent.xmotion.y / dp->drv.p->font_height; | |||||
if(newx >= width) | if(newx >= width) | ||||
newx = width - 1; | newx = width - 1; | ||||
@@ -63,7 +63,7 @@ static int _lowlevel_event(caca_display_t *, caca_privevent_t *); | |||||
* \param ev A pointer to a caca_event structure, or NULL. | * \param ev A pointer to a caca_event structure, or NULL. | ||||
* \return 1 if a matching event was received, or 0 if the wait timeouted. | * \return 1 if a matching event was received, or 0 if the wait timeouted. | ||||
*/ | */ | ||||
int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||||
int caca_get_event(caca_display_t *dp, int event_mask, | |||||
caca_event_t *ev, int timeout) | caca_event_t *ev, int timeout) | ||||
{ | { | ||||
caca_privevent_t privevent; | caca_privevent_t privevent; | ||||
@@ -127,9 +127,9 @@ int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||||
* \param dp The libcaca graphical context. | * \param dp The libcaca graphical context. | ||||
* \return The X mouse coordinate. | * \return The X mouse coordinate. | ||||
*/ | */ | ||||
unsigned int caca_get_mouse_x(caca_display_t const *dp) | |||||
int caca_get_mouse_x(caca_display_t const *dp) | |||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
int width = cucul_get_canvas_width(dp->cv); | |||||
if(dp->mouse.x >= width) | if(dp->mouse.x >= width) | ||||
return width - 1; | return width - 1; | ||||
@@ -149,9 +149,9 @@ unsigned int caca_get_mouse_x(caca_display_t const *dp) | |||||
* \param dp The libcaca graphical context. | * \param dp The libcaca graphical context. | ||||
* \return The Y mouse coordinate. | * \return The Y mouse coordinate. | ||||
*/ | */ | ||||
unsigned int caca_get_mouse_y(caca_display_t const *dp) | |||||
int caca_get_mouse_y(caca_display_t const *dp) | |||||
{ | { | ||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int height = cucul_get_canvas_height(dp->cv); | |||||
if(dp->mouse.y >= height) | if(dp->mouse.y >= height) | ||||
return height - 1; | return height - 1; | ||||
@@ -198,7 +198,7 @@ enum caca_event_type caca_get_event_type(caca_event_t const *ev) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The key value. | * \return The key value. | ||||
*/ | */ | ||||
unsigned int caca_get_event_key_ch(caca_event_t const *ev) | |||||
int caca_get_event_key_ch(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.key.ch; | return ((caca_privevent_t const *)ev)->data.key.ch; | ||||
} | } | ||||
@@ -249,7 +249,7 @@ int caca_get_event_key_utf8(caca_event_t const *ev, char *utf8) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The event's mouse button. | * \return The event's mouse button. | ||||
*/ | */ | ||||
unsigned int caca_get_event_mouse_button(caca_event_t const *ev) | |||||
int caca_get_event_mouse_button(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.mouse.button; | return ((caca_privevent_t const *)ev)->data.mouse.button; | ||||
} | } | ||||
@@ -265,7 +265,7 @@ unsigned int caca_get_event_mouse_button(caca_event_t const *ev) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The event's X mouse coordinate. | * \return The event's X mouse coordinate. | ||||
*/ | */ | ||||
unsigned int caca_get_event_mouse_x(caca_event_t const *ev) | |||||
int caca_get_event_mouse_x(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.mouse.x; | return ((caca_privevent_t const *)ev)->data.mouse.x; | ||||
} | } | ||||
@@ -281,7 +281,7 @@ unsigned int caca_get_event_mouse_x(caca_event_t const *ev) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The event's Y mouse coordinate. | * \return The event's Y mouse coordinate. | ||||
*/ | */ | ||||
unsigned int caca_get_event_mouse_y(caca_event_t const *ev) | |||||
int caca_get_event_mouse_y(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.mouse.y; | return ((caca_privevent_t const *)ev)->data.mouse.y; | ||||
} | } | ||||
@@ -297,7 +297,7 @@ unsigned int caca_get_event_mouse_y(caca_event_t const *ev) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The event's new display width value. | * \return The event's new display width value. | ||||
*/ | */ | ||||
unsigned int caca_get_event_resize_width(caca_event_t const *ev) | |||||
int caca_get_event_resize_width(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.resize.w; | return ((caca_privevent_t const *)ev)->data.resize.w; | ||||
} | } | ||||
@@ -313,7 +313,7 @@ unsigned int caca_get_event_resize_width(caca_event_t const *ev) | |||||
* \param ev The libcaca event. | * \param ev The libcaca event. | ||||
* \return The event's new display height value. | * \return The event's new display height value. | ||||
*/ | */ | ||||
unsigned int caca_get_event_resize_height(caca_event_t const *ev) | |||||
int caca_get_event_resize_height(caca_event_t const *ev) | |||||
{ | { | ||||
return ((caca_privevent_t const *)ev)->data.resize.h; | return ((caca_privevent_t const *)ev)->data.resize.h; | ||||
} | } | ||||
@@ -325,7 +325,7 @@ unsigned int caca_get_event_resize_height(caca_event_t const *ev) | |||||
static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev) | static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
{ | { | ||||
#if defined(USE_SLANG) || defined(USE_NCURSES) | #if defined(USE_SLANG) || defined(USE_NCURSES) | ||||
unsigned int ticks; | |||||
int ticks; | |||||
#endif | #endif | ||||
int ret; | int ret; | ||||
@@ -62,7 +62,7 @@ int caca_set_display_title(caca_display_t *dp, char const *title) | |||||
* \param dp The libcaca display context. | * \param dp The libcaca display context. | ||||
* \return The display width. | * \return The display width. | ||||
*/ | */ | ||||
unsigned int caca_get_display_width(caca_display_t const *dp) | |||||
int caca_get_display_width(caca_display_t const *dp) | |||||
{ | { | ||||
return dp->drv.get_display_width(dp); | return dp->drv.get_display_width(dp); | ||||
} | } | ||||
@@ -79,7 +79,7 @@ unsigned int caca_get_display_width(caca_display_t const *dp) | |||||
* \param dp The libcaca display context. | * \param dp The libcaca display context. | ||||
* \return The display height. | * \return The display height. | ||||
*/ | */ | ||||
unsigned int caca_get_display_height(caca_display_t const *dp) | |||||
int caca_get_display_height(caca_display_t const *dp) | |||||
{ | { | ||||
return dp->drv.get_display_height(dp); | return dp->drv.get_display_height(dp); | ||||
} | } | ||||
@@ -93,14 +93,21 @@ unsigned int caca_get_display_height(caca_display_t const *dp) | |||||
* If the argument is zero, constant framerate is disabled. This is the | * If the argument is zero, constant framerate is disabled. This is the | ||||
* default behaviour. | * default behaviour. | ||||
* | * | ||||
* This function never fails. | |||||
* If an error occurs, -1 is returned and \b errno is set accordingly: | |||||
* - \c EINVAL Refresh delay value is invalid. | |||||
* | * | ||||
* \param dp The libcaca display context. | * \param dp The libcaca display context. | ||||
* \param usec The refresh delay in microseconds. | * \param usec The refresh delay in microseconds. | ||||
* \return This function always returns 0. | |||||
* \return 0 upon success, -1 if an error occurred. | |||||
*/ | */ | ||||
int caca_set_display_time(caca_display_t *dp, unsigned int usec) | |||||
int caca_set_display_time(caca_display_t *dp, int usec) | |||||
{ | { | ||||
if(usec < 0) | |||||
{ | |||||
seterrno(EINVAL); | |||||
return -1; | |||||
} | |||||
dp->delay = usec; | dp->delay = usec; | ||||
return 0; | return 0; | ||||
} | } | ||||
@@ -118,7 +125,7 @@ int caca_set_display_time(caca_display_t *dp, unsigned int usec) | |||||
* \param dp The libcaca display context. | * \param dp The libcaca display context. | ||||
* \return The render time in microseconds. | * \return The render time in microseconds. | ||||
*/ | */ | ||||
unsigned int caca_get_display_time(caca_display_t const *dp) | |||||
int caca_get_display_time(caca_display_t const *dp) | |||||
{ | { | ||||
return dp->rendertime; | return dp->rendertime; | ||||
} | } | ||||
@@ -35,7 +35,7 @@ | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
void _caca_sleep(unsigned int usec) | |||||
void _caca_sleep(int usec) | |||||
{ | { | ||||
#if defined(HAVE_USLEEP) | #if defined(HAVE_USLEEP) | ||||
usleep(usec); | usleep(usec); | ||||
@@ -46,15 +46,15 @@ void _caca_sleep(unsigned int usec) | |||||
#endif | #endif | ||||
} | } | ||||
unsigned int _caca_getticks(caca_timer_t *timer) | |||||
int _caca_getticks(caca_timer_t *timer) | |||||
{ | { | ||||
#if defined(HAVE_GETTIMEOFDAY) | #if defined(HAVE_GETTIMEOFDAY) | ||||
struct timeval tv; | struct timeval tv; | ||||
#elif defined(USE_WIN32) | #elif defined(USE_WIN32) | ||||
static __int64 freq = -1; /* FIXME: can this move to caca_context? */ | static __int64 freq = -1; /* FIXME: can this move to caca_context? */ | ||||
unsigned __int64 usec; | |||||
__int64 usec; | |||||
#endif | #endif | ||||
unsigned int ticks = 0; | |||||
int ticks = 0; | |||||
int new_sec, new_usec; | int new_sec, new_usec; | ||||
#if defined(HAVE_GETTIMEOFDAY) | #if defined(HAVE_GETTIMEOFDAY) | ||||
@@ -299,7 +299,7 @@ int cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...) | |||||
int cucul_clear_canvas(cucul_canvas_t *cv) | int cucul_clear_canvas(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t attr = cv->curattr; | uint32_t attr = cv->curattr; | ||||
unsigned int n; | |||||
int n; | |||||
for(n = cv->width * cv->height; n--; ) | for(n = cv->width * cv->height; n--; ) | ||||
{ | { | ||||
@@ -393,21 +393,21 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
endi = (x + src->width >= dst->width) ? dst->width - x : src->width; | endi = (x + src->width >= dst->width) ? dst->width - x : src->width; | ||||
endj = (y + src->height >= dst->height) ? dst->height - y : src->height; | endj = (y + src->height >= dst->height) ? dst->height - y : src->height; | ||||
if((unsigned int)starti > src->width || (unsigned int)startj > src->height | |||||
if(starti > src->width || startj > src->height | |||||
|| starti >= endi || startj >= endj) | || starti >= endi || startj >= endj) | ||||
return 0; | return 0; | ||||
for(j = startj; j < endj; j++) | for(j = startj; j < endj; j++) | ||||
{ | { | ||||
unsigned int dstix = (j + y) * dst->width + starti + x; | |||||
unsigned int srcix = j * src->width + starti; | |||||
int dstix = (j + y) * dst->width + starti + x; | |||||
int srcix = j * src->width + starti; | |||||
int stride = endi - starti; | int stride = endi - starti; | ||||
/* FIXME: we are ignoring the mask here */ | /* FIXME: we are ignoring the mask here */ | ||||
if((starti + x) && dst->chars[dstix] == CUCUL_MAGIC_FULLWIDTH) | if((starti + x) && dst->chars[dstix] == CUCUL_MAGIC_FULLWIDTH) | ||||
dst->chars[dstix - 1] = ' '; | dst->chars[dstix - 1] = ' '; | ||||
if((unsigned int)(endi + x) < dst->width | |||||
if(endi + x < dst->width | |||||
&& dst->chars[dstix + stride] == CUCUL_MAGIC_FULLWIDTH) | && dst->chars[dstix + stride] == CUCUL_MAGIC_FULLWIDTH) | ||||
dst->chars[dstix + stride] = ' '; | dst->chars[dstix + stride] = ' '; | ||||
@@ -432,8 +432,7 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
if(src->chars[srcix] == CUCUL_MAGIC_FULLWIDTH) | if(src->chars[srcix] == CUCUL_MAGIC_FULLWIDTH) | ||||
dst->chars[dstix] = ' '; | dst->chars[dstix] = ' '; | ||||
if((unsigned int)endi < src->width | |||||
&& src->chars[endi] == CUCUL_MAGIC_FULLWIDTH) | |||||
if(endi < src->width && src->chars[endi] == CUCUL_MAGIC_FULLWIDTH) | |||||
dst->chars[dstix + stride - 1] = ' '; | dst->chars[dstix + stride - 1] = ' '; | ||||
} | } | ||||
@@ -447,6 +446,7 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
* are affected by this function. | * are affected by this function. | ||||
* | * | ||||
* If an error occurs, -1 is returned and \b errno is set accordingly: | * If an error occurs, -1 is returned and \b errno is set accordingly: | ||||
* - \c EINVAL Specified width or height is invalid. | |||||
* - \c EBUSY The canvas is in use by a display driver and cannot be resized. | * - \c EBUSY The canvas is in use by a display driver and cannot be resized. | ||||
* - \c ENOMEM Not enough memory for the requested canvas size. If this | * - \c ENOMEM Not enough memory for the requested canvas size. If this | ||||
* happens, the canvas handle becomes invalid and should not be used. | * happens, the canvas handle becomes invalid and should not be used. | ||||
@@ -458,11 +458,10 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
* \param h The height of the cropped area. | * \param h The height of the cropped area. | ||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, | |||||
unsigned int w, unsigned int h) | |||||
int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, int w, int h) | |||||
{ | { | ||||
cucul_canvas_t *new; | cucul_canvas_t *new; | ||||
unsigned int f, saved_f, framecount; | |||||
int f, saved_f, framecount; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -470,6 +469,12 @@ int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, | |||||
return -1; | return -1; | ||||
} | } | ||||
if(w < 0 || h < 0) | |||||
{ | |||||
seterrno(EINVAL); | |||||
return -1; | |||||
} | |||||
new = cucul_create_canvas(w, h); | new = cucul_create_canvas(w, h); | ||||
framecount = cucul_get_frame_count(cv); | framecount = cucul_get_frame_count(cv); | ||||
@@ -33,7 +33,7 @@ | |||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
static int cucul_resize(cucul_canvas_t *, unsigned int, unsigned int); | |||||
static int cucul_resize(cucul_canvas_t *, int, int); | |||||
/** \brief Initialise a \e libcucul canvas. | /** \brief Initialise a \e libcucul canvas. | ||||
* | * | ||||
@@ -46,15 +46,24 @@ static int cucul_resize(cucul_canvas_t *, unsigned int, unsigned int); | |||||
* corner. | * corner. | ||||
* | * | ||||
* If an error occurs, NULL is returned and \b errno is set accordingly: | * If an error occurs, NULL is returned and \b errno is set accordingly: | ||||
* - \c EINVAL Specified width or height is invalid. | |||||
* - \c ENOMEM Not enough memory for the requested canvas size. | * - \c ENOMEM Not enough memory for the requested canvas size. | ||||
* | * | ||||
* \param width The desired canvas width | * \param width The desired canvas width | ||||
* \param height The desired canvas height | * \param height The desired canvas height | ||||
* \return A libcucul canvas handle upon success, NULL if an error occurred. | * \return A libcucul canvas handle upon success, NULL if an error occurred. | ||||
*/ | */ | ||||
cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) | |||||
cucul_canvas_t * cucul_create_canvas(int width, int height) | |||||
{ | { | ||||
cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t)); | |||||
cucul_canvas_t *cv; | |||||
if(width < 0 || height < 0) | |||||
{ | |||||
seterrno(EINVAL); | |||||
return NULL; | |||||
} | |||||
cv = malloc(sizeof(cucul_canvas_t)); | |||||
if(!cv) | if(!cv) | ||||
goto nomem; | goto nomem; | ||||
@@ -190,6 +199,7 @@ int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p) | |||||
* for more about this. | * for more about this. | ||||
* | * | ||||
* If an error occurs, -1 is returned and \b errno is set accordingly: | * If an error occurs, -1 is returned and \b errno is set accordingly: | ||||
* - \c EINVAL Specified width or height is invalid. | |||||
* - \c EBUSY The canvas is in use by a display driver and cannot be resized. | * - \c EBUSY The canvas is in use by a display driver and cannot be resized. | ||||
* - \c ENOMEM Not enough memory for the requested canvas size. If this | * - \c ENOMEM Not enough memory for the requested canvas size. If this | ||||
* happens, the canvas handle becomes invalid and should not be used. | * happens, the canvas handle becomes invalid and should not be used. | ||||
@@ -199,9 +209,14 @@ int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p) | |||||
* \param height The desired canvas height. | * \param height The desired canvas height. | ||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, | |||||
unsigned int height) | |||||
int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height) | |||||
{ | { | ||||
if(width < 0 || height < 0) | |||||
{ | |||||
seterrno(EINVAL); | |||||
return -1; | |||||
} | |||||
if(cv->refcount && cv->resize_callback | if(cv->refcount && cv->resize_callback | ||||
&& !cv->resize_callback(cv->resize_data)) | && !cv->resize_callback(cv->resize_data)) | ||||
{ | { | ||||
@@ -221,7 +236,7 @@ int cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, | |||||
* \param cv A libcucul canvas. | * \param cv A libcucul canvas. | ||||
* \return The canvas width. | * \return The canvas width. | ||||
*/ | */ | ||||
unsigned int cucul_get_canvas_width(cucul_canvas_t const *cv) | |||||
int cucul_get_canvas_width(cucul_canvas_t const *cv) | |||||
{ | { | ||||
return cv->width; | return cv->width; | ||||
} | } | ||||
@@ -235,7 +250,7 @@ unsigned int cucul_get_canvas_width(cucul_canvas_t const *cv) | |||||
* \param cv A libcucul canvas. | * \param cv A libcucul canvas. | ||||
* \return The canvas height. | * \return The canvas height. | ||||
*/ | */ | ||||
unsigned int cucul_get_canvas_height(cucul_canvas_t const *cv) | |||||
int cucul_get_canvas_height(cucul_canvas_t const *cv) | |||||
{ | { | ||||
return cv->height; | return cv->height; | ||||
} | } | ||||
@@ -292,7 +307,7 @@ uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *cv) | |||||
*/ | */ | ||||
int cucul_free_canvas(cucul_canvas_t *cv) | int cucul_free_canvas(cucul_canvas_t *cv) | ||||
{ | { | ||||
unsigned int f; | |||||
int f; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -356,9 +371,9 @@ char const * cucul_get_version(void) | |||||
* XXX: The following functions are local. | * XXX: The following functions are local. | ||||
*/ | */ | ||||
int cucul_resize(cucul_canvas_t *cv, unsigned int width, unsigned int height) | |||||
int cucul_resize(cucul_canvas_t *cv, int width, int height) | |||||
{ | { | ||||
unsigned int x, y, f, old_width, old_height, new_size, old_size; | |||||
int x, y, f, old_width, old_height, new_size, old_size; | |||||
old_width = cv->width; | old_width = cv->width; | ||||
old_height = cv->height; | old_height = cv->height; | ||||
@@ -426,7 +441,7 @@ int cucul_resize(cucul_canvas_t *cv, unsigned int width, unsigned int height) | |||||
{ | { | ||||
/* New width is smaller. Copy as many lines as possible. Ignore | /* New width is smaller. Copy as many lines as possible. Ignore | ||||
* the first line, it is already in place. */ | * the first line, it is already in place. */ | ||||
unsigned int lines = height < old_height ? height : old_height; | |||||
int lines = height < old_height ? height : old_height; | |||||
for(f = 0; f < cv->framecount; f++) | for(f = 0; f < cv->framecount; f++) | ||||
{ | { | ||||
@@ -27,7 +27,8 @@ | |||||
#include <cucul_types.h> | #include <cucul_types.h> | ||||
#undef __extern | #undef __extern | ||||
#if defined(_WIN32) && defined(__LIBCUCUL__) | |||||
#if defined(_DOXYGEN_SKIP_ME) | |||||
#elif defined(_WIN32) && defined(__LIBCUCUL__) | |||||
# define __extern extern __declspec(dllexport) | # define __extern extern __declspec(dllexport) | ||||
#else | #else | ||||
# define __extern extern | # define __extern extern | ||||
@@ -86,13 +87,12 @@ typedef struct cucul_file cucul_file_t; | |||||
* initialisation, system information retrieval and configuration. | * initialisation, system information retrieval and configuration. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
__extern cucul_canvas_t * cucul_create_canvas(unsigned int, unsigned int); | |||||
__extern cucul_canvas_t * cucul_create_canvas(int, int); | |||||
__extern int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *); | __extern int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *); | ||||
__extern int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *); | __extern int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *); | ||||
__extern int cucul_set_canvas_size(cucul_canvas_t *, unsigned int, | |||||
unsigned int); | |||||
__extern unsigned int cucul_get_canvas_width(cucul_canvas_t const *); | |||||
__extern unsigned int cucul_get_canvas_height(cucul_canvas_t const *); | |||||
__extern int cucul_set_canvas_size(cucul_canvas_t *, int, int); | |||||
__extern int cucul_get_canvas_width(cucul_canvas_t const *); | |||||
__extern int cucul_get_canvas_height(cucul_canvas_t const *); | |||||
__extern uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *); | __extern uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *); | ||||
__extern uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *); | __extern uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *); | ||||
__extern int cucul_free_canvas(cucul_canvas_t *); | __extern int cucul_free_canvas(cucul_canvas_t *); | ||||
@@ -125,8 +125,7 @@ __extern int cucul_get_canvas_handle_x(cucul_canvas_t const *); | |||||
__extern int cucul_get_canvas_handle_y(cucul_canvas_t const *); | __extern int cucul_get_canvas_handle_y(cucul_canvas_t const *); | ||||
__extern int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, | __extern int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, | ||||
cucul_canvas_t const *); | cucul_canvas_t const *); | ||||
__extern int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int, | |||||
unsigned int, unsigned int); | |||||
__extern int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int, int, int); | |||||
/* @} */ | /* @} */ | ||||
/** \defgroup cucul_transform libcucul canvas transformation | /** \defgroup cucul_transform libcucul canvas transformation | ||||
@@ -207,12 +206,12 @@ __extern int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, | |||||
* removal, copying etc. | * removal, copying etc. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
__extern unsigned int cucul_get_frame_count(cucul_canvas_t const *); | |||||
__extern int cucul_set_frame(cucul_canvas_t *, unsigned int); | |||||
__extern int cucul_get_frame_count(cucul_canvas_t const *); | |||||
__extern int cucul_set_frame(cucul_canvas_t *, int); | |||||
__extern char const *cucul_get_frame_name(cucul_canvas_t const *); | __extern char const *cucul_get_frame_name(cucul_canvas_t const *); | ||||
__extern int cucul_set_frame_name(cucul_canvas_t *, char const *); | __extern int cucul_set_frame_name(cucul_canvas_t *, char const *); | ||||
__extern int cucul_create_frame(cucul_canvas_t *, unsigned int); | |||||
__extern int cucul_free_frame(cucul_canvas_t *, unsigned int); | |||||
__extern int cucul_create_frame(cucul_canvas_t *, int); | |||||
__extern int cucul_free_frame(cucul_canvas_t *, int); | |||||
/* @} */ | /* @} */ | ||||
/** \defgroup cucul_dither libcucul bitmap dithering | /** \defgroup cucul_dither libcucul bitmap dithering | ||||
@@ -221,13 +220,12 @@ __extern int cucul_free_frame(cucul_canvas_t *, unsigned int); | |||||
* rendering. | * rendering. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
__extern cucul_dither_t *cucul_create_dither(unsigned int, unsigned int, | |||||
unsigned int, unsigned int, | |||||
__extern cucul_dither_t *cucul_create_dither(int, int, int, int, | |||||
uint32_t, uint32_t, | uint32_t, uint32_t, | ||||
uint32_t, uint32_t); | uint32_t, uint32_t); | ||||
__extern int cucul_set_dither_palette(cucul_dither_t *, | __extern int cucul_set_dither_palette(cucul_dither_t *, | ||||
unsigned int r[], unsigned int g[], | |||||
unsigned int b[], unsigned int a[]); | |||||
uint32_t r[], uint32_t g[], | |||||
uint32_t b[], uint32_t a[]); | |||||
__extern int cucul_set_dither_brightness(cucul_dither_t *, float); | __extern int cucul_set_dither_brightness(cucul_dither_t *, float); | ||||
__extern float cucul_get_dither_brightness(cucul_dither_t const *); | __extern float cucul_get_dither_brightness(cucul_dither_t const *); | ||||
__extern int cucul_set_dither_gamma(cucul_dither_t *, float); | __extern int cucul_set_dither_gamma(cucul_dither_t *, float); | ||||
@@ -261,14 +259,13 @@ __extern int cucul_free_dither(cucul_dither_t *); | |||||
* canvas to bitmap rendering. | * canvas to bitmap rendering. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
__extern cucul_font_t *cucul_load_font(void const *, unsigned int); | |||||
__extern cucul_font_t *cucul_load_font(void const *, size_t); | |||||
__extern char const * const * cucul_get_font_list(void); | __extern char const * const * cucul_get_font_list(void); | ||||
__extern unsigned int cucul_get_font_width(cucul_font_t const *); | |||||
__extern unsigned int cucul_get_font_height(cucul_font_t const *); | |||||
__extern unsigned int const *cucul_get_font_blocks(cucul_font_t const *); | |||||
__extern int cucul_get_font_width(cucul_font_t const *); | |||||
__extern int cucul_get_font_height(cucul_font_t const *); | |||||
__extern uint32_t const *cucul_get_font_blocks(cucul_font_t const *); | |||||
__extern int cucul_render_canvas(cucul_canvas_t const *, cucul_font_t const *, | __extern int cucul_render_canvas(cucul_canvas_t const *, cucul_font_t const *, | ||||
void *, unsigned int, unsigned int, | |||||
unsigned int); | |||||
void *, int, int, int); | |||||
__extern int cucul_free_font(cucul_font_t *); | __extern int cucul_free_font(cucul_font_t *); | ||||
/* @} */ | /* @} */ | ||||
@@ -366,8 +363,6 @@ __extern char const * const * cucul_get_dither_mode_list(cucul_dither_t | |||||
} | } | ||||
#endif | #endif | ||||
#if !defined(_DOXYGEN_SKIP_ME) | |||||
# undef __extern | |||||
#endif | |||||
#undef __extern | |||||
#endif /* __CUCUL_H__ */ | #endif /* __CUCUL_H__ */ |
@@ -22,7 +22,7 @@ typedef struct cucul_figfont cucul_figfont_t; | |||||
struct cucul_frame | struct cucul_frame | ||||
{ | { | ||||
/* Frame size */ | /* Frame size */ | ||||
unsigned int width, height; | |||||
int width, height; | |||||
/* Cell information */ | /* Cell information */ | ||||
uint32_t *chars; | uint32_t *chars; | ||||
@@ -43,17 +43,17 @@ struct cucul_canvas | |||||
* to this structure. The function is quite hacky. */ | * to this structure. The function is quite hacky. */ | ||||
/* Frame information */ | /* Frame information */ | ||||
unsigned int frame, framecount; | |||||
int frame, framecount; | |||||
struct cucul_frame *frames; | struct cucul_frame *frames; | ||||
/* Canvas management */ | /* Canvas management */ | ||||
unsigned int refcount; | |||||
unsigned int autoinc; | |||||
int refcount; | |||||
int autoinc; | |||||
int (*resize_callback)(void *); | int (*resize_callback)(void *); | ||||
void *resize_data; | void *resize_data; | ||||
/* Shortcut to the active frame information */ | /* Shortcut to the active frame information */ | ||||
unsigned int width, height; | |||||
int width, height; | |||||
uint32_t *chars; | uint32_t *chars; | ||||
uint32_t *attrs; | uint32_t *attrs; | ||||
uint32_t curattr; | uint32_t curattr; | ||||
@@ -64,7 +64,7 @@ struct cucul_canvas | |||||
struct cucul_buffer | struct cucul_buffer | ||||
{ | { | ||||
unsigned long int size; | |||||
size_t size; | |||||
char *data; | char *data; | ||||
int user_data; | int user_data; | ||||
}; | }; | ||||
@@ -138,12 +138,12 @@ struct cucul_dither | |||||
char const *algo_name; | char const *algo_name; | ||||
void (*init_dither) (int); | void (*init_dither) (int); | ||||
unsigned int (*get_dither) (void); | |||||
int (*get_dither) (void); | |||||
void (*increment_dither) (void); | void (*increment_dither) (void); | ||||
char const *glyph_name; | char const *glyph_name; | ||||
uint32_t const * glyphs; | uint32_t const * glyphs; | ||||
unsigned glyph_count; | |||||
int glyph_count; | |||||
int invert; | int invert; | ||||
}; | }; | ||||
@@ -178,27 +178,27 @@ static int init_lookup(void); | |||||
/* Dithering algorithms */ | /* Dithering algorithms */ | ||||
static void init_no_dither(int); | static void init_no_dither(int); | ||||
static unsigned int get_no_dither(void); | |||||
static int get_no_dither(void); | |||||
static void increment_no_dither(void); | static void increment_no_dither(void); | ||||
static void init_fstein_dither(int); | static void init_fstein_dither(int); | ||||
static unsigned int get_fstein_dither(void); | |||||
static int get_fstein_dither(void); | |||||
static void increment_fstein_dither(void); | static void increment_fstein_dither(void); | ||||
static void init_ordered2_dither(int); | static void init_ordered2_dither(int); | ||||
static unsigned int get_ordered2_dither(void); | |||||
static int get_ordered2_dither(void); | |||||
static void increment_ordered2_dither(void); | static void increment_ordered2_dither(void); | ||||
static void init_ordered4_dither(int); | static void init_ordered4_dither(int); | ||||
static unsigned int get_ordered4_dither(void); | |||||
static int get_ordered4_dither(void); | |||||
static void increment_ordered4_dither(void); | static void increment_ordered4_dither(void); | ||||
static void init_ordered8_dither(int); | static void init_ordered8_dither(int); | ||||
static unsigned int get_ordered8_dither(void); | |||||
static int get_ordered8_dither(void); | |||||
static void increment_ordered8_dither(void); | static void increment_ordered8_dither(void); | ||||
static void init_random_dither(int); | static void init_random_dither(int); | ||||
static unsigned int get_random_dither(void); | |||||
static int get_random_dither(void); | |||||
static void increment_random_dither(void); | static void increment_random_dither(void); | ||||
static inline int sq(int x) | static inline int sq(int x) | ||||
@@ -260,8 +260,7 @@ static inline void rgb2hsv_default(int r, int g, int b, | |||||
* \param amask Bitmask for alpha values. | * \param amask Bitmask for alpha values. | ||||
* \return Dither object upon success, NULL if an error occurred. | * \return Dither object upon success, NULL if an error occurred. | ||||
*/ | */ | ||||
cucul_dither_t *cucul_create_dither(unsigned int bpp, unsigned int w, | |||||
unsigned int h, unsigned int pitch, | |||||
cucul_dither_t *cucul_create_dither(int bpp, int w, int h, int pitch, | |||||
uint32_t rmask, uint32_t gmask, | uint32_t rmask, uint32_t gmask, | ||||
uint32_t bmask, uint32_t amask) | uint32_t bmask, uint32_t amask) | ||||
{ | { | ||||
@@ -269,7 +268,7 @@ cucul_dither_t *cucul_create_dither(unsigned int bpp, unsigned int w, | |||||
int i; | int i; | ||||
/* Minor sanity test */ | /* Minor sanity test */ | ||||
if(!w || !h || !pitch || bpp > 32 || bpp < 8) | |||||
if(w < 0 || h < 0 || pitch < 0 || bpp > 32 || bpp < 8) | |||||
{ | { | ||||
seterrno(EINVAL); | seterrno(EINVAL); | ||||
return NULL; | return NULL; | ||||
@@ -373,8 +372,8 @@ cucul_dither_t *cucul_create_dither(unsigned int bpp, unsigned int w, | |||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_set_dither_palette(cucul_dither_t *d, | int cucul_set_dither_palette(cucul_dither_t *d, | ||||
unsigned int red[], unsigned int green[], | |||||
unsigned int blue[], unsigned int alpha[]) | |||||
uint32_t red[], uint32_t green[], | |||||
uint32_t blue[], uint32_t alpha[]) | |||||
{ | { | ||||
int i, has_alpha = 0; | int i, has_alpha = 0; | ||||
@@ -946,8 +945,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h, | |||||
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; | int *floyd_steinberg, *fs_r, *fs_g, *fs_b; | ||||
uint32_t savedattr; | uint32_t savedattr; | ||||
int fs_length; | int fs_length; | ||||
int x1, y1, x2, y2, pitch, deltax, deltay; | |||||
unsigned int dchmax; | |||||
int x1, y1, x2, y2, pitch, deltax, deltay, dchmax; | |||||
if(!d || !pixels) | if(!d || !pixels) | ||||
return 0; | return 0; | ||||
@@ -981,14 +979,13 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h, | |||||
x <= x2 && x <= (int)cv->width; | x <= x2 && x <= (int)cv->width; | ||||
x++) | x++) | ||||
{ | { | ||||
unsigned int i; | |||||
int ch = 0, distmin; | |||||
unsigned int rgba[4]; | unsigned int rgba[4]; | ||||
int error[3]; | |||||
int i, ch = 0, distmin; | |||||
int fg_r = 0, fg_g = 0, fg_b = 0, bg_r, bg_g, bg_b; | int fg_r = 0, fg_g = 0, fg_b = 0, bg_r, bg_g, bg_b; | ||||
int fromx, fromy, tox, toy, myx, myy, dots, dist; | int fromx, fromy, tox, toy, myx, myy, dots, dist; | ||||
int error[3]; | |||||
unsigned int outfg = 0, outbg = 0; | |||||
int outfg = 0, outbg = 0; | |||||
uint32_t outch; | uint32_t outch; | ||||
rgba[0] = rgba[1] = rgba[2] = rgba[3] = 0; | rgba[0] = rgba[1] = rgba[2] = rgba[3] = 0; | ||||
@@ -1362,7 +1359,7 @@ static void init_no_dither(int line) | |||||
; | ; | ||||
} | } | ||||
static unsigned int get_no_dither(void) | |||||
static int get_no_dither(void) | |||||
{ | { | ||||
return 0x80; | return 0x80; | ||||
} | } | ||||
@@ -1380,7 +1377,7 @@ static void init_fstein_dither(int line) | |||||
; | ; | ||||
} | } | ||||
static unsigned int get_fstein_dither(void) | |||||
static int get_fstein_dither(void) | |||||
{ | { | ||||
return 0x80; | return 0x80; | ||||
} | } | ||||
@@ -1393,12 +1390,12 @@ static void increment_fstein_dither(void) | |||||
/* | /* | ||||
* Ordered 2 dithering | * Ordered 2 dithering | ||||
*/ | */ | ||||
static unsigned int const *ordered2_table; | |||||
static unsigned int ordered2_index; | |||||
static int const *ordered2_table; | |||||
static int ordered2_index; | |||||
static void init_ordered2_dither(int line) | static void init_ordered2_dither(int line) | ||||
{ | { | ||||
static unsigned int const dither2x2[] = | |||||
static int const dither2x2[] = | |||||
{ | { | ||||
0x00, 0x80, | 0x00, 0x80, | ||||
0xc0, 0x40, | 0xc0, 0x40, | ||||
@@ -1408,7 +1405,7 @@ static void init_ordered2_dither(int line) | |||||
ordered2_index = 0; | ordered2_index = 0; | ||||
} | } | ||||
static unsigned int get_ordered2_dither(void) | |||||
static int get_ordered2_dither(void) | |||||
{ | { | ||||
return ordered2_table[ordered2_index]; | return ordered2_table[ordered2_index]; | ||||
} | } | ||||
@@ -1425,12 +1422,12 @@ static void increment_ordered2_dither(void) | |||||
-1, -6, -5, 2, | -1, -6, -5, 2, | ||||
-2, -7, -8, 3, | -2, -7, -8, 3, | ||||
4, -3, -4, -7};*/ | 4, -3, -4, -7};*/ | ||||
static unsigned int const *ordered4_table; | |||||
static unsigned int ordered4_index; | |||||
static int const *ordered4_table; | |||||
static int ordered4_index; | |||||
static void init_ordered4_dither(int line) | static void init_ordered4_dither(int line) | ||||
{ | { | ||||
static unsigned int const dither4x4[] = | |||||
static int const dither4x4[] = | |||||
{ | { | ||||
0x00, 0x80, 0x20, 0xa0, | 0x00, 0x80, 0x20, 0xa0, | ||||
0xc0, 0x40, 0xe0, 0x60, | 0xc0, 0x40, 0xe0, 0x60, | ||||
@@ -1442,7 +1439,7 @@ static void init_ordered4_dither(int line) | |||||
ordered4_index = 0; | ordered4_index = 0; | ||||
} | } | ||||
static unsigned int get_ordered4_dither(void) | |||||
static int get_ordered4_dither(void) | |||||
{ | { | ||||
return ordered4_table[ordered4_index]; | return ordered4_table[ordered4_index]; | ||||
} | } | ||||
@@ -1455,12 +1452,12 @@ static void increment_ordered4_dither(void) | |||||
/* | /* | ||||
* Ordered 8 dithering | * Ordered 8 dithering | ||||
*/ | */ | ||||
static unsigned int const *ordered8_table; | |||||
static unsigned int ordered8_index; | |||||
static int const *ordered8_table; | |||||
static int ordered8_index; | |||||
static void init_ordered8_dither(int line) | static void init_ordered8_dither(int line) | ||||
{ | { | ||||
static unsigned int const dither8x8[] = | |||||
static int const dither8x8[] = | |||||
{ | { | ||||
0x00, 0x80, 0x20, 0xa0, 0x08, 0x88, 0x28, 0xa8, | 0x00, 0x80, 0x20, 0xa0, 0x08, 0x88, 0x28, 0xa8, | ||||
0xc0, 0x40, 0xe0, 0x60, 0xc8, 0x48, 0xe8, 0x68, | 0xc0, 0x40, 0xe0, 0x60, 0xc8, 0x48, 0xe8, 0x68, | ||||
@@ -1476,7 +1473,7 @@ static void init_ordered8_dither(int line) | |||||
ordered8_index = 0; | ordered8_index = 0; | ||||
} | } | ||||
static unsigned int get_ordered8_dither(void) | |||||
static int get_ordered8_dither(void) | |||||
{ | { | ||||
return ordered8_table[ordered8_index]; | return ordered8_table[ordered8_index]; | ||||
} | } | ||||
@@ -1494,7 +1491,7 @@ static void init_random_dither(int line) | |||||
; | ; | ||||
} | } | ||||
static unsigned int get_random_dither(void) | |||||
static int get_random_dither(void) | |||||
{ | { | ||||
return cucul_rand(0x00, 0x100); | return cucul_rand(0x00, 0x100); | ||||
} | } | ||||
@@ -1509,7 +1506,7 @@ static void increment_random_dither(void) | |||||
*/ | */ | ||||
static int init_lookup(void) | static int init_lookup(void) | ||||
{ | { | ||||
unsigned int v, s, h; | |||||
int v, s, h; | |||||
/* These ones are constant */ | /* These ones are constant */ | ||||
lookup_colors[0] = CUCUL_BLACK; | lookup_colors[0] = CUCUL_BLACK; | ||||
@@ -162,7 +162,7 @@ char const * const * cucul_get_export_list(void) | |||||
static void *export_caca(cucul_canvas_t const *cv, size_t *bytes) | static void *export_caca(cucul_canvas_t const *cv, size_t *bytes) | ||||
{ | { | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int f, n; | |||||
int f, n; | |||||
/* 52 bytes for the header: | /* 52 bytes for the header: | ||||
* - 4 bytes for "\xCA\xCA" + "CV" | * - 4 bytes for "\xCA\xCA" + "CV" | ||||
@@ -222,7 +222,7 @@ static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes, | |||||
}; | }; | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
/* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus | /* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus | ||||
* 4 max bytes for a UTF-8 character). | * 4 max bytes for a UTF-8 character). | ||||
@@ -302,7 +302,7 @@ static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes) | |||||
}; | }; | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
uint8_t prevfg = -1; | uint8_t prevfg = -1; | ||||
uint8_t prevbg = -1; | uint8_t prevbg = -1; | ||||
@@ -376,7 +376,7 @@ static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes) | |||||
static void *export_html(cucul_canvas_t const *cv, size_t *bytes) | static void *export_html(cucul_canvas_t const *cv, size_t *bytes) | ||||
{ | { | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y, len; | |||||
int x, y, len; | |||||
/* The HTML header: less than 1000 bytes | /* The HTML header: less than 1000 bytes | ||||
* A line: 7 chars for "<br />\n" | * A line: 7 chars for "<br />\n" | ||||
@@ -458,7 +458,7 @@ static void *export_html(cucul_canvas_t const *cv, size_t *bytes) | |||||
static void *export_html3(cucul_canvas_t const *cv, size_t *bytes) | static void *export_html3(cucul_canvas_t const *cv, size_t *bytes) | ||||
{ | { | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y, len; | |||||
int x, y, len; | |||||
/* The HTML table markup: less than 1000 bytes | /* The HTML table markup: less than 1000 bytes | ||||
* A line: 10 chars for "<tr></tr>\n" | * A line: 10 chars for "<tr></tr>\n" | ||||
@@ -482,7 +482,7 @@ static void *export_html3(cucul_canvas_t const *cv, size_t *bytes) | |||||
for(x = 0; x < cv->width; x += len) | for(x = 0; x < cv->width; x += len) | ||||
{ | { | ||||
unsigned int i, needfont; | |||||
int i, needfont; | |||||
/* Use colspan option to factor cells with same attributes | /* Use colspan option to factor cells with same attributes | ||||
* (see below) */ | * (see below) */ | ||||
@@ -559,7 +559,7 @@ static void *export_html3(cucul_canvas_t const *cv, size_t *bytes) | |||||
static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes) | static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes) | ||||
{ | { | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y, len; | |||||
int x, y, len; | |||||
/* The font markup: less than 100 bytes | /* The font markup: less than 100 bytes | ||||
* A line: 1 char for "\n" | * A line: 1 char for "\n" | ||||
@@ -580,7 +580,7 @@ static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes) | |||||
for(x = 0; x < cv->width; x += len) | for(x = 0; x < cv->width; x += len) | ||||
{ | { | ||||
unsigned int i, needback, needfront; | |||||
int i, needback, needfront; | |||||
/* Use colspan option to factor cells with same attributes | /* Use colspan option to factor cells with same attributes | ||||
* (see below) */ | * (see below) */ | ||||
@@ -666,7 +666,7 @@ static void *export_irc(cucul_canvas_t const *cv, size_t *bytes) | |||||
}; | }; | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
/* 14 bytes assumed for max length per pixel. Worst case scenario: | /* 14 bytes assumed for max length per pixel. Worst case scenario: | ||||
* ^Cxx,yy 6 bytes | * ^Cxx,yy 6 bytes | ||||
@@ -792,7 +792,7 @@ static void *export_ps(cucul_canvas_t const *cv, size_t *bytes) | |||||
"6 10 scale\n"; | "6 10 scale\n"; | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
/* 200 is arbitrary but should be ok */ | /* 200 is arbitrary but should be ok */ | ||||
*bytes = strlen(ps_header) + 100 + cv->height * (32 + cv->width * 200); | *bytes = strlen(ps_header) + 100 + cv->height * (32 + cv->width * 200); | ||||
@@ -883,7 +883,7 @@ static void *export_svg(cucul_canvas_t const *cv, size_t *bytes) | |||||
" xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n"; | " xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n"; | ||||
char *data, *cur; | char *data, *cur; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
/* 200 is arbitrary but should be ok */ | /* 200 is arbitrary but should be ok */ | ||||
*bytes = strlen(svg_header) + 128 + cv->width * cv->height * 200; | *bytes = strlen(svg_header) + 128 + cv->width * cv->height * 200; | ||||
@@ -964,7 +964,7 @@ static void *export_tga(cucul_canvas_t const *cv, size_t *bytes) | |||||
char const * const *fontlist; | char const * const *fontlist; | ||||
char *data, *cur; | char *data, *cur; | ||||
cucul_font_t *f; | cucul_font_t *f; | ||||
unsigned int i, w, h; | |||||
int i, w, h; | |||||
fontlist = cucul_get_font_list(); | fontlist = cucul_get_font_list(); | ||||
if(!fontlist[0]) | if(!fontlist[0]) | ||||
@@ -33,22 +33,22 @@ | |||||
struct cucul_figfont | struct cucul_figfont | ||||
{ | { | ||||
unsigned int term_width; | |||||
int term_width; | |||||
int x, y, w, h, lines; | int x, y, w, h, lines; | ||||
enum { H_DEFAULT, H_KERN, H_SMUSH, H_NONE, H_OVERLAP } hmode; | enum { H_DEFAULT, H_KERN, H_SMUSH, H_NONE, H_OVERLAP } hmode; | ||||
unsigned int hsmushrule; | |||||
int hsmushrule; | |||||
uint32_t hardblank; | uint32_t hardblank; | ||||
unsigned int height, baseline, max_length; | |||||
int height, baseline, max_length; | |||||
int old_layout; | int old_layout; | ||||
unsigned int print_direction, full_layout, codetag_count; | |||||
unsigned int glyphs; | |||||
int print_direction, full_layout, codetag_count; | |||||
int glyphs; | |||||
cucul_canvas_t *fontcv, *charcv; | cucul_canvas_t *fontcv, *charcv; | ||||
int *left, *right; /* Unused yet */ | int *left, *right; /* Unused yet */ | ||||
unsigned int *lookup; | |||||
uint32_t *lookup; | |||||
}; | }; | ||||
static uint32_t hsmush(uint32_t ch1, uint32_t ch2, unsigned int rule); | |||||
static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule); | |||||
static cucul_figfont_t * open_figfont(char const *); | static cucul_figfont_t * open_figfont(char const *); | ||||
static int free_figfont(cucul_figfont_t *); | static int free_figfont(cucul_figfont_t *); | ||||
@@ -130,7 +130,7 @@ int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path) | |||||
int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch) | int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch) | ||||
{ | { | ||||
cucul_figfont_t *ff = cv->ff; | cucul_figfont_t *ff = cv->ff; | ||||
unsigned int c, w, h, x, y, overlap, extra, xleft, xright; | |||||
int c, w, h, x, y, overlap, extra, xleft, xright; | |||||
switch(ch) | switch(ch) | ||||
{ | { | ||||
@@ -253,7 +253,7 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch) | |||||
static int flush_figlet(cucul_canvas_t *cv) | static int flush_figlet(cucul_canvas_t *cv) | ||||
{ | { | ||||
cucul_figfont_t *ff = cv->ff; | cucul_figfont_t *ff = cv->ff; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
//ff->torender = cv; | //ff->torender = cv; | ||||
//cucul_set_canvas_size(ff->torender, ff->w, ff->h); | //cucul_set_canvas_size(ff->torender, ff->w, ff->h); | ||||
@@ -291,7 +291,7 @@ cucul_figfont_t * open_figfont(char const *path) | |||||
cucul_figfont_t *ff; | cucul_figfont_t *ff; | ||||
char *data = NULL; | char *data = NULL; | ||||
cucul_file_t *f; | cucul_file_t *f; | ||||
unsigned int i, j, size, comment_lines; | |||||
int i, j, size, comment_lines; | |||||
ff = malloc(sizeof(cucul_figfont_t)); | ff = malloc(sizeof(cucul_figfont_t)); | ||||
if(!ff) | if(!ff) | ||||
@@ -487,7 +487,7 @@ int free_figfont(cucul_figfont_t *ff) | |||||
return 0; | return 0; | ||||
} | } | ||||
static uint32_t hsmush(uint32_t ch1, uint32_t ch2, unsigned int rule) | |||||
static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule) | |||||
{ | { | ||||
/* Rule 1 */ | /* Rule 1 */ | ||||
if((rule & 0x01) && ch1 == ch2 && ch1 != 0xa0) | if((rule & 0x01) && ch1 == ch2 && ch1 != 0xa0) | ||||
@@ -70,10 +70,9 @@ struct cucul_font | |||||
#define DECLARE_UNPACKGLYPH(bpp) \ | #define DECLARE_UNPACKGLYPH(bpp) \ | ||||
static inline void \ | static inline void \ | ||||
unpack_glyph ## bpp(uint8_t *glyph, uint8_t *packed_data, \ | |||||
unsigned int n) \ | |||||
unpack_glyph ## bpp(uint8_t *glyph, uint8_t *packed_data, int n) \ | |||||
{ \ | { \ | ||||
unsigned int i; \ | |||||
int i; \ | |||||
\ | \ | ||||
for(i = 0; i < n; i++) \ | for(i = 0; i < n; i++) \ | ||||
{ \ | { \ | ||||
@@ -111,10 +110,10 @@ DECLARE_UNPACKGLYPH(1) | |||||
* \param size The size of the memory area, or 0 if the font name is given. | * \param size The size of the memory area, or 0 if the font name is given. | ||||
* \return A font handle or NULL in case of error. | * \return A font handle or NULL in case of error. | ||||
*/ | */ | ||||
cucul_font_t *cucul_load_font(void const *data, unsigned int size) | |||||
cucul_font_t *cucul_load_font(void const *data, size_t size) | |||||
{ | { | ||||
cucul_font_t *f; | cucul_font_t *f; | ||||
unsigned int i; | |||||
int i; | |||||
if(size == 0) | if(size == 0) | ||||
{ | { | ||||
@@ -247,7 +246,7 @@ cucul_font_t *cucul_load_font(void const *data, unsigned int size) | |||||
f->private + 4 + sizeof(struct font_header) | f->private + 4 + sizeof(struct font_header) | ||||
+ f->header.blocks * sizeof(struct block_info), | + f->header.blocks * sizeof(struct block_info), | ||||
f->header.glyphs * sizeof(struct glyph_info)); | f->header.glyphs * sizeof(struct glyph_info)); | ||||
for(i = 0; i < f->header.glyphs; i++) | |||||
for(i = 0; i < (int)f->header.glyphs; i++) | |||||
{ | { | ||||
f->glyph_list[i].width = hton16(f->glyph_list[i].width); | f->glyph_list[i].width = hton16(f->glyph_list[i].width); | ||||
f->glyph_list[i].height = hton16(f->glyph_list[i].height); | f->glyph_list[i].height = hton16(f->glyph_list[i].height); | ||||
@@ -324,7 +323,7 @@ char const * const * cucul_get_font_list(void) | |||||
* \param f The font, as returned by cucul_load_font() | * \param f The font, as returned by cucul_load_font() | ||||
* \return The standard glyph width. | * \return The standard glyph width. | ||||
*/ | */ | ||||
unsigned int cucul_get_font_width(cucul_font_t const *f) | |||||
int cucul_get_font_width(cucul_font_t const *f) | |||||
{ | { | ||||
return f->header.width; | return f->header.width; | ||||
} | } | ||||
@@ -339,7 +338,7 @@ unsigned int cucul_get_font_width(cucul_font_t const *f) | |||||
* \param f The font, as returned by cucul_load_font() | * \param f The font, as returned by cucul_load_font() | ||||
* \return The standard glyph height. | * \return The standard glyph height. | ||||
*/ | */ | ||||
unsigned int cucul_get_font_height(cucul_font_t const *f) | |||||
int cucul_get_font_height(cucul_font_t const *f) | |||||
{ | { | ||||
return f->header.height; | return f->header.height; | ||||
} | } | ||||
@@ -404,7 +403,8 @@ int cucul_free_font(cucul_font_t *f) | |||||
* Glyphs that do not fit in the image buffer are currently not rendered at | * Glyphs that do not fit in the image buffer are currently not rendered at | ||||
* all. They may be cropped instead in future versions. | * all. They may be cropped instead in future versions. | ||||
* | * | ||||
* This function never fails. | |||||
* If an error occurs, -1 is returned and \b errno is set accordingly: | |||||
* - \c EINVAL Specified width, height or pitch is invalid. | |||||
* | * | ||||
* \param cv The canvas to render | * \param cv The canvas to render | ||||
* \param f The font, as returned by cucul_load_font() | * \param f The font, as returned by cucul_load_font() | ||||
@@ -412,14 +412,19 @@ int cucul_free_font(cucul_font_t *f) | |||||
* \param width The width (in pixels) of the image buffer | * \param width The width (in pixels) of the image buffer | ||||
* \param height The height (in pixels) of the image buffer | * \param height The height (in pixels) of the image buffer | ||||
* \param pitch The pitch (in bytes) of an image buffer line. | * \param pitch The pitch (in bytes) of an image buffer line. | ||||
* \return This function always returns 0. | |||||
* \return 0 in case of success, -1 if an error occurred. | |||||
*/ | */ | ||||
int cucul_render_canvas(cucul_canvas_t const *cv, cucul_font_t const *f, | int cucul_render_canvas(cucul_canvas_t const *cv, cucul_font_t const *f, | ||||
void *buf, unsigned int width, | |||||
unsigned int height, unsigned int pitch) | |||||
void *buf, int width, int height, int pitch) | |||||
{ | { | ||||
uint8_t *glyph = NULL; | uint8_t *glyph = NULL; | ||||
unsigned int x, y, xmax, ymax; | |||||
int x, y, xmax, ymax; | |||||
if(width < 0 || height < 0 || pitch < 0) | |||||
{ | |||||
seterrno(EINVAL); | |||||
return -1; | |||||
} | |||||
if(f->header.bpp != 8) | if(f->header.bpp != 8) | ||||
glyph = malloc(f->header.width * 2 * f->header.height); | glyph = malloc(f->header.width * 2 * f->header.height); | ||||
@@ -439,11 +444,11 @@ int cucul_render_canvas(cucul_canvas_t const *cv, cucul_font_t const *f, | |||||
for(x = 0; x < xmax; x++) | for(x = 0; x < xmax; x++) | ||||
{ | { | ||||
uint8_t argb[8]; | uint8_t argb[8]; | ||||
unsigned int starty = y * f->header.height; | |||||
unsigned int startx = x * f->header.width; | |||||
int starty = y * f->header.height; | |||||
int startx = x * f->header.width; | |||||
uint32_t ch = cv->chars[y * cv->width + x]; | uint32_t ch = cv->chars[y * cv->width + x]; | ||||
uint32_t attr = cv->attrs[y * cv->width + x]; | uint32_t attr = cv->attrs[y * cv->width + x]; | ||||
unsigned int b, i, j; | |||||
int b, i, j; | |||||
struct glyph_info *g; | struct glyph_info *g; | ||||
/* Find the Unicode block where our glyph lies */ | /* Find the Unicode block where our glyph lies */ | ||||
@@ -36,7 +36,7 @@ | |||||
* \param cv A libcucul canvas | * \param cv A libcucul canvas | ||||
* \return The frame count | * \return The frame count | ||||
*/ | */ | ||||
unsigned int cucul_get_frame_count(cucul_canvas_t const *cv) | |||||
int cucul_get_frame_count(cucul_canvas_t const *cv) | |||||
{ | { | ||||
return cv->framecount; | return cv->framecount; | ||||
} | } | ||||
@@ -56,9 +56,9 @@ unsigned int cucul_get_frame_count(cucul_canvas_t const *cv) | |||||
* \param id The canvas frame to activate | * \param id The canvas frame to activate | ||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_set_frame(cucul_canvas_t *cv, unsigned int id) | |||||
int cucul_set_frame(cucul_canvas_t *cv, int id) | |||||
{ | { | ||||
if(id >= cv->framecount) | |||||
if(id < 0 || id >= cv->framecount) | |||||
{ | { | ||||
seterrno(EINVAL); | seterrno(EINVAL); | ||||
return -1; | return -1; | ||||
@@ -124,7 +124,8 @@ int cucul_set_frame_name(cucul_canvas_t *cv, char const *name) | |||||
* The frame index indicates where the frame should be inserted. Valid | * The frame index indicates where the frame should be inserted. Valid | ||||
* values range from 0 to the current canvas frame count. If the frame | * values range from 0 to the current canvas frame count. If the frame | ||||
* index is greater than or equals the current canvas frame count, the new | * index is greater than or equals the current canvas frame count, the new | ||||
* frame is appended at the end of the canvas. | |||||
* frame is appended at the end of the canvas. If the frame index is less | |||||
* than zero, the new frame is inserted at index 0. | |||||
* | * | ||||
* The active frame does not change, but its index may be renumbered due | * The active frame does not change, but its index may be renumbered due | ||||
* to the insertion. | * to the insertion. | ||||
@@ -136,12 +137,14 @@ int cucul_set_frame_name(cucul_canvas_t *cv, char const *name) | |||||
* \param id The index where to insert the new frame | * \param id The index where to insert the new frame | ||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_create_frame(cucul_canvas_t *cv, unsigned int id) | |||||
int cucul_create_frame(cucul_canvas_t *cv, int id) | |||||
{ | { | ||||
unsigned int size = cv->width * cv->height; | |||||
unsigned int f; | |||||
int size = cv->width * cv->height; | |||||
int f; | |||||
if(id > cv->framecount) | |||||
if(id < 0) | |||||
id = 0; | |||||
else if(id > cv->framecount) | |||||
id = cv->framecount; | id = cv->framecount; | ||||
cv->framecount++; | cv->framecount++; | ||||
@@ -194,11 +197,11 @@ int cucul_create_frame(cucul_canvas_t *cv, unsigned int id) | |||||
* \param id The index of the frame to delete | * \param id The index of the frame to delete | ||||
* \return 0 in case of success, -1 if an error occurred. | * \return 0 in case of success, -1 if an error occurred. | ||||
*/ | */ | ||||
int cucul_free_frame(cucul_canvas_t *cv, unsigned int id) | |||||
int cucul_free_frame(cucul_canvas_t *cv, int id) | |||||
{ | { | ||||
unsigned int f; | |||||
int f; | |||||
if(id >= cv->framecount) | |||||
if(id < 0 || id >= cv->framecount) | |||||
{ | { | ||||
seterrno(EINVAL); | seterrno(EINVAL); | ||||
return -1; | return -1; | ||||
@@ -46,7 +46,7 @@ static void rightpair(uint32_t pair[2]); | |||||
int cucul_invert(cucul_canvas_t *cv) | int cucul_invert(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t *attrs = cv->attrs; | uint32_t *attrs = cv->attrs; | ||||
unsigned int i; | |||||
int i; | |||||
for(i = cv->height * cv->width; i--; ) | for(i = cv->height * cv->width; i--; ) | ||||
{ | { | ||||
@@ -71,7 +71,7 @@ int cucul_invert(cucul_canvas_t *cv) | |||||
*/ | */ | ||||
int cucul_flip(cucul_canvas_t *cv) | int cucul_flip(cucul_canvas_t *cv) | ||||
{ | { | ||||
unsigned int y; | |||||
int y; | |||||
for(y = 0; y < cv->height; y++) | for(y = 0; y < cv->height; y++) | ||||
{ | { | ||||
@@ -130,7 +130,7 @@ int cucul_flip(cucul_canvas_t *cv) | |||||
*/ | */ | ||||
int cucul_flop(cucul_canvas_t *cv) | int cucul_flop(cucul_canvas_t *cv) | ||||
{ | { | ||||
unsigned int x; | |||||
int x; | |||||
for(x = 0; x < cv->width; x++) | for(x = 0; x < cv->width; x++) | ||||
{ | { | ||||
@@ -180,7 +180,7 @@ int cucul_rotate_180(cucul_canvas_t *cv) | |||||
uint32_t *cend = cbegin + cv->width * cv->height - 1; | uint32_t *cend = cbegin + cv->width * cv->height - 1; | ||||
uint32_t *abegin = cv->attrs; | uint32_t *abegin = cv->attrs; | ||||
uint32_t *aend = abegin + cv->width * cv->height - 1; | uint32_t *aend = abegin + cv->width * cv->height - 1; | ||||
unsigned int y; | |||||
int y; | |||||
while(cbegin < cend) | while(cbegin < cend) | ||||
{ | { | ||||
@@ -242,7 +242,7 @@ int cucul_rotate_180(cucul_canvas_t *cv) | |||||
int cucul_rotate_left(cucul_canvas_t *cv) | int cucul_rotate_left(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t *newchars, *newattrs; | uint32_t *newchars, *newattrs; | ||||
unsigned int x, y, w2, h2; | |||||
int x, y, w2, h2; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -359,7 +359,7 @@ int cucul_rotate_left(cucul_canvas_t *cv) | |||||
int cucul_rotate_right(cucul_canvas_t *cv) | int cucul_rotate_right(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t *newchars, *newattrs; | uint32_t *newchars, *newattrs; | ||||
unsigned int x, y, w2, h2; | |||||
int x, y, w2, h2; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -474,7 +474,7 @@ int cucul_rotate_right(cucul_canvas_t *cv) | |||||
int cucul_stretch_left(cucul_canvas_t *cv) | int cucul_stretch_left(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t *newchars, *newattrs; | uint32_t *newchars, *newattrs; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -565,7 +565,7 @@ int cucul_stretch_left(cucul_canvas_t *cv) | |||||
int cucul_stretch_right(cucul_canvas_t *cv) | int cucul_stretch_right(cucul_canvas_t *cv) | ||||
{ | { | ||||
uint32_t *newchars, *newattrs; | uint32_t *newchars, *newattrs; | ||||
unsigned int x, y; | |||||
int x, y; | |||||
if(cv->refcount) | if(cv->refcount) | ||||
{ | { | ||||
@@ -37,8 +37,8 @@ int main(int argc, char *argv[]) | |||||
{ | { | ||||
cucul_canvas_t *cv, *pig; | cucul_canvas_t *cv, *pig; | ||||
void *buffer; | void *buffer; | ||||
unsigned long int len; | |||||
unsigned int i, j; | |||||
size_t len; | |||||
int i, j; | |||||
pig = cucul_create_canvas(0, 0); | pig = cucul_create_canvas(0, 0); | ||||
cucul_import_memory(pig, STRING, strlen(STRING), "text"); | cucul_import_memory(pig, STRING, strlen(STRING), "text"); | ||||