
# HG changeset patch
# User Fojtik
# Date 1669244884 -3600
# Node ID 8865df608664d3026a17784392a8fd0f31c81ed2
# Parent  24e495529da3046d9ff84453bcb24e470c66fb94
Forged CVS or TXT could hang WP2LaTeX into endless loop - fixed.

--- wp2latex.git.orig/sources.cc/images/ras_img.cc
+++ wp2latex.git/sources.cc/images/ras_img.cc
@@ -62,7 +62,7 @@
 const char UnitName[] = "Rasters";
 
 
-#ifdef _MSC_VER  
+#ifdef _MSC_VER
   #pragma warning(disable: 4244)
 #endif
 
@@ -957,7 +957,11 @@
          Raster->SetValue2D(x,y,ReadInt(f,(char *)&ch));
        //if IOresult!=0  goto Konec;
        x++;
-       if(ch=='.') ReadInt(f,(char *)&ch);	//dummy read frac part
+       if(ch=='.')
+       {
+         ch = 0;			// Toss away decimal dot.
+         ReadInt(f,(char *)&ch);	// Dummy read frac part
+       }
        if(feof(f)) break;
        while(ch==' ') ch=fgetc(f);		//read spaces to next number
        if(ch==',')				// gobble comma that separate values
@@ -3647,13 +3651,13 @@
 	  if(isalpha(ch)) break;	//unexpected character occured
 
 	  i=ReadInt(f,&ch);
-	  if(ch=='.') ReadInt(f,&ch);	//dummy read frac part
+	  if(ch=='.') {ch=0; ReadInt(f,&ch);}	//dummy read frac part
 	  if(Raster->GetPlanes()==24)
 	    {
 	    i+=256*ReadInt(f,&ch);
-	    if(ch=='.') ReadInt(f,&ch);	//dummy read frac part
+	    if(ch=='.') {ch=0; ReadInt(f,&ch);}	//dummy read frac part
 	    i+=65536*ReadInt(f,&ch);
-	    if(ch=='.') ReadInt(f,&ch);	//dummy read frac part
+	    if(ch=='.') {ch=0; ReadInt(f,&ch);} //dummy read frac part
 	    }
 
 	  Raster->SetValue2D(x,y,i);
@@ -5162,7 +5166,11 @@
          Raster->SetValue2D(x, y, ReadInt(f,(char *)&ch));
        //if IOresult!=0  goto Konec;
        x++;
-       if(ch=='.') ReadInt(f,(char *)&ch);	//dummy read frac part
+       if(ch=='.')
+       {
+         ch = 0;
+         ReadInt(f,(char *)&ch);	//dummy read frac part
+       }
        if(feof(f)) break;
        while(ch==' ') ch=fgetc(f);	//read spaces to next number
        } while(!(ch==0 || ch==10 || ch==13 || ch==';' ||  ch>128 || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z')) );
--- wp2latex.git.orig/sources.cc/images/raster.cc
+++ wp2latex.git/sources.cc/images/raster.cc
@@ -1443,24 +1443,27 @@
 
 /* ------------ 64 bit planes DOUBLE -------------- */
 
+/// Normalises value to the range 0 - 0xFFFFFFFF.
 DWORD Raster1D_64FltBit::GetValue1D(unsigned x) const
 {
   if(x>=Size1D) return 0;
-  return((((double *)Data1D)[x] - Min)*(Max-Min));
+  return(0xFFFFFFFF*(((double *)Data1D)[x] - Min)/(Max-Min));
 }
 
+void Raster1D_64FltBit::SetValue1D(unsigned x, DWORD NewValue)
+{
+  if(x>=Size1D) return;
+  ((double *)Data1D)[x] = Min + (double)NewValue*(Max-Min)/0xFFFFFFFF;
+  return;
+}
+
+
 double Raster1D_64FltBit::GetValue1Dd(unsigned x) const
 {
   if(x>=Size1D) return 0;
   return(((double *)Data1D)[x]);
 }
 
-void Raster1D_64FltBit::SetValue1D(unsigned x, DWORD NewValue)
-{
-  if(x>=Size1D) return;
-  ((double *)Data1D)[x] = Min + (double)NewValue/(Max-Min);
-  return;
-}
 
 void Raster1D_64FltBit::SetValue1Dd(unsigned x, double NewValue)
 {
--- wp2latex.git.orig/sources.cc/images/rasterut.cc
+++ wp2latex.git/sources.cc/images/rasterut.cc
@@ -222,12 +222,14 @@
 	     DWORD b=Raster->GetValue2D(Offset1D,Offset2D);
 	     switch(Raster->GetPlanes())
 	     {
-	       case  1: b *= 0xFF; break;
-	       case  2: b *= 85; break;		// 255/3 = 85  -> 85*3=0xFF
-	       case  4: b *= 17; break;		// 255/15=17   -> 17*15=0xFF
-	       case 16: b >>= 8; break;
-	       case 24: b >>= 16; break;
-	       case 32: b >>= 24; break;
+	       case   1: b *= 0xFF; break;
+	       case   2: b *= 85; break;		// 255/3 = 85  -> 85*3=0xFF
+	       case   4: b *= 17; break;		// 255/15=17   -> 17*15=0xFF
+	       case  16: b >>= 8; break;
+	       case  24: b >>= 16; break;
+	       case  32:
+	       case -32:				// floats are normalised to the full range 0 ... 0xFFFFFFFF.
+	       case -64: b>>=24; break;
 	     }
 	     return b | 0x100*b | 0x10000*b;
 	     }
--- wp2latex.git.orig/sources.cc/wp2latex.h
+++ wp2latex.git/sources.cc/wp2latex.h
@@ -18,7 +18,7 @@
 #define LineLength   80		/* Split lines after more than LineLength charcters */
 
 #define VersionWP2L	"3.110"
-#define VersionDate	"19 Nov 2022"  /* day (space) month (space) full year */
+#define VersionDate	"23 Nov 2022"  /* day (space) month (space) full year */
 
 
 /* Constants for a flag InputPS */
