changeset 7926:d74f996e005d

__magick_read__.cc: configuration and style fixes
author John W. Eaton <jwe@octave.org>
date Mon, 14 Jul 2008 16:00:09 -0400
parents 9316b59903c9
children 0487e46da18e
files ChangeLog Makeconf.in configure.in scripts/ChangeLog scripts/image/Makefile.in src/ChangeLog src/DLD-FUNCTIONS/__magick_read__.cc src/Makefile.in src/oct-conf.h.in src/toplev.cc
diffstat 10 files changed, 334 insertions(+), 232 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jul 12 10:11:30 2008 -0400
+++ b/ChangeLog	Mon Jul 14 16:00:09 2008 -0400
@@ -1,3 +1,12 @@
+2008-07-14  John W. Eaton  <jwe@octave.org>
+
+	* Makeconf.in (MAGICK_CONFIG): Substitute here.
+	(MAGICK_INCFLAGS, MAGICK_LIBS): Define using GraphicsMagick++
+	config script.
+	(do-subst-config-vals): Include MAGICK_LIBS and MAGICK_INCFLAGS in
+	list of substitutions.
+	* configure.in: Check for GraphicsMagick++ config script.
+
 2008-07-10  John W. Eaton  <jwe@octave.org>
 
 	* octMakefile.in (DIRS_TO_MAKE): Delete $(localfcnfilepath) and
--- a/Makeconf.in	Sat Jul 12 10:11:30 2008 -0400
+++ b/Makeconf.in	Mon Jul 14 16:00:09 2008 -0400
@@ -146,6 +146,10 @@
 endif
 INCFLAGS = $(TMP_IF_1) $(TMP_IF_2)
 
+MAGICK_CONFIG = @MAGICK_CONFIG@
+MAGICK_INCFLAGS = $(shell $(MAGICK_CONFIG) --cppflags)
+MAGICK_LIBS = $(shell $(MAGICK_CONFIG) --ldflags --libs)
+
 LIBFLAGS = -L$(TOPDIR)
 
 DEFS = @DEFS@
@@ -504,6 +508,8 @@
   -e "s|%OCTAVE_CONF_LIBREADLINE%|\"${LIBREADLINE}\"|" \
   -e "s|%OCTAVE_CONF_LIBS%|\"${LIBS}\"|" \
   -e "s|%OCTAVE_CONF_LN_S%|\"${LN_S}\"|" \
+  -e "s|%OCTAVE_CONF_MAGICK_INCFLAGS%|\"${MAGICK_INCFLAGS}\"|" \
+  -e "s|%OCTAVE_CONF_MAGICK_LIBS%|\"${MAGICK_LIBS}\"|" \
   -e 's|%OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%|\"@MKOCTFILE_DL_LDFLAGS@\"|' \
   -e "s|%OCTAVE_CONF_OCTINCLUDEDIR%|\"${octincludedir}\"|" \
   -e "s|%OCTAVE_CONF_OCTLIBDIR%|\"${octlibdir}\"|" \
--- a/configure.in	Sat Jul 12 10:11:30 2008 -0400
+++ b/configure.in	Mon Jul 14 16:00:09 2008 -0400
@@ -635,6 +635,13 @@
   warn_curl="cURL library not found.  The urlread and urlwrite functions will be disabled."
 fi
 
+# GraphicsMagick++
+
+warn_magick=
+AC_CHECK_PROGS(MAGICK_CONFIG, [GraphicsMagick++-config GraphicsMagick-config])
+if test -z "$MAGICK_CONFIG"; then
+  warn_magick="GraphicsMagick++ config script not found.  Assuming GraphicsMagic++ library and header files are missing, so imread will not be fully functional"
+fi
 
 # ---------------------------------------------------------------------
 
@@ -2016,6 +2023,7 @@
   gnuplot:              $GNUPLOT
   OPENGL libraries:     $OPENGL_LIBS
   fltk backend libs:    $GRAPHICS_LIBS
+  Magick config:        $MAGICK_CONFIG
 
   Do internal array bounds checking:  $BOUNDS_CHECKING
   Build static libraries:             $STATIC_LIBS
@@ -2132,6 +2140,11 @@
   warn_msg_printed=true
 fi
 
+if test -n "$warn_magick"; then
+  AC_MSG_WARN($warn_magick)
+  warn_msg_printed=true
+fi
+
 if test -n "$warn_hdf5"; then
   AC_MSG_WARN($warn_hdf5)
   warn_msg_printed=true
--- a/scripts/ChangeLog	Sat Jul 12 10:11:30 2008 -0400
+++ b/scripts/ChangeLog	Mon Jul 14 16:00:09 2008 -0400
@@ -1,3 +1,7 @@
+2008-07-14  John W. Eaton  <jwe@octave.org>
+
+	* image/Makefile.in (SOURCES): Add imread.m to the list.
+
 2008-07-14  Thomas L. Scofield  <scofield@calvin.edu>
 
 	* image/imread.m: New file from Octave Forge.
--- a/scripts/image/Makefile.in	Sat Jul 12 10:11:30 2008 -0400
+++ b/scripts/image/Makefile.in	Mon Jul 14 16:00:09 2008 -0400
@@ -35,9 +35,9 @@
 
 SOURCES = __img__.m __img_via_file__.m autumn.m bone.m brighten.m colormap.m \
   contrast.m cool.m copper.m flag.m gmap40.m gray.m gray2ind.m hot.m hsv.m \
-  hsv2rgb.m image.m image_viewer.m imagesc.m imshow.m ind2gray.m ind2rgb.m \
-  jet.m loadimage.m ntsc2rgb.m ocean.m pink.m prism.m rainbow.m rgb2hsv.m \
-  rgb2ind.m rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m
+  hsv2rgb.m image.m image_viewer.m imagesc.m imread.m imshow.m ind2gray.m \
+  ind2rgb.m jet.m loadimage.m ntsc2rgb.m ocean.m pink.m prism.m rainbow.m \
+  rgb2hsv.m rgb2ind.m rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m
 
 IMAGES = default.img
 
--- a/src/ChangeLog	Sat Jul 12 10:11:30 2008 -0400
+++ b/src/ChangeLog	Mon Jul 14 16:00:09 2008 -0400
@@ -1,3 +1,18 @@
+2008-07-14  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/__magick_read__.cc: Delete "using namespace std"
+	and "using namespace Magick" directives.  Style fixes.
+
+	* oct-conf.h.in (OCTAVE_CONF_MAGICK_INCFLAGS,
+	OCTAVE_CONF_MAGICK_LIBS): Substitute here.
+	* toplev.cc (octave_config_info): Include MAGICK_INCFLAGS and
+	MAGICK_LIBS in the struct.
+	* Makefile.in (DLD_XSRC): Add __magick_read__.cc to the list.
+	(OCTAVE_LIBS): Add $(MAGICK_LIBS) to the list for static linking case.
+	(__magick_read__.d, __magick_read__.o, pic/__magick_read__.o):
+	Append MAGICK_INCFLAGS to CPPFLAGS.
+	(__magick_read__.oct): Append MAGICK_LIBS to LDFLAGS.
+
 2008-07-14  Thomas L. Scofield  <scofield@calvin.edu>
 
 	* DLD-FUNCTIONS/__magick_read__.cc: New file from Octave Forge.
--- a/src/DLD-FUNCTIONS/__magick_read__.cc	Sat Jul 12 10:11:30 2008 -0400
+++ b/src/DLD-FUNCTIONS/__magick_read__.cc	Mon Jul 14 16:00:09 2008 -0400
@@ -21,40 +21,45 @@
 
 */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include <octave/oct.h>
+#include "defun-dld.h"
+#include "error.h"
+
 #include <GraphicsMagick/Magick++.h>
-#include <iostream>
-using namespace std;
-using namespace Magick;
 
 unsigned int
-scaleQuantumToDepth (const Quantum &_quantum, unsigned int depth)
+scale_quantum_to_depth (const Magick::Quantum& quantum, unsigned int depth)
 {
-  return (static_cast<unsigned int> (static_cast<double>(_quantum) / 
-                                     MaxRGB * ((1 << depth) - 1)));
+  return (static_cast<unsigned int> (static_cast<double> (quantum)
+				     / MaxRGB * ((1 << depth) - 1)));
 }
 
 octave_value_list
-read_indexed_images( vector<Image> imvec, Array<int> frameidx, bool wantalpha )
+read_indexed_images (std::vector<Magick::Image>& imvec,
+		     const Array<int>& frameidx, bool wantalpha)
 {
   octave_value_list output;
+
   int rows = imvec[0].baseRows ();
   int columns = imvec[0].baseColumns ();
   int nframes = frameidx.length ();
-  ImageType type = imvec[0].type ();
-    
+
+  Magick::ImageType type = imvec[0].type ();
+
   unsigned int mapsize = imvec[0].colorMapSize ();
   int i = mapsize;
   unsigned int depth = 0;
-  while (i >>= 1) depth++;
+  while (i >>= 1)
+    depth++;
   i = 0;
   depth--;
-  while (depth >>= 1) i++;
+  while (depth >>= 1)
+    i++;
   depth = 1 << i;
 
-  int x, y, frame;
-  const IndexPacket *pix;
   switch (depth)
     {
     case 1:
@@ -62,303 +67,339 @@
     case 4:
     case 8:
       {
-      uint8NDArray im = uint8NDArray(dim_vector ( rows, columns, nframes ));
-      for (frame=0; frame < nframes; frame++)
-        {
-        imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        pix = imvec[frameidx(frame)].getConstIndexes ();
-        i = 0;      
-        for ( y=0; y < rows; y++ )
-          for ( x=0; x < columns; x++ )
-            im(y, x, frame) = static_cast<octave_uint8>(pix[i++]);
-        }
+	uint8NDArray im = uint8NDArray (dim_vector (rows, columns, nframes));
+
+	for (int frame = 0; frame < nframes; frame++)
+	  {
+	    imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+	    const Magick::IndexPacket *pix
+	      = imvec[frameidx(frame)].getConstIndexes ();
+	    i = 0;
+	    for (int y = 0; y < rows; y++)
+	      for (int x = 0; x < columns; x++)
+		im(y,x,frame) = static_cast<octave_uint8> (pix[i++]);
+	  }
       im.chop_trailing_singletons ();
       output(0) = octave_value (im);
       }
       break;
+
     case 16:
       {
-      uint16NDArray im = uint16NDArray(dim_vector( rows, columns, nframes ));
-      for (frame=0; frame < nframes; frame++)
-        {
-        imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        pix = imvec[frameidx(frame)].getConstIndexes ();        
-        i = 0;      
-        for ( y=0; y < rows; y++ )
-          for ( x=0; x < columns; x++ )
-            im(y, x, frame) = static_cast<octave_uint16>(pix[i++]);
-        }
+	uint16NDArray im = uint16NDArray (dim_vector(rows, columns, nframes));
+	for (int frame = 0; frame < nframes; frame++)
+	  {
+	    imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+	    const Magick::IndexPacket *pix
+	      = imvec[frameidx(frame)].getConstIndexes ();
+	    i = 0;
+	    for (int y = 0; y < rows; y++)
+	      for (int x = 0; x < columns; x++)
+		im(y,x,frame) = static_cast<octave_uint16> (pix[i++]);
+	  }
         im.chop_trailing_singletons ();
         output(0) = octave_value (im);
       }
       break;
+
     default:
-      error ("Index depths bigger than 16-bit not supported");
+      error ("__magic_read__: index depths bigger than 16-bit not supported");
       return octave_value_list ();
     }
 
-  ColorRGB c;
-  Matrix map = Matrix ( mapsize, 3 );
+  Matrix map = Matrix (mapsize, 3);
   Matrix alpha;
+
   switch (type)
     {
-    case PaletteMatteType:
-/*    warning ("palettematte");
-      map = Matrix ( mapsize, 3 );
-      alpha = Matrix ( mapsize, 1 );
-      for ( i = 0; i < mapsize; i++ )
+    case Magick::PaletteMatteType:
+#if 0
+      warning ("palettematte");
+      Matrix map (mapsize, 3);
+      Matrix alpha (mapsize, 1);
+      for (i = 0; i < mapsize; i++)
         {
-        warning ( "%d", i );
-        c = imvec[0].colorMap (i);
-        map(i, 0) = c.red ();
-        map(i, 1) = c.green ();
-        map(i, 2) = c.blue ();
-        alpha(i, 1) = c.alpha ();                
+	  warning ("%d", i);
+	  Magick::ColorRGB c = imvec[0].colorMap (i);
+	  map(i,0) = c.red ();
+	  map(i,1) = c.green ();
+	  map(i,2) = c.blue ();
+	  alpha(i,1) = c.alpha ();
         }
-      break;        */
-    case PaletteType:
-      alpha = Matrix ( 0, 0 );
-      for ( i = 0; i < mapsize; i++ )
+      break;
+#endif
+
+    case Magick::PaletteType:
+      alpha = Matrix (0, 0);
+      for (i = 0; i < mapsize; i++)
         {
-        c = imvec[0].colorMap (i);
-        map(i, 0) = c.red ();
-        map(i, 1) = c.green ();
-        map(i, 2) = c.blue ();        
+	  Magick::ColorRGB c = imvec[0].colorMap (i);
+	  map(i,0) = c.red ();
+	  map(i,1) = c.green ();
+	  map(i,2) = c.blue ();
         }
-      break;        
+      break;
+
     default:
-      error ("Unsupported indexed image type");
+      error ("__magick_read__: unsupported indexed image type");
       return octave_value_list ();
     }
 
-  output(1) = octave_value (map);
   if (wantalpha)
-    output(2) = octave_value (alpha);
+    output(2) = alpha;
+
+  output(1) = map;
+
   return output;
 }
 
 template <class T>
-octave_value_list read_images( vector<Image> imvec, Array<int> frameidx,
-                               unsigned int depth )
+octave_value_list
+read_images (const std::vector<Magick::Image>& imvec,
+	     const Array<int>& frameidx, unsigned int depth)
 {
-  int i;
-  T im;  
+  octave_value_list retval (3, Matrix ());
+
+  T im;
+
   int rows = imvec[0].baseRows ();
   int columns = imvec[0].baseColumns ();
   int nframes = frameidx.length ();
-  ImageType type = imvec[0].type ();
-  int x, y, frame;
-  const PixelPacket *pix;
+
   dim_vector idim = dim_vector ();
   idim.resize (4);
   idim(0) = rows;
   idim(1) = columns;
   idim(2) = 1;
   idim(3) = nframes;
+
   Array<int> idx (dim_vector (4));
+
+  Magick::ImageType type = imvec[0].type ();
+
   switch (type)
     {
-    case BilevelType:
-    //    break;
-    case GrayscaleType:
-      im = T(dim_vector ( rows, columns, nframes ));
-      for ( frame=0; frame < nframes; frame++ )
+    case Magick::BilevelType:
+    case Magick::GrayscaleType:
+      im = T(dim_vector (rows, columns, nframes));
+      for (int frame = 0; frame < nframes; frame++)
         {
-        pix = imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        i = 0;      
-        for ( y=0; y < rows; y++ )
-          for ( x=0; x < columns; x++ )
-            im(y, x, frame) = scaleQuantumToDepth ( pix[i++].red, depth );
+	  const Magick::PixelPacket *pix
+	    = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+
+	  int i = 0;
+
+	  for (int y = 0; y < rows; y++)
+	    for (int x = 0; x < columns; x++)
+	      im(y, x, frame) = scale_quantum_to_depth (pix[i++].red, depth);
+        }
+      break;
+
+    case Magick::GrayscaleMatteType:
+      idim(2) = 2;
+      im = T (idim);
+      for (int frame = 0; frame < nframes; frame++)
+        {
+	  const Magick::PixelPacket *pix
+	    = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+
+	  int i = 0;
+	  idx(3) = frame;
+
+	  for (int y = 0; y < rows; y++)
+	    {
+	      idx(0) = y;
+	      for (int x = 0; x < columns; x++)
+		{
+		  idx(1) = x;
+		  idx(2) = 0;
+		  im(idx) = scale_quantum_to_depth (pix[i].red, depth);
+		  idx(2) = 1;
+		  im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
+		  i++;
+		}
+	    }
         }
       break;
-    case GrayscaleMatteType:
-      idim(2) = 2;
-      im = T(idim);
-      for ( frame=0; frame < nframes; frame++ )
-        {
-        idx(3) = frame;
-        i = 0;
-        pix = imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        for ( y=0; y < rows; y++ )
-          {
-          idx(0) = y;
-          for ( x=0; x < columns; x++ )
-            {
-            idx(1) = x;
-            idx(2) = 0;
-            im(idx) = scaleQuantumToDepth ( pix[i].red, depth );
-            idx(2) = 1;
-            im(idx) = scaleQuantumToDepth ( pix[i].opacity, depth );
-            i++;
-            }
-          }
-        }    
-      break;
-    case PaletteType:
-    case TrueColorType:
+
+    case Magick::PaletteType:
+    case Magick::TrueColorType:
       idim(2) = 3;
-      im = T(idim);      
-      for ( frame=0; frame < nframes; frame++ )
+      im = T (idim);
+      for (int frame=0; frame < nframes; frame++)
         {
-        idx(3) = frame;
-        i = 0;
-        pix = imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        for ( y=0; y < rows; y++ )
-          {
-          idx(0) = y;
-          for ( x=0; x < columns; x++ )
-            {
-            idx(1) = x;
-            idx(2) = 0;
-            im(idx) = scaleQuantumToDepth ( pix[i].red, depth );
-            idx(2) = 1;
-            im(idx) = scaleQuantumToDepth ( pix[i].green, depth );
-            idx(2) = 2;
-            im(idx) = scaleQuantumToDepth ( pix[i].blue, depth );
-            i++;
-            }
-          }
-        }      
+	  const Magick::PixelPacket *pix
+	    = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+
+	  int i = 0;
+	  idx(3) = frame;
+
+	  for (int y = 0; y < rows; y++)
+	    {
+	      idx(0) = y;
+	      for (int x = 0; x < columns; x++)
+		{
+		  idx(1) = x;
+		  idx(2) = 0;
+		  im(idx) = scale_quantum_to_depth (pix[i].red, depth);
+		  idx(2) = 1;
+		  im(idx) = scale_quantum_to_depth (pix[i].green, depth);
+		  idx(2) = 2;
+		  im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
+		  i++;
+		}
+	    }
+        }
       break;
-    case PaletteMatteType:
-    case TrueColorMatteType:
-    case ColorSeparationType:
+
+    case Magick::PaletteMatteType:
+    case Magick::TrueColorMatteType:
+    case Magick::ColorSeparationType:
       idim(2) = 4;
-      im = T(idim);            
-      for ( frame=0; frame < nframes; frame++ )
+      im = T (idim);
+      for (int frame=0; frame < nframes; frame++)
         {
-        idx(3) = frame;
-        i = 0;
-        pix = imvec[frameidx(frame)].getConstPixels ( 0, 0, columns, rows );
-        for ( y=0; y < rows; y++ )
-          {
-          idx(0) = y;
-          for ( x=0; x < columns; x++ )
-            {
-            idx(1) = x;
-            idx(2) = 0;
-            im(idx) = scaleQuantumToDepth ( pix[i].red, depth );
-            idx(2) = 1;
-            im(idx) = scaleQuantumToDepth ( pix[i].green, depth );
-            idx(2) = 2;
-            im(idx) = scaleQuantumToDepth ( pix[i].blue, depth );
-            idx(2) = 3;
-            im(idx) = scaleQuantumToDepth ( pix[i].opacity, depth );
-            i++;
-            }
-          }
-        }      
+	  const Magick::PixelPacket *pix
+	    = imvec[frameidx(frame)].getConstPixels (0, 0, columns, rows);
+
+	  int i = 0;
+	  idx(3) = frame;
+
+	  for (int y = 0; y < rows; y++)
+	    {
+	      idx(0) = y;
+	      for (int x = 0; x < columns; x++)
+		{
+		  idx(1) = x;
+		  idx(2) = 0;
+		  im(idx) = scale_quantum_to_depth (pix[i].red, depth);
+		  idx(2) = 1;
+		  im(idx) = scale_quantum_to_depth (pix[i].green, depth);
+		  idx(2) = 2;
+		  im(idx) = scale_quantum_to_depth (pix[i].blue, depth);
+		  idx(2) = 3;
+		  im(idx) = scale_quantum_to_depth (pix[i].opacity, depth);
+		  i++;
+		}
+	    }
+        }
       break;
+
     default:
-      error ("Undefined Imagemagick image type");
-      return octave_value_list ();
+      error ("__magick_read__: undefined ImageMagick image type");
+      return retval;
     }
 
   im.chop_trailing_singletons ();
-  return octave_value_list (octave_value (im));
+
+  retval(0) = im;
+
+  return retval;
 }
 
-// instantiate templates
-template octave_value_list
-read_images<boolNDArray> ( vector<Image>, Array<int>, unsigned int depth );
-template octave_value_list
-read_images<uint8NDArray> ( vector<Image>, Array<int>, unsigned int depth );
-template octave_value_list
-read_images<uint16NDArray> ( vector<Image>, Array<int>, unsigned int depth );
-
-DEFUN_DLD ( __magick_read__, args, nargout, "\
--*- texinfo -*-\n\
-@deftypefn {Function File} {@var{m} =} __imagemagick_read__(@var{fname}, @var{index})\n\
-@deftypefnx{Function File} {[@var{m}, @var{colormap}] =} __imagemagick_read__(@var{fname}, @var{index})\n\
-@deftypefnx{Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __imagemagick_read__(@var{fname}, @var{index})\n\
+DEFUN_DLD (__magick_read__, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Function File} {@var{m} =} __magick_read__(@var{fname}, @var{index})\n\
+@deftypefnx{Function File} {[@var{m}, @var{colormap}] =} __magick_read__(@var{fname}, @var{index})\n\
+@deftypefnx{Function File} {[@var{m}, @var{colormap}, @var{alpha}] =} __magick_read__(@var{fname}, @var{index})\n\
 Read images with ImageMagick++. In general you should not be using this function.\n\
 Instead you should use @code{imread}.\n\
 @seealso{imread}\n\
-@end deftypefn\n\
-" )
+@end deftypefn")
 {
   octave_value_list output;
-  int i;    
-  if( args.length() > 2 || args.length() < 1 || !args(0).is_string() \
-            || nargout > 3 )
+
+  if (args.length() > 2 || args.length() < 1 || ! args(0).is_string ()
+      || nargout > 3)
     {
       print_usage ();
-      return octave_value_list ();
+      return output;
     }
+
   Array<int> frameidx;
-  if ( args.length() == 2 && args(1).is_real_type() )
+
+  if (args.length() == 2 && args(1).is_real_type())
     frameidx = args(1).int_vector_value();
   else
     {
-    frameidx = Array<int> (1);
-    frameidx(0) = 1;
+      frameidx = Array<int> (1);
+      frameidx(0) = 1;
     }
 
-  vector<Image> imvec;
+  std::vector<Magick::Image> imvec;
+
   try
     {
-    // Read a file into vector of image objects
-    readImages(&imvec, args(0).string_value ());
+      // Read a file into vector of image objects
+      Magick::readImages (&imvec, args(0).string_value ());
+    }
+  catch (Magick::Warning& w)
+    {
+      warning ("Magick++ warning: %s", w.what ());
     }
-  catch (Warning &warning_)
-    { warning ( "Magick++ warning: %s", warning_.what () ); }
-  catch (ErrorCoder &error_)
-    { warning ( "Magick++ coder error: %s", error_.what () ); }
-  catch (Exception &error_)
+  catch (Magick::ErrorCoder& e)
     {
-    error ( "Magick++ exception: %s", error_.what () );
-    imvec.clear ();
-    return octave_value_list ();
+      warning ("Magick++ coder error: %s", e.what ());
+    }
+  catch (Magick::Exception& e)
+    {
+      error ("Magick++ exception: %s", e.what ());
+      return output;
     }
 
-  int nframes = imvec.size ();
-  for ( i = 0; i < frameidx.length(); i++ )
+  for (int i = 0; i < frameidx.length(); i++)
     {
-    frameidx(i) = frameidx(i) - 1;
-    if ( frameidx(i) >= nframes || frameidx(i) < 0 )
-      {
-      error ("Invalid index vector");
-      imvec.clear ();
-      return output;
-      }
+      frameidx(i) = frameidx(i) - 1;
+
+      int nframes = imvec.size ();
+
+      if (frameidx(i) >= nframes || frameidx(i) < 0)
+	{
+	  error ("__magick_read__: invalid index vector");
+	  return output;
+	}
     }
-    
-  ClassType klass = imvec[0].classType ();
-  if ( klass == PseudoClass && nargout > 1 )
-    output = read_indexed_images( imvec, frameidx, (nargout == 3) );
+
+  Magick::ClassType klass = imvec[0].classType ();
+
+  if (klass == Magick::PseudoClass && nargout > 1)
+    output = read_indexed_images (imvec, frameidx, (nargout == 3));
   else
     {
-    unsigned int depth = imvec[0].modulusDepth ();
-    i = 0;
-    while (depth >>= 1) i++;
-    depth = 1 << i;
-    
-    switch (depth)
-      {
-      case 1:
-        output = read_images<boolNDArray> ( imvec, frameidx, depth );
-        break;
-      case 2:
-      case 4:
-      case 8:
-        output = read_images<uint8NDArray> ( imvec, frameidx, depth) ;
-        break;
-      case 16:
-        output = read_images<uint16NDArray> ( imvec, frameidx, depth );
-        break;
-      case 32:
-      case 64:
+      unsigned int depth = imvec[0].modulusDepth ();
+      int i = 0;
+      while (depth >>= 1)
+	i++;
+      depth = 1 << i;
+
+      switch (depth)
+	{
+	case 1:
+	  output = read_images<boolNDArray> (imvec, frameidx, depth);
+	  break;
+
+	case 2:
+	case 4:
+	case 8:
+	  output = read_images<uint8NDArray> (imvec, frameidx, depth) ;
+	  break;
+
+	case 16:
+	  output = read_images<uint16NDArray> (imvec, frameidx, depth);
+	  break;
+
+	case 32:
+	case 64:
         default:
-        error ("Image depths bigger than 16-bit not supported");
-      }
-    if (nargout > 1)
-      {
-      output(1) = Matrix ( 0, 0 );
-      if (nargout > 2)
-        output(2) = Matrix ( 0, 0 );
-      }
+	  error ("__magick_read__: image depths bigger than 16-bit not supported");
+	}
     }
-  imvec.clear ();
 
   return output;
 }
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- a/src/Makefile.in	Sat Jul 12 10:11:30 2008 -0400
+++ b/src/Makefile.in	Mon Jul 14 16:00:09 2008 -0400
@@ -77,7 +77,7 @@
 	spparms.cc sqrtm.cc svd.cc syl.cc symrcm.cc symbfact.cc \
 	time.cc tsearch.cc typecast.cc \
 	urlwrite.cc __contourc__.cc __delaunayn__.cc __dsearchn__.cc \
-	__glpk__.cc __lin_interpn__.cc __pchip_deriv__.cc \
+	__glpk__.cc __lin_interpn__.cc __magick_read__.cc __pchip_deriv__.cc \
 	__qp__.cc __voronoi__.cc __convn__.cc
 
 DLD_SRC := $(addprefix DLD-FUNCTIONS/, $(DLD_XSRC))
@@ -273,7 +273,7 @@
     $(LIBPLPLOT) $(LIBGLOB)
 else
   OCTAVE_LIBS = $(LIBOCTINTERP) $(LIBOCTAVE) $(QHULL_LIBS) \
-    $(GLPK_LIBS) $(REGEX_LIBS) $(SPECIAL_MATH_LIB) $(LIBCRUFT) \
+    $(GLPK_LIBS) $(MAGICK_LIBS) $(REGEX_LIBS) $(SPECIAL_MATH_LIB) $(LIBCRUFT) \
     $(LIBPLPLOT) $(LIBGLOB)
 endif
 
@@ -625,6 +625,10 @@
 	  || (rm -f $@-t; exit 1)
 	@mv $@-t $@
 
+__magick_read__.d: CPPFLAGS += $(MAGICK_INCFLAGS)
+__magick_read__.o pic/__magick_read__.o: CPPFLAGS += $(MAGICK_INCFLAGS)
+__magick_read__.oct: DL_LDFLAGS += $(MAGICK_LIBS)
+
 # How to make a .oct file from a .o file:
 
 ifeq ($(ENABLE_DYNAMIC_LINKING), true)
--- a/src/oct-conf.h.in	Sat Jul 12 10:11:30 2008 -0400
+++ b/src/oct-conf.h.in	Mon Jul 14 16:00:09 2008 -0400
@@ -229,6 +229,14 @@
 #define OCTAVE_CONF_LN_S %OCTAVE_CONF_LN_S%
 #endif
 
+#ifndef OCTAVE_CONF_MAGICK_INCFLAGS
+#define OCTAVE_CONF_MAGICK_INCFLAGS %OCTAVE_CONF_MAGICK_INCFLAGS%
+#endif
+
+#ifndef OCTAVE_CONF_MAGICK_LIBS
+#define OCTAVE_CONF_MAGICK_LIBS %OCTAVE_CONF_MAGICK_LIBS%
+#endif
+
 #ifndef OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS
 #define OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS %OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%
 #endif
--- a/src/toplev.cc	Sat Jul 12 10:11:30 2008 -0400
+++ b/src/toplev.cc	Mon Jul 14 16:00:09 2008 -0400
@@ -1149,6 +1149,8 @@
       { false, "LIBREADLINE", OCTAVE_CONF_LIBREADLINE },
       { false, "LIBS", OCTAVE_CONF_LIBS },
       { false, "LN_S", OCTAVE_CONF_LN_S },
+      { false, "MAGICK_INCFLAGS", OCTAVE_CONF_MAGICK_INCFLAGS },
+      { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS },
       { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS },
       { false, "RANLIB", OCTAVE_CONF_RANLIB },
       { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG },