• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revision3918dc4cb9e4a7abbeb555dad8d18dfc93bf2aff (tree)
Time2022-11-12 07:14:06
AuthorFojtik
CommiterFojtik

Log Message

Fix deffect in EPS reader; do not consume too much bytes (full HDU) on stack for FITS reader.

Change Summary

Incremental Difference

diff -r 2761052e2643 -r 3918dc4cb9e4 trunk/sources.cc/images/ras_img.cc
--- a/trunk/sources.cc/images/ras_img.cc Wed Nov 09 12:13:19 2022 +0100
+++ b/trunk/sources.cc/images/ras_img.cc Fri Nov 11 23:14:06 2022 +0100
@@ -816,7 +816,7 @@
816816 ConvertMe->Set(*CurrImg->Raster->GetRowRaster(i));
817817 fwrite(ConvertMe->Data1D,ldblk,1,f);
818818 }
819- else
819+ else // Direct support.
820820 {
821821 if(StoredPlanes==24) RGB_BGR((char *)CurrImg->Raster->GetRow(i),CurrImg->Raster->GetSize1D());
822822 fwrite(CurrImg->Raster->GetRow(i),ldblk,1,f);
@@ -1289,11 +1289,11 @@
12891289 {
12901290 if(!strcmp(a,"/cmap"))
12911291 {
1292- i=ftell(F);
1293- planes=ReadInt(F,&ch);
1294- if(planes>0 && planes<=256)
1292+ i = ftell(F);
1293+ planes = ReadInt(F,&ch);
1294+ if(planes>0 && planes/3<=256)
12951295 {
1296- Palette=BuildPalette(planes/3,8);
1296+ Palette = BuildPalette(planes/3,8);
12971297 }
12981298 fseek(F,i,SEEK_SET);
12991299 }
@@ -2002,7 +2002,7 @@
20022002 /** This procedure process one separate fits file. */
20032003 Image LoadPictureFITS(const char *Name)
20042004 {
2005-char HDU[36][80];
2005+char HDU_LINE[80];
20062006 char identifier[80];
20072007 char value[80];
20082008 char comment[80];
@@ -2030,21 +2030,20 @@
20302030 memset(Axes,0,sizeof(Axes));
20312031 // memset(&attr,0,sizeof(attr));
20322032 Naxis = 0;
2033- memset(HDU,0,sizeof(HDU));
2033+ memset(HDU_LINE,0,sizeof(HDU_LINE));
20342034
20352035 while(!feof(F))
2036+ {
2037+ for(int i=0; i<36; i++) // Parse separate rows in HDU.
20362038 {
2037- if(fread(HDU,sizeof(HDU),1,F)!=1)
2038- break;
2039-
2040- for(int i=0; i<36; i++) // parse separate rows
2041- {
2039+ if(fread(HDU_LINE,sizeof(HDU_LINE)-1,1,F) != 1) goto ExitPoint;
2040+
20422041 *identifier = *value = *comment = 0;
20432042 // parse identifier
20442043 pos=0; j=0;
20452044 while(j<sizeof(identifier)-1)
20462045 {
2047- c = HDU[i][j++];
2046+ c = HDU_LINE[j++];
20482047 if(isspace((unsigned char)c)) continue;
20492048 if(c=='=') break;
20502049 if(c=='/') goto COMMENT;
@@ -2057,7 +2056,7 @@
20572056 pos = 0;
20582057 while(j<80)
20592058 {
2060- c = HDU[i][j++];
2059+ c = HDU_LINE[j++];
20612060 if(isspace((unsigned char)c) && *value==0) continue;
20622061 if(c=='/') break;
20632062 value[pos++] = c;
@@ -2074,7 +2073,7 @@
20742073 pos = 0;
20752074 while(j<80)
20762075 {
2077- c = HDU[i][j++];
2076+ c = HDU_LINE[j++];
20782077 if(isspace((unsigned char)c) && *comment==0) continue;
20792078 comment[pos++] = c;
20802079 comment[pos] = 0;
@@ -2173,14 +2172,14 @@
21732172
21742173 if(Naxis==2)
21752174 {
2176- Raster=CreateRaster2D(Axes[0],Axes[1],BitPix);
2175+ Raster = CreateRaster2D(Axes[0],Axes[1],BitPix);
21772176 if(Raster==NULL) goto ExitPoint;
21782177
21792178 ldblk = (labs(Raster->GetPlanes())*Raster->GetSize1D()+7)/8;
21802179 for(j=0; j<Raster->Size2D; j++)
21812180 {
21822181 if(fread(Raster->GetRow(Raster->Size2D-j-1),ldblk,1,F)!=1) {goto ExitPoint;}
2183- if(Endian == 1) //!!! chyba !!!
2182+ if(Endian == 1) // Error, this works on low endian architecture only.
21842183 {
21852184 switch(BitPix)
21862185 {
@@ -2190,6 +2189,8 @@
21902189 case 32: FixSignedMSBValues((BYTE*)Raster->GetRow(Raster->Size2D-j-1), Raster->GetSize1D(), 4);
21912190 case -32: swab32((BYTE*)Raster->GetRow(Raster->Size2D-j-1),Raster->GetSize1D());
21922191 break;
2192+ case 16: swab16((BYTE*)Raster->GetRow(Raster->Size2D-j-1),Raster->GetSize1D());
2193+ break;
21932194 }
21942195 }
21952196 else
@@ -2202,6 +2203,19 @@
22022203
22032204 // AlineProc(j,p);
22042205 }
2206+ } else if(Naxis==3)
2207+ {
2208+ if(Axes[0]==3 && (BitPix==8 || BitPix==16)) // This is considered as RGB.
2209+ {
2210+ Raster = CreateRaster2DRGB(Axes[1],Axes[2],BitPix);
2211+ if(Raster==NULL) goto ExitPoint;
2212+
2213+ ldblk = (labs(Raster->GetPlanes())*Raster->GetSize1D()+7)/8;
2214+ for(j=0; j<Raster->Size2D; j++)
2215+ {
2216+ if(fread(Raster->GetRow(Raster->Size2D-j-1),ldblk,1,F)!=1) {goto ExitPoint;}
2217+ }
2218+ }
22052219 }
22062220
22072221 Img.AttachRaster(Raster);
@@ -2252,6 +2266,7 @@
22522266 FILE *f;
22532267 char HDU[36][80];
22542268 char depth;
2269+char channels;
22552270 Raster1DAbstract *RPixels = NULL;
22562271 unsigned ldblk;
22572272 unsigned y;
@@ -2261,11 +2276,19 @@
22612276 /* Open output image file. */
22622277 if((f=fopen(Name,"wb"))==NULL) return(-1);
22632278
2264- if(Img.Raster->GetPlanes() > 8)
2279+ channels = 1;
2280+ depth = Img.Raster->GetPlanes();
2281+
2282+ if(depth > 8)
22652283 {
2266- if(Img.Raster->GetPlanes() > 16)
2284+ if(depth > 16)
22672285 {
2268- if(Img.Raster->GetPlanes() > 32)
2286+ if(Img.Raster->Channels()==3 && depth==24)
2287+ {
2288+ depth = 8;
2289+ channels = 3;
2290+ }
2291+ else if(depth > 32)
22692292 depth=64;
22702293 else
22712294 depth=32;
@@ -2276,7 +2299,7 @@
22762299 else
22772300 depth=8;
22782301
2279- ldblk = Img.Raster->GetSize1D() * (depth/8);
2302+ ldblk = Img.Raster->GetSize1D() * ((depth*channels)/8);
22802303 switch(Img.Raster->GetPlanes())
22812304 {
22822305 case -64:ldblk = Img.Raster->GetSize1D()*8; depth=-64; break;
@@ -2284,7 +2307,9 @@
22842307 case 8: break;
22852308 case 16: break;
22862309 case 32: break;
2287- case 64: break; // no pixels intermediate buffer needed
2310+ case 64: break; // no pixels intermediate buffer needed
2311+ case 24: if(channels==3) break;
2312+ // fallback, use conversion for 24bit gray
22882313 default: RPixels = CreateRaster1D(Img.Raster->GetSize1D(), depth);
22892314 if(RPixels->Data1D==NULL) goto FINISH;
22902315 }
@@ -2294,14 +2319,28 @@
22942319 InsertRowHDU(HDU[0], "SIMPLE = T");
22952320 y = sprintf(HDU[1], "BITPIX = %d", (int)depth);
22962321 HDU[1][y] = ' ';
2297- InsertRowHDU(HDU[2], "NAXIS = 2");
2298- y = sprintf(HDU[3], "NAXIS1 = %10lu",(unsigned long)Img.Raster->GetSize1D());
2299- HDU[3][y] = ' ';
2300- y = sprintf(HDU[4], "NAXIS2 = %10lu",(unsigned long)Img.Raster->Size2D);
2301- HDU[4][y] = ' ';
2322+ if(channels>1)
2323+ {
2324+ InsertRowHDU(HDU[2], "NAXIS = 3");
2325+ y = sprintf(HDU[3], "NAXIS1 = %u", (unsigned long)channels);
2326+ HDU[3][y] = ' ';
2327+ y = sprintf(HDU[4], "NAXIS2 = %10lu",(unsigned long)Img.Raster->GetSize1D());
2328+ HDU[4][y] = ' ';
2329+ y = sprintf(HDU[5], "NAXIS3 = %10lu",(unsigned long)Img.Raster->Size2D);
2330+ HDU[5][y] = ' ';
2331+ }
2332+ else
2333+ {
2334+ InsertRowHDU(HDU[2], "NAXIS = 2");
2335+ y = sprintf(HDU[3], "NAXIS1 = %10lu",(unsigned long)Img.Raster->GetSize1D());
2336+ HDU[3][y] = ' ';
2337+ y = sprintf(HDU[4], "NAXIS2 = %10lu",(unsigned long)Img.Raster->Size2D);
2338+ HDU[4][y] = ' ';
2339+ }
23022340
23032341 {
23042342 int row = 5;
2343+ if(channels>1) row=6;
23052344
23062345 if(Img.Raster->GetPlanes()<0)
23072346 {
@@ -2328,7 +2367,7 @@
23282367 if(depth==64)
23292368 y = sprintf(HDU[row], "DATAMAX = 9223372036854775807"); // "DATAMAX = %19llu",0x7FFFFFFFFFFFFFFFll);
23302369 else
2331- y = sprintf(HDU[row], "DATAMAX = %10lu",(unsigned long)1<<Img.Raster->GetPlanes());
2370+ y = sprintf(HDU[row], "DATAMAX = %10lu",(unsigned long)1<<(Img.Raster->GetPlanes()/channels));
23322371
23332372 HDU[row++][y] = ' ';
23342373 }
@@ -2361,9 +2400,9 @@
23612400 swab32((BYTE *)Img.Raster->GetRow(y), Img.Raster->GetSize1D());
23622401 if(depth==32)
23632402 FixSignedMSBValues((BYTE *)Img.Raster->GetRow(y), Img.Raster->GetSize1D(), 4);
2364-
2403+
23652404 fwrite(Img.Raster->GetRow(y),ldblk,1,f);
2366-
2405+
23672406 if(depth==64)
23682407 FixSignedMSBValues((BYTE *)Img.Raster->GetRow(y), Img.Raster->GetSize1D(), 8);
23692408 if(depth==-64 || depth==64)
diff -r 2761052e2643 -r 3918dc4cb9e4 trunk/sources.cc/wp2latex.h
--- a/trunk/sources.cc/wp2latex.h Wed Nov 09 12:13:19 2022 +0100
+++ b/trunk/sources.cc/wp2latex.h Fri Nov 11 23:14:06 2022 +0100
@@ -17,8 +17,8 @@
1717
1818 #define LineLength 80 /* Split lines after more than LineLength charcters */
1919
20-#define VersionWP2L "3.110"
21-#define VersionDate "7 Nov 2022" /* day (space) month (space) full year */
20+#define VersionWP2L "3.pre111"
21+#define VersionDate "11 Nov 2022" /* day (space) month (space) full year */
2222
2323
2424 /* Constants for a flag InputPS */
Show on old repository browser