From e1d6f308227a1014e3ac8edfd69e00da984ca598 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 5 Dec 2012 02:17:17 +0000 Subject: handle errors opening image file and try to report them to the Pd window svn path=/trunk/externals/moonlib/; revision=16649 --- image.c | 20 ++++++++++++-------- image.tcl | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 image.tcl diff --git a/image.c b/image.c index 0406213..79cb3ac 100644 --- a/image.c +++ b/image.c @@ -1,4 +1,5 @@ -#include +#include "m_pd.h" +#include "m_imp.h" #include "g_canvas.h" #include #include @@ -63,7 +64,8 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) sys_vgui("image create photo img%x\n",x); x->x_localimage=1; } - if(fname) sys_vgui("img%x configure -file {%s}\n",x,fname); + if(fname) + sys_vgui("::moonlib::image::configure .x%lx img%x {%s}\n",x,x,fname); sys_vgui(".x%lx.c create image %d %d -image img%x -tags %xS\n", glist_getcanvas(glist), text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x); @@ -85,10 +87,7 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) void image_erase(t_image *x,t_glist *glist) { - int n; - sys_vgui(".x%lx.c delete %xS\n", - glist_getcanvas(glist), x); - + sys_vgui(".x%lx.c delete %xS\n", glist_getcanvas(glist), x); } @@ -220,11 +219,13 @@ void image_open(t_gobj *z,t_symbol *file) x->x_localimage=1; } sys_vgui("img%x blank\n",x); - sys_vgui("img%x configure -file {%s}\n",x,fname); + sys_vgui("::moonlib::image::configure .x%lx img%x {%s}\n",x,x,fname); if(oldtype) sys_vgui(".x%lx.c itemconfigure %xS -image img%x\n", glist_getcanvas(x->x_glist),x,x); } } + else + pd_error(x, "[image]: error opening file '%s'", file->s_name); } void image_load(t_gobj *z,t_symbol *image,t_symbol *file) @@ -234,7 +235,7 @@ void image_load(t_gobj *z,t_symbol *image,t_symbol *file) fname=image_get_filename(x,file->s_name); if(fname) - sys_vgui("image create photo %s -file {%s}\n",image->s_name,fname); + sys_vgui("::moonlib::image::create_photo .x%lx %s {%s}\n",x,image->s_name,fname); } void image_set(t_gobj *z,t_symbol *image) @@ -313,6 +314,9 @@ void image_setup(void) class_setsavefn(image_class,&image_save); #endif + sys_vgui("eval [read [open {%s/%s.tcl}]]\n", + image_class->c_externdir->s_name, + image_class->c_name->s_name); } diff --git a/image.tcl b/image.tcl new file mode 100644 index 0000000..7f4f22c --- /dev/null +++ b/image.tcl @@ -0,0 +1,15 @@ + +namespace eval ::moonlib::image:: { +} + +proc ::moonlib::image::configure {obj_id img filename} { + if { [catch {$img configure -file $filename} fid]} { + ::pdwindow::logpost $obj_id 1 "[image]: error reading '$filename':\n$fid\n" + } +} + +proc ::moonlib::image::create_photo {obj_id img filename} { + if { [catch {image create photo $img -file $filename} fid]} { + ::pdwindow::logpost $obj_id 1 "[image]: error reading '$filename':\n$fid\n" + } +} -- cgit v1.2.1