From 08177fa58119f9e67fdffb32ee20dbf05bd4fa78 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 10 Jun 2004 20:41:26 +0000 Subject: [project @ 2004-06-10 20:41:26 by bursa] Add global content list. Better error handling in content code. Improved code documentation. Remove some obsolete functions. Implement debug window listing contents. svn path=/import/netsurf/; revision=951 --- riscos/dialog.c | 3 +- riscos/draw.c | 51 ++++++++++++----------------- riscos/draw.h | 8 ++--- riscos/gif.c | 64 +++++++++++++++++++++++++++---------- riscos/gif.h | 11 +++---- riscos/gifread.c | 29 +++++++++-------- riscos/gui.c | 11 ++++++- riscos/gui.h | 8 ++++- riscos/htmlredraw.c | 6 ++-- riscos/jpeg.c | 35 +++++++++++++------- riscos/jpeg.h | 10 +++--- riscos/png.c | 72 ++++++++++++++++++++++++++--------------- riscos/png.h | 13 ++++---- riscos/sprite.c | 92 +++++++++++++++++++++++++++++++---------------------- riscos/sprite.h | 15 ++++----- riscos/wimp.c | 1 + 16 files changed, 256 insertions(+), 173 deletions(-) (limited to 'riscos') diff --git a/riscos/dialog.c b/riscos/dialog.c index e59b3ba02..47c279515 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -33,7 +33,7 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_401li, #endif dialog_zoom, dialog_pageinfo, dialog_objinfo, dialog_tooltip, - dialog_warning, dialog_config_th_pane; + dialog_warning, dialog_config_th_pane, dialog_debug; static int font_size; static int font_min_size; @@ -83,6 +83,7 @@ void ro_gui_dialog_init(void) dialog_objinfo = ro_gui_dialog_create("objectinfo"); dialog_tooltip = ro_gui_dialog_create("tooltip"); dialog_warning = ro_gui_dialog_create("warning"); + dialog_debug = ro_gui_dialog_create("debug"); set_browser_choices(); set_proxy_choices(); diff --git a/riscos/draw.c b/riscos/draw.c index b59a96261..fbe4251cf 100644 --- a/riscos/draw.c +++ b/riscos/draw.c @@ -18,56 +18,47 @@ #ifdef WITH_DRAW -int draw_convert(struct content *c, unsigned int width, unsigned int height) +bool draw_convert(struct content *c, int width, int height) { + union content_msg_data msg_data; + os_box bbox; os_error *error; - os_trfm *matrix = xcalloc(1, sizeof(os_trfm)); - os_box *bbox = xcalloc(1, sizeof(os_box)); - - /* Full size image (1:1) */ - matrix->entries[0][0] = 1 << 16; - matrix->entries[0][1] = 0; - matrix->entries[1][0] = 0; - matrix->entries[1][1] = 1 << 16; - matrix->entries[2][0] = 0; - matrix->entries[2][1] = 0; /* BBox contents in Draw units (256*OS unit) */ error = xdrawfile_bbox(0, (drawfile_diagram*)(c->source_data), - (int)c->source_size, matrix, bbox); - + (int) c->source_size, 0, &bbox); if (error) { - LOG(("error: %s", error->errmess)); - xfree(matrix); - xfree(bbox); - return 1; + LOG(("xdrawfile_bbox: 0x%x: %s", + error->errnum, error->errmess)); + msg_data.error = error->errmess; + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } /* c->width & c->height stored as (OS units/2) => divide by 512 to convert from draw units */ - c->width = ((bbox->x1 - bbox->x0) / 512); - c->height = ((bbox->y1 - bbox->y0) / 512); - c->data.draw.x0 = bbox->x0 / 2; - c->data.draw.y0 = bbox->y0 / 2; - c->title = xcalloc(100, 1); - sprintf(c->title, messages_get("DrawTitle"), c->width, + c->width = ((bbox.x1 - bbox.x0) / 512); + c->height = ((bbox.y1 - bbox.y0) / 512); + c->data.draw.x0 = bbox.x0 / 2; + c->data.draw.y0 = bbox.y0 / 2; + c->title = malloc(100); + if (c->title) + snprintf(c->title, 100, messages_get("DrawTitle"), c->width, c->height, c->source_size); c->status = CONTENT_STATUS_DONE; - xfree(matrix); - xfree(bbox); - return 0; + return true; } void draw_destroy(struct content *c) { - xfree(c->title); + free(c->title); } -void draw_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void draw_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { os_trfm matrix; diff --git a/riscos/draw.h b/riscos/draw.h index bb1f88d3f..67752a3dd 100644 --- a/riscos/draw.h +++ b/riscos/draw.h @@ -14,10 +14,10 @@ struct content_draw_data { int x0, y0; }; -int draw_convert(struct content *c, unsigned int width, unsigned int height); +bool draw_convert(struct content *c, int width, int height); void draw_destroy(struct content *c); -void draw_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void draw_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale); #endif diff --git a/riscos/gif.c b/riscos/gif.c index e15c5ebe4..9cd50829a 100644 --- a/riscos/gif.c +++ b/riscos/gif.c @@ -21,6 +21,7 @@ #include "netsurf/riscos/options.h" #include "netsurf/riscos/tinct.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" @@ -38,19 +39,27 @@ static void nsgif_animate(void *p); -void nsgif_init(void) { -} -void nsgif_create(struct content *c, const char *params[]) { +bool nsgif_create(struct content *c, const char *params[]) { + union content_msg_data msg_data; /* Initialise our data structure */ - c->data.gif.gif = (gif_animation *)xcalloc(sizeof(gif_animation), 1); + c->data.gif.gif = calloc(sizeof(gif_animation), 1); + if (!c->data.gif.gif) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } c->data.gif.current_frame = 0; + return true; } -int nsgif_convert(struct content *c, unsigned int iwidth, unsigned int iheight) { +bool nsgif_convert(struct content *c, int iwidth, int iheight) { + int res; struct gif_animation *gif; + union content_msg_data msg_data; /* Create our animation */ @@ -61,38 +70,59 @@ int nsgif_convert(struct content *c, unsigned int iwidth, unsigned int iheight) /* Initialise the GIF */ - gif_initialise(gif); + res = gif_initialise(gif); + if (res < 0) { + if (res == GIF_INSUFFICIENT_MEMORY) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + } else { + msg_data.error = messages_get("BadGIF"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + } + return false; + } /* Abort on bad GIFs */ - if ((gif->frame_count_partial == 0) || (gif->width == 0) || (gif->height == 0)) return 1; + if ((gif->frame_count_partial == 0) || (gif->width == 0) || + (gif->height == 0)) { + msg_data.error = messages_get("BadGIF"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } /* Store our content width */ c->width = gif->width; c->height = gif->height; + /* Initialise the first frame so if we try to use the image data directly prior to + a plot we get some sensible data + */ + res = gif_decode_frame(c->data.gif.gif, 0); + if (res < 0 && res != GIF_INSUFFICIENT_FRAME_DATA) { + msg_data.error = messages_get("BadGIF"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + /* Schedule the animation if we have one */ if (gif->frame_count > 1) { schedule(gif->frames[0].frame_delay, nsgif_animate, c); } - /* Initialise the first frame so if we try to use the image data directly prior to - a plot we get some sensible data - */ - gif_decode_frame(c->data.gif.gif, 0); - /* Exit as a success */ c->status = CONTENT_STATUS_DONE; - return 0; + return true; } -void nsgif_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nsgif_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { int previous_frame; @@ -152,7 +182,7 @@ void nsgif_destroy(struct content *c) */ schedule_remove(nsgif_animate, c); gif_finalise(c->data.gif.gif); - xfree(c->data.gif.gif); + free(c->data.gif.gif); } diff --git a/riscos/gif.h b/riscos/gif.h index 526716dec..f6365071a 100644 --- a/riscos/gif.h +++ b/riscos/gif.h @@ -25,13 +25,12 @@ struct content_gif_data { unsigned int current_frame; }; -void nsgif_init(void); -void nsgif_create(struct content *c, const char *params[]); -int nsgif_convert(struct content *c, unsigned int width, unsigned int height); +bool nsgif_create(struct content *c, const char *params[]); +bool nsgif_convert(struct content *c, int width, int height); void nsgif_destroy(struct content *c); -void nsgif_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nsgif_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale); #endif diff --git a/riscos/gifread.c b/riscos/gifread.c index 3f4306374..3e9d39b69 100644 --- a/riscos/gifread.c +++ b/riscos/gifread.c @@ -96,11 +96,12 @@ static int clear_image = FALSE; any information that hasn't already been decoded. If an error occurs, all previously decoded frames are retained. - @return -5 for GIF frame data error - -4 for insufficient data to process any more frames - -3 for memory error - -2 for GIF error - -1 for insufficient data to do anything + @return GIF_FRAME_DATA_ERROR for GIF frame data error + GIF_INSUFFICIENT_FRAME_DATA for insufficient data to process + any more frames + GIF_INSUFFICIENT_MEMORY for memory error + GIF_DATA_ERROR for GIF error + GIF_INSUFFICIENT_DATA for insufficient data to do anything 0 for successful decoding 1 for successful decoding (all frames completely read) */ @@ -112,7 +113,7 @@ int gif_initialise(struct gif_animation *gif) { /* Check for sufficient data to be a GIF */ - if (gif->buffer_size < 13) return -1; + if (gif->buffer_size < 13) return GIF_INSUFFICIENT_DATA; /* Get our current processing position */ @@ -244,12 +245,12 @@ int gif_initialise(struct gif_animation *gif) { if (gif->frame_count_partial > 0) { /* Set the redraw for the first frame to the maximum frame size */ - gif->frames[0].redraw_required = 0; + gif->frames[0].redraw_required = 0; gif->frames[0].redraw_x = 0; gif->frames[0].redraw_y = 0; gif->frames[0].redraw_width = gif->width; gif->frames[0].redraw_height = gif->height; - + /* We now work backwards to update the redraw characteristics of frames with clear codes to stop a snowball effect of the redraw areas. It doesn't really make much difference for most images, and will not work as well @@ -282,7 +283,7 @@ int gif_initialise(struct gif_animation *gif) { } } } - + } /* If there was a memory error tell the caller @@ -512,7 +513,7 @@ int gif_initialise_frame(struct gif_animation *gif) { gif->frames[frame].redraw_width = width; gif->frames[frame].redraw_height = height; } - + /* if we are clearing the background then we need to redraw enough to cover the previous frame too */ @@ -584,10 +585,10 @@ int gif_initialise_frame(struct gif_animation *gif) { /** Decodes a GIF frame. - @return -5 for GIF frame data error - -4 for insufficient data to complete the frame - -2 for GIF error (invalid frame header) - -1 for insufficient data to do anything + @return GIF_FRAME_DATA_ERROR for GIF frame data error + GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame + GIF_DATA_ERROR for GIF error (invalid frame header) + GIF_INSUFFICIENT_DATA for insufficient data to do anything 0 for successful decoding */ int gif_decode_frame(struct gif_animation *gif, unsigned int frame) { diff --git a/riscos/gui.c b/riscos/gui.c index 3f33e0581..dc36dd1bf 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -374,7 +374,7 @@ void ro_gui_check_resolvers(void) if (resolvers) { LOG(("Inet$Resolvers '%s'", resolvers)); } else { - LOG(("Inet$Resolvers not set", resolvers)); + LOG(("Inet$Resolvers not set")); warn_user("Resolvers", 0); } } @@ -613,6 +613,8 @@ void ro_gui_redraw_window_request(wimp_draw *redraw) ro_gui_redraw_config_th_pane(redraw); else if (redraw->w == history_window) ro_gui_history_redraw(redraw); + else if (redraw->w == dialog_debug) + ro_gui_debugwin_redraw(redraw); else { g = ro_lookup_gui_from_w(redraw->w); if (g != NULL) @@ -660,6 +662,11 @@ void ro_gui_close_window_request(wimp_close *close) { gui_window *g; + if (close->w == dialog_debug) { + ro_gui_debugwin_close(); + return; + } + g = ro_lookup_gui_from_w(close->w); if (g) { @@ -719,6 +726,8 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer) "file:///%%3CNetSurf$Dir%%3E/Docs/intro_%s", option_language)) >= 0 && length < sizeof(url)) browser_window_create(url, NULL); + } else if (pointer->buttons == wimp_CLICK_ADJUST) { + ro_gui_debugwin_open(); } } diff --git a/riscos/gui.h b/riscos/gui.h index db56bbc77..91839cc76 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -23,7 +23,8 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_config_prox, dialog_config_th, dialog_zoom, dialog_pageinfo, - dialog_objinfo, dialog_tooltip, dialog_warning, dialog_config_th_pane; + dialog_objinfo, dialog_tooltip, dialog_warning, dialog_config_th_pane, + dialog_debug; extern wimp_w history_window; extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu; extern int iconbar_menu_height; @@ -195,6 +196,11 @@ void schedule(int t, void (*callback)(void *p), void *p); void schedule_remove(void (*callback)(void *p), void *p); void schedule_run(void); +/* in debugwin.c */ +void ro_gui_debugwin_open(void); +void ro_gui_debugwin_close(void); +void ro_gui_debugwin_redraw(wimp_draw *redraw); + /* icon numbers */ #define ICON_TOOLBAR_BACK 0 #define ICON_TOOLBAR_FORWARD 1 diff --git a/riscos/htmlredraw.c b/riscos/htmlredraw.c index 3e40aa6ac..d39acc1f4 100644 --- a/riscos/htmlredraw.c +++ b/riscos/htmlredraw.c @@ -60,9 +60,9 @@ static os_trfm trfm = { { { 0, 0 } } }; -void html_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void html_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { bool select_on = false; diff --git a/riscos/jpeg.c b/riscos/jpeg.c index 14128192d..ea8cb120b 100644 --- a/riscos/jpeg.c +++ b/riscos/jpeg.c @@ -40,6 +40,9 @@ #endif +static char nsjpeg_error_buffer[JMSG_LENGTH_MAX]; + + struct nsjpeg_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; @@ -57,9 +60,10 @@ static void nsjpeg_term_source(j_decompress_ptr cinfo); * Create a CONTENT_JPEG. */ -void nsjpeg_create(struct content *c, const char *params[]) +bool nsjpeg_create(struct content *c, const char *params[]) { c->data.jpeg.sprite_area = 0; + return true; } @@ -67,7 +71,7 @@ void nsjpeg_create(struct content *c, const char *params[]) * Convert a CONTENT_JPEG for display. */ -int nsjpeg_convert(struct content *c, unsigned int w, unsigned int h) +bool nsjpeg_convert(struct content *c, int w, int h) { struct jpeg_decompress_struct cinfo; struct nsjpeg_error_mgr jerr; @@ -80,13 +84,17 @@ int nsjpeg_convert(struct content *c, unsigned int w, unsigned int h) unsigned int area_size; osspriteop_area *sprite_area = 0; osspriteop_header *sprite; + union content_msg_data msg_data; cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = nsjpeg_error_exit; if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); free(sprite_area); - return 1; + + msg_data.error = nsjpeg_error_buffer; + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } jpeg_create_decompress(&cinfo); source_mgr.next_input_byte = c->source_data; @@ -104,7 +112,12 @@ int nsjpeg_convert(struct content *c, unsigned int w, unsigned int h) sprite_area = malloc(area_size); if (!sprite_area) { LOG(("malloc failed")); - return 1; + jpeg_destroy_decompress(&cinfo); + + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; } /* area control block */ @@ -142,10 +155,10 @@ int nsjpeg_convert(struct content *c, unsigned int w, unsigned int h) c->data.jpeg.sprite_area = sprite_area; c->title = malloc(100); if (c->title) - sprintf(c->title, messages_get("JPEGTitle"), + snprintf(c->title, 100, messages_get("JPEGTitle"), width, height, c->source_size); c->status = CONTENT_STATUS_DONE; - return 0; + return true; } @@ -158,7 +171,7 @@ int nsjpeg_convert(struct content *c, unsigned int w, unsigned int h) void nsjpeg_error_exit(j_common_ptr cinfo) { struct nsjpeg_error_mgr *err = (struct nsjpeg_error_mgr *) cinfo->err; - (*cinfo->err->output_message) (cinfo); + err->pub.format_message(cinfo, nsjpeg_error_buffer); longjmp(err->setjmp_buffer, 1); } @@ -229,9 +242,9 @@ void nsjpeg_destroy(struct content *c) * Redraw a CONTENT_JPEG. */ -void nsjpeg_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nsjpeg_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { unsigned int tinct_options; @@ -255,7 +268,7 @@ void nsjpeg_redraw(struct content *c, long x, long y, _IN(2) | _IN(3) | _IN(4) | _IN(5) | _IN(6) | _IN(7), (char *) c->data.jpeg.sprite_area + c->data.jpeg.sprite_area->first, - x, (int) (y - height), + x, y - height, width, height, tinct_options); } diff --git a/riscos/jpeg.h b/riscos/jpeg.h index 928ec252f..8db1ba502 100644 --- a/riscos/jpeg.h +++ b/riscos/jpeg.h @@ -16,12 +16,12 @@ struct content_jpeg_data { osspriteop_area *sprite_area; }; -void nsjpeg_create(struct content *c, const char *params[]); -int nsjpeg_convert(struct content *c, unsigned int width, unsigned int height); +bool nsjpeg_create(struct content *c, const char *params[]); +bool nsjpeg_convert(struct content *c, int width, int height); void nsjpeg_destroy(struct content *c); -void nsjpeg_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nsjpeg_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale); #endif diff --git a/riscos/png.c b/riscos/png.c index 2c269c839..b31c992d3 100644 --- a/riscos/png.c +++ b/riscos/png.c @@ -32,19 +32,29 @@ static void row_callback(png_structp png, png_bytep new_row, static void end_callback(png_structp png, png_infop info); -void nspng_init(void) +bool nspng_create(struct content *c, const char *params[]) { -} - + union content_msg_data msg_data; -void nspng_create(struct content *c, const char *params[]) -{ c->data.png.sprite_area = 0; c->data.png.png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - assert(c->data.png.png != 0); + if (!c->data.png.png) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } c->data.png.info = png_create_info_struct(c->data.png.png); - assert(c->data.png.info != 0); + if (!c->data.png.info) { + png_destroy_read_struct(&c->data.png.png, + &c->data.png.info, 0); + + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } if (setjmp(png_jmpbuf(c->data.png.png))) { png_destroy_read_struct(&c->data.png.png, @@ -52,30 +62,38 @@ void nspng_create(struct content *c, const char *params[]) LOG(("Failed to set callbacks")); c->data.png.png = NULL; c->data.png.info = NULL; - return; + + msg_data.error = messages_get("PNGError"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } png_set_progressive_read_fn(c->data.png.png, c, info_callback, row_callback, end_callback); + + return true; } -void nspng_process_data(struct content *c, char *data, unsigned long size) +bool nspng_process_data(struct content *c, char *data, unsigned int size) { + union content_msg_data msg_data; + if (setjmp(png_jmpbuf(c->data.png.png))) { png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0); LOG(("Failed to process data")); c->data.png.png = NULL; c->data.png.info = NULL; - return; + + msg_data.error = messages_get("PNGError"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } - LOG(("data %p, size %li", data, size)); - png_process_data(c->data.png.png, c->data.png.info, - data, size); + png_process_data(c->data.png.png, c->data.png.info, data, size); - c->size += size; + return true; } @@ -224,30 +242,32 @@ void end_callback(png_structp png, png_infop info) -int nspng_convert(struct content *c, unsigned int width, unsigned int height) +bool nspng_convert(struct content *c, int width, int height) { - if (c->data.png.png == NULL || c->data.png.info == NULL) - return 1; + assert(c->data.png.png); + assert(c->data.png.info); png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0); - c->title = xcalloc(100, 1); - sprintf(c->title, messages_get("PNGTitle"), c->width, c->height); + c->title = malloc(100); + if (c->title) + snprintf(c->title, 100, messages_get("PNGTitle"), + c->width, c->height); c->status = CONTENT_STATUS_DONE; - return 0; + return true; } void nspng_destroy(struct content *c) { - xfree(c->title); - xfree(c->data.png.sprite_area); + free(c->title); + free(c->data.png.sprite_area); } -void nspng_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nspng_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { unsigned int tinct_options; @@ -269,7 +289,7 @@ void nspng_redraw(struct content *c, long x, long y, */ _swix(Tinct_PlotScaledAlpha, _IN(2) | _IN(3) | _IN(4) | _IN(5) | _IN(6) | _IN(7), ((char *) c->data.png.sprite_area + c->data.png.sprite_area->first), - x, (int)(y - height), + x, y - height, width, height, tinct_options); } diff --git a/riscos/png.h b/riscos/png.h index ead45d290..49d311efd 100644 --- a/riscos/png.h +++ b/riscos/png.h @@ -22,13 +22,12 @@ struct content_png_data { char *sprite_image; }; -void nspng_init(void); -void nspng_create(struct content *c, const char *params[]); -void nspng_process_data(struct content *c, char *data, unsigned long size); -int nspng_convert(struct content *c, unsigned int width, unsigned int height); +bool nspng_create(struct content *c, const char *params[]); +bool nspng_process_data(struct content *c, char *data, unsigned int size); +bool nspng_convert(struct content *c, int width, int height); void nspng_destroy(struct content *c); -void nspng_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void nspng_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale); #endif diff --git a/riscos/sprite.c b/riscos/sprite.c index b7d2bf068..b5c5f64bb 100644 --- a/riscos/sprite.c +++ b/riscos/sprite.c @@ -19,74 +19,90 @@ #ifdef WITH_SPRITE -void sprite_create(struct content *c, const char *params[]) +bool sprite_create(struct content *c, const char *params[]) { - c->data.sprite.data = xcalloc(4, 1); + union content_msg_data msg_data; + + c->data.sprite.data = malloc(4); + if (!c->data.sprite.data) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } c->data.sprite.length = 4; + return true; } -void sprite_process_data(struct content *c, char *data, unsigned long size) +bool sprite_process_data(struct content *c, char *data, unsigned int size) { - c->data.sprite.data = xrealloc(c->data.sprite.data, c->data.sprite.length + size); - memcpy((char*)(c->data.sprite.data) + c->data.sprite.length, data, size); + char *sprite_data; + union content_msg_data msg_data; + + sprite_data = realloc(c->data.sprite.data, + c->data.sprite.length + size); + if (!sprite_data) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } + c->data.sprite.data = sprite_data; + memcpy((char*)(c->data.sprite.data) + c->data.sprite.length, + data, size); c->data.sprite.length += size; c->size += size; + return true; } -int sprite_convert(struct content *c, unsigned int width, unsigned int height) +bool sprite_convert(struct content *c, int width, int height) { os_error *error; int w, h; + union content_msg_data msg_data; osspriteop_area *area = (osspriteop_area*)c->data.sprite.data; - /* fill in the size (first word) of the area */ + /* fill in the size (first word) of the area */ area->size = c->data.sprite.length; error = xosspriteop_read_sprite_info(osspriteop_PTR, - area, - (osspriteop_id)((char*)(c->data.sprite.data) + area->first), - &w, &h, NULL, NULL); - - if (error) { - LOG(("error: %s", error->errmess)); - return 1; - } + area, + (osspriteop_id)((char*)(c->data.sprite.data) + area->first), + &w, &h, NULL, NULL); + if (error) { + LOG(("xosspriteop_read_sprite_info: 0x%x: %s", + error->errnum, error->errmess)); + msg_data.error = error->errmess; + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } c->width = w; c->height = h; - c->title = xcalloc(100, 1); - sprintf(c->title, messages_get("SpriteTitle"), c->width, - c->height, c->data.sprite.length); + c->title = malloc(100); + if (c->title) + snprintf(c->title, 100, messages_get("SpriteTitle"), c->width, + c->height, c->data.sprite.length); c->status = CONTENT_STATUS_DONE; - return 0; -} - - -void sprite_revive(struct content *c, unsigned int width, unsigned int height) -{ -} - - -void sprite_reformat(struct content *c, unsigned int width, unsigned int height) -{ + return true; } void sprite_destroy(struct content *c) { - xfree(c->data.sprite.data); - xfree(c->title); + free(c->data.sprite.data); + free(c->title); } -void sprite_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void sprite_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale) { - unsigned int size; + unsigned int size; osspriteop_area *area = (osspriteop_area*)c->data.sprite.data; osspriteop_trans_tab *table; os_factors factors; @@ -94,14 +110,14 @@ void sprite_redraw(struct content *c, long x, long y, xcolourtrans_generate_table_for_sprite( area, (osspriteop_id)((char*)(c->data.sprite.data) + - area->first), + area->first), colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE, 0, colourtrans_GIVEN_SPRITE, 0, 0, &size); table = xcalloc(size, 1); xcolourtrans_generate_table_for_sprite( area, (osspriteop_id)((char*)(c->data.sprite.data) + - area->first), + area->first), colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE, table, colourtrans_GIVEN_SPRITE, 0, 0, 0); @@ -113,7 +129,7 @@ void sprite_redraw(struct content *c, long x, long y, xosspriteop_put_sprite_scaled(osspriteop_PTR, area, (osspriteop_id)((char*)(c->data.sprite.data) + - area->first), + area->first), x, (int)(y - height), osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table); diff --git a/riscos/sprite.h b/riscos/sprite.h index 183a5494f..39cf23eb1 100644 --- a/riscos/sprite.h +++ b/riscos/sprite.h @@ -17,15 +17,12 @@ struct content_sprite_data { unsigned long length; }; -void sprite_init(void); -void sprite_create(struct content *c, const char *params[]); -void sprite_process_data(struct content *c, char *data, unsigned long size); -int sprite_convert(struct content *c, unsigned int width, unsigned int height); -void sprite_revive(struct content *c, unsigned int width, unsigned int height); -void sprite_reformat(struct content *c, unsigned int width, unsigned int height); +bool sprite_create(struct content *c, const char *params[]); +bool sprite_process_data(struct content *c, char *data, unsigned int size); +bool sprite_convert(struct content *c, int width, int height); void sprite_destroy(struct content *c); -void sprite_redraw(struct content *c, long x, long y, - unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1, +void sprite_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale); #endif diff --git a/riscos/wimp.c b/riscos/wimp.c index b5f16e69b..8880232c9 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -21,6 +21,7 @@ #include "netsurf/desktop/gui.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" /* Wimp_Extend,11 block */ -- cgit v1.2.3