Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 imview (1.1.9c-8ubuntu2) precise; urgency=low
 .
   * No change rebuild for imagemagick4 transition
Author: Michael Terry <mterry@ubuntu.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- imview-1.1.9c.orig/printSpect.cxx
+++ imview-1.1.9c/printSpect.cxx
@@ -49,6 +49,7 @@
 #include <setjmp.h>
 #include <signal.h>
 #include <FL/Fl_File_Chooser.H>
+#include <FL/Fl_Int_Input.H>
 #include <FL/fl_ask.H>
 #include "imview.hxx"
 #include "io/imSystem.hxx"
@@ -539,7 +540,7 @@ void epscheck_cb(Fl_Check_Button *, prin
     return;
 }
 
-void nbcopies_cb(Fl_Input *, printspect *)
+void nbcopies_cb(Fl_Int_Input *, printspect *)
 {
     dbgprintf("Nb of copies callback\n");
     return;
--- imview-1.1.9c.orig/printPrefs.cxx
+++ imview-1.1.9c/printPrefs.cxx
@@ -50,6 +50,7 @@
 #include <errno.h>
 #include <string> // needed by nocase.H
 #include <FL/Fl_File_Chooser.H>
+#include <FL/Fl_Int_Input.H>
 #include <FL/fl_ask.H>
 #include "imview.hxx"
 #include "nocase.hxx"
@@ -588,7 +589,7 @@ void epscheck_cb(Fl_Check_Button *, prin
     return;
 }
 
-void nbcopies_cb(Fl_Input *, printprefs *)
+void nbcopies_cb(Fl_Int_Input *, printprefs *)
 {
     dbgprintf("Nb of copies callback\n");
     return;
--- imview-1.1.9c.orig/menubar.hxx
+++ imview-1.1.9c/menubar.hxx
@@ -61,7 +61,8 @@
 #define ONLINEHELP         "quickhelp.html"
 #define LICENSE            "gpl.html"
 #define WARRANTY           "warranty.html"
-#define HELPURL            "http://extra.cmis.csiro.au/IA/talbot/ee02only/imview/"
+#define HELPURL            "http://www.cmis.csiro.au/Hugues.Talbot/imview/online/imview.html"
+#define LOCALHELP          "/usr/share/doc/imview-doc/html/imview.html"
 
 #define IMAGE_LIST_BEGIN   "Image list"
 #define CLUT_LIST_BEGIN    "Default Colourmap"
--- /dev/null
+++ imview-1.1.9c/imview.xpm
@@ -0,0 +1,294 @@
+/* XPM */
+static char *imview_icon_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"32 32 256 2",
+"   c #010101",
+".  c #080504",
+"X  c #0A0B04",
+"o  c #0C0B0A",
+"O  c #050506",
+"+  c #01021C",
+"@  c #100D0B",
+"#  c #12140D",
+"$  c #14190C",
+"%  c #18110A",
+"&  c #131313",
+"*  c #1A1C11",
+"=  c #1B1919",
+"-  c #181318",
+";  c #110F15",
+":  c #181C22",
+">  c #04042B",
+",  c #1A2212",
+"<  c #192514",
+"1  c #1B2913",
+"2  c #1A242B",
+"3  c #201B0D",
+"4  c #201E11",
+"5  c #201818",
+"6  c #36151B",
+"7  c #2E1110",
+"8  c #251B20",
+"9  c #232112",
+"0  c #242A14",
+"q  c #2B2B13",
+"w  c #292617",
+"e  c #2B3616",
+"r  c #2D3919",
+"t  c #263716",
+"y  c #312C14",
+"u  c #323D1A",
+"i  c #373816",
+"p  c #28280B",
+"a  c #2A2628",
+"s  c #333333",
+"d  c #393737",
+"f  c #342C2A",
+"g  c #1C1B7B",
+"h  c #0B0C6F",
+"j  c #39374A",
+"k  c #3D3762",
+"l  c #252070",
+"z  c #14145B",
+"x  c #2E4618",
+"c  c #33421B",
+"v  c #38481A",
+"b  c #3B5718",
+"n  c #354D20",
+"m  c #3A5921",
+"M  c #387C15",
+"N  c #4A1529",
+"B  c #433417",
+"V  c #5D3217",
+"C  c #443522",
+"Z  c #493728",
+"A  c #4D3035",
+"S  c #6D2216",
+"D  c #62383E",
+"F  c #6D2C36",
+"G  c #583754",
+"H  c #573C44",
+"J  c #623745",
+"K  c #6A3468",
+"L  c #464A1A",
+"P  c #47551A",
+"I  c #564C1A",
+"U  c #57571B",
+"Y  c #54480F",
+"T  c #465721",
+"R  c #54452E",
+"E  c #594A3C",
+"W  c #4B5022",
+"Q  c #477416",
+"!  c #566515",
+"~  c #4F7018",
+"^  c #466525",
+"/  c #566723",
+"(  c #567427",
+")  c #4B7228",
+"_  c #615018",
+"`  c #6A563A",
+"'  c #775936",
+"]  c #735233",
+"[  c #677C2B",
+"{  c #434344",
+"}  c #4B4B4B",
+"|  c #574648",
+" . c #5C4C59",
+".. c #5A5A5A",
+"X. c #555252",
+"o. c #554A51",
+"O. c #5C6077",
+"+. c #624546",
+"@. c #645D5C",
+"#. c #76594F",
+"$. c #775459",
+"%. c #764552",
+"&. c #6E566A",
+"*. c #786952",
+"=. c #6C6C6C",
+"-. c #646464",
+";. c #756764",
+":. c #737373",
+">. c #79797A",
+",. c #706C76",
+"<. c #52507E",
+"1. c #0C119C",
+"2. c #05088B",
+"3. c #0C12B5",
+"4. c #1517A8",
+"5. c #1419B6",
+"6. c #080CA2",
+"7. c #1E228F",
+"8. c #1B20B6",
+"9. c #2F2B90",
+"0. c #2525A9",
+"q. c #2527B8",
+"w. c #0F17C2",
+"e. c #1A20C4",
+"r. c #272AC3",
+"t. c #44319C",
+"y. c #483C8D",
+"u. c #463CA2",
+"i. c #4037B6",
+"p. c #5C5184",
+"a. c #554693",
+"s. c #544EB3",
+"d. c #725D88",
+"f. c #69538E",
+"g. c #645BB3",
+"h. c #796A98",
+"j. c #6C6592",
+"k. c #6269B7",
+"l. c #6F6AA2",
+"z. c #5E862E",
+"x. c #648717",
+"c. c #678F32",
+"v. c #788572",
+"b. c #7E8483",
+"n. c #801E31",
+"m. c #953226",
+"M. c #853010",
+"N. c #8C3A54",
+"B. c #B93558",
+"V. c #82572E",
+"C. c #8C683B",
+"Z. c #AF4420",
+"A. c #8B5758",
+"S. c #895E42",
+"D. c #865265",
+"F. c #8C7455",
+"G. c #947549",
+"H. c #977A56",
+"J. c #846D48",
+"K. c #8A6366",
+"L. c #8B7668",
+"P. c #936667",
+"I. c #947578",
+"U. c #93756F",
+"Y. c #A74C5D",
+"T. c #A74874",
+"R. c #AB4F6B",
+"E. c #A77B49",
+"W. c #AD7E4A",
+"Q. c #B96C78",
+"!. c #A96F6C",
+"~. c #CC4D1D",
+"^. c #C0546F",
+"/. c #C3787E",
+"(. c #CC4D5D",
+"). c #945C84",
+"_. c #8B7696",
+"`. c #8A78AE",
+"'. c #A87F8A",
+"]. c #8D79D0",
+"[. c #CB7E8F",
+"{. c #9D8262",
+"}. c #82817B",
+"|. c #AB8358",
+" X c #B8834C",
+".X c #B88755",
+"XX c #A88768",
+"oX c #A48775",
+"OX c #BC926C",
+"+X c #BA9474",
+"@X c #B38E6B",
+"#X c #BDB476",
+"$X c #C78E56",
+"%X c #CA9057",
+"&X c #C08446",
+"*X c #C89467",
+"=X c #C59876",
+"-X c #D49F72",
+";X c #828482",
+":X c #898A89",
+">X c #988987",
+",X c #988D9B",
+"<X c #96938A",
+"1X c #969796",
+"2X c #928CAD",
+"3X c #9FA39E",
+"4X c #9EB4BB",
+"5X c #AA8D96",
+"6X c #AC998E",
+"7X c #A39B96",
+"8X c #B69887",
+"9X c #B89A9A",
+"0X c #B2878F",
+"qX c #AB9ABB",
+"wX c #A7A799",
+"eX c #B1A29D",
+"rX c #B7A898",
+"tX c #AAAAA9",
+"yX c #A7AAA4",
+"uX c #BBA7A7",
+"iX c #B3B3AB",
+"pX c #BABBBB",
+"aX c #B5B4B2",
+"sX c #ADB0A9",
+"dX c #ADB1CF",
+"fX c #BAC294",
+"gX c #BDC0BD",
+"hX c #9FC9F0",
+"jX c #AAC5D6",
+"kX c #B0D0DE",
+"lX c #B7DCE6",
+"zX c #C39D86",
+"xX c #C69599",
+"cX c #D6838F",
+"vX c #C19CA2",
+"bX c #C6A496",
+"nX c #C8A4AA",
+"mX c #C8B9B6",
+"MX c #D1A7A4",
+"NX c #D0B4B3",
+"BX c #CFB7C7",
+"VX c #C5C1BC",
+"CX c #DFDEA3",
+"ZX c #D6D099",
+"AX c #C8C8C6",
+"SX c #D1D2CD",
+"DX c #DCDCDC",
+"FX c #D8D6D0",
+"GX c #D0C2C1",
+"HX c #DEE1DE",
+"JX c #E5C2C3",
+"KX c #F9CBCB",
+"LX c #E0E1DC",
+"PX c #E9E8E7",
+"IX c #FEFEFE",
+"UX c #F2F2F2",
+/* pixels */
+"            f ' ' G.G.H.G.J.F.;.N 6 % ; O o o ; 7Xl.D.K.Y.b.[.(.",
+"        o ` ' C.H.XX{.G.E.F.nX).F 6 8 - = # ; 1X!.T.K.K.Y.nXuX7X",
+"a   @.% oXL.wX{.G.E @   w >XBXI.; : 5 6 6 mXI.T.^.B.}.eXI.6XVXsX",
+"..O =.F.rX@XwXXXE   } :.& o 6X!.; 8 N N.MXPXuX<X}.I.7XsXaX>XrX<X",
+"  @ J.XX X|.|.8X@ } IXIXAX  $.0XK J G :XuXBXAXFXGXeX9XsX6XA.%.9X",
+"  ` {.G.E.|.|.8X  :.IXIXUX  | 5XN - - H !./.K.A s 9XcXN.N @.@.Q.",
+"Z XX XE. X|.bXzXa = SXUX=.  L.rX% : : @.mXT.A.F f !.cX'.J F J @.",
+"|.+XW. X.X|.OXOXF.o       E nX9XJ J $.&.).vXxX>X..yXuX5X:X=.=.b.",
+"+X@X%X%X=XbX=X8X8X|.#.R 5XBXNXxXGX,X_.,.>XxXaXLXAX3X'.| SXiXSXyX",
+"OX.X.XOXzXzXOXI.| w O O ;.8XU.d O O A d J 9XPXAXs   o a BXwXuXpX",
+"|. XE.=XMX`     O d :.s O O   = =.-.. 7 MXJXMXo = :...  X.>XQ.:X",
+"|.C.XXMXbX. { pXUXIXIX{   { AXIXIXIX1X  I.mXpX  aXIXIXX.+.xX%.uX",
+"|. XMXNX*X@ s 1XPXIXIX;   f =.;XPXIXPX  =.AXyX  :XIXIX>.| LX{ o.",
+"$XOX-X*X%XV.%   tXIXDX  Z = ;   >.IXIX= A sXsX& =.IXIX} | PXD.$.",
+"%X*X%X X*X&X'   DXIXtX  =XKXKXZ d IXIXs 8 1XxX5 d IXPXO X.wXY.D.",
+"B C B C Z B 3 @ IXIX:.  R E } 5 & IXIX} 5 DX9X. ..IX>.   .pXnXnX",
+"# # # & # & O d IXIX{ O $ $ $ o   IXIX-.. ,XH   AXPX; 2 qXdXqXa.",
+"# & # < t < O =.IXIX# @ y y y #   HXIX>.  <.  X.IX..O h 4.6.6.6.",
+"< < < < < &   1XIXDX  $ 0 0 0 , . jXIX<X  - . DXaX  z 6.8.3.6.4.",
+"< $ * $ , $   SXIXtX  0 r w , $   tXIXtX    ;XPX- + 0.4.q.4.5.3.",
+"< < n r t $ O UXIX>.  t 0 0 t 0   :XIXVX  s IX}   7.0.5.q.8.5.3.",
+"n x t * , X f IXIX{ X c v v v e   :.IXDXo DX;X  j h.s.q.r.e.w.w.",
+"1 0 n u 0 O ..IXIX& p v t 0 U Y . ..IXUXtXpXO > g.p.h.l.g h 1.3.",
+"= , T / t   >.IXIX&     O   q x.X { IXIXDX& + 2.e.s.p.k d.a.h f.",
+"q n ( x r   =.IXIXHXtXpXUX  p ~ X } IXUXs $ k l q.q.g p.d.#.S Z.",
+"e e Q t u $ & AXIXPXpX=.=   L !   >.IX{   *.*.#XZXh.k <.] S C.pX",
+"r m M c b e O           7 B P U         ;.oX#.<X4Xv.v.fXCXwXlXhX",
+"i m Q u L P ~ e y q Y M.~.V y _ p * a | &...G I.=X*.:.jXjXkXjXlX",
+"c P P W ( / Q / / P x.P I i c I _ 5 s.s.`.f.p.@XA._._.2XdX`.O.dX",
+"c b x ( z.P b ( c.( ! B q T L i 3 - 4.4.r.&.S J 2X].t.l z g s.l.",
+"^ ) [ ^ n m ) z.I q 9 4 4 4 w w 5 - 4.4.t.m.P._.h.g.a.a.f.j.j.k.",
+"r x u r m v P u w 4 4 4 * 4 * y i - 0.9.m.D.t.a.!.H.P.d.l.k.s.s."
+};
--- imview-1.1.9c.orig/imview.hxx
+++ imview-1.1.9c/imview.hxx
@@ -81,7 +81,7 @@ using std::string;
 
 // Installation path
 #if !defined(PrefPath)
-#define PrefPath  "/usr/local/share/Imview"
+#define PrefPath  "/usr/local/share/imview"
 #endif
 
 
--- imview-1.1.9c.orig/imview.cxx
+++ imview-1.1.9c/imview.cxx
@@ -69,6 +69,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <X11/xpm.h>
+#include <limits.h>
 
 #ifdef WIN32_NOTCYGWIN
 #   include <windows.h>
@@ -117,6 +119,7 @@
 #include "sliceSlider.hxx" // generic panel with linked slider/value
 #include "view3d.hxx"  // 3D image viewer
 #include "patchlevel.h"
+#include "imview.xpm"
 
 typedef map<string,image_psfile>::const_iterator cmi;  // const Map iterator
 
@@ -2090,6 +2093,11 @@ int main(int argc, char **argv)
 	// do not show it though
     }
     
+    // add an icon to main window
+    Pixmap icon_pixmap, icon_mask;
+    XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display),
+	                    imview_icon_xpm, &icon_pixmap, &icon_mask, NULL);
+    mainWindow->icon((char *)icon_pixmap);
     if (performFork) srv_dbgprintf("About to put main window on screen\n");
     // show the main window
     mainWindow->show(argc, argv);
--- imview-1.1.9c.orig/imtranslate.cxx
+++ imview-1.1.9c/imtranslate.cxx
@@ -528,10 +528,10 @@ double *imageIO::getRawDataVector(int xp
                 returnInfo[i] = (double) *((uchar *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
         } else {
             if (currImgNbSamples == 1)
-                returnInfo[0] = (double) *(imdata + currImgWidth*ypos + xpos);
+                returnInfo[0] = (double) *(imdata + (long)currImgWidth*(long)ypos + xpos);
             else if (currImgNbSamples == 3) {
                 uchar *xp;
-                xp = imdata + 3 * (currImgWidth*ypos + xpos);
+                xp = imdata + 3 * ((long)currImgWidth*(long)ypos + xpos);
                 returnInfo[0] = (double) *xp;
                 returnInfo[1] = (double) *(xp+1);
                 returnInfo[2] = (double) *(xp+2);
@@ -543,14 +543,14 @@ double *imageIO::getRawDataVector(int xp
     case IM_INT2:
         if (currBuffp != 0) {
             for (int i = 0 ; i < currImgNbSamples ; i++) 
-                returnInfo[i] = (double) *((short *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((short *)currBuffp[i] + zoff + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
     case IM_UINT2:
         if (currBuffp != 0) {
             for (int i = 0 ; i < currImgNbSamples ; i++) 
-                returnInfo[i] = (double) *((unsigned short *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((unsigned short *)currBuffp[i] + zoff + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
@@ -558,21 +558,21 @@ double *imageIO::getRawDataVector(int xp
     case IM_UINT4:
         if (currBuffp != 0) {
             for (int i = 0 ; i < currImgNbSamples ; i++) 
-                returnInfo[i] = (double) *((int *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((int *)currBuffp[i] + zoff + (long)currImgWidth*(long)ypos + xpos);
         }
         break;
 
     case IM_FLOAT:
         if (currBuffp != 0) {
             for (int i = 0 ; i < currImgNbSamples ; i++) 
-                returnInfo[i] = (double)  *((float *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double)  *((float *)currBuffp[i] + zoff + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
     case IM_DOUBLE:
         if (currBuffp != 0) {
             for (int i = 0 ; i < currImgNbSamples ; i++) 
-                returnInfo[i] = *((double *)currBuffp[i] + zoff + currImgWidth*ypos + xpos);
+                returnInfo[i] = *((double *)currBuffp[i] + zoff + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
@@ -722,16 +722,16 @@ double *imageIO::get3DRawDataVector(int
     case IM_INT1:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness; i++) 
-                returnInfo[i] = (double) *((uchar *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((uchar *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         } else {
             if (currImgNbSamples == 1)
                 for (int i = 0 ; i < currImgThickness; i++) 
-                    returnInfo[i] = (double) *(imdata + zoff*i + currImgWidth*ypos + xpos);
+                    returnInfo[i] = (double) *(imdata + zoff*i + (long)currImgWidth*(long)ypos + xpos);
             else if (currImgNbSamples == 3) {
                 uchar *xp;
-                xp = imdata + 3 * (currImgWidth*ypos + xpos);
+                xp = imdata + 3 * ((long)currImgWidth*(long)ypos + xpos);
                 for (int i = 0 ; i < currImgThickness; i++) 
-                    returnInfo[i] = (double) *(imdata + 3 * (zoff*i + currImgWidth*ypos + xpos) + cpos);
+                    returnInfo[i] = (double) *(imdata + 3 * (zoff*i + (long)currImgWidth*(long)ypos + xpos) + cpos);
             } 
         }
         break;
@@ -740,14 +740,14 @@ double *imageIO::get3DRawDataVector(int
     case IM_INT2:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness ; i++) 
-                returnInfo[i] = (double) *((short *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((short *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
     case IM_UINT2:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness ; i++) 
-                returnInfo[i] = (double) *((unsigned short *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((unsigned short *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
@@ -755,21 +755,21 @@ double *imageIO::get3DRawDataVector(int
     case IM_UINT4:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness ; i++) 
-                returnInfo[i] = (double) *((int *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double) *((int *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         }
         break;
 
     case IM_FLOAT:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness ; i++) 
-                returnInfo[i] = (double)  *((float *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = (double)  *((float *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
     case IM_DOUBLE:
         if ((currBuffp != 0) && (currBuffp[cpos] != 0)) {
             for (int i = 0 ; i < currImgThickness ; i++) 
-                returnInfo[i] = *((double *)currBuffp[cpos] + zoff*i + currImgWidth*ypos + xpos);
+                returnInfo[i] = *((double *)currBuffp[cpos] + zoff*i + (long)currImgWidth*(long)ypos + xpos);
         } 
         break;
 
@@ -999,7 +999,7 @@ void imageIO::translateForDisplay(bool k
                       typeName(currPixType));
             freeCurrentBuffers();
             // fake buffer to get through this tough point
-            newbuf = new uchar[currImgWidth*currImgHeight];
+            newbuf = new uchar[(long)currImgWidth*(long)currImgHeight];
             newspp = 1;
             break;      
         }
@@ -1083,13 +1083,13 @@ int imageIO::applyCLUTtoCurrentImage(con
                     if ((currBuffp = (void **)malloc(sizeof(void *))) == 0) {
                         errprintf("ApplyCLUTtoCurrentImage: not enough memory!\n");
                         retval = 2;
-                    } else if ((currBuffp[0] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                    } else if ((currBuffp[0] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                         free(currBuffp);
                         currBuffp = 0;
                         errprintf("ApplyCLUTtoCurrentImage: not enough memory!\n");
                         retval = 3;
                     } else {
-                        memcpy(currBuffp[0], imdata, currImgWidth*currImgHeight*sizeof(uchar));
+                        memcpy(currBuffp[0], imdata, (long)currImgWidth*(long)currImgHeight*sizeof(uchar));
                     }
                 }
             }
@@ -1313,13 +1313,13 @@ int imageIO::saveToRawBuffers(bool keepG
                     if ((currBuffp = (void **)malloc(sizeof(void *))) == 0) {
                         errprintf("saveToRawBuffers: not enough memory!\n");
                         retval = 2;
-                    } else if ((currBuffp[0] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                    } else if ((currBuffp[0] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                         free(currBuffp);
                         currBuffp = 0;
                         errprintf("saveToRawBuffers: not enough memory!\n");
                         retval = 3;
                     } else {
-                        memcpy(currBuffp[0], imdata, currImgWidth*currImgHeight*sizeof(uchar));
+                        memcpy(currBuffp[0], imdata, (long)currImgWidth*(long)currImgHeight*sizeof(uchar));
                         dontFreeBuffers = false; // we _can_ free these buffers!
                     }
                 }
@@ -1337,18 +1337,18 @@ int imageIO::saveToRawBuffers(bool keepG
                     if ((currBuffp = (void **)malloc(3*sizeof(void *))) == 0) {
                         errprintf("saveToRawBuffers: not enough memory!\n");
                         retval = 2;
-                    } else if ((currBuffp[0] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                    } else if ((currBuffp[0] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                         free(currBuffp);
                         currBuffp = 0;
                         errprintf("saveToRawBuffers: not enough memory for first component!\n");
                         retval = 3;
-                    } else if ((currBuffp[1] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                    } else if ((currBuffp[1] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                         free(currBuffp[0]);
                         free(currBuffp);
                         currBuffp = 0;
                         errprintf("saveToRawBuffers: not enough memory for second component!\n");
                         retval = 3;
-                    } else if ((currBuffp[2] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                    } else if ((currBuffp[2] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                         free(currBuffp[1]);
                         free(currBuffp[0]);
                         free(currBuffp);
@@ -1356,9 +1356,9 @@ int imageIO::saveToRawBuffers(bool keepG
                         errprintf("saveToRawBuffers: not enough memory for third component!\n");
                         retval = 3;
                     } else {
-                        memcpy(currBuffp[0], imdata, currImgWidth*currImgHeight*sizeof(uchar));
-                        memcpy(currBuffp[1], imdata, currImgWidth*currImgHeight*sizeof(uchar));
-                        memcpy(currBuffp[2], imdata, currImgWidth*currImgHeight*sizeof(uchar));
+                        memcpy(currBuffp[0], imdata, (long)currImgWidth*(long)currImgHeight*sizeof(uchar));
+                        memcpy(currBuffp[1], imdata, (long)currImgWidth*(long)currImgHeight*sizeof(uchar));
+                        memcpy(currBuffp[2], imdata, (long)currImgWidth*(long)currImgHeight*sizeof(uchar));
                         imspp = 3;
                         currImgNbSamples = 3;
                         dontFreeBuffers = false; // these buffers _can_ be freed
@@ -1378,18 +1378,18 @@ int imageIO::saveToRawBuffers(bool keepG
                 if ((currBuffp = (void **)malloc(3*sizeof(void *))) == 0) {
                     errprintf("saveToRawBuffers: not enough memory!\n");
                     retval = 2;
-                } else if ((currBuffp[0] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                } else if ((currBuffp[0] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                     free(currBuffp);
                     currBuffp = 0;
                     errprintf("saveToRawBuffers: not enough memory for first component!\n");
                     retval = 3;
-                } else if ((currBuffp[1] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                } else if ((currBuffp[1] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                     free(currBuffp[0]);
                     free(currBuffp);
                     currBuffp = 0;
                     errprintf("saveToRawBuffers: not enough memory for second component!\n");
                     retval = 3;
-                } else if ((currBuffp[2] = (uchar *)malloc(currImgWidth*currImgHeight*sizeof(uchar))) == 0) {
+                } else if ((currBuffp[2] = (uchar *)malloc((long)currImgWidth*(long)currImgHeight*sizeof(uchar))) == 0) {
                     free(currBuffp[1]);
                     free(currBuffp[0]);
                     free(currBuffp);
@@ -1631,10 +1631,10 @@ void imageIO::applyGamma_UINT1(int *imDe
         newDepth = 3;
 	// allocate new memory
         dbgprintf("Allocating a new buffer\n");
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
 
         p = *outbuf;
-        end = *outbuf + 3*currImgWidth * currImgHeight;
+        end = *outbuf + 3*(long)currImgWidth * (long)currImgHeight;
         qR = (uchar *)(currBuffp[0]) + buffZOffset;
         qG = (uchar *)(currBuffp[1]) + buffZOffset;
         qB = (uchar *)(currBuffp[2]) + buffZOffset;
@@ -1658,9 +1658,9 @@ void imageIO::applyGamma_UINT1(int *imDe
 	dbgprintf("Image with %d samples, processing sample %d\n", currImgNbSamples, currComp);
 	newDepth = 1;
 	dbgprintf("Allocating a new buffer\n");
-	*outbuf = new uchar[currImgWidth*currImgHeight];
+	*outbuf = new uchar[(long)currImgWidth*(long)currImgHeight];
 	p = *outbuf;
-	end = *outbuf + currImgWidth * currImgHeight;
+	end = *outbuf + (long)currImgWidth * (long)currImgHeight;
 	q = (uchar *)(currBuffp[currComp]) + buffZOffset;
 	// only the first map is relevant
 	assert(Rmap != 0);
@@ -1698,7 +1698,7 @@ template <class T> void imageIO::applyGa
         dbgprintf("Image with 3 samples, treating as RGB\n");
         newDepth = 3;
         dbgprintf("Allocating a new buffer\n");
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
         minval = *((T *)(currBuffp[0]) + buffZOffset);
@@ -1706,7 +1706,7 @@ template <class T> void imageIO::applyGa
 
         for (i = 0 ; i < 3 ; i++) {
             q = (T *)(currBuffp[i]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             while (q < iend) {
                 if (*q < minval)
                     minval = *q;
@@ -1728,7 +1728,7 @@ template <class T> void imageIO::applyGa
                 w1 = highthresh - lowthresh;
 
                 q = (T *)(currBuffp[i]) + buffZOffset;
-                iend = q + currImgWidth * currImgHeight;
+                iend = q + (long)currImgWidth * (long)currImgHeight;
                 p = *outbuf  + i;
                 while (q < iend) {
                     if (*q <= lowthresh) {
@@ -1750,7 +1750,7 @@ template <class T> void imageIO::applyGa
 		w1 = highthresh - lowthresh;
 
 		q = (T *)(currBuffp[i]) + buffZOffset;
-		iend = q + currImgWidth * currImgHeight;
+		iend = q + (long)currImgWidth * (long)currImgHeight;
 		p = *outbuf  + i;
 		while (q < iend) {
                     if (*q <= lowthresh) {
@@ -1771,14 +1771,14 @@ template <class T> void imageIO::applyGa
 	dbgprintf("Image with %d samples, processing sample %d\n", currImgNbSamples, currComp);
 	newDepth = 1;
 	dbgprintf("Allocating a new buffer\n");
-	*outbuf = new uchar[currImgWidth*currImgHeight];
+	*outbuf = new uchar[(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
 	minval = *((T *)(currBuffp[currComp]) + buffZOffset);
 	maxval = minval;
 
 	q = (T *)(currBuffp[currComp]) + buffZOffset;
-	iend = q + currImgWidth * currImgHeight;
+	iend = q + (long)currImgWidth * (long)currImgHeight;
 
 	// only the red-channel transform is relevant
 	while (q < iend) {
@@ -1801,7 +1801,7 @@ template <class T> void imageIO::applyGa
             w1 = highthresh - lowthresh;
 
             q = (T *)(currBuffp[currComp]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < iend) {
 		if (*q <= lowthresh) {
@@ -1823,7 +1823,7 @@ template <class T> void imageIO::applyGa
             w1 = highthresh - lowthresh;
 
             q = (T *)(currBuffp[currComp]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < iend) {
                 if (*q <= lowthresh) {
@@ -1867,14 +1867,14 @@ void imageIO::applyGamma_UINT2(int *imDe
         dbgprintf("Image with 3 samples, treating as RGB\n");
         newDepth = 3;
         dbgprintf("Allocating a new buffer\n");
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
         minval = USHRT_MAX;
         maxval = 0; // yes we know that
         for (i = 0 ; i < 3 ; i++) {
             q = (ushort *)(currBuffp[i]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             while (q < dend) {
                 if (*q < minval)
                     minval = *q;
@@ -1896,7 +1896,7 @@ void imageIO::applyGamma_UINT2(int *imDe
                 w1 = highthresh - lowthresh;
 
                 q = (ushort *)(currBuffp[i]) + buffZOffset;
-                dend = q + currImgWidth * currImgHeight;
+                dend = q + (long)currImgWidth * (long)currImgHeight;
                 p = *outbuf  + i;
                 while (q < dend) {
                     if (*q <= lowthresh) {
@@ -1918,7 +1918,7 @@ void imageIO::applyGamma_UINT2(int *imDe
 		w1 = highthresh - lowthresh;
 
 		q = (ushort *)(currBuffp[i]) + buffZOffset;
-		dend = q + currImgWidth * currImgHeight;
+		dend = q + (long)currImgWidth * (long)currImgHeight;
 		p = *outbuf  + i;
 		while (q < dend) {
                     if (*q <= lowthresh) {
@@ -1939,14 +1939,14 @@ void imageIO::applyGamma_UINT2(int *imDe
 	dbgprintf("Image with %d samples, processing sample %d\n", currImgNbSamples, currComp);
 	newDepth = 1;
 	dbgprintf("Allocating a new buffer\n");
-	*outbuf = new uchar[currImgWidth*currImgHeight];
+	*outbuf = new uchar[(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
 	minval = USHRT_MAX;
 	maxval = 0;
 
 	q = (ushort *)(currBuffp[currComp]) + buffZOffset;
-	dend = q + currImgWidth * currImgHeight;
+	dend = q + (long)currImgWidth * (long)currImgHeight;
 
 	// only the red-channel transform is relevant
 	while (q < dend) {
@@ -1968,7 +1968,7 @@ void imageIO::applyGamma_UINT2(int *imDe
             w1 = highthresh - lowthresh;
 
             q = (ushort *)(currBuffp[currComp]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < dend) {
 		if (*q <= lowthresh) {
@@ -1990,7 +1990,7 @@ void imageIO::applyGamma_UINT2(int *imDe
             w1 = highthresh - lowthresh;
 
             q = (ushort *)(currBuffp[currComp]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < dend) {
                 if (*q <= lowthresh) {
@@ -2031,14 +2031,14 @@ void imageIO::applyGamma_INT4(int *imDep
         dbgprintf("Image with 3 samples, treating as RGB\n");
         newDepth = 3;
         dbgprintf("Allocating a new buffer\n");
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
         minval = INT_MAX;
         maxval = INT_MIN;
         for (i = 0 ; i < 3 ; i++) {
             q = (int *)(currBuffp[i]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             while (q < iend) {
                 if (*q < minval)
                     minval = *q;
@@ -2060,7 +2060,7 @@ void imageIO::applyGamma_INT4(int *imDep
                 w1 = highthresh - lowthresh;
 
                 q = (int *)(currBuffp[i]) + buffZOffset;
-                iend = q + currImgWidth * currImgHeight;
+                iend = q + (long)currImgWidth * (long)currImgHeight;
                 p = *outbuf  + i;
                 while (q < iend) {
                     if (*q <= lowthresh) {
@@ -2082,7 +2082,7 @@ void imageIO::applyGamma_INT4(int *imDep
 		w1 = highthresh - lowthresh;
 
 		q = (int *)(currBuffp[i]) + buffZOffset;
-		iend = q + currImgWidth * currImgHeight;
+		iend = q + (long)currImgWidth * (long)currImgHeight;
 		p = *outbuf  + i;
 		while (q < iend) {
                     if (*q <= lowthresh) {
@@ -2110,7 +2110,7 @@ void imageIO::applyGamma_INT4(int *imDep
 	maxval = INT_MIN;
 
 	q = (int *)(currBuffp[currComp]) + buffZOffset;
-	iend = q + currImgWidth * currImgHeight;
+	iend = q + (long)currImgWidth * (long)currImgHeight;
 
 	// only the red-channel transform is relevant
 	while (q < iend) {
@@ -2132,7 +2132,7 @@ void imageIO::applyGamma_INT4(int *imDep
             w1 = highthresh - lowthresh;
 
             q = (int *)(currBuffp[currComp]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < iend) {
 		if (*q <= lowthresh) {
@@ -2154,7 +2154,7 @@ void imageIO::applyGamma_INT4(int *imDep
             w1 = highthresh - lowthresh;
 
             q = (int *)(currBuffp[currComp]) + buffZOffset;
-            iend = q + currImgWidth * currImgHeight;
+            iend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < iend) {
                 if (*q <= lowthresh) {
@@ -2198,14 +2198,14 @@ void imageIO::applyGamma_DBL(int *imDept
         dbgprintf("Image with 3 samples, treating as RGB\n");
         newDepth = 3;
         dbgprintf("Allocating a new buffer\n");
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
         minval = DBL_MAX;
         maxval = DBL_MIN;
         for (i = 0 ; i < 3 ; i++) {
             q = (double *)(currBuffp[i]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             while (q < dend) {
                 if (*q < minval)
                     minval = *q;
@@ -2227,7 +2227,7 @@ void imageIO::applyGamma_DBL(int *imDept
                 w1 = highthresh - lowthresh;
 
                 q = (double *)(currBuffp[i]) + buffZOffset;
-                dend = q + currImgWidth * currImgHeight;
+                dend = q + (long)currImgWidth * (long)currImgHeight;
                 p = *outbuf  + i;
                 while (q < dend) {
                     if (*q <= lowthresh) {
@@ -2249,7 +2249,7 @@ void imageIO::applyGamma_DBL(int *imDept
 		w1 = highthresh - lowthresh;
 
 		q = (double *)(currBuffp[i]) + buffZOffset;
-		dend = q + currImgWidth * currImgHeight;
+		dend = q + (long)currImgWidth * (long)currImgHeight;
 		p = *outbuf  + i;
 		while (q < dend) {
                     if (*q <= lowthresh) {
@@ -2270,14 +2270,14 @@ void imageIO::applyGamma_DBL(int *imDept
 	dbgprintf("Image with %d samples, processing sample %d\n", currImgNbSamples, currComp);
 	newDepth = 1;
 	dbgprintf("Allocating a new buffer\n");
-	*outbuf = new uchar[currImgWidth*currImgHeight];
+	*outbuf = new uchar[(long)currImgWidth*(long)currImgHeight];
 
 	// find global min and max now.
 	minval = DBL_MAX;
 	maxval = DBL_MIN;
 
 	q = (double *)(currBuffp[currComp]) + buffZOffset;
-	dend = q + currImgWidth * currImgHeight;
+	dend = q + (long)currImgWidth * (long)currImgHeight;
 
 	// only the red-channel transform is relevant
 	while (q < dend) {
@@ -2299,7 +2299,7 @@ void imageIO::applyGamma_DBL(int *imDept
             w1 = highthresh - lowthresh;
 
             q = (double *)(currBuffp[currComp]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < dend) {
 		if (*q <= lowthresh) {
@@ -2321,7 +2321,7 @@ void imageIO::applyGamma_DBL(int *imDept
             w1 = highthresh - lowthresh;
 
             q = (double *)(currBuffp[currComp]) + buffZOffset;
-            dend = q + currImgWidth * currImgHeight;
+            dend = q + (long)currImgWidth * (long)currImgHeight;
             p = *outbuf;
             while (q < dend) {
                 if (*q <= lowthresh) {
@@ -2361,13 +2361,13 @@ int imageIO::setPixelInOverlay(int index
     int retval = 0;
 
     if (!overlay) {
-        overlay = new uchar[currImgWidth * currImgHeight];
+        overlay = new uchar[(long)currImgWidth * (long)currImgHeight];
         ovlspp = 1;
-        memset(overlay, 0, currImgWidth * currImgHeight * sizeof(uchar));
+        memset(overlay, 0, (long)currImgWidth * (long)currImgHeight * sizeof(uchar));
     }
 
     // array bounds check
-    if (index < currImgWidth*currImgHeight)
+    if (index < (long)currImgWidth*(long)currImgHeight)
         overlay[index] = value;
 
     return retval;
@@ -2396,11 +2396,11 @@ int imageIO::applyOverlayToCurrentImage(
 	if (ovlspp == 1) {
 	    if (imspp != 3) {
                 // we'll have to make it colour
-                newbuf = new uchar[3*currImgWidth*currImgHeight];
+                newbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
                 p = imdata;
                 q = newbuf;
-                r = overlay + currZpos * currImgWidth * currImgHeight;
-                end = q + 3*currImgWidth * currImgHeight;
+                r = overlay + currZpos * (long)currImgWidth * (long)currImgHeight;
+                end = q + 3*(long)currImgWidth * (long)currImgHeight;
 	
                 /* this will ensure we can safely apply the colour overlay */
                 assert(MAX_FL_COLOURS > 255);
@@ -2429,7 +2429,7 @@ int imageIO::applyOverlayToCurrentImage(
             } else {
                 q = imdata;
                 r = overlay + currZpos * currImgWidth * currImgHeight;
-                end = q + 3*currImgWidth * currImgHeight;
+                end = q + 3*(long)currImgWidth * (long)currImgHeight;
 		    
                 if (ovl_transparency == 0.0) {
                     while (q != end) {
@@ -2453,15 +2453,15 @@ int imageIO::applyOverlayToCurrentImage(
 	} else { // ovlspp == 3
 	    if (imspp != 3) {
                 // we'll have to make it colour
-                newbuf = new uchar[3*currImgWidth*currImgHeight];
+                newbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
                 p = imdata;
                 q = newbuf;
                 r = overlay;
-                end = q + 3*currImgWidth * currImgHeight;
+                end = q + 3*(long)currImgWidth * (long)currImgHeight;
 	
                 if (ovl_transparency == 0.0) {
                     // very simple and very fast
-                    memcpy(newbuf, overlay, 3 * currImgWidth * currImgHeight);
+                    memcpy(newbuf, overlay, 3 * (long)currImgWidth * (long)currImgHeight);
                 } else {
                     // more expensive calculation
                     while (q != end) {
@@ -2481,11 +2481,11 @@ int imageIO::applyOverlayToCurrentImage(
                 // just overwrite imdata
                 q = imdata;
                 r = overlay;
-                end = q + 3*currImgWidth * currImgHeight;
+                end = q + 3*(long)currImgWidth * (long)currImgHeight;
 		    
                 if (ovl_transparency == 0.0) {
                     // simple
-                    memcpy(imdata, overlay, 3 * currImgWidth * currImgHeight);
+                    memcpy(imdata, overlay, 3 * (long)currImgWidth * (long)currImgHeight);
                 } else {
                     while (q != end) {
                         *q = (uchar)(*r + (*q - *r) * ovl_transparency);
@@ -2640,7 +2640,7 @@ void imageIO::applyImageParameters(IMAGE
     if (p->zslice >= currImgThickness)
         p->zslice = currImgThickness - 1;
     currZpos = p->zslice;
-    buffZOffset = currZpos * (currImgWidth*currImgHeight); 
+    buffZOffset = currZpos * ((long)currImgWidth*(long)currImgHeight);
 
     // if image is multisample, worry about current sample
     if (p->comp < 0)
@@ -2723,9 +2723,9 @@ void imageIO::convertUINT1withLUT(int *i
     if (currImgNbSamples == 1) {
         dbgprintf("Expected number of samples: 1\n");
         *imDepth = 3;
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
         p = *outbuf;
-        end = *outbuf + 3*currImgWidth * currImgHeight;
+        end = *outbuf + 3*(long)currImgWidth * (long)currImgHeight;
         q = (uchar *)(currBuffp[0]) + buffZOffset;
 
         while (p < end) {
@@ -2750,9 +2750,9 @@ void imageIO::convertDirectLUT(int *imDe
     if (imspp == 1) {
         dbgprintf("Expected number of samples: 1\n");
         *imDepth = 3;
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
         p = *outbuf;
-        end = *outbuf + 3*currImgWidth * currImgHeight;
+        end = *outbuf + 3*(long)currImgWidth * (long)currImgHeight;
         q = imdata;
 
         while (p < end) {
@@ -2780,9 +2780,9 @@ void imageIO::convertINT4withLUT_wraparo
     if (currImgNbSamples == 1) {
         dbgprintf("Expected number of samples: 1\n");
         *imDepth = 3;
-        *outbuf = new uchar[3*currImgWidth*currImgHeight];
+        *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
         p = *outbuf;
-        end = *outbuf + 3*currImgWidth * currImgHeight;
+        end = *outbuf + 3*(long)currImgWidth * (long)currImgHeight;
         q = (int *)(currBuffp[0]) + buffZOffset;
 
         while (p < end) {
@@ -2819,9 +2819,9 @@ template <class T> void imageIO::convert
 
     dbgprintf("Pixel type is arbitrary, of size %d, CLUT is present, %d samples present\n", sizeof(T), currImgNbSamples);
     *imDepth = 3;
-    *outbuf = new uchar[3*currImgWidth*currImgHeight];
+    *outbuf = new uchar[3*(long)currImgWidth*(long)currImgHeight];
     p = *outbuf;
-    end = *outbuf + 3*currImgWidth * currImgHeight;
+    end = *outbuf + 3*(long)currImgWidth * (long)currImgHeight;
     q = (T *)(currBuffp[currComp]) + buffZOffset;
 
     while (p < end) {
@@ -2844,10 +2844,10 @@ void imageIO::convertBINARY(int *imDepth
     if (currImgNbSamples >= 1) {
         // nothing much to do: save first buffer to outbuff
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         p = *outbuf;
         q = (uchar *)(currBuffp[currComp]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         while (p != end)
             *p++ = (*q++) ? 0 :  255;
         if ((currImgNbSamples == 1) && (currImgThickness == 1)) {
@@ -2876,8 +2876,8 @@ void imageIO::convertUINT1(int *imDepth,
     if (currImgNbSamples == 1) {
         // probably the simplest of all cases:
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
-        memcpy(*outbuf, (char *)(currBuffp[0]) + buffZOffset, currImgWidth * currImgHeight);
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
+        memcpy(*outbuf, (char *)(currBuffp[0]) + buffZOffset, (long)currImgWidth * (long)currImgHeight);
         if ((currImgThickness == 1) && freeBuffers)
             freeCurrentBuffers();
     } else if (interpretRGB && (currImgNbSamples == 3)) {
@@ -2886,14 +2886,14 @@ void imageIO::convertUINT1(int *imDepth,
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
         p = *outbuf;
-        end = *outbuf + currImgNbSamples*currImgWidth * currImgHeight;
+        end = *outbuf + currImgNbSamples*(long)currImgWidth * (long)currImgHeight;
         qR = (uchar *)(currBuffp[0]) + buffZOffset;
         qG = (uchar *)(currBuffp[1]) + buffZOffset;
         qB = (uchar *)(currBuffp[2]) + buffZOffset;
 
-        while (p != end) {
+        while (p < end) {
             *p++ = *qR++;
             *p++ = *qG++;
             *p++ = *qB++;
@@ -2903,8 +2903,8 @@ void imageIO::convertUINT1(int *imDepth,
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
-        memcpy(*outbuf, (char *)(currBuffp[currComp]) + buffZOffset, currImgWidth * currImgHeight);
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
+        memcpy(*outbuf, (char *)(currBuffp[currComp]) + buffZOffset, (long)currImgWidth * (long)currImgHeight);
         dbgprintf("There are %d uchar buffers in this image\n", currImgNbSamples);
         // don't free the Buffers as we may need them...
     } else {
@@ -2947,14 +2947,14 @@ template <class T> void imageIO::convert
 
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         if (minmaxAllSlices) {
             p = (T *)(currBuffp[0]);
-            end =  p + currImgWidth * currImgHeight * currImgThickness;
+            end =  p + (long)currImgWidth * (long)currImgHeight * currImgThickness;
         } else {
             p = (T *)(currBuffp[0]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
         }
         if (minmaxAllSlices && minmax_iscached()) {
             dbgprintf("Using cached min/max values\n");
@@ -2980,7 +2980,7 @@ template <class T> void imageIO::convert
         dbgprintf("Nbsamples = 1 ; min = %f , max = %f\n", (double)minval, (double)maxval);
         p = (T *)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (makeChar && (minval >= nada) && (maxval <= 255)) {
             // this  image fits in a char, just copy things through
             while (q < endq) {
@@ -3007,7 +3007,7 @@ template <class T> void imageIO::convert
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[(long)currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         if (minmaxAllSlices && minmax_iscached()) {
             double cmin, cmax;
@@ -3024,10 +3024,10 @@ template <class T> void imageIO::convert
             for (i = 0 ; i < currImgNbSamples ; i++) {
                 if (minmaxAllSlices) {
                     p = (T *)(currBuffp[i]) + buffZOffset;
-                    end =  p + currImgWidth * currImgHeight;
+                    end =  p + (long)currImgWidth * (long)currImgHeight;
                 } else {
                     p = (T *)(currBuffp[i]);
-                    end =  p + currImgWidth * currImgHeight * currImgThickness;
+                    end =  p + (long)currImgWidth * (long)currImgHeight * currImgThickness;
                 }
                 while (p < end) {
                     if (*p > maxval)
@@ -3047,7 +3047,7 @@ template <class T> void imageIO::convert
         pG = (T *)(currBuffp[1]) + buffZOffset;
         pB = (T *)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (makeChar && (minval >= nada && maxval <= 255)) {
             // this image fits on a char: just copy things through
             while (q < endq) {
@@ -3080,7 +3080,7 @@ template <class T> void imageIO::convert
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         if (minmaxAllSlices && minmax_iscached()) {
             double cmin, cmax;
@@ -3100,10 +3100,10 @@ template <class T> void imageIO::convert
                 for (i = 0 ; i <  currImgNbSamples ; i++) {
                     if (minmaxAllSlices) {
                         p = (T *)(currBuffp[i]);
-                        end = p + currImgWidth * currImgHeight * currImgThickness;
+                        end = p + (long)currImgWidth * (long)currImgHeight * currImgThickness;
                     } else {
                         p = (T *)(currBuffp[i]) + buffZOffset;
-                        end = p + currImgWidth * currImgHeight;
+                        end = p + (long)currImgWidth * (long)currImgHeight;
                     }
                     while (p < end) {
                         if (*p > maxval)
@@ -3117,11 +3117,11 @@ template <class T> void imageIO::convert
                 if (minmaxAllSlices) {
                     minval = maxval = *((T *)currBuffp[currComp]);
                     p = (T *)(currBuffp[currComp]);
-                    end = p + currImgWidth * currImgHeight * currImgThickness;
+                    end = p + (long)currImgWidth * (long)currImgHeight * currImgThickness;
                 } else {
                     minval = maxval = *(((T *)currBuffp[currComp]) + buffZOffset);
                     p = (T *)(currBuffp[currComp]) + buffZOffset;
-                    end = p + currImgWidth * currImgHeight;
+                    end = p + (long)currImgWidth * (long)currImgHeight;
                 }
                 while (p < end) {
                     if (*p > maxval)
@@ -3141,7 +3141,7 @@ template <class T> void imageIO::convert
         // just worry about the current sample for display
         p = (T *)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (makeChar && (minval >= nada && maxval <= 255)) {
             // this image fits in a char, just copy things through
             while (q < endq) {
@@ -3183,10 +3183,10 @@ void imageIO::convertINT2(int *imDepth,
     dbgprintf("Pixel type is int2 (short)\n");
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         p = (short *)(currBuffp[0]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         minval = maxval = *p++;
         while (p < end) {
             if (*p > maxval)
@@ -3197,7 +3197,7 @@ void imageIO::convertINT2(int *imDepth,
         }
         p = (short *)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this `short' image fits in a char, just copy things through
             while (q < endq) {
@@ -3224,12 +3224,12 @@ void imageIO::convertINT2(int *imDepth,
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[(long)currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         minval =  maxval = *((short *)(currBuffp[0]) + buffZOffset);
         for (i = 0 ; i < currImgNbSamples ; i++) {
             p = (short *)(currBuffp[i]) + buffZOffset;
-            end =  p + currImgWidth * currImgHeight;
+            end =  p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3242,7 +3242,7 @@ void imageIO::convertINT2(int *imDepth,
         pG = (short *)(currBuffp[1]) + buffZOffset;
         pB = (short *)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + (long)currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this image fits on a char: just copy things through
             while (q < endq) {
@@ -3275,13 +3275,13 @@ void imageIO::convertINT2(int *imDepth,
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         minval = maxval =  *(((short *)currBuffp[currComp]) + buffZOffset);
         // take the min and max across all samples!
         for (i = 0 ; i <  currImgNbSamples ; i++) {
             p = (short *)(currBuffp[i]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3292,7 +3292,7 @@ void imageIO::convertINT2(int *imDepth,
         }
         p = (short *)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this `short' image fits in a char, just copy things through
             while (q < endq) {
@@ -3333,10 +3333,10 @@ void imageIO::convertUINT2(int *imDepth,
     dbgprintf("Pixel type is int2 (unsigned short)\n");
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         p = (unsigned short *)(currBuffp[0]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         minval = maxval = *p++;
         while (p < end) {
             if (*p > maxval)
@@ -3347,7 +3347,7 @@ void imageIO::convertUINT2(int *imDepth,
         }
         p = (unsigned short *)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval <= 255) {
             // this `unsigned short' image fits in a char, just copy things through
             while (q < endq) {
@@ -3374,7 +3374,7 @@ void imageIO::convertUINT2(int *imDepth,
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         minval =  maxval = *((unsigned short *)(currBuffp[0]) + buffZOffset);
         for (i = 0 ; i < currImgNbSamples ; i++) {
@@ -3392,7 +3392,7 @@ void imageIO::convertUINT2(int *imDepth,
         pG = (unsigned short *)(currBuffp[1]) + buffZOffset;
         pB = (unsigned short *)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (maxval <= 255) {
             // this image fits on a char: just copy things through
             while (q < endq) {
@@ -3425,13 +3425,13 @@ void imageIO::convertUINT2(int *imDepth,
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         minval = maxval =  *(((unsigned short *)currBuffp[currComp]) + buffZOffset);
         // take the min and max across all samples!
         for (i = 0 ; i <  currImgNbSamples ; i++) {
             p = (unsigned short *)(currBuffp[i]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3442,7 +3442,7 @@ void imageIO::convertUINT2(int *imDepth,
         }
         p = (unsigned short *)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval <= 255) {
             // this `unsigned short' image fits in a char, just copy things through
             while (q < endq) {
@@ -3484,10 +3484,10 @@ void imageIO::convertUINT4(int *imDepth,
     dbgprintf("Pixel type is int4\n");
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         p = (unsigned int*)(currBuffp[0]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         minval = maxval = *p++;
         while (p < end) {
             if (*p > maxval)
@@ -3498,7 +3498,7 @@ void imageIO::convertUINT4(int *imDepth,
         }
         p = (unsigned int*)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval <= 255) {
             // this `int' image fits in a char, just copy things through
             while (q < endq) {
@@ -3525,12 +3525,12 @@ void imageIO::convertUINT4(int *imDepth,
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[(long)currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         minval =  maxval = *((unsigned int*)(currBuffp[0]) + buffZOffset);
         for (i = 0 ; i < currImgNbSamples ; i++) {
             p = (unsigned int*)(currBuffp[i]) + buffZOffset;
-            end =  p + currImgWidth * currImgHeight;
+            end =  p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3543,7 +3543,7 @@ void imageIO::convertUINT4(int *imDepth,
         pG = (unsigned int*)(currBuffp[1]) + buffZOffset;
         pB = (unsigned int*)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (maxval <= 255) {
             // this image fits on a char: just copy things through
             while (q < endq) {
@@ -3576,13 +3576,13 @@ void imageIO::convertUINT4(int *imDepth,
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         minval = maxval =  *((unsigned int*)currBuffp[currComp] + buffZOffset);
         // take the min and max across all samples!
         for (i = 0 ; i <  currImgNbSamples ; i++) {
             p = (unsigned int*)(currBuffp[i]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3593,7 +3593,7 @@ void imageIO::convertUINT4(int *imDepth,
         }
         p = (unsigned int*)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval <= 255) {
             // this `int' image fits in a char, just copy things through
             while (q < endq) {
@@ -3633,10 +3633,10 @@ void imageIO::convertINT4(int *imDepth,
     dbgprintf("Pixel type is int4\n");
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         p = (int *)(currBuffp[0]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         minval = maxval = *p++;
         while (p < end) {
             if (*p > maxval)
@@ -3647,7 +3647,7 @@ void imageIO::convertINT4(int *imDepth,
         }
         p = (int *)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this `int' image fits in a char, just copy things through
             while (q < endq) {
@@ -3674,12 +3674,12 @@ void imageIO::convertINT4(int *imDepth,
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         minval =  maxval = *((int *)(currBuffp[0]) + buffZOffset);
         for (i = 0 ; i < currImgNbSamples ; i++) {
             p = (int *)(currBuffp[i]) + buffZOffset;
-            end =  p + currImgWidth * currImgHeight;
+            end =  p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3692,7 +3692,7 @@ void imageIO::convertINT4(int *imDepth,
         pG = (int *)(currBuffp[1]) + buffZOffset;
         pB = (int *)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this image fits on a char: just copy things through
             while (q < endq) {
@@ -3725,13 +3725,13 @@ void imageIO::convertINT4(int *imDepth,
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         minval = maxval =  *(((int *)currBuffp[currComp]) + buffZOffset);
         // take the min and max across all samples!
         for (i = 0 ; i <  currImgNbSamples ; i++) {
             p = (int *)(currBuffp[i]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3742,7 +3742,7 @@ void imageIO::convertINT4(int *imDepth,
         }
         p = (int *)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (minval >= 0 && maxval <= 255) {
             // this `int' image fits in a char, just copy things through
             while (q < endq) {
@@ -3783,10 +3783,10 @@ void imageIO::convertDOUBLE(int *imDepth
     dbgprintf("Pixel type is double\n");
     if (currImgNbSamples == 1) {
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         p = (double *)(currBuffp[0]) + buffZOffset;
-        end = p + currImgWidth * currImgHeight;
+        end = p + (long)currImgWidth * (long)currImgHeight;
         minval = maxval = *p++;
         while (p < end) {
             if (*p > maxval)
@@ -3797,7 +3797,7 @@ void imageIO::convertDOUBLE(int *imDepth
         }
         p = (double *)(currBuffp[0]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval != minval)
             while (q < endq) {
                 *q++ = (uchar)((((*p++) - minval) * 255.0)/(maxval-minval));
@@ -3812,12 +3812,12 @@ void imageIO::convertDOUBLE(int *imDepth
             dbgprintf("Interpreting image as RGB even though it isn't...\n");
         }
         *imDepth = 3;
-        *outbuf = new uchar[currImgNbSamples*currImgWidth*currImgHeight];
+        *outbuf = new uchar[currImgNbSamples*(long)currImgWidth*(long)currImgHeight];
 
         minval =  maxval = *((double *)(currBuffp[0]) + buffZOffset);
         for (i = 0 ; i < currImgNbSamples ; i++) {
             p = (double *)(currBuffp[i]) + buffZOffset;
-            end =  p + currImgWidth * currImgHeight;
+            end =  p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3830,7 +3830,7 @@ void imageIO::convertDOUBLE(int *imDepth
         pG = (double *)(currBuffp[1]) + buffZOffset;
         pB = (double *)(currBuffp[2]) + buffZOffset;
         q = *outbuf;
-        endq = q  + currImgNbSamples*currImgWidth*currImgHeight;
+        endq = q  + currImgNbSamples*(long)currImgWidth*(long)currImgHeight;
         if (maxval != minval) {
             // doesn't fit on a char: do a grey-level scaling
             while (q < endq) {
@@ -3849,13 +3849,13 @@ void imageIO::convertDOUBLE(int *imDepth
     } else if (currImgNbSamples > 0) {
         // display only the current sample
         *imDepth = 1;
-        *outbuf = new uchar[currImgWidth * currImgHeight];
+        *outbuf = new uchar[(long)currImgWidth * (long)currImgHeight];
         // adjust values
         minval = maxval =  *(((double *)currBuffp[currComp]) + buffZOffset);
         // take the min and max across all samples!
         for (i = 0 ; i <  currImgNbSamples ; i++) {
             p = (double *)(currBuffp[i]) + buffZOffset;
-            end = p + currImgWidth * currImgHeight;
+            end = p + (long)currImgWidth * (long)currImgHeight;
             while (p < end) {
                 if (*p > maxval)
                     maxval = *p;
@@ -3867,7 +3867,7 @@ void imageIO::convertDOUBLE(int *imDepth
         dbgprintf("Double image, range: min=%.6g, max=%.6g\n", minval, maxval);
         p = (double *)(currBuffp[currComp]) + buffZOffset;
         q = *outbuf;
-        endq = q + currImgWidth * currImgHeight;
+        endq = q + (long)currImgWidth * (long)currImgHeight;
         if (maxval != minval)
             while (q < endq) {
                 *q++ = (uchar)((((*p++) - minval) * 255)/(maxval-minval));
--- imview-1.1.9c.orig/imnmspc.hxx
+++ imview-1.1.9c/imnmspc.hxx
@@ -37,6 +37,7 @@
  *
  * For those compilers that require the namespace definition.
  * At the moment, this only counts MSVC++
+ * (GCC-4 now requires namespace statements as well - Teemu Ikonen 2006-07-06)
  *      
  *-----------------------------------------------------------------------*/
 
@@ -44,13 +45,14 @@
 #ifndef IMNAMESPACE_H
 #define IMNAMESPACE_H
 
-#if defined(_MSC_VER) // Visual C++
-
 namespace std {
     // empty here
 }
 
 using namespace std;
+
+#if defined(_MSC_VER) // Visual C++
+
 // suppress warning about identifier being too long to be debugged...
 #pragma warning(disable:4786)
 
--- imview-1.1.9c.orig/imlines.cxx
+++ imview-1.1.9c/imlines.cxx
@@ -129,7 +129,7 @@ imline::imline(int x1, int y1, int x2, i
 	    int id = IOBlackBox->imageDepth();
 	    if (id != 1) {
 		uchar *dp;
-		dp = IOBlackBox->imageData() + id * delta;
+		dp = IOBlackBox->imageData() + id * (long)delta;
 		aPoint.R = *dp;
 		aPoint.G = *(dp+1);
 		aPoint.B = *(dp+2);
--- imview-1.1.9c.orig/imageViewer.cxx
+++ imview-1.1.9c/imageViewer.cxx
@@ -163,6 +163,9 @@ imageViewer::imageViewer(int x, int y, i
 
     // must call this to close the group
     end();
+
+    parentWindow = (imviewWindow *)parent();
+
 }
 
 imageViewer::~imageViewer()
--- imview-1.1.9c.orig/imageIO.cxx
+++ imview-1.1.9c/imageIO.cxx
@@ -629,7 +629,7 @@ int imageIO::renderOverlay(const char *f
             || (thepixtype == IM_UINT4)) {
             if (imspp == 1) {
 		// image is OK, render in buffer
-                uchar *ovl = new uchar[w*h*z];
+                uchar *ovl = new uchar[(long)w*(long)h*(long)z];
 
                 switch (thepixtype) {
                 case IM_BINARY:
@@ -637,7 +637,7 @@ int imageIO::renderOverlay(const char *f
                 case IM_UINT1:
                 {
                     char **b = (char **)p;
-                    memcpy(ovl, b[0], w * h * z * sizeof(uchar));
+                    memcpy(ovl, b[0], (long)w * (long)h * (long)z * sizeof(uchar));
                 }
                 break;
 
@@ -649,7 +649,7 @@ int imageIO::renderOverlay(const char *f
 
                     ovlb = ovl;
                     begin = b[0];
-                    end = begin + w * h * z;
+                    end = begin + (long)w * (long)h * (long)z;
 
                     while (begin != end)
                         *ovlb++ = *begin++ & 0xFF;
@@ -665,7 +665,7 @@ int imageIO::renderOverlay(const char *f
 
                     ovlb = ovl;
                     begin = b[0];
-                    end = begin + w * h * z;
+                    end = begin + (long)w * (long)h * (long)z;
 
                     while (begin != end)
                         *ovlb++ = *begin++ & 0xFF;
@@ -681,7 +681,7 @@ int imageIO::renderOverlay(const char *f
 
                     ovlb = ovl;
                     begin = b[0];
-                    end = begin + w * h * z;
+                    end = begin + (long)w * (long)h * (long)z;
 
                     while (begin != end)
                         *ovlb++ = *begin++ & 0xFF;
@@ -697,7 +697,7 @@ int imageIO::renderOverlay(const char *f
 
                     ovlb = ovl;
                     begin = b[0];
-                    end = begin + w * h * z;
+                    end = begin + (long)w * (long)h * (long)z;
 
                     while (begin != end)
                         *ovlb++ = *begin++ & 0xFF;
@@ -719,7 +719,7 @@ int imageIO::renderOverlay(const char *f
                 }
             } else if (imspp == 3) {
 		// image is OK, render in buffer
-                uchar *ovl = new uchar[3*w*h*z];
+                uchar *ovl = new uchar[3*(long)w*(long)h*(long)z];
                 int i;
 
 		// overlay buffer will be arranged RGBRGBRGB...
@@ -734,7 +734,7 @@ int imageIO::renderOverlay(const char *f
 
                     for (i = 0 ; i < 3  ; i++) {
                         begin = b[i];
-                        end = begin + w * h * z;
+                        end = begin + (long)w * (long)h * (long)z;
                         ovlb = ovl+i;
 
                         while(begin != end) {
@@ -753,7 +753,7 @@ int imageIO::renderOverlay(const char *f
 
                     for (i = 0 ; i < 3  ; i++) {
                         begin = b[i];
-                        end = begin + w * h * z;
+                        end = begin + (long)w * (long)h * (long)z;
                         ovlb = ovl+i;
 
                         while(begin != end) {
@@ -773,7 +773,7 @@ int imageIO::renderOverlay(const char *f
 
                     for (i = 0 ; i < 3  ; i++) {
                         begin = b[i];
-                        end = begin + w * h * z;
+                        end = begin + (long)w * (long)h * (long)z;
                         ovlb = ovl+i;
 
                         while(begin != end) {
@@ -792,7 +792,7 @@ int imageIO::renderOverlay(const char *f
 
                     for (i = 0 ; i < 3  ; i++) {
                         begin = b[i];
-                        end = begin + w * h * z;
+                        end = begin + (long)w * (long)h * (long)z;
                         ovlb = ovl+i;
 
                         while(begin != end) {
@@ -811,7 +811,7 @@ int imageIO::renderOverlay(const char *f
 
                     for (i = 0 ; i < 3  ; i++) {
                         begin = b[i];
-                        end = begin + w * h * z;
+                        end = begin + (long)w * (long)h * (long)z;
                         ovlb = ovl+i;
 
                         while(begin != end) {
@@ -868,7 +868,7 @@ int imageIO::write(const char *filename,
 
 int imageIO::wholeImage(uchar **bufR, uchar **bufG, uchar **bufB)
 {
-    int nbpix = currImgWidth*currImgHeight;
+    long nbpix = (long)currImgWidth*(long)currImgHeight;
 
     if (imspp == 1) {
         // simply return a copy of the image data
@@ -909,13 +909,13 @@ int imageIO::subsetImage(uchar **bufR, u
     if (imspp == 1) {
         int      j;
         uchar    *ucp, *ucpl;
-        long     nbpix = bh*bw;
+        long     nbpix = (long)bh*(long)bw;
 
         *bufR = new uchar[nbpix];
         *bufG = *bufB = 0;
         for (j = 0 ; j < bh ; j++) {
-            ucp = imdata + (by+j)*currImgWidth + bx;
-            ucpl = *bufR + j*bw;
+            ucp = imdata + (by+j)*(long)currImgWidth + bx;
+            ucpl = *bufR + j*(long)bw;
             memcpy(ucpl, ucp, bw);
         }
     } else if (imspp == 3) {
@@ -928,10 +928,10 @@ int imageIO::subsetImage(uchar **bufR, u
         *bufB = new uchar[nbpix];
 
         for (j = 0 ; j < bh ; j++) {
-            ucp = imdata + 3*((by+j)*currImgWidth + bx);
-            ucpr = *bufR + j*bw;
-            ucpg = *bufG + j*bw;
-            ucpb = *bufB + j*bw;
+            ucp = imdata + 3*((by+j)*(long)currImgWidth + bx);
+            ucpr = *bufR + j*(long)bw;
+            ucpg = *bufG + j*(long)bw;
+            ucpb = *bufB + j*(long)bw;
             for (i = 0 ; i < bw ; i++) {
                 *ucpr++ = *ucp++;
                 *ucpg++ = *ucp++;
@@ -972,13 +972,13 @@ int imageIO::subsetForBH(vector<BHPoint>
             case IM_UINT1:
             case IM_INT1: {
                 uchar *ucpX, *ucpY;
-                ucpX = (uchar*)currBuffp[Xcomp] + zoff + currImgWidth*by + bx;
-                ucpY = (uchar*)currBuffp[Ycomp] + zoff + currImgWidth*by + bx;
+                ucpX = (uchar*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)by + bx;
+                ucpY = (uchar*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)by + bx;
                 minXval = maxXval = (double)*ucpX;
                 minYval = maxYval = (double)*ucpY;
                 for (j = 0 ; j < bh ; j++) {
-                    ucpX = (uchar*)currBuffp[Xcomp] + zoff + currImgWidth*(by+j) + bx;
-                    ucpY = (uchar*)currBuffp[Ycomp] + zoff + currImgWidth*(by+j) + bx;
+                    ucpX = (uchar*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
+                    ucpY = (uchar*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
                     for (i = 0 ; i < bw ; i++) {
                         dx = (double)*ucpX;
                         dy = (double)*ucpY;
@@ -1000,13 +1000,13 @@ int imageIO::subsetForBH(vector<BHPoint>
             case IM_INT4:
             case IM_UINT4: {
                 int *ucpX, *ucpY;
-                ucpX = (int*)currBuffp[Xcomp] + zoff + currImgWidth*by + bx;
-                ucpY = (int*)currBuffp[Ycomp] + zoff + currImgWidth*by + bx;
+                ucpX = (int*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)by + bx;
+                ucpY = (int*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)by + bx;
                 minXval = maxXval = (double)*ucpX;
                 minYval = maxYval = (double)*ucpY;
                 for (j = 0 ; j < bh ; j++) {
-                    ucpX = (int*)currBuffp[Xcomp] + zoff + currImgWidth*(by+j) + bx;
-                    ucpY = (int*)currBuffp[Ycomp] + zoff + currImgWidth*(by+j) + bx;
+                    ucpX = (int*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
+                    ucpY = (int*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
                     for (i = 0 ; i < bw ; i++) {
                         dx = (double)*ucpX;
                         dy = (double)*ucpY;
@@ -1016,7 +1016,7 @@ int imageIO::subsetForBH(vector<BHPoint>
                         if (dx > maxXval) maxXval = dx;
                         if (dy > maxYval) maxYval = dy;
 
-                        delta = bx+i + (by+j)*currImgWidth;
+                        delta = bx+i + (long)(by+j)*(long)currImgWidth;
                         v.push_back(BHPoint(BHPBlack,delta,dx ,dy));
                         ucpX++;
                         ucpY++;
@@ -1027,13 +1027,13 @@ int imageIO::subsetForBH(vector<BHPoint>
 
             case IM_DOUBLE: {
                 double *ucpX, *ucpY;
-                ucpX = (double*)currBuffp[Xcomp] + zoff + currImgWidth*by + bx;
-                ucpY = (double*)currBuffp[Ycomp] + zoff + currImgWidth*by + bx;
+                ucpX = (double*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)by + bx;
+                ucpY = (double*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)by + bx;
                 minXval = maxXval = (double)*ucpX;
                 minYval = maxYval = (double)*ucpY;
                 for (j = 0 ; j < bh ; j++) {
-                    ucpX = (double*)currBuffp[Xcomp] + zoff + currImgWidth*(by+j) + bx;
-                    ucpY = (double*)currBuffp[Ycomp] + zoff + currImgWidth*(by+j) + bx;
+                    ucpX = (double*)currBuffp[Xcomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
+                    ucpY = (double*)currBuffp[Ycomp] + zoff + (long)currImgWidth*(long)(by+j) + bx;
                     for (i = 0 ; i < bw ; i++) {
                         dx = *ucpX;
                         dy = *ucpY;
@@ -1043,7 +1043,7 @@ int imageIO::subsetForBH(vector<BHPoint>
                         if (dx > maxXval) maxXval = dx;
                         if (dy > maxYval) maxYval = dy;
 
-                        delta = bx+i + (by+j)*currImgWidth;
+                        delta = bx+i + (long)(by+j)*(long)currImgWidth;
                         v.push_back(BHPoint(BHPBlack,delta,dx ,dy));
                         ucpX++;
                         ucpY++;
@@ -1064,7 +1064,7 @@ int imageIO::subsetForBH(vector<BHPoint>
             minXval = maxXval = (double)*(beg + Xcomp);
             minYval = maxYval = (double)*(beg + Ycomp);
             for (j = 0 ; j < bh ; j++) {
-                beg = imdata + currImgNbSamples*((by+j)*currImgWidth + bx);
+                beg = imdata + currImgNbSamples*((long)(by+j)*(long)currImgWidth + bx);
                 ucpX = beg + Xcomp;
                 ucpY = beg + Ycomp;
                 for (i = 0 ; i < bw ; i++) {
@@ -1076,7 +1076,7 @@ int imageIO::subsetForBH(vector<BHPoint>
                     if (dx > maxXval) maxXval = dx;
                     if (dy > maxYval) maxYval = dy;
 
-                    delta = bx+i + (by+j)*currImgWidth;
+                    delta = bx+i + (long)(by+j)*(long)currImgWidth;
                     v.push_back(BHPoint(BHPBlack,delta,dx ,dy));
                     ucpX += currImgNbSamples;
                     ucpY += currImgNbSamples;
--- imview-1.1.9c.orig/bivHist.cxx
+++ imview-1.1.9c/bivHist.cxx
@@ -45,7 +45,9 @@
 
 #include <stdlib.h>
 #include <stdio.h> // for sprintf
+#include <limits.h>
 
+#include <climits>
 #include <algorithm>
 
 #include "imview.hxx"
--- imview-1.1.9c.orig/Makefile.in
+++ imview-1.1.9c/Makefile.in
@@ -19,11 +19,11 @@ subdirs         = @subdirs@
 top_srcdir      = @top_srcdir@
 srcdir          = @srcdir@
 bindir          = $(exec_prefix)/bin
-infodir         = $(prefix)/info
+infodir         = @infodir@
 libdir          = $(prefix)/lib/gnudl
-mandir          = $(prefix)/man/man1
+mandir          = @mandir@/man1
 datadir         = @datadir@
-datadestdir     = $(datadir)/Imview
+datadestdir     = $(datadir)/imview
 
 # compilers and flags
 CC              = @CC@
@@ -174,7 +174,7 @@ insure:
 $(TARGET) : $(UILIB) $(IOLIB) $(SRVLIB) $(OBJECTS)
 	$(SENTINEL) $(CXX) $(STATIC) $(CXXTRA) $(CXXFLAGS) -o $(TARGET) $(OBJECTS) $(UILIB) $(IOLIB) $(SRVLIB) $(LDFLAGS) $(LDLIBS) $(LDXTRA) $(FENCE)
 	$(FLTK_CONFIG) --post $(TARGET)
-	@(cd ${TOP} ; ./buildnb)
+#	@(cd ${TOP} ; ./buildnb)
 
 $(UILIB):
 	(cd fluid ; $(MAKE) )
@@ -217,20 +217,20 @@ install-bin:
 install-lut:
 	@$(mkinstalldirs) $(DESTDIR)$(datadestdir)
 	@for i in ${top_srcdir}/support/*.lut ${top_srcdir}/support/*.jpg ; do \
-		${INSTALL} $$i  $(DESTDIR)$(datadestdir)/ ;\
+		${INSTALL} --mode="u=rw,go=r" $$i  $(DESTDIR)$(datadestdir)/ ;\
 	done
 
 install-help:
 	@$(mkinstalldirs) $(DESTDIR)$(datadestdir)/doc
 	@for i in ${top_srcdir}/doc/quickhelp*.html ; do \
-		${INSTALL} $$i $(DESTDIR)$(datadestdir)/doc/  ;\
+		${INSTALL} --mode="u=rw,go=r" $$i $(DESTDIR)$(datadestdir)/doc/  ;\
 	done
 	@-${INSTALL} -d $(DESTDIR)$(datadestdir)
-	@-${INSTALL} ${top_srcdir}/doc/gpl.html $(DESTDIR)$(datadestdir)/doc/
-	@-${INSTALL} ${top_srcdir}/doc/warranty.html $(DESTDIR)$(datadestdir)/doc/
+	@-${INSTALL} --mode="u=rw,go=r" ${top_srcdir}/doc/gpl.html $(DESTDIR)$(datadestdir)/doc/
+	@-${INSTALL} --mode="u=rw,go=r" ${top_srcdir}/doc/warranty.html $(DESTDIR)$(datadestdir)/doc/
 	@-${INSTALL} -d $(DESTDIR)$(mandir)
 	@-${INSTALL} ${top_srcdir}/doc/imview.1 $(DESTDIR)$(mandir)/
-	@gzip $(DESTDIR)$(mandir)/imview.1
+	@gzip -9 $(DESTDIR)$(mandir)/imview.1
 
 # strip executables before installing.
 install-strip: install-lut install-help
--- imview-1.1.9c.orig/COPYRIGHT
+++ imview-1.1.9c/COPYRIGHT
@@ -16,8 +16,7 @@ PURPOSE.  See the GNU General Public Lic
 A copy of the GNU General Public License is available in the file
 COPYING.  If you did not receive it, write to:
 
-        		The Free Software Foundation
-        		59 Temple Place
-			Suite 330
-			Boston, MA 02111, USA
-
+                        Free Software Foundation, Inc.
+                        51 Franklin St
+                        Fifth Floor
+                        Boston, MA 02110-1301, USA.
--- imview-1.1.9c.orig/configure.in
+++ imview-1.1.9c/configure.in
@@ -274,9 +274,9 @@ else
 	fltk_include_flags=`$my_fltk_config --use-images --cxxflags`
 	FLUID=${START}fluid
 	dnl Include extra library (FLTK-1.1.x) for handling various image formats.
-	LDFLAGS="$LDFLAGS `$my_fltk_config --use-images --ldstaticflags`"
+	LDFLAGS="$LDFLAGS `$my_fltk_config --use-images --ldflags`"
 	Cppflags="$CPPFLAGS $fltk_include_flags"
-	FLTKLIB="`$my_fltk_config --use-images --ldstaticflags`"
+	FLTKLIB="`$my_fltk_config --use-images --ldflags`"
 	fltklib=$fltk_cfg_name
 fi
 
@@ -438,16 +438,22 @@ AC_CHECK_FUNCS(usleep nanosleep)
 if test "$have_x" = "yes" ; then
 	dnl some headers might be poorly defined, in particular regarding X11 headers and Solaris (things have improved lately)
 	# Check for X	
-	AC_PATH_XTRA
+# This macro causes an unused dependency to libXt. In Debian, the fltk
+# build dependency should pull in all the needed X gunk, but no more.
+# - TI 2006-07-06
+#	AC_PATH_XTRA
+# Adding empty X_EXTRA_LIBS
+	AC_SUBST(X_EXTRA_LIBS, "")
+
 	echo "Ignoring libraries \"$X_PRE_LIBS\" requested by configure."
 	dnl# LIBS="$LIBS$X_LIBS$X_PRE_LIBS"
 	if test "$with_magick" != "no" ; then
 		# this seems to be sufficient somehow	
 		# as Magick will include the right libraries and flags already
-		XLIBS="-lX11 -lXext" 
+		XLIBS="-lX11 -lXext -lXpm"
 	else
 		# I'm not sure how reliable this is...
-		XLIBS="$X_LIBS -lX11 -lXext"
+		XLIBS="$X_LIBS -lX11 -lXext -lXpm"
 	fi
 	# LIBS="$LIBS$X_LIBS"
 	CFLAGS="$CFLAGS $X_CFLAGS"
@@ -466,7 +472,6 @@ dnl# add warnings to compiler switches:
 dnl# do this last so messing with switches does not break tests
 if test -n "$GXX"; then
     GCC_ACCEPTS_INCLUDE_DIR # this will add -I$INCLUDE_DIR if the compiler does not complain about it.
-    GCC_ACCEPTS_DEPRECATED_HEADERS # this will test if -Wno-deprecated is necessary
 
     CFLAGS="-Wall $CFLAGS"
     # GNU C++ is sometimes missing bits of the STL
@@ -744,29 +749,36 @@ fi
 dnl ImageMagick is very useful, but optional
 dnl Moreover the API keeps changing and that's really annoying.
 
+# Use pkg-config instead of Magick-config (-TI 2005-12-01)
 if test "$with_magick" != "no"
 then
 	MAGICKLIB=''
 	# check if we can find the configuration utility
-	AC_CHECK_PROG(HAVE_MAGICK_CONFIG, Magick-config, "yes", "no")
+#	AC_CHECK_PROG(HAVE_MAGICK_CONFIG, Magick-config, "yes", "no")
+	HAVE_MAGICK_CONFIG="yes"
 	if test "$HAVE_MAGICK_CONFIG" != "no"
 	then
 		# verify that Magick associated libraries are not incompatible
-		if test "$have_x" != "yes" -a "`Magick-config --libs | grep X11`" != "" ; then
+#		if test "$have_x" != "yes" -a "`Magick-config --libs | grep X11`" != "" ; then
+		if test "$have_x" != "yes" ; then
 		# conflict
 			echo "Magick library conflicts with requested absence of X11 library usage"
 			with_magick=no
 		else
 			# this might turn really ugly
-			CPPFLAGS="$CPPFLAGS "`Magick-config --cppflags`
-			LDFLAGS="$LDFLAGS "`Magick-config --ldflags`
-			IMLIBS="$IMLIBS "`Magick-config --libs`
+#			CPPFLAGS="$CPPFLAGS "`Magick-config --cppflags`
+#			LDFLAGS="$LDFLAGS "`Magick-config --ldflags`
+#			IMLIBS="$IMLIBS "`Magick-config --libs`
+                        MAGICKNAME=$(pkg-config ImageMagick --libs-only-l | sed 's/-l//')
+                        CPPFLAGS="$CPPFLAGS "`pkg-config ImageMagick --cflags`
+			LDFLAGS="$LDFLAGS "`pkg-config ImageMagick --libs-only-L`
+			IMLIBS="$IMLIBS "`pkg-config ImageMagick --libs`
 			# we are not finished: we must check we have the correct version
-			AC_CHECK_LIB(Magick, DispatchImage, 
-				AC_DEFINE(HAVE_MAGICK) MAGICKLIB=" -lMagick",
+			AC_CHECK_LIB($MAGICKNAME, DispatchImage, 
+				AC_DEFINE(HAVE_MAGICK) MAGICKLIB=" -l$MAGICKNAME",
 				MAGICKLIB="",
 				$IMLIBS)
-			if test "$MAGICKLIB" != " -lMagick" ; then
+			if test "$MAGICKLIB" != " -l$MAGICKNAME" ; then
 				echo "Magick library found, but version is incorrect, we need version 5.x ; 6.x is not supported at this stage."
 				with_magick="no"
 			else			
@@ -851,7 +863,7 @@ AC_SUBST(IMLIBS)
 
 
 dnl Installation stuff
-eval PrefPath="${DATA_DIR}/Imview/"
+eval PrefPath="${DATA_DIR}/imview/"
 AC_DEFINE_UNQUOTED(PrefPath,"$PrefPath",Define directory where preference and .lut files will live.)
 
 # optional
--- imview-1.1.9c.orig/configure
+++ imview-1.1.9c/configure
@@ -1739,9 +1739,9 @@ else
 	fltk_images_name=`$my_fltk_config --libs | sed 's/\(.*fltk\)\(\.a$\)/\1_images.a/'`
 		fltk_include_flags=`$my_fltk_config --use-images --cxxflags`
 	FLUID=${START}fluid
-		LDFLAGS="$LDFLAGS `$my_fltk_config --use-images --ldstaticflags`"
+		LDFLAGS="$LDFLAGS `$my_fltk_config --use-images --ldflags`"
 	Cppflags="$CPPFLAGS $fltk_include_flags"
-	FLTKLIB="`$my_fltk_config --use-images --ldstaticflags`"
+	FLTKLIB="`$my_fltk_config --use-images --ldflags`"
 	fltklib=$fltk_cfg_name
 fi
 
--- imview-1.1.9c.orig/transferHistoBox.cxx
+++ imview-1.1.9c/transferHistoBox.cxx
@@ -63,7 +63,7 @@ void myTransferHistoBox::makeHisto()
     for (i = 0 ; i < 256 ; i++)
 	theHisto[i] = 0;
 
-    nbpix = IOBlackBox->imageWidth() * IOBlackBox->imageHeight();
+    nbpix = (long)IOBlackBox->imageWidth() * (long)IOBlackBox->imageHeight();
     spp = IOBlackBox->imageDepth();
     
     if (spp == 1) {
--- imview-1.1.9c.orig/my_Image.cxx
+++ imview-1.1.9c/my_Image.cxx
@@ -220,9 +220,9 @@ KEYWORDS:
     // realloc buffer, don't care about old content.
     //dbgprintf("Display: b->w=%d, b->d=%d, d=%d, x=%d, y=%d, w=%d, h=%d\n",
     //	   b->w, b->d, d, x, y, w, h);
-    buf = (uchar *)malloc(w * h * d * sizeof(uchar));
+    buf = (uchar *)malloc((long)w * (long)h * (long)d * sizeof(uchar));
     for (i = 0 ; i < h ; i++) {
-	memcpy(buf + i*w*d, b->data()[0] + d*x + (y+i) * b->w() * d, w * d);
+	memcpy(buf + (long)i*(long)w*(long)d, b->data()[0] + (long)d*(long)x + (long)(y+i) * (long)b->w() * (long)d, (long)w * (long)d);
     }
 
     if (d == 1) {
@@ -269,8 +269,8 @@ KEYWORDS:
 **/
 
     int    i, j, k, ii;
-    int    ex, inc1x, inc2x;
-    int    ey, inc1y, inc2y;
+    long   ex, inc1x, inc2x;
+    long   ey, inc1y, inc2y;
     uchar  *op;
     const  uchar *ip;
     
@@ -294,7 +294,7 @@ KEYWORDS:
 	    }
 	}
 	op = outbuf + i*ow*d;
-	ip = inbuf + d*x + (y+ii) * iw * d;
+	ip = inbuf + d*x + (y+ii) * (long)iw * d;
 	// first pixel of the line
 	for (k = 0 ; k < d ; k++) {
 	    *op++ = *(ip + k);
@@ -354,7 +354,7 @@ KEYWORDS:
 **/
 
     int    i, ii;
-    int    ey, inc1y, inc2y;
+    long   ey, inc1y, inc2y;
     
     assert(oh > h); // we are zooming in
     assert(h > 0);   // the bounding box does not have 0 height
@@ -367,7 +367,7 @@ KEYWORDS:
     
     // first line special case:
     ii = 0;
-    memcpy(outbuf, inbuf + d * (x + y * iw), ow*d);
+    memcpy(outbuf, inbuf + d * (x + y * (long)iw), ow*d);
     if (ey > 0) {
 	ey += inc1y;
 	++ii;
@@ -380,7 +380,7 @@ KEYWORDS:
             // we have to work out a new line
             ey += inc1y;
             memcpy(outbuf + d * i*ow, 
-                   inbuf + d* (x + (y+ii) * iw), 
+                   inbuf + d* (x + (y+ii) * (long)iw),
                    ow*d);
             ++ii;
         } else {
@@ -430,8 +430,8 @@ KEYWORDS:
 **/
 
     int    i, j, k;
-    int    ex, inc1x, inc2x;
-    int    ey, inc2y;
+    long   ex, inc1x, inc2x;
+    long   ey, inc2y;
     uchar  *op;
     const  uchar *ip;
     
@@ -442,8 +442,8 @@ KEYWORDS:
 
 
     for (i = 0 ; i < oh ; ++i) {
-	op = outbuf + i*ow*d;
-	ip = inbuf + d*x + (y+i) * iw * d;
+	op = outbuf + i*(long)ow*d;
+	ip = inbuf + d*x + (y+i) * (long)iw * d;
 	// first pixel of the line
 	for (k = 0 ; k < d ; ++k) {
 	    *op++ = *(ip + k);
@@ -500,7 +500,7 @@ KEYWORDS:
     int                     i, j, k;
     int                     *accum;
     int                     nbaccum;
-    int                     ex, inc1x, inc2x;
+    long                    ex, inc1x, inc2x;
     uchar                   *op;
     const uchar             *ip;
 	
@@ -514,7 +514,7 @@ KEYWORDS:
 	// set up the line pointers
 	// output will be the intermediary buffer
 	op = outbuf + i*ow*d; // same as above
-	ip = inbuf + d * (x + (y+i) * iw) ; // line are not zoomed out yet.
+	ip = inbuf + d * (x + (y+i) * (long)iw) ; // line are not zoomed out yet.
 	// work out what to write
 	
 	// -- first pixel
@@ -575,7 +575,7 @@ KEYWORDS:
 **/
 
     int                     i, j, k;
-    int                     ex, inc1x, inc2x;
+    long                    ex, inc1x, inc2x;
     uchar                   *op;
     const uchar              *ip;
 	
@@ -587,8 +587,8 @@ KEYWORDS:
 	inc2x = 2 * ow;
 	// set up the line pointers
 	// output will be the intermediary buffer
-	op = outbuf + i*ow*d; // same as above
-	ip = inbuf + d * (x + (y+i) * iw) ; // line are not zoomed out yet.
+	op = outbuf + i*(long)ow*(long)d; // same as above
+	ip = inbuf + d * (x + ((long)y+i) * (long)iw) ; // line are not zoomed out yet.
 	// work out what to write
 	for (j = 0 ; j < w ; j++) {
 	    if (ex > 0) {
@@ -619,7 +619,7 @@ static void zoomouth_smooth(uchar *outbu
     int                     i, j, k;
     int                     *accum;
     int                     nbaccum;
-    int                     ey, inc1y, inc2y;
+    long                    ey, inc1y, inc2y;
     uchar                   *op;
     const uchar             *ip;
 
@@ -633,7 +633,7 @@ static void zoomouth_smooth(uchar *outbu
 	// output will be the final buffer
 	op = outbuf + j * d;
 	// input will be the intermediary buffer allocated above
-	ip = inbuf + d * ((x+j) + y*iw);
+	ip = inbuf + d * ((x+j) + y*(long)iw);
 	// work out what to write
 	// first pixel
 	for (k = 0 ; k < d ; k++) 
@@ -678,7 +678,7 @@ static void zoomouth(uchar *outbuf,	 /*
 		     int h)	 /* height of BB */
 {
     int                     i, j, k;
-    int                     ey, inc1y, inc2y;
+    long                    ey, inc1y, inc2y;
     uchar                   *op;
     const uchar             *ip;
 
@@ -691,7 +691,7 @@ static void zoomouth(uchar *outbuf,	 /*
 	// output will be the final buffer
 	op = outbuf + j * d;
 	// input will be the intermediary buffer allocated above
-	ip = inbuf + d * ((x+j) + y*iw);
+	ip = inbuf + d * ((x+j) + y*(long)iw);
 	// work out what to write
 	// rest of the column
 	for (i = 0 ; i < h ; i++) {
@@ -824,7 +824,7 @@ KEYWORDS:
 	    free(buf2);
 	    buf2 = 0;
 	}
-	buf2 = (uchar *)malloc(ow * h * d * sizeof(uchar));
+	buf2 = (uchar *)malloc(ow * (long)h * d * sizeof(uchar));
 	// zoom out the x dimension
 	if (drawsmooth)
 	    zoomoutw_smooth(buf2,(const uchar*)(b->data()[0]),ow,d,b->w(),x,y,w,h);
--- imview-1.1.9c.orig/menucb.cxx
+++ imview-1.1.9c/menucb.cxx
@@ -1079,24 +1079,34 @@ void onlinehelp_cb(Fl_Object *, void *)
     }
 }
 
-// lauches netscape to read the full documentation
+// lauches a browser to read the full documentation
 void fulldocument_cb(Fl_Object *, void *)
 {
     static char command[1024];
+    char helpurl[1024];
+    FILE *helpfile;
 
+    if((helpfile = fopen(LOCALHELP, "r")) != NULL) {
+       fclose(helpfile);
+       strncpy(helpurl, "file://", 1024);
+       strncat(helpurl, LOCALHELP, 1016);
+    } else {
+       strncpy(helpurl, HELPURL, 1024);
+    }
+   
     sprintf(command,
-	    "netscape -remote openURL\\(%s,new-window\\)", HELPURL);
+	    "sensible-browser %s &", helpurl);
     int ret = system((const char *)command);
     if (ret != 0) {
-	// try calling netscape directly!
+	// try calling firefox directly!
 	sprintf(command,
-		"netscape %s &", HELPURL);
+		"firefox %s &", helpurl);
 	ret = system((const char *)command);
 	if (ret != 0)
-	    errprintf("Sorry, can't start netscape\n"
+	    errprintf("Sorry, can't start browser\n"
 		      "Help URL is:\n"
 		      "%s",
-		      HELPURL);
+		      helpurl);
     }
 }
 
--- imview-1.1.9c.orig/transferRGBHistoBox.cxx
+++ imview-1.1.9c/transferRGBHistoBox.cxx
@@ -66,7 +66,7 @@ void myTransferRGBHistoBox::makeHisto()
 	theRGBHisto[i][2] = 0;
     }
 
-    nbpix = IOBlackBox->imageWidth() * IOBlackBox->imageHeight();
+    nbpix = (long)IOBlackBox->imageWidth() * (long)IOBlackBox->imageHeight();
     spp = IOBlackBox->imageDepth();
     
     if (spp == 1) {
--- imview-1.1.9c.orig/transferRGBFunction.cxx
+++ imview-1.1.9c/transferRGBFunction.cxx
@@ -763,7 +763,7 @@ void normalisebutton_cb(Fl_Button*, tran
     panel->affectChannels(normR, normG, normB);
     panel->ensureImageRedraw(true); // we want the result to be shown on the image
     
-    nbpix = IOBlackBox->imageWidth() * IOBlackBox->imageHeight();
+    nbpix = (long)IOBlackBox->imageWidth() * (long)IOBlackBox->imageHeight();
     spp = IOBlackBox->imageDepth();
 
     maxval = 0;
--- imview-1.1.9c.orig/transferFunction.cxx
+++ imview-1.1.9c/transferFunction.cxx
@@ -503,7 +503,7 @@ void normalisebutton_cb(Fl_Button*, tran
     unsigned char *p, *end;
     double slope, startp;
     
-    nbpix = IOBlackBox->imageWidth() * IOBlackBox->imageHeight();
+    nbpix = (long)IOBlackBox->imageWidth() * (long)IOBlackBox->imageHeight();
     spp = IOBlackBox->imageDepth();
 
     maxval = 0;
--- imview-1.1.9c.orig/client/imclient.c
+++ imview-1.1.9c/client/imclient.c
@@ -1524,7 +1524,7 @@ int imviewputimage(IMAGE       *I,
     LIARdebug("\n"
 	      "Timings: start to put                : %6.4f sec\n"
 	      "         put to beginning of upload  : %6.4f sec\n"
-	      "         begining of upload to end   : %6.4f sec\n"
+	      "         beginning of upload to end  : %6.4f sec\n"
 	      "         close conn to exit          : %6.4f sec\n"
 	      "-------------------------------------           \n"
 	      "         put to close conn           : %6.4f sec\n"
@@ -1997,7 +1997,7 @@ int imviewput2(IMAGE          *I,
 	      "         opening of socket to login  : %6.4f sec\n"
 	      "         login to put                : %6.4f sec\n"
 	      "         put to beginning of upload  : %6.4f sec\n"
-	      "         begining of upload to end   : %6.4f sec\n"
+	      "         beginning of upload to end  : %6.4f sec\n"
 	      "         end of upload to close conn : %6.4f sec\n"
 	      "         close conn to exit          : %6.4f sec\n"
 	      "-------------------------------------           \n"
--- imview-1.1.9c.orig/doc/imview.1
+++ imview-1.1.9c/doc/imview.1
@@ -51,7 +51,7 @@ variable-controlled TMPDIR directory are
 .TP
 \fB-disable_io_keys\fR
 This option disables some I/O shortcut that are not menu-dependent, such as c
-that closes an image. This is useful in conjuction with options \fI-hide_menubar\fR and \fI-disable_menubar\fR
+that closes an image. This is useful in conjunction with options \fI-hide_menubar\fR and \fI-disable_menubar\fR
 for limiting the user's interaction with the application.
 .TP
 \fB-disable_menubar\fR
@@ -68,7 +68,7 @@ restrict the user's control over \fBimvi
 \fB-fork\fR
 Sends \fBimview\fR to the background (works on all platforms including windows). It is
 better to use this option rather than the shell semantics (adding & at the end of the command
-under Unix) when the server is ran in conjuction with \fI-server\fR,
+under Unix) when the server is ran in conjunction with \fI-server\fR,
 because imview will synchonize the foreground and background processes so that the foreground
 process can know the server port number.
 .TP
@@ -100,7 +100,7 @@ the size of the images while values grea
 .TP
 \fB-no_magick\fR
 Disables the use of the ImageMagick library. This library is very useful for reading and
-writing a large number of file formats but tries to do to much sometimes, such as converting text files to
+writing a large number of file formats but tries to do too much sometimes, such as converting text files to
 images.
 .TP
 \fB-p <pointfile>\fR
@@ -170,7 +170,7 @@ Will display all images in the directory
 .SS "ADVANCED USAGE"
 
 .nf
- % imview aGreyLevelImage.tif -c heat.lut
+ % imview aGreyLevelImage.tif \-c heat.lut
 .fi
 .PP
 Will display image aGreyLevelImage.tif. Assuming this image only contains grey-level information
@@ -179,7 +179,7 @@ Will display image aGreyLevelImage.tif.
 .SS "SERVER USAGE"
 
 .nf
- % imview -server -fork
+ % imview \-server \-fork
 Port: 7600
 .fi
 .PP
@@ -207,7 +207,7 @@ Connection closed by foreign host.
 a sample client that can upload images into imview, as follows: 
 
 .nf
- % imclient -p 7600 /home/talbot/images/astro/jupiter.tiff
+ % imclient \-p 7600 /home/talbot/images/astro/jupiter.tiff
 .fi
 .SH "BUGS"
 .PP
@@ -230,7 +230,7 @@ are present.
 .SH "FILES"
 .PP
 .TP
-\fB~/.imview/preferences\fR
+\fB~/.fltk/hugues.talbot_csiro.au/imview.prefs\fR
 User preferences
 .TP
 \fB<Installation directory>/Imview/*.lut\fR
--- imview-1.1.9c.orig/io/readps.cxx
+++ imview-1.1.9c/io/readps.cxx
@@ -209,7 +209,7 @@ void psinfo::parsefile(void)
 		dbgprintf("going back to beginning and shifting the origin\n");
 		TmpFile.seekp(0, ios_base::beg);
 		TmpFile << os_translate.str() << endl;
-		dbgprintf("Writing %s at the begining\n", os_translate.str().c_str());
+		dbgprintf("Writing %s at the beginning\n", os_translate.str().c_str());
 	    }
 	}
 
--- imview-1.1.9c.orig/io/readpnm.cxx
+++ imview-1.1.9c/io/readpnm.cxx
@@ -333,7 +333,7 @@ static int load_pgm_ascii(FILE *fp,
     
     if ((*pixtype == IM_BINARY) || (*pixtype == IM_UINT1)) {
 	// get all the data
-	buffp[0] = malloc(ncol*nrow*sizeof(unsigned char));
+	buffp[0] = malloc((long)ncol*(long)nrow*sizeof(unsigned char));
 	cp = (unsigned char *)(buffp[0]);
 	for (j = 0 ; j < ncol ; j++) {
 	    for (i = 0 ; i < nrow ; i++) {
@@ -341,7 +341,7 @@ static int load_pgm_ascii(FILE *fp,
 	    }
 	}
     } else { // short
-	buffp[0] = malloc(ncol*nrow*sizeof(unsigned short));
+	buffp[0] = malloc((long)ncol*(long)nrow*sizeof(unsigned short));
 	sp = (unsigned short *)(buffp[0]);
 	for (j = 0 ; j < nrow ; j++) {
 	    for (i = 0 ; i < ncol ; i++) {
@@ -448,11 +448,11 @@ static int load_pgm_raw(FILE *fp,
     
     if ((*pixtype == IM_BINARY) || (*pixtype == IM_UINT1)) {
 	// get all the data
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
 	cp = (unsigned char *)(buffp[0]);
-	numgot = fread(cp, (size_t) 1, (size_t) nrow*ncol*nslice, fp);
+	numgot = fread(cp, (size_t) 1, (size_t) ((long)nrow*(long)ncol*(long)nslice), fp);
     } else { // unsigned short
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
 	sp = (unsigned short *)(buffp[0]);
         for (k = 0 ; k < nslice ; ++k) {
             for (j = 0 ; j < nrow ; j++) {
@@ -538,7 +538,7 @@ static int load_pbm_ascii(FILE *fp,
     buffp = (void **)malloc(sizeof(void *));
     
 	// get all the data
-    buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
+    buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
     cp = (unsigned char *)(buffp[0]);
     for (j = 0 ; j < nrow ; j++) {
 	for (i = 0 ; i < ncol ; i++) {
@@ -586,7 +586,7 @@ static int load_pbm_raw(FILE *fp,
     buffp = (void **)malloc(sizeof(void *));
     
     // get all the data
-    buffp[0] = malloc(ncol * nrow * nslice * sizeof(unsigned char));
+    buffp[0] = malloc((long)ncol * (long)nrow * (long)nslice * sizeof(unsigned char));
     cp = (unsigned char *)(buffp[0]);
 
     for (l = 0 , k = 0 ; l < nslice ; ++l) {
@@ -653,9 +653,9 @@ static int load_ppm_ascii(FILE *fp,
     
     if ((*pixtype == IM_BINARY) || (*pixtype == IM_UINT1)) {
 	// get all the data
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
-	buffp[1] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
-	buffp[2] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
+	buffp[1] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
+	buffp[2] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
 	cpR = (unsigned char *)(buffp[0]);
 	cpG = (unsigned char *)(buffp[1]);
 	cpB = (unsigned char *)(buffp[2]);
@@ -669,9 +669,9 @@ static int load_ppm_ascii(FILE *fp,
             }
         }
     } else { // short
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
-	buffp[1] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
-	buffp[2] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
+	buffp[1] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
+	buffp[2] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
 	spR = (unsigned short *)(buffp[0]);
 	spG = (unsigned short *)(buffp[1]);
 	spB = (unsigned short *)(buffp[2]);
@@ -732,8 +732,8 @@ static int load_MC_long_ppm_raw(FILE *fp
     
     // one buffer
     buffp = (void **)malloc(sizeof(void*));
-    buffp[1] = (void*) malloc(ncol*nrow*nslice*sizeof(int32_t));
-    numread = fread(buffp[1], sizeof(int32_t), ncol*nrow*nslice, fp);
+    buffp[1] = (void*) malloc((long)ncol*(long)nrow*(long)nslice*sizeof(int32_t));
+    numread = fread(buffp[1], sizeof(int32_t), (long)ncol*(long)nrow*(long)nslice, fp);
     if (numread < ncol*nrow*nslice) {
         garbage = true;
         retval = -1;   
@@ -792,9 +792,9 @@ static int load_ppm_raw(FILE *fp,
     if ((*pixtype == IM_BINARY) || (*pixtype == IM_UINT1)) {
 	// get all the data
 	// get all the data
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
-	buffp[1] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
-	buffp[2] = malloc(ncol*nrow*nslice*sizeof(unsigned char));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
+	buffp[1] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
+	buffp[2] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned char));
 	cpR = (unsigned char *)(buffp[0]);
 	cpG = (unsigned char *)(buffp[1]);
 	cpB = (unsigned char *)(buffp[2]);
@@ -808,9 +808,9 @@ static int load_ppm_raw(FILE *fp,
             }
         }
     } else { // short
-	buffp[0] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
-	buffp[1] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
-	buffp[2] = malloc(ncol*nrow*nslice*sizeof(unsigned short));
+	buffp[0] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
+	buffp[1] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
+	buffp[2] = malloc((long)ncol*(long)nrow*(long)nslice*sizeof(unsigned short));
 	spR = (unsigned short *)(buffp[0]);
 	spG = (unsigned short *)(buffp[1]);
 	spB = (unsigned short *)(buffp[2]);
--- imview-1.1.9c.orig/io/readjpeg.cxx
+++ imview-1.1.9c/io/readjpeg.cxx
@@ -199,11 +199,11 @@ KEYWORDS:
   *w = cinfo.output_width;
   *h = cinfo.output_height;
   *d = cinfo.output_components;
-  ibuffer = new unsigned char[(*w)*(*h)*(*d)];
+  ibuffer = new unsigned char[((long)*w)*((long)*h)*((long)*d)];
   rp = ibuffer;
-  while (rp < ibuffer + (*w)*(*h)*(*d)) {
+  while (rp < ibuffer + ((long)*w)*((long)*h)*((long)*d)) {
     jpeg_read_scanlines(&cinfo, &rp, 1);
-    rp += (*w)*(*d);
+    rp += ((long)*w)*((long)*d);
   }
   jpeg_finish_decompress(&cinfo);
   jpeg_destroy_decompress(&cinfo);
--- imview-1.1.9c.orig/io/readMagick.cxx
+++ imview-1.1.9c/io/readMagick.cxx
@@ -190,11 +190,11 @@ int readMagickImage(const char *name, in
 	h = p->rows;
 	if (myIsGrayImage(p,&exception)) {
 	    d = 1;
-	    outbuf = (uchar *) malloc(w*h*d*sizeof(uchar));
+	    outbuf = (uchar *) malloc((long)w*(long)h*(long)d*sizeof(uchar));
 	    myDispatchImage(p, 0, 0, w, h, "R", CharPixel, outbuf,&exception);
 	} else {
 	    d = 3;
-	    outbuf = (uchar *) malloc(w*h*d*sizeof(uchar));
+	    outbuf = (uchar *) malloc((long)w*(long)h*(long)d*sizeof(uchar));
 	    myDispatchImage(p, 0, 0, w, h, "RGB", CharPixel, outbuf, &exception);
 	}
 	// talk to the black box
--- imview-1.1.9c.orig/io/newprefio.cxx
+++ imview-1.1.9c/io/newprefio.cxx
@@ -139,7 +139,7 @@ int imprefs::readprefs(const char *)
     imPostscript.get("gspath", gspath_, "gs", DFLTSTRLEN-1);
     imPostscript.get("gvpath", gvpath_, "ghostview", DFLTSTRLEN-1);
     imPostscript.get("psRenderRes", psRenderRes_, 150.0);
-    imPostscript.get("psDiplayRes", psDisplayRes_, 75.0);
+    imPostscript.get("psDisplayRes", psDisplayRes_, 75.0);
     imPostscript.get("psRenderDepth", ival, 0);
     psRenderDepth_ = (psrendertype)ival;
     imPostscript.get("psRenderSmooth", ival, 0);
@@ -182,7 +182,7 @@ int imprefs::writeprefs(const char *)
     imPostscript.set("gspath", gspath_);
     imPostscript.set("gvpath", gvpath_);
     imPostscript.set("psRenderRes", psRenderRes_);
-    imPostscript.set("psDiplayRes", psDisplayRes_);
+    imPostscript.set("psDisplayRes", psDisplayRes_);
     imPostscript.set("psRenderDepth", (int)psRenderDepth_);
     imPostscript.set("psRenderSmooth", (int)psRenderSmooth_);
     imPostscript.set("psAntialiasRender", (int)psAntialiasRender_);
--- imview-1.1.9c.orig/io/cpostscript.cxx
+++ imview-1.1.9c/io/cpostscript.cxx
@@ -166,7 +166,7 @@ int compose_PostScript_code(HIMAGE *theI
 
     /* case of the EPS */
     if (win_type != WIN_EPS) {
-	myDebug("Standart ps code to eventually print on a page");
+	myDebug("Standard ps code to eventually print on a page");
 	/* get the actual bounds of the window */
 	ps_getWindowBounds(paperType, win_type, orientation, &boundOx, &boundOy, &boundW, &boundH);
 	/* startup */
@@ -895,7 +895,7 @@ void ps_drawRibbon(float boundOx, float
 
 
     /* variable */
-    fprintf(tbp, "\n\n%%%% Optionnal ribbon\n");
+    fprintf(tbp, "\n\n%%%% Optional ribbon\n");
     fprintf(tbp, "/nbgray 256 def\n");		/* that's a constant.. */
     fprintf(tbp, "/wherex %d def\n", xpos);
     fprintf(tbp, "/wherey %d def\n", ypos);
--- imview-1.1.9c.orig/server/interpreter.hxx
+++ imview-1.1.9c/server/interpreter.hxx
@@ -100,11 +100,11 @@ public:
 };
 
 // much-needed authentication
-class user:public action{
+class interpreter_user:public action{
     string server_user; // who is running the server now?
     // static bool   matches;
 public:
-    user(void); // constructor
+    interpreter_user(void); // constructor
     // static bool unauthenticate(void) {matches = false;}
     // static bool authenticated(void) {return matches;}
     int perform(vector<string> &l, string &result);
--- imview-1.1.9c.orig/server/interpreter.cxx
+++ imview-1.1.9c/server/interpreter.cxx
@@ -336,7 +336,7 @@ int interpreter_help::perform(vector<str
 
 //bool user::matches = false; // no one is authenticated by default
 
-user::user(void) {
+interpreter_user::interpreter_user(void) {
     // find out who is running the show
     // this is a bit flaky, but should do for now. Proper security will
     // be for later.
@@ -379,7 +379,7 @@ user::user(void) {
     return;
 }
 
-int user::perform(vector<string> &l, string &result) {
+int interpreter_user::perform(vector<string> &l, string &result) {
     ostringstream osm, osnm;
     string        fullname;
 
@@ -657,7 +657,7 @@ int put::callback(void *buf, unsigned lo
                 // saying an image has been transmitted.
                 // constructs a string from a char * label
                 const string uniqs=myheader->label;
-                srv_dbgprintf("Ok so far. Asking the GUI to please diplay img %s\n", myheader->label);
+                srv_dbgprintf("Ok so far. Asking the GUI to please display img %s\n", myheader->label);
                 IOBlackBox->pleaseDisplay(uniqs);
                 // note: we can't call the GUI directly as we are within
                 // the server's thread.
@@ -926,7 +926,7 @@ int reset::perform(vector<string> &l, st
 int close_image::perform(vector<string> &l, string &result) {
     if (mainViewer) {
         if (l.size() == 0) {
-            close_cb(0,0); // close the currently diplayed image
+            close_cb(0,0); // close the currently displayed image
             return 0;
         } else if (cmp_nocase(l[0], OVERLAY_MARKER) == 0) {
             closeoverlay_cb(0,0);
@@ -1238,7 +1238,7 @@ void imagewindowfit::set
         mainViewer->setdisplaymode(static_cast<displaymode>(maybenextmode));
         break;
     default:
-        dbgprintf("Diplay mode given (%d) is incorrect\n", maybenextmode);
+        dbgprintf("Display mode given (%d) is incorrect\n", maybenextmode);
         break; // don't change the display mode
     }
     mainMenuBar->redraw();
@@ -1439,7 +1439,7 @@ interpreter::interpreter() {
     tokens["help"]  = new interpreter_help;
     tokens["?"]     = new interpreter_help;
     tokens["pf"]    = new print_pointfile;
-    tokens["user"]  = new user;
+    tokens["user"]  = new interpreter_user;
     tokens["deny"]  = new deny;
     tokens["put"]   = new put;
     tokens["putm"]  = new putm;
--- imview-1.1.9c.orig/server/imserver.cxx
+++ imview-1.1.9c/server/imserver.cxx
@@ -230,7 +230,7 @@ void imview_server::manage_results(void)
     for (p = lc.begin(); p != lc.end() ; p++) {
         if (!(*p)->result_isempty()) {
             // send the result through the socket
-            srv_dbgprintf("sending result throught the socket\n");
+            srv_dbgprintf("sending result through the socket\n");
             (*p)->sendResult();
         }
     }
