[gs-cvs] rev 7073 - trunk/gs/jasper/src/appl

giles at ghostscript.com giles at ghostscript.com
Wed Sep 27 22:56:04 PDT 2006


Author: giles
Date: 2006-09-27 22:56:04 -0700 (Wed, 27 Sep 2006)
New Revision: 7073

Modified:
   trunk/gs/jasper/src/appl/imgcmp.c
   trunk/gs/jasper/src/appl/imginfo.c
   trunk/gs/jasper/src/appl/jasper.c
   trunk/gs/jasper/src/appl/jasper_sdl.c
   trunk/gs/jasper/src/appl/jiv.c
Log:
Add an error callback to the example jasper applications. Previously they
always failed (or succeeded) silently.

DETAILS:

The fprintf() calls were replaced with jas_eprintf() in this code along
with everywhere else, but no actual callback was installed, so the 
applications weren't able to give any feedback at all. So we now provide
a simple callback that just passes the message on to stderr as is appropriate
for a library client.


Modified: trunk/gs/jasper/src/appl/imgcmp.c
===================================================================
--- trunk/gs/jasper/src/appl/imgcmp.c	2006-09-27 20:37:41 UTC (rev 7072)
+++ trunk/gs/jasper/src/appl/imgcmp.c	2006-09-28 05:56:04 UTC (rev 7073)
@@ -62,7 +62,7 @@
 /*
  * Image Comparison Program
  *
- * $Id$
+ * $Id: $
  */
 
 /******************************************************************************\
@@ -113,8 +113,9 @@
 double msen(jas_matrix_t *x, jas_matrix_t *y, int n);
 double psnr(jas_matrix_t *x, jas_matrix_t *y, int depth);
 jas_image_t *makediffimage(jas_matrix_t *origdata, jas_matrix_t *recondata);
-void usage(void);
-void cmdinfo(void);
+static void usage(void);
+static void cmdinfo(void);
+static void errprint(jas_error_t err, char *msg);
 
 /******************************************************************************\
 *
@@ -189,9 +190,13 @@
 	minonly = 0;
 
 	if (jas_init()) {
+		errprint(0, "error: cannot initialize jasper library\n");
 		abort();
 	}
 
+	/* set our error callback */
+	jas_set_error_cb(errprint);
+
 	cmdname = argv[0];
 
 	/* Parse the command line options. */
@@ -546,7 +551,7 @@
 *
 \******************************************************************************/
 
-void cmdinfo()
+static void cmdinfo()
 {
 	jas_eprintf("Image Comparison Utility (Version %s).\n",
 	  JAS_VERSION);
@@ -556,7 +561,7 @@
 	  );
 }
 
-void usage()
+static void usage()
 {
 	cmdinfo();
 	jas_eprintf("usage:\n");
@@ -575,3 +580,9 @@
 	  );
 	exit(EXIT_FAILURE);
 }
+
+static void errprint(jas_error_t err, char *msg)
+{
+	fprintf(stderr, "%s", msg);
+}
+

Modified: trunk/gs/jasper/src/appl/imginfo.c
===================================================================
--- trunk/gs/jasper/src/appl/imginfo.c	2006-09-27 20:37:41 UTC (rev 7072)
+++ trunk/gs/jasper/src/appl/imginfo.c	2006-09-28 05:56:04 UTC (rev 7073)
@@ -62,7 +62,7 @@
 /*
  * Image Information Program
  *
- * $Id$
+ * $Id: $
  */
 
 /******************************************************************************\
@@ -94,6 +94,7 @@
 
 static void usage(void);
 static void cmdinfo(void);
+static void errprint(jas_error_t err, char *msg);
 
 /******************************************************************************\
 *
@@ -128,9 +129,13 @@
 	char *fmtname;
 
 	if (jas_init()) {
+		errprint(0, "error: cannot initialize jasper library\n");
 		abort();
 	}
 
+	/* set our error callback */
+	jas_set_error_cb(errprint);
+
 	cmdname = argv[0];
 
 	infile = 0;
@@ -221,3 +226,9 @@
 	jas_eprintf("[-f image_file]\n");
 	exit(EXIT_FAILURE);
 }
+
+static void errprint(jas_error_t err, char *msg)
+{
+	fprintf(stderr, "%s", msg);
+}
+

Modified: trunk/gs/jasper/src/appl/jasper.c
===================================================================
--- trunk/gs/jasper/src/appl/jasper.c	2006-09-27 20:37:41 UTC (rev 7072)
+++ trunk/gs/jasper/src/appl/jasper.c	2006-09-28 05:56:04 UTC (rev 7073)
@@ -64,7 +64,7 @@
 /*
  * JasPer Transcoder Program
  *
- * $Id$
+ * $Id: $
  */
 
 /******************************************************************************\
@@ -132,6 +132,7 @@
 void badusage(void);
 void cmdinfo(void);
 int addopt(char *optstr, int maxlen, char *s);
+void errprint(jas_error_t err, char *msg);
 
 /******************************************************************************\
 * Global data.
@@ -164,9 +165,13 @@
 	}
 
 	if (jas_init()) {
+		errprint(0, "error: cannot initialize jasper library\n");
 		abort();
 	}
 
+	/* set our error callback */
+	jas_set_error_cb(errprint);
+
 	/* Parse the command line options. */
 	if (!(cmdopts = cmdopts_parse(argc, argv))) {
 		jas_eprintf("error: cannot parse command line\n");
@@ -525,6 +530,11 @@
 	exit(EXIT_FAILURE);
 }
 
+void errprint(jas_error_t err, char *msg)
+{
+	fprintf(stderr, "%s", msg);
+}
+
 #if 0
 jas_image_t *converttosrgb(jas_image_t *inimage)
 {

Modified: trunk/gs/jasper/src/appl/jasper_sdl.c
===================================================================
--- trunk/gs/jasper/src/appl/jasper_sdl.c	2006-09-27 20:37:41 UTC (rev 7072)
+++ trunk/gs/jasper/src/appl/jasper_sdl.c	2006-09-28 05:56:04 UTC (rev 7073)
@@ -23,9 +23,9 @@
 int copy_jas_image(jas_image_t * image, SDL_Surface * window);
 int display_jas_image(jas_image_t * image);
 
-void wait_close(void);
+static void wait_close(void);
+static void errprint(jas_error_t err, char *msg);
 
-
 /** implementation **/
 
 int
@@ -141,7 +141,7 @@
     return 0;
 }
 
-void wait_close(void)
+static void wait_close(void)
 {
     SDL_Event event;
 
@@ -226,9 +226,10 @@
     int i;
 
     if (jas_init()) {
-        jas_eprintf("error: unable to initialize jasper library\n");
+        errprint(0, "error: unable to initialize jasper library\n");
         exit(1);
     }
+    jas_set_error_cb(errprint);
     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
         jas_eprintf("error: unable to initialize SDL: %s\n", SDL_GetError());
         exit(2);
@@ -243,3 +244,9 @@
 
     return 0;
 }
+
+static void errprint(jas_error_t err, char *msg)
+{
+       fprintf(stderr, "%s", msg);
+}
+

Modified: trunk/gs/jasper/src/appl/jiv.c
===================================================================
--- trunk/gs/jasper/src/appl/jiv.c	2006-09-27 20:37:41 UTC (rev 7072)
+++ trunk/gs/jasper/src/appl/jiv.c	2006-09-28 05:56:04 UTC (rev 7073)
@@ -180,6 +180,7 @@
 
 static void cleanupandexit(int);
 static void init(void);
+static void errprint(jas_error_t err, char *msg);
 
 /******************************************************************************\
 *
@@ -219,9 +220,13 @@
 
 	/* Initialize the JasPer library. */
 	if (jas_init()) {
+		errprint(0, "error: cannot initialize jasper library\n");
 		abort();
 	}
 
+	/* set our error callback */
+	jas_set_error_cb(errprint);
+
 	glutInit(&argc, argv);
 	glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
 	glutCreateWindow(cmdname);
@@ -1044,3 +1049,9 @@
 	gs.vp.data = 0;
 	gs.dirty = 1;
 }
+
+static void errprint(jas_error_t err, char *msg)
+{
+	fprintf(stderr, "%s", msg);
+}
+



More information about the gs-cvs mailing list