• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revision6ba0b40636f799ca2eb852bdc208a47ce86ae1e1 (tree)
Time2022-11-16 08:07:30
AuthorFojtik
CommiterFojtik

Log Message

Create local palette when GIF has multiple scenes.

Change Summary

Incremental Difference

diff -r 5624f407b2f4 -r 6ba0b40636f7 trunk/sources.cc/images/ras_gif.cc
--- a/trunk/sources.cc/images/ras_gif.cc Tue Nov 15 09:24:06 2022 +0100
+++ b/trunk/sources.cc/images/ras_gif.cc Wed Nov 16 00:07:30 2022 +0100
@@ -28,6 +28,8 @@
2828 #include "struct.h"
2929
3030
31+// https://tronche.com/computer-graphics/gif/gif89a.html
32+
3133 //--------------------------GIF---------------------------
3234 #ifdef SupportGIF
3335
@@ -42,7 +44,7 @@
4244 typedef struct
4345 {
4446 WORD Left, Top, Width, Height;
45- BYTE Flag;
47+ BYTE Flag; //Local Color Table Flag 1 Bit; Interlace Flag 1 Bit; Sort Flag 1 Bit; Reserved 2 Bits; Size of Local Color Table 3 Bits
4648 } TypeGIFImageDescriptor;
4749
4850
@@ -297,7 +299,7 @@
297299 }
298300 break;
299301
300- case 0x2C:
302+ case 0x2C:
301303 if(LoadGIFImageDescriptor(f,GIFImageDescriptor)!=9) goto FINISH;
302304 Interlace = -1;
303305 if((GIFImageDescriptor.Flag & 64)>0) Interlace=0;
@@ -492,17 +494,17 @@
492494 if(GlobPalette) NumColors = GlobPalette->Size1D;
493495
494496 WORD GlobalColorTableSize;
495- BYTE GlobalColorTableFlag;
497+ //BYTE GlobalColorTableFlag;
496498 if(NumColors>0)
497499 {
498500 NumColors = 1 << BitsNeeded(NumColors);
499501 GlobalColorTableSize = BitsNeeded(NumColors) - 1;
500- GlobalColorTableFlag = 1;
502+ //GlobalColorTableFlag = 1;
501503 }
502504 else
503505 {
504506 GlobalColorTableSize = 0;
505- GlobalColorTableFlag = 0;
507+ //GlobalColorTableFlag = 0;
506508 }
507509
508510 BYTE Flag = (Img.Raster->GetPlanes() << 4) |
@@ -524,7 +526,7 @@
524526 else
525527 {
526528 fwrite(GlobPalette->Data1D,3,GlobPalette->Size1D,f);
527- for(int i=GlobPalette->Size1D; i<GlobalColorTableSize; i++)
529+ for(int i=GlobPalette->Size1D; i<GlobalColorTableSize; i++) // feed rest of palette with zeros.
528530 {
529531 fputc(0, f);
530532 fputc(0, f);
@@ -969,6 +971,7 @@
969971 TypeGIFImageDescriptor ID;
970972 const Image *CurrentImage;
971973 APalette *GlobPalette = NULL;
974+bool NeedLocalPalette = false;
972975
973976 if(Img.Raster==NULL) return(-10);
974977 if(Img.Raster->GetPlanes()>8) return(-11);
@@ -980,7 +983,7 @@
980983 if(Img.Palette!=NULL)
981984 {
982985 GlobPalette = Img.Palette;
983- GlobPalette->UsageCount++;
986+ GlobPalette->UsageCount++;
984987 }
985988 else
986989 {
@@ -992,6 +995,8 @@
992995 }
993996 }
994997 }
998+ else
999+ NeedLocalPalette = true;
9951000
9961001 /* Write GIF signature */
9971002 int ret = StoreGIFHeader(f,Img,GlobPalette);
@@ -1020,8 +1025,54 @@
10201025 ID.Top = 0;
10211026 ID.Width = CurrentImage->Raster->Size1D;
10221027 ID.Height = CurrentImage->Raster->Size2D;
1023- ID.Flag = 0;
1028+ ID.Flag = 0;
1029+ if(NeedLocalPalette)
1030+ {
1031+ WORD NumColors = 1 << Img.Raster->GetPlanes();
1032+ GlobPalette = Img.Palette;
1033+ if(GlobPalette!=NULL)
1034+ {
1035+ GlobPalette->UsageCount++;
1036+ }
1037+ else
1038+ {
1039+ GlobPalette = BuildPalette(NumColors, 8);
1040+ if(GlobPalette)
1041+ {
1042+ GlobPalette->UsageCount++;
1043+ FillGray(GlobPalette);
1044+ }
1045+ }
1046+ WORD LocalColorTableSize;
1047+ if(NumColors>0)
1048+ {
1049+ NumColors = 1 << BitsNeeded(NumColors);
1050+ LocalColorTableSize = BitsNeeded(NumColors) - 1;
1051+ }
1052+ else
1053+ LocalColorTableSize = 0;
1054+ if(GlobPalette)
1055+ ID.Flag = 0x80 | (LocalColorTableSize & 0x7);
1056+ }
10241057 SaveGIFImageDescriptor(f,ID);
1058+ if((ID.Flag & 0x80)>0) /*Local Color Map*/
1059+ {
1060+ WORD LocalColorTableSize = (unsigned)2 << (ID.Flag & 7);
1061+ if(GlobPalette->Size1D >= LocalColorTableSize)
1062+ fwrite(GlobPalette->Data1D,3,LocalColorTableSize,f);
1063+ else
1064+ {
1065+ fwrite(GlobPalette->Data1D,3,GlobPalette->Size1D,f);
1066+ for(int i=GlobPalette->Size1D; i<LocalColorTableSize; i++) // feed rest of palette with zeros.
1067+ {
1068+ fputc(0, f);
1069+ fputc(0, f);
1070+ fputc(0, f);
1071+ }
1072+ }
1073+ if(GlobPalette->UsageCount-- <= 1) delete GlobPalette;
1074+ GlobPalette = NULL;
1075+ }
10251076
10261077 WbitStream GIF_Writer(f,CurrentImage->Raster);
10271078 GIF_Writer.codesize = CurrentImage->Raster->GetPlanes();
@@ -1031,7 +1082,7 @@
10311082 GIF_Writer.LZW_Compress();
10321083
10331084 /* Write terminating 0-byte */
1034- fputc(0,f);
1085+ fputc(0,f);
10351086
10361087 CurrentImage = CurrentImage->Next;
10371088 } while(CurrentImage != NULL);
diff -r 5624f407b2f4 -r 6ba0b40636f7 trunk/sources.cc/wp2latex.h
--- a/trunk/sources.cc/wp2latex.h Tue Nov 15 09:24:06 2022 +0100
+++ b/trunk/sources.cc/wp2latex.h Wed Nov 16 00:07:30 2022 +0100
@@ -18,7 +18,7 @@
1818 #define LineLength 80 /* Split lines after more than LineLength charcters */
1919
2020 #define VersionWP2L "3.pre111"
21-#define VersionDate "12 Nov 2022" /* day (space) month (space) full year */
21+#define VersionDate "15 Nov 2022" /* day (space) month (space) full year */
2222
2323
2424 /* Constants for a flag InputPS */
Show on old repository browser