• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revisiond133927d4930223a9c337e4d84c4a05e57946c64 (tree)
Zeit2022-11-21 18:02:03
AutorFojtik
CommiterFojtik

Log Message

Remove abundant stricmp define fix. Fix palette storing into PCX.

Ändern Zusammenfassung

Diff

diff -r 31e762a55dc6 -r d133927d4930 trunk/sources.cc/images/filehnd.cc
--- a/trunk/sources.cc/images/filehnd.cc Sun Nov 20 00:35:12 2022 +0100
+++ b/trunk/sources.cc/images/filehnd.cc Mon Nov 21 10:02:03 2022 +0100
@@ -9,16 +9,6 @@
99 #include "common.h"
1010 #include "raster.h"
1111
12-#ifndef __Have_stricmp
13- #ifdef __Have_strcasecmp
14- #define stricmp strcasecmp
15- #endif
16- #ifndef stricmp //already fixed?
17- #define stricmp strcmp
18- #endif
19-#endif
20-
21-
2212
2313 /** This class is a container for loader modules. */
2414 TImageFileHandler *TImageFileHandler::First=NULL;
@@ -109,7 +99,7 @@
10999 {
110100 if(LoadPicture_XXX->LoadPicture!=NULL)
111101 {
112- Img=LoadPicture_XXX->LoadPicture(Name);
102+ Img = LoadPicture_XXX->LoadPicture(Name);
113103 if(Img.Raster!=NULL) return(Img);
114104 }
115105 }
diff -r 31e762a55dc6 -r d133927d4930 trunk/sources.cc/images/imgsupp.cc
--- a/trunk/sources.cc/images/imgsupp.cc Sun Nov 20 00:35:12 2022 +0100
+++ b/trunk/sources.cc/images/imgsupp.cc Mon Nov 21 10:02:03 2022 +0100
@@ -309,11 +309,11 @@
309309 #else
310310 NULL,
311311 #endif
312- //#if SupportRAS_SUN>=3
313- // SavePictureRAS_SUN);
314- //#else
312+ #if SupportRAS_SUN>=3
313+ SavePictureRAS_SUN,
314+ #else
315315 NULL,
316- //#endif
316+ #endif
317317 "SUN");
318318 #endif
319319
diff -r 31e762a55dc6 -r d133927d4930 trunk/sources.cc/images/ras_img.cc
--- a/trunk/sources.cc/images/ras_img.cc Sun Nov 20 00:35:12 2022 +0100
+++ b/trunk/sources.cc/images/ras_img.cc Mon Nov 21 10:02:03 2022 +0100
@@ -550,7 +550,7 @@
550550 i--;
551551 }
552552 continue;
553- };
553+ }
554554
555555 if(x>=ldblk)
556556 continue;
@@ -564,10 +564,10 @@
564564 x+=k;
565565 i-=k;
566566 }
567- };
567+ }
568568 // if AlineProc<>nil then AlineProc^.NextLine;
569569 if(feof(f)) goto End_of_bitmap; //unexpected end
570- };
570+ }
571571 break;
572572 }
573573
@@ -592,7 +592,7 @@
592592 x+=i&0xFF;
593593 y-=(i>>8)-1;
594594 break;
595- };
595+ }
596596
597597 k=0;
598598 ldblk=0;
@@ -606,7 +606,7 @@
606606 case 1:Raster->SetValue2D(x,y,ldblk & 0xF);break;
607607 case 2:Raster->SetValue2D(x,y,ldblk >> 12);break;
608608 case 3:Raster->SetValue2D(x,y,(ldblk >> 8) & 0xF);break;
609- };
609+ }
610610 x++;
611611 i--;
612612 k=(k+1) & 3;
@@ -1091,7 +1091,7 @@
10911091 RunCount=fgetc(f);
10921092 if(feof(f)) goto Finish; /*wrong data: unexpected eof in line*/
10931093 RunCountMasked=RunCount & 0x7F;
1094- };
1094+ }
10951095 if(EncodedByte!=1) goto Finish; /*wrong data: size incorrect*/
10961096 i=0; /*guess a number of bit planes*/
10971097 if(ldblk==Header.width) i=8;
@@ -1209,7 +1209,7 @@
12091209 Img.AttachRaster(Raster);
12101210 Img.AttachPalette(Palette);
12111211 return(Img);
1212-}; /*LoadCUT*/
1212+} /*LoadCUT*/
12131213
12141214 #endif
12151215
@@ -3279,12 +3279,14 @@
32793279 t->tm_hour,t->tm_min,t->tm_sec,
32803280 t->tm_year+1900);
32813281 Header[0x7D]=1;
3282- Header[0x7E]='I';
3283- Header[0x7F]='M';
3282+ *(WORD*)(Header+0x7E) = 'I' + 256*'M'; // This will work on both endian architectures.
3283+ //Header[0x7E]='I'; Intel low endian result.
3284+ //Header[0x7F]='M';
32843285 }
32853286
32863287
3287-/**This procedure saves image data into MATLAB MAT file*/
3288+/**This procedure saves image data into MATLAB MAT file.
3289+ * Please note that MAT file is stored in native endian. */
32883290 int SavePictureMAT(const char *Name, const Image &Img)
32893291 {
32903292 FILE *f;
@@ -3300,27 +3302,27 @@
33003302 char MATLAB_HDR[184];
33013303 DWORD DataSize;
33023304
3303- DataSize=(DWORD)Img.Raster->GetSize1D() * (DWORD)Img.Raster->Size2D;
3305+ DataSize = (DWORD)Img.Raster->GetSize1D() * (DWORD)Img.Raster->Size2D;
33043306
33053307 memset(MATLAB_HDR,' ',124);
33063308 memset(MATLAB_HDR+124,0,sizeof(MATLAB_HDR)-124);
33073309
33083310 BuildMAT_TXT(MATLAB_HDR);
33093311
3310- *(DWORD *)&(MATLAB_HDR[0x80])=miMATRIX;
3311- MATLAB_HDR[0x88]=0x6;
3312- MATLAB_HDR[0x8C]=mxUINT8_CLASS;
3313- MATLAB_HDR[0x90]=0x6;
3314- MATLAB_HDR[0x98]=0x5;
3315- MATLAB_HDR[0x9C] = IsColor?12:0x8; //DimFlag
3312+ *(DWORD *)&(MATLAB_HDR[0x80]) = miMATRIX;
3313+ *(DWORD *)&(MATLAB_HDR[0x88]) = 0x6;
3314+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxUINT8_CLASS;
3315+ *(DWORD *)&(MATLAB_HDR[0x90]) = 0x6;
3316+ *(DWORD *)&(MATLAB_HDR[0x98]) = 0x5;
3317+ *(DWORD *)&(MATLAB_HDR[0x9C]) = IsColor?12:0x8; //DimFlag
33163318 *(DWORD *)&(MATLAB_HDR[0xA0])=Img.Raster->Size2D; //Rotate image 90 degs
33173319 *(DWORD *)&(MATLAB_HDR[0xA4])=Img.Raster->GetSize1D(); //Rotate image 90 degs
3318- MATLAB_HDR[0xA8]=1;
3319- MATLAB_HDR[0xAA]=1; //NameFlag
3320- MATLAB_HDR[0xAC]='M'; //matrix name
3320+ *(WORD *)&(MATLAB_HDR[0xA8]) = 1;
3321+ *(WORD *)&(MATLAB_HDR[0xAA]) = 1; //NameFlag
3322+ *(DWORD *)&(MATLAB_HDR[0xAC]) = 'M'; //matrix name
33213323 if(IsColor)
33223324 {
3323- MATLAB_HDR[0xB0]=miUINT8; //BYTE
3325+ *(DWORD *)&(MATLAB_HDR[0xB0]) = miUINT8; //BYTE
33243326 DataSize *= 3;
33253327 }
33263328 else
@@ -3330,34 +3332,34 @@
33303332 case 1:
33313333 case 2:
33323334 case 4:
3333- case 8: MATLAB_HDR[0xB0]=miUINT8;
3334- MATLAB_HDR[0x8C]=mxUINT8_CLASS;
3335+ case 8: *(DWORD *)&(MATLAB_HDR[0xB0]) = miUINT8;
3336+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxUINT8_CLASS;
33353337 break; //BYTE
3336- case 16: MATLAB_HDR[0xB0]=miUINT16;
3337- MATLAB_HDR[0x8C]=mxUINT16_CLASS;
3338+ case 16: *(DWORD *)&(MATLAB_HDR[0xB0]) = miUINT16;
3339+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxUINT16_CLASS;
33383340 DataSize *= 2;
33393341 break; //WORD
33403342 case 24:
3341- case 32: MATLAB_HDR[0xB0]=miUINT32;
3342- MATLAB_HDR[0x8C]=mxUINT32_CLASS;
3343+ case 32: *(DWORD *)&(MATLAB_HDR[0xB0]) = miUINT32;
3344+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxUINT32_CLASS;
33433345 DataSize *= 4;
33443346 break; //DWORD
3345- case -32:MATLAB_HDR[0xB0]=miSINGLE;
3346- MATLAB_HDR[0x8C]=mxSINGLE_CLASS;
3347+ case -32:*(DWORD *)&(MATLAB_HDR[0xB0]) = miSINGLE;
3348+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxSINGLE_CLASS;
33473349 DataSize *= 4;
33483350 break;
3349- case -64:MATLAB_HDR[0xB0]=miDOUBLE;
3350- MATLAB_HDR[0x8C]=mxDOUBLE_CLASS;
3351+ case -64:*(DWORD *)&(MATLAB_HDR[0xB0]) = miDOUBLE;
3352+ *(DWORD *)&(MATLAB_HDR[0x8C]) = mxDOUBLE_CLASS;
33513353 DataSize *= 8;
33523354 break;
33533355 default: goto FINISH;
33543356 }
33553357 }
33563358
3357- padding=((BYTE)(DataSize-1) & 0x7) ^ 0x7;
3359+ padding = ((BYTE)(DataSize-1) & 0x7) ^ 0x7;
33583360 *(DWORD *)&(MATLAB_HDR[0x84]) = DataSize + 56l + (DWORD)padding;
33593361
3360- *(DWORD *)&(MATLAB_HDR[0xB4])=DataSize;
3362+ *(DWORD *)&(MATLAB_HDR[0xB4]) = DataSize;
33613363
33623364 unsigned ix;
33633365 if(IsColor)
@@ -3389,7 +3391,7 @@
33893391 {
33903392 fwrite(MATLAB_HDR,1,sizeof(MATLAB_HDR),f);
33913393
3392- switch(MATLAB_HDR[0xB0])
3394+ switch(*(DWORD*)&(MATLAB_HDR[0xB0]))
33933395 {
33943396 case miUINT8:
33953397 {
@@ -3743,6 +3745,9 @@
37433745
37443746 //-----------------------PCX------------------------------
37453747 #ifdef SupportPCX
3748+
3749+// http://fileformats.archiveteam.org/wiki/PCX
3750+
37463751 struct RGBColor
37473752 {
37483753 BYTE Red,Green,Blue;
@@ -3849,7 +3854,7 @@
38493854 {
38503855 Cnt=C & 0x3F;
38513856 fread(&C,1,1,f);
3852- };
3857+ }
38533858 RestOfLast:
38543859 while(Cnt>0)
38553860 {
@@ -3876,7 +3881,7 @@
38763881 }
38773882 if((Header.BitPerPix==8)&&(Raster->GetPlanes()==24))
38783883 { /*RGB image*/
3879-// if not aplane in [1,2,3] asm int 3; };
3884+// if not aplane in [1,2,3] asm int 3; }
38803885 Raster->GetRowRaster(Y)->Join8Bit(data,Raster->GetPlanes()-8*Aplane);
38813886 }
38823887 }
@@ -3950,7 +3955,7 @@
39503955 const int Mask=0xC0;
39513956 const int MaxCnt=63;
39523957 FILE *F;
3953-WORD X,Y,OC,C,Cnt;
3958+WORD X,Y,Cnt;
39543959 PCXHeader PCXFile;
39553960 BYTE *data;
39563961 BYTE *ptrb;
@@ -3959,6 +3964,7 @@
39593964 BYTE Aplane;
39603965 APalette *Palette=NULL;
39613966 int k;
3967+BYTE C, OC;
39623968
39633969 if(Img.Raster==NULL) return(-10);
39643970
@@ -3982,14 +3988,14 @@
39823988 case 1:if(Img.Palette!=NULL && Img.Palette->Size1D>=2)
39833989 {
39843990 PCXFile.NumPlanes = 2; // Palette cannot be displayed in 1 plane bilevel mode, add a dummy plane.
3985- C = 3*2;
3991+ C = 2;
39863992 goto InternalPalette;
39873993 }
39883994 PCXFile.BytesPerLine = (PCXFile.BytesPerLine+7) >> 3;
39893995 break;
3990- case 2:C = 3*4;
3996+ case 2:C = 4;
39913997 goto InternalPalette;
3992- case 4:C = 3*16;
3998+ case 4:C = 16;
39933999 InternalPalette:
39944000 bbuf=(BYTE *)malloc((Img.Raster->GetSize1D()+7) >> 3);
39954001 PCXFile.BytesPerLine=(PCXFile.BytesPerLine+7) >> 3;
@@ -3999,16 +4005,25 @@
39994005 Palette = BuildPalette(1<<Img.Raster->GetPlanes(),8);
40004006 PCXFile.PaletteInfo = 2;
40014007 }
4002- memcpy(&PCXFile.ColorMap,Palette->Data1D,C); // TODO: This is wrong!
4008+ while(C-->0)
4009+ {
4010+ PCXFile.ColorMap[C].Red = Palette->R(C);
4011+ PCXFile.ColorMap[C].Green = Palette->G(C);
4012+ PCXFile.ColorMap[C].Blue = Palette->B(C);
4013+ }
40034014 if(Palette!=Img.Palette) delete Palette;
40044015 Palette=NULL;
40054016 break;
40064017 case 8:PCXFile.BitPerPix = 8;
40074018 PCXFile.NumPlanes = 1;
40084019 break;
4009- case 24:PCXFile.BitPerPix = 8;
4020+ case 24:PCXFile.BitPerPix = 8; // RGB format
40104021 PCXFile.NumPlanes = 3;
4011- bbuf=(BYTE *)malloc(Img.Raster->GetSize1D());
4022+ bbuf = (BYTE *)malloc(Img.Raster->GetSize1D());
4023+ break;
4024+ case 32:PCXFile.BitPerPix = 8; // RGBA format
4025+ PCXFile.NumPlanes = 4;
4026+ bbuf = (BYTE *)malloc(Img.Raster->GetSize1D());
40124027 break;
40134028 default:return(-2);
40144029 }
@@ -4065,7 +4080,7 @@
40654080 }
40664081 data[datapos]=OC;
40674082 datapos++;
4068- Cnt=0;
4083+ Cnt = 0;
40694084 }
40704085 fwrite(data,datapos,1,F);
40714086 }
@@ -4091,9 +4106,9 @@
40914106 k = Palette->GetPlanes()/3 - 8;
40924107 if(k<0) k = 0;
40934108
4094- fputc(12,F); //{paleta}
4095-
4096- for(X=0;X<=255;X++)
4109+ fputc(12,F); // palette
4110+
4111+ for(X=0; X<=255; X++)
40974112 {
40984113 fputc(Palette->R(X)>>k,F); //Red;
40994114 fputc(Palette->G(X)>>k,F); //Green;
@@ -4118,7 +4133,7 @@
41184133 //-------------------------RAS-TopoL-----------------------
41194134 #ifdef SupportRAS
41204135
4121-struct RasHeader
4136+struct TopolRasHeader
41224137 {
41234138 char Name[20];
41244139 SWORD Rows;
@@ -4154,7 +4169,9 @@
41544169 };
41554170
41564171
4157-inline long LoadTopolHeader(FILE *f, RasHeader &SU)
4172+#if SupportRAS>=4 || SupportRAS==2
4173+
4174+inline long LoadTopolHeader(FILE *f, TopolRasHeader &SU)
41584175 {
41594176 #if defined(__PackedStructures__)
41604177 return(fread(&SU,1,sizeof(SU),f));
@@ -4168,20 +4185,19 @@
41684185 #endif
41694186 }
41704187
4171-#if SupportRAS>=4 || SupportRAS==2
41724188 Image LoadPictureRAS(const char *Name)
41734189 {
41744190 FILE *f;
41754191 WORD Ldblk;
41764192 WORD j,i,k;
4177-RasHeader Header;
4193+TopolRasHeader Header;
41784194 Image Img;
41794195 Raster2DAbstract *Raster=NULL;
41804196 APalette *Palette=NULL;
41814197 char *NameBuffer=NULL;
41824198 DWORD *Offsets=NULL;
4183-WORD TilesAcross,TilesDown;
4184-WORD TilX,TilY;
4199+WORD TilesAcross, TilesDown;
4200+WORD TilX, TilY;
41854201
41864202 if((f=fopen(Name,"rb"))==NULL) return(Img);
41874203
@@ -4193,7 +4209,7 @@
41934209 if(Header.Name[i]<' ') goto FINISH;
41944210 }
41954211 if(Header.Komprese!=0) goto FINISH;
4196- if(Header.Rows==0 || Header.Cols==0 ) goto FINISH;
4212+ if(Header.Rows<=0 || Header.Cols<=0 ) goto FINISH;
41974213 if(Header.Verze>2) goto FINISH; //unknown version
41984214
41994215 switch(Header.TypSou)
@@ -4359,24 +4375,38 @@
43594375 }
43604376 MezFail:
43614377
4362-
43634378 FINISH:
43644379 if(f) fclose(f);
43654380 if(NameBuffer) {free(NameBuffer);NameBuffer=NULL;}
43664381 Img.AttachRaster(Raster);
4367- Img.AttachPalette(Palette);
4382+ Img.AttachPalette(Palette);
43684383 return(Img);
43694384 }
43704385 #endif
43714386
43724387
43734388 #if SupportRAS>=3
4389+
4390+inline long SaveTopolHeader(FILE *f, TopolRasHeader &SU)
4391+{
4392+#if defined(__PackedStructures__)
4393+ return(fwrite(&SU,1,sizeof(SU),f));
4394+#else
4395+ return(savestruct(f,"a20wwwdwwwqqqqqwwddba423",
4396+ SU.Name,SU.Rows,SU.Cols,SU.TypSou,SU.Zoom,SU.Verze,
4397+ SU.Komprese,SU.Stav,
4398+ SU.xRasMin,SU.yRasMin,SU.xRasMax,SU.yRasMax,SU.Scale, //from release 2
4399+ SU.TileWidth,SU.TileHeight,SU.TileOffsets,SU.TileByteCounts,
4400+ SU.TileCompression,SU.Dummy));
4401+#endif
4402+}
4403+
43744404 int SavePictureRAS(const char *Name,const Image &Img)
43754405 {
43764406 FILE *f;
43774407 WORD Ldblk;
43784408 WORD i;
4379-RasHeader Header;
4409+TopolRasHeader Header;
43804410 paletteRAS pal;
43814411 char *PalName=NULL;
43824412
@@ -4384,8 +4414,8 @@
43844414
43854415 memset(&Header,0,sizeof(Header));
43864416 memset(&Header.Name,' ',sizeof(Header.Name));
4387- Header.Cols=Img.Raster->GetSize1D();
4388- Header.Rows=Img.Raster->Size2D;
4417+ Header.Cols = Img.Raster->GetSize1D();
4418+ Header.Rows = Img.Raster->Size2D;
43894419 switch(Img.Raster->GetPlanes())
43904420 {
43914421 case 1:Header.TypSou=0;
@@ -4405,10 +4435,10 @@
44054435
44064436 if((f=fopen(Name,"wb"))==NULL) return(-1);
44074437
4408- fwrite(&Header,sizeof(Header),1,f);
4409-
4410- fseek(f,0x200,SEEK_SET);
4411- Ldblk=((long)Img.Raster->GetPlanes()*Img.Raster->GetSize1D()+7) / 8;
4438+ i = SaveTopolHeader(f,Header);
4439+ if(i!=512) {fclose(f);return -3;}
4440+
4441+ Ldblk = ((long)Img.Raster->GetPlanes()*Img.Raster->GetSize1D()+7) / 8;
44124442 for(i=0;i<Header.Rows;i++)
44134443 {
44144444 fwrite(Img.Raster->GetRow(i),Ldblk,1,f);
@@ -4432,10 +4462,10 @@
44324462 }
44334463 free(PalName);
44344464
4435- i=(1 << Img.Raster->GetPlanes())-1;
4465+ i = (1 << Img.Raster->GetPlanes())-1;
44364466 fputc(i,f);
44374467
4438- for(i=0;i<(1 << Img.Raster->GetPlanes());i++)
4468+ for(i=0; i<(1 << Img.Raster->GetPlanes()); i++)
44394469 {
44404470 pal.Flag=i;
44414471 pal.Red= Img.Palette->R(i); //Red;
@@ -4458,14 +4488,30 @@
44584488 //-------------------------RAS-SUN-------------------------
44594489 #ifdef SupportRAS_SUN
44604490
4491+// https://www.fileformat.info/format/sunraster/egff.htm
4492+
4493+// Raster type:
4494+//0000h Old
4495+//0001h Standard
4496+//0002h Byte-encoded
4497+//0003h RGB format
4498+//0004h TIFF format
4499+//0005h IFF format
4500+//FFFFh Experimental
4501+
4502+// Color map type:
4503+//0000h No color map
4504+//0001h RGB color map
4505+//0002h Raw color map
4506+
44614507 struct SUNRASHeader
44624508 {
4463- DWORD ras_magic;
4464- DWORD ras_width;
4465- DWORD ras_height;
4466- DWORD ras_depth;
4467- DWORD ras_length;
4468- DWORD ras_type;
4509+ DWORD ras_magic; ///< Magic (identification) number.
4510+ DWORD ras_width; ///< Width of image in pixels.
4511+ DWORD ras_height; ///< Height of image in pixels.
4512+ DWORD ras_depth; ///< Number of bits per pixel.
4513+ DWORD ras_length; ///< Size of image data in bytes.
4514+ DWORD ras_type; ///< Type of raster file
44694515 DWORD ras_maptype;
44704516 DWORD ras_maplength;
44714517 };
@@ -4488,8 +4534,7 @@
44884534 Image LoadPictureRAS_SUN(const char *Name)
44894535 {
44904536 FILE *f;
4491-WORD Ldblk;
4492-WORD k,w,i;
4537+WORD w,i;
44934538 SUNRASHeader Header;
44944539 Image Img;
44954540 Raster2DAbstract *Raster=NULL;
@@ -4506,51 +4551,129 @@
45064551 goto FINISH; //incorrect identifier
45074552 }
45084553
4509- Raster=CreateRaster2D(Header.ras_width,Header.ras_height,Header.ras_depth);
4554+ Raster = CreateRaster2D(Header.ras_width,Header.ras_height,Header.ras_depth);
45104555 if(Raster==NULL) goto FINISH;
4511-//if(AlineProc!=NULL) AlineProc^.InitPassing(p.y,'Loading SUNRAS');
4556+ //if(AlineProc!=NULL) AlineProc^.InitPassing(p.y,'Loading SUNRAS');
45124557
45134558 if(Header.ras_maptype!=0 && Header.ras_maplength!=0)
45144559 {
4515- Palette=BuildPalette(1<<Header.ras_depth,8);
4516- w=(Header.ras_maplength / 3) - 1;
4517- if( w < (1<<Header.ras_depth) )
4560+ Palette = BuildPalette(1<<Header.ras_depth,8);
4561+ w = (Header.ras_maplength / 3) - 1;
4562+ if(w < (1<<Header.ras_depth) )
45184563 {
45194564 for(i=0;i<=w;i++) Palette->R(i,fgetc(f)); //Red
45204565 for(i=0;i<=w;i++) Palette->G(i,fgetc(f)); //Green
45214566 for(i=0;i<=w;i++) Palette->B(i,fgetc(f)); //Blue
4522- };
4567+ }
45234568 if(GrayPalette(Palette,Raster->GetPlanes()))
4524- {
4525- delete Palette;
4526- Palette=NULL;
4527- }
4569+ {
4570+ delete Palette;
4571+ Palette=NULL;
4572+ }
45284573
45294574 fseek(f,sizeof(Header)+Header.ras_maplength,SEEK_SET);
4530- };
4531-
4532- Ldblk=((long)Header.ras_depth*Header.ras_width+7) / 8;
4533- k=(-Ldblk) & 1;
4534- for(i=0;i<Header.ras_height;i++)
4535- {
4536- if(fread(Raster->GetRow(i),Ldblk,1,f)!=1) goto FINISH;
4537- if(i<Header.ras_height-1) fseek(f,k,SEEK_CUR); //docteni do konce radku
4575+ }
4576+
4577+ {
4578+ const long Ldblk = ((long)Header.ras_depth*Header.ras_width+7) / 8;
4579+ const char Padding = (-Ldblk) & 1;
4580+ for(i=0; i<Header.ras_height; i++)
4581+ {
4582+ if(fread(Raster->GetRow(i),Ldblk,1,f)!=1) goto FINISH;
4583+ if(Header.ras_depth==24 && Header.ras_type!=3)
4584+ RGB_BGR((char *)Raster->GetRow(i),Raster->GetSize1D());
4585+
4586+ if(i<Header.ras_height-1 && Padding>0)
4587+ fseek(f,Padding,SEEK_CUR); //docteni do konce radku
45384588 //if InOutRes!=0 then goto KONEC;
45394589 //if AlineProc!=NULL then AlineProc^.NextLine;
4540- }
4541-
4542- if(Header.ras_depth==24)
4543- for(i=0;i<Raster->Size2D;i++)
4544- RGB_BGR((char *)Raster->GetRow(i),Raster->GetSize1D());
4590+ }
4591+ }
45454592
45464593 FINISH:
45474594 fclose(f);
45484595 Img.AttachRaster(Raster);
4549- Img.AttachPalette(Palette);
4596+ Img.AttachPalette(Palette);
45504597 return(Img);
45514598 }
45524599 #endif
45534600
4601+
4602+#if SupportRAS_SUN>=3
4603+#endif
4604+
4605+inline long SaveSUNRASHeader(FILE *f, SUNRASHeader &SU)
4606+{
4607+#if defined(__PackedStructures__)
4608+ return(fwrite(&SU,1,sizeof(SU),f));
4609+#else
4610+ return(savestruct(f,"DDDDDDDD",
4611+ SU.ras_magic, SU.ras_width, SU.ras_height,
4612+ SU.ras_depth, SU.ras_length, SU.ras_type,
4613+ SU.ras_maptype, SU.ras_maplength));
4614+#endif
4615+}
4616+
4617+int SavePictureRAS_SUN(const char *Name, const Image &Img)
4618+{
4619+SUNRASHeader Header;
4620+FILE *f;
4621+long Ldblk;
4622+char padding;
4623+int i;
4624+int Result = 0;
4625+
4626+ if(Img.Raster==NULL) return(-10);
4627+
4628+ if((f=fopen(Name,"wb"))==NULL) return(-1);
4629+
4630+ Header.ras_magic = 0x59A66A95;
4631+ Header.ras_width = Img.Raster->Size1D;
4632+ Header.ras_height = Img.Raster->Size2D;
4633+ Header.ras_depth = labs(Img.Raster->GetPlanes());
4634+
4635+ Ldblk = ((long)Header.ras_depth*Header.ras_width+7) / 8;
4636+ padding = (-Ldblk) & 1;
4637+
4638+ Header.ras_length = Header.ras_height * (padding + Ldblk);
4639+ Header.ras_type = 0001; // Standard
4640+ if(Img.Palette!=NULL && Img.Palette->GetSize1D()>0)
4641+ {
4642+ Header.ras_maptype = 1;
4643+ Header.ras_maplength = 3*Img.Palette->GetSize1D();
4644+ }
4645+ else
4646+ {
4647+ Header.ras_maptype = 0;
4648+ Header.ras_maplength = 0;
4649+ }
4650+ if(SaveSUNRASHeader(f,Header) != 32)
4651+ {Result=-1; goto FINISH;}
4652+
4653+ if(Header.ras_maptype!=0 && Header.ras_maplength!=0)
4654+ {
4655+ for(i=0; i<Img.Palette->GetSize1D(); i++) fputc(Img.Palette->R(i),f);
4656+ for(i=0; i<Img.Palette->GetSize1D(); i++) fputc(Img.Palette->G(i),f);
4657+ for(i=0; i<Img.Palette->GetSize1D(); i++) fputc(Img.Palette->B(i),f);
4658+ }
4659+
4660+ for(i=0; i<Header.ras_height; i++)
4661+ {
4662+ if(Header.ras_depth==24)
4663+ RGB_BGR((char *)Img.Raster->GetRow(i),Img.Raster->GetSize1D());
4664+ Result = fwrite(Img.Raster->GetRow(i),Ldblk,1,f);
4665+ if(Header.ras_depth==24)
4666+ RGB_BGR((char *)Img.Raster->GetRow(i),Img.Raster->GetSize1D());
4667+ if(Result!=1) {Result=-2; goto FINISH;}
4668+ if(padding>0) fwrite(&padding,1,1, f);
4669+ }
4670+ Result = 0;
4671+
4672+FINISH:
4673+ fclose(f);
4674+return Result;
4675+}
4676+
45544677 #endif
45554678 //-----------------End of RAS-SUN routines---------------
45564679
@@ -4643,7 +4766,7 @@
46434766 if((f=fopen(Name,"rb"))==NULL) return(Img);
46444767 // Pbuf.Init;
46454768 // p.Erase;
4646- if(fread(&Header,2,1,f)!=1) {fclose(f);return(Img);};
4769+ if(fread(&Header,2,1,f)!=1) {fclose(f);return(Img);}
46474770
46484771 RdWORD_TIFF=NULL;RdDWORD_TIFF=NULL;
46494772 if(Header.CharId[0]=='I' && Header.CharId[1]=='I')
@@ -6612,7 +6735,7 @@
66126735 {
66136736 fread(&bbuf,1,1,f);
66146737 InsertByte(bbuf);
6615- };
6738+ }
66166739 }
66176740 else { // repeat previous line runcount*
66186741 fread(&RunCount,1,1,f);
Show on old repository browser