• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revision96c1066d71ed05d083a9dbabe61c838c36d2462c (tree)
Zeit2022-09-27 07:46:17
AutorFojtik
CommiterFojtik

Log Message

Load and save multiple frames from BMP file.

Ändern Zusammenfassung

Diff

diff -r 4b83b8979d13 -r 96c1066d71ed trunk/sources.cc/images/ras_img.cc
--- a/trunk/sources.cc/images/ras_img.cc Fri Sep 23 09:08:27 2022 +0200
+++ b/trunk/sources.cc/images/ras_img.cc Tue Sep 27 00:46:17 2022 +0200
@@ -536,13 +536,14 @@
536536 #endif
537537 }
538538
539-void LoadBmpStream(Image &Img,FILE *f, DWORD Header_bfOffBits);
539+void LoadBmpStream(Image &Img, FILE *f, DWORD Header_bfOffBits);
540540
541541 Image LoadPictureBMP(const char *Name)
542542 {
543543 Image Img;
544544 FILE *f;
545545 BMPHeader Header;
546+Image *CurrImg = &Img;
546547
547548 if((f=fopen(Name,"rb"))==NULL) return(Img);
548549
@@ -551,6 +552,18 @@
551552
552553 LoadBmpStream(Img,f,Header.bfOffBits);
553554
555+ while(!feof(f))
556+ {
557+ long FilePos = ftell(f);
558+ if(LoadBmpHeader(f,Header)!=14) break;
559+ if((Header.bfType[0]!='B')||(Header.bfType[1]!='M')) break;
560+
561+ while(CurrImg->Next != NULL) CurrImg=CurrImg->Next; // Seek to the end of chain.
562+ CurrImg->Next = new Image;
563+ CurrImg = CurrImg->Next;
564+ LoadBmpStream(*CurrImg, f, FilePos+Header.bfOffBits);
565+ }
566+
554567 ENDPROC:
555568 fclose(f);
556569 return(Img);
@@ -558,7 +571,7 @@
558571
559572
560573 /** This procedure loads BMP without a header. It is usefull e.g. for reading WMF.*/
561-void LoadBmpStream(Image &Img,FILE *f, DWORD Header_bfOffBits)
574+void LoadBmpStream(Image &Img, FILE *f, DWORD Header_bfOffBits)
562575 {
563576 WORD ldblk;
564577 unsigned i;
@@ -849,7 +862,7 @@
849862 }
850863
851864
852-int SavePictureBMP(const char *Name,const Image &Img)
865+int SavePictureBMP(const char *Name, const Image &Img)
853866 {
854867 FILE *f;
855868 unsigned ldblk;
@@ -860,121 +873,129 @@
860873 BMP_RGBQuad PalItem;
861874 char StoredPlanes;
862875 Raster1DAbstract *ConvertMe=NULL;
876+long StartFramePos=0;
877+const Image *CurrImg=&Img;
863878
864879 if(Img.Raster==NULL) return(-10);
865880
866881 if((f=fopen(Name,"wb"))==NULL) return(-1);
867882
868- StoredPlanes = Img.Raster->GetPlanes();
869- if(StoredPlanes==2) // BMP does not support 2 planes - provide conversion.
883+ do
870884 {
871- StoredPlanes = 4;
872- if(Img.ImageType()==ImageGray)
873- CreateRaster1D(Img.Raster->GetSize1D(), StoredPlanes);
874- else
885+ StoredPlanes = CurrImg->Raster->GetPlanes();
886+ if(StoredPlanes==2) // BMP does not support 2 planes - provide conversion.
875887 {
876- ConvertMe = new Raster1D_4BitIDX;
877- ConvertMe->Allocate1D(Img.Raster->GetSize1D());
878- }
879- }
880- else if(Img.ImageType()==ImageGray)
881- {
882- if(StoredPlanes==32) //StoredPlanes==16 ||
883- {
884- StoredPlanes = 8; //32 bit Gray images needs to be scalled
885- ConvertMe = CreateRaster1D(Img.Raster->GetSize1D(), StoredPlanes);
886- }
887- }
888-
889- if(Img.ImageType()==ImageTrueColor)
890- {
891- if(StoredPlanes==32 || StoredPlanes==64)
888+ StoredPlanes = 4;
889+ if(CurrImg->ImageType()==ImageGray)
890+ CreateRaster1D(CurrImg->Raster->GetSize1D(), StoredPlanes);
891+ else
892892 {
893- StoredPlanes = 24;
894- ConvertMe = CreateRaster1DRGB(Img.Raster->GetSize1D(),8);
893+ ConvertMe = new Raster1D_4BitIDX;
894+ ConvertMe->Allocate1D(CurrImg->Raster->GetSize1D());
895895 }
896896 }
897-
898- ldblk = (StoredPlanes*Img.Raster->GetSize1D()+7)/8;
899-
900- memset(&Header,0,sizeof(Header));
901- memmove(&Header.bfType,"BM",2);
897+ else if(CurrImg->ImageType()==ImageGray)
898+ {
899+ if(StoredPlanes==32) //StoredPlanes==16 ||
900+ {
901+ StoredPlanes = 8; //32 bit Gray images needs to be scalled
902+ ConvertMe = CreateRaster1D(CurrImg->Raster->GetSize1D(), StoredPlanes);
903+ }
904+ }
905+
906+ if(CurrImg->ImageType()==ImageTrueColor)
907+ {
908+ if(StoredPlanes==32 || StoredPlanes==64)
909+ {
910+ StoredPlanes = 24;
911+ ConvertMe = CreateRaster1DRGB(CurrImg->Raster->GetSize1D(),8);
912+ }
913+ }
914+
915+ ldblk = (StoredPlanes*CurrImg->Raster->GetSize1D()+7)/8;
916+
917+ memset(&Header,0,sizeof(Header));
918+ memmove(&Header.bfType,"BM",2);
902919 #if defined(__PackedStructures__)
903- Header.bfOffBits = sizeof(Header)+sizeof(Info);
920+ Header.bfOffBits = sizeof(Header)+sizeof(Info);
904921 #else
905- Header.bfOffBits = 14 + 40;
922+ Header.bfOffBits = 14 + 40;
906923 #endif
907- if (StoredPlanes==4 || StoredPlanes==8)
908- Header.bfOffBits+=(1 << (StoredPlanes + 2));
909- Header.bfSize = Header.bfOffBits + Img.Raster->Size2D*((ldblk+3) & 0xFFFC);
910-
911- memset(&Info,0,sizeof(Info));
912- Info.BIH.biSize = 40;
913- Info.BIH.biWidth = Img.Raster->GetSize1D();
914- Info.BIH.biHeight = Img.Raster->Size2D;
915- Info.BIH.biPlanes = 1;
916- Info.BIH.biBitCount = StoredPlanes;
917- Info.BIH.biCompression = 0; //I don't allow compression
918- Info.BIH.biSizeImage = Header.bfSize-Header.bfOffBits;
919- if(StoredPlanes==4 || StoredPlanes==8) Info.BIH.biClrUsed=1 << (StoredPlanes);
920-
921- SaveBmpHeader(f,Header);
922- SaveBmpInfHdr(f,Info.BIH);
923-
924- if((StoredPlanes==4)||(StoredPlanes==8))
925- { //palette
924+ if (StoredPlanes==4 || StoredPlanes==8)
925+ Header.bfOffBits+=(1 << (StoredPlanes + 2));
926+ Header.bfSize = Header.bfOffBits + CurrImg->Raster->Size2D*((ldblk+3) & 0xFFFC);
927+
928+ memset(&Info,0,sizeof(Info));
929+ Info.BIH.biSize = 40;
930+ Info.BIH.biWidth = CurrImg->Raster->GetSize1D();
931+ Info.BIH.biHeight = CurrImg->Raster->Size2D;
932+ Info.BIH.biPlanes = 1;
933+ Info.BIH.biBitCount = StoredPlanes;
934+ Info.BIH.biCompression = 0; //I don't allow compression
935+ Info.BIH.biSizeImage = Header.bfSize-Header.bfOffBits;
936+ if(StoredPlanes==4 || StoredPlanes==8) Info.BIH.biClrUsed=1 << (StoredPlanes);
937+
938+ SaveBmpHeader(f,Header);
939+ SaveBmpInfHdr(f,Info.BIH);
940+
941+ if((StoredPlanes==4)||(StoredPlanes==8))
942+ { //palette
926943 // gray=p.palette==NULL;
927944 // if(gray) CreatePalette(p.palette,p.planes);
928- PalItem.rgbReserved=0;
929-
930- if(Img.Palette==NULL)
931- {
932- k=1;
933- if(StoredPlanes==4) k=16;
934- for(i=0;i<(1 << StoredPlanes) /*p.palette^.Colors-1*/ ;i++)
935- {
945+ PalItem.rgbReserved=0;
946+
947+ if(CurrImg->Palette==NULL)
948+ {
949+ k = 1;
950+ if(StoredPlanes==4) k=16;
951+ for(i=0;i<(1 << StoredPlanes) /*p.palette^.Colors-1*/ ;i++)
952+ {
936953 PalItem.rgbRed= k*i; // p.palette^.pal[K].Red;
937954 PalItem.rgbGreen=k*i; // p.palette^.pal[K].Green;
938955 PalItem.rgbBlue=k*i; // p.palette^.pal[K].Blue;
939956 fwrite(&PalItem,sizeof(PalItem),1,f);
940- }
957+ }
941958 // if Gray then ErasePalette(p.palette);
942- }
943- else
944- {
945- k=Img.Palette->GetPlanes()/3-8;
959+ }
960+ else
961+ {
962+ k=CurrImg->Palette->GetPlanes()/3-8;
946963 if(k<0) k=0;
947964 for(i=0;i<(1 << StoredPlanes) /*p.palette^.Colors-1*/ ;i++)
948965 {
949- PalItem.rgbRed = Img.Palette->R(i)>>k; // p.palette^.pal[K].Red;
950- PalItem.rgbGreen = Img.Palette->G(i)>>k;// p.palette^.pal[K].Green;
951- PalItem.rgbBlue = Img.Palette->B(i)>>k; // p.palette^.pal[K].Blue;
966+ PalItem.rgbRed = CurrImg->Palette->R(i)>>k; // p.palette^.pal[K].Red;
967+ PalItem.rgbGreen = CurrImg->Palette->G(i)>>k;// p.palette^.pal[K].Green;
968+ PalItem.rgbBlue = CurrImg->Palette->B(i)>>k; // p.palette^.pal[K].Blue;
952969 fwrite(&PalItem,sizeof(PalItem),1,f);
953970 }
954- }
955- }
956-
957- fseek(f,Header.bfOffBits,SEEK_SET);
958- k=(-(int)ldblk)& 3;
959- for(i=Img.Raster->Size2D-1; i>=0; i--)
960- {
961- if(ConvertMe!=NULL)
971+ }
972+ }
973+
974+ fseek(f, StartFramePos+Header.bfOffBits, SEEK_SET);
975+ k = (-(int)ldblk)& 3;
976+ for(i=CurrImg->Raster->Size2D-1; i>=0; i--)
977+ {
978+ if(ConvertMe!=NULL)
962979 {
963- ConvertMe->Set(*Img.Raster->GetRowRaster(i));
980+ ConvertMe->Set(*CurrImg->Raster->GetRowRaster(i));
964981 fwrite(ConvertMe->Data1D,ldblk,1,f);
965982 }
966- else
983+ else
967984 {
968- if(StoredPlanes==24) RGB_BGR((char *)Img.Raster->GetRow(i),Img.Raster->GetSize1D());
969- fwrite(Img.Raster->GetRow(i),ldblk,1,f);
970- if(StoredPlanes==24) RGB_BGR((char *)Img.Raster->GetRow(i),Img.Raster->GetSize1D());
985+ if(StoredPlanes==24) RGB_BGR((char *)CurrImg->Raster->GetRow(i),CurrImg->Raster->GetSize1D());
986+ fwrite(CurrImg->Raster->GetRow(i),ldblk,1,f);
987+ if(StoredPlanes==24) RGB_BGR((char *)CurrImg->Raster->GetRow(i),CurrImg->Raster->GetSize1D());
971988 }
972- fwrite(&Header.bfReserved1,k,1,f); //write zeroes to end of line
989+ fwrite(&Header.bfReserved1,k,1,f); //write zeroes to end of line
973990 // AlineProc(i,p);
974- }
991+ }
992+ if(ConvertMe) {delete(ConvertMe);ConvertMe=NULL;}
993+
994+ CurrImg = CurrImg->Next;
995+ StartFramePos = ftell(f);
996+ } while(CurrImg!=NULL);
975997
976998 fclose(f);
977- if(ConvertMe) {delete(ConvertMe);ConvertMe=NULL;}
978999 return(0);
9791000 }
9801001 #endif
@@ -6324,63 +6345,69 @@
63246345 int SavePictureTXTgm(const char *Name, const Image &Img)
63256346 {
63266347 FILE *f;
6327-WORD i,j;
6348+WORD i, j;
63286349 DWORD pix;
63296350 BYTE *Buffer24Bit;
6351+const Image *CurrImg;
63306352
63316353 if(Img.Raster==NULL) return(-10);
63326354
6333- Buffer24Bit = (BYTE*)calloc(Img.Raster->GetSize1D(),3);
6334- if(Buffer24Bit==NULL) return(-11);
6335-
6336- if((f=fopen(Name,"wt"))==NULL)
6337- {
6338- free(Buffer24Bit);
6339- return(-1);
6340- }
6355+ if((f=fopen(Name,"wt"))==NULL) return(-1);
63416356 //if AlineProc<>nil AlineProc^.InitPassing(p.y*p.planes,'Saving TXT gm');
63426357
6343- for(i=0;i<Img.Raster->Size2D;i++)
6358+ CurrImg = &Img;
6359+
6360+ do
6361+ {
6362+ if(CurrImg->Raster!=NULL)
63446363 {
6345- if((Img.ImageType() & 0xFF00) == ImagePalette)
6364+ Buffer24Bit = (BYTE*)calloc(CurrImg->Raster->GetSize1D(),3);
6365+ if(Buffer24Bit==NULL) break;
6366+
6367+ for(i=0; i<CurrImg->Raster->Size2D; i++)
63466368 {
6347- for(j=0;j<Img.Raster->GetSize1D();j++)
6369+ if((CurrImg->ImageType() & 0xFF00) == ImagePalette)
6370+ {
6371+ for(j=0;j<CurrImg->Raster->GetSize1D();j++)
63486372 { //0,0: (175,160,148) #865F58
6349- pix = Img.Raster->GetValue2D(j,i);
6350- pix = Img.Palette->GetValue1D(pix);
6351- fprintf(f,"%u,%u: (%d,%d,%d) #%6.6lX\n", j, i,
6373+ pix = CurrImg->Raster->GetValue2D(j,i);
6374+ pix = CurrImg->Palette->GetValue1D(pix);
6375+ fprintf(f,"%u,%u: (%d,%d,%d) #%6.6lX\n", j, i,
63526376 (int)(pix & 0xFF), (int)((pix>>8)&0xFF), (int)(pix>>16), (long)pix);
63536377 }
6354- }
6355- else
6356- {
6357- if(Img.Raster->GetPlanes()>8 && Img.Raster->GetPlanes()<=16)
6378+ }
6379+ else
6380+ {
6381+ if(CurrImg->Raster->GetPlanes()>8 && CurrImg->Raster->GetPlanes()<=16)
63586382 { /* Slow 16 bit processing. */
6359- for(j=0;j<Img.Raster->GetSize1D();j++)
6383+ for(j=0;j<CurrImg->Raster->GetSize1D();j++)
63606384 { //0,0: (175,160,148) #86005F005800
6361- pix = Img.Raster->GetValue2D(j,i);
6362- fprintf(f,"%u,%u: (%u,%u,%u) #%4X%4X%4X\n", j, i,
6363- pix, pix, pix,
6364- pix, pix, pix);
6385+ pix = CurrImg->Raster->GetValue2D(j,i);
6386+ fprintf(f,"%u,%u: (%u,%u,%u) #%4X%4X%4X\n", j, i,
6387+ pix, pix, pix,
6388+ pix, pix, pix);
63656389 }
63666390 }
6367- else
6391+ else
63686392 {
6369- Img.Raster->GetRowRaster(i)->Get24BitRGB(Buffer24Bit);
6370- for(j=0;j<Img.Raster->GetSize1D();j++)
6393+ CurrImg->Raster->GetRowRaster(i)->Get24BitRGB(Buffer24Bit);
6394+ for(j=0;j<CurrImg->Raster->GetSize1D();j++)
63716395 { //0,0: (175,160,148) #865F58
6372- fprintf(f,"%u,%u: (%u,%u,%u) #%2X%2X%2X\n", j, i,
6373- Buffer24Bit[3*j], Buffer24Bit[3*j+1], Buffer24Bit[3*j+2],
6374- Buffer24Bit[3*j], Buffer24Bit[3*j+1], Buffer24Bit[3*j+2] );
6375- }
6396+ fprintf(f,"%u,%u: (%u,%u,%u) #%2X%2X%2X\n", j, i,
6397+ Buffer24Bit[3*j], Buffer24Bit[3*j+1], Buffer24Bit[3*j+2],
6398+ Buffer24Bit[3*j], Buffer24Bit[3*j+1], Buffer24Bit[3*j+2] );
6399+ }
63766400 }
6377- }
6378-
6379- fprintf(f,"\n");
6380- //if AlineProc<>nil then AlineProc^.NextLine;
6401+ }
6402+
6403+ fprintf(f,"\n");
6404+ //if AlineProc<>nil then AlineProc^.NextLine;
6405+ }
63816406 }
63826407
6383- if(Buffer24Bit!=NULL) {free(Buffer24Bit);Buffer24Bit=NULL;}
6408+ if(Buffer24Bit!=NULL) {free(Buffer24Bit);Buffer24Bit=NULL;}
6409+ CurrImg = CurrImg->Next;
6410+ } while (CurrImg!=NULL);
63846411
63856412 fclose(f);
63866413 return(0);
diff -r 4b83b8979d13 -r 96c1066d71ed trunk/sources.cc/wp2latex.h
--- a/trunk/sources.cc/wp2latex.h Fri Sep 23 09:08:27 2022 +0200
+++ b/trunk/sources.cc/wp2latex.h Tue Sep 27 00:46:17 2022 +0200
@@ -18,7 +18,7 @@
1818 #define LineLength 80 /* Split lines after more than LineLength charcters */
1919
2020 #define VersionWP2L "3.pre109"
21-#define VersionDate "18 Sep 2022" /* day (space) month (space) full year */
21+#define VersionDate "23 Sep 2022" /* day (space) month (space) full year */
2222
2323
2424 /* Constants for a flag InputPS */
Show on old repository browser