Debian Codegraph @

src/gifSave.cpp

raw symbols ◀ ▶ SCIP
3 Debian patches touch this file
1 /*
2 GIFWRAPPER!
3
4 This file is included in QuteMol project
5 as temporary hack waiting for WxWidgets to support
6 saving in GIF format (patent is now expired!)
7
8 */
9
10 #include <gif_lib.h>
11 #include <stdio.h>
•12 #include <sys/types.h>
13 #include <sys/stat.h>
14
15 #include <vector>
16
17 using namespace std;
18
19 typedef unsigned char Bytecxx . . $ Byte#;
20
21 typedef vectorcxx . . $ std/vector#<GifByteType> Framecxx . . $ Frame#;
22
23 #include "gifSave.h"cxx . . $ `<file>/src/gifSave.h`/
24
25 // global vairables
26
27
28 static vectorcxx . . $ std/vector#<Framecxx . . $ Frame#> framescxx . . $ frames.;
29 static vectorcxx . . $ std/vector#<int> delaycxx . . $ delay.;
30
31 static ColorMapObject* outputPalettecxx . . $ outputPalette.;
32
33 GifWrappercxx . . $ GifWrapper#::GifWrappercxx . . $ GifWrapper#GifWrapper(49f6e7a06ebc5aa8).(){
34 framescxx . . $ frames..clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
35 delaycxx . . $ delay..clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
36 }
37
38
39 static int gifsxcxx . . $ gifsx., gifsycxx . . $ gifsy.;
40 bool GifWrappercxx . . $ GifWrapper#::AddFramecxx . . $ GifWrapper#AddFrame(61c9b99c75d32557).(Bytecxx . . $ Byte#* data, int sx, int sy, float dt){
41
42 gifsxcxx . . $ gifsx.=sx;
43 gifsycxx . . $ gifsy.=sy;
44
45 unsigned int npix=sx*sy;
46
47
48 int paletteSize=256;
49
50
51 Framecxx . . $ Frame# outputcxx . . $ std/vector#vector(83fdeebbe0501a83).(npix);//=(Frame) malloc(npix);
52
53
54 if (framescxx . . $ frames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()==0) {
55
56
57 Framecxx . . $ Frame# rcxx . . $ std/vector#vector(83fdeebbe0501a83).(npix),gcxx . . $ std/vector#vector(83fdeebbe0501a83).(npix),bcxx . . $ std/vector#vector(83fdeebbe0501a83).(npix);
58
59 // de-interlaeve
•60 for (unsigned int i=0, j=0; i<npix; i++){
61 r[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=data[j++];
62 g[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=data[j++];
63 b[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=data[j++];
64 }
65
•66 outputPalettecxx . . $ outputPalette. = GifMakeMapObject(paletteSize, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
67 if (!outputPalettecxx . . $ outputPalette.) return false;
68
•69 if (GifQuantizeBuffer(sx, sy, &paletteSize,
70 &(r[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]),&(g[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]),&(b[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]), &(output[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]),
71 outputPalettecxx . . $ outputPalette.->Colors) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) return false;
72
73
74 } else {
75 // maunal assignment of color indices
•76 for (unsigned int i = 0, j=0; i < npix; i++) {
77 int minIndex = 0,
78 minDist = 3 * 256 * 256;
79 GifColorType *c = outputPalettecxx . . $ outputPalette.->Colors;
80
81 /* Find closest color in first color map to this color. */
82 for (int k = 0; k < outputPalettecxx . . $ outputPalette.->ColorCount; k++) {
83 int dr = (int(c[k].Red) - data[j] ) ;
84 int dg = (int(c[k].Green) - data[j+1] ) ;
85 int db = (int(c[k].Blue) - data[j+2] ) ;
86
87 int dist=dr*dr+dg*dg+db*db;
88
89 if (minDist > dist) {
90 minDist = dist;
91 minIndex = k;
92 }
93 }
94 j+=3;
95 output[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = minIndex;
96 }
97
98 }
99
100 framescxx . . $ frames..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(output);
101
102 delaycxx . . $ delay..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(int(dt*100.0));
103 return true;
104 }
105
106
107
108 bool AddLoopcxx . . $ AddLoop(efe6cffacfdecff5).(GifFileType *gf){
109
110 /* yes this was another attempt at supporting the loop extension */
111 int loop_count;
112 loop_count=0;
113 {
114 unsigned char nsle[12] = "NETSCAPE2.0";
115 unsigned char subblock[3];
116 //if (EGifPutExtension(gf, 0xFF, 11, nsle) == GIF_ERROR) {
•117 if (EGifPutExtensionLeader(gf, APPLICATION_EXT_FUNC_CODEcxx . . $ `<external>/10551564925796585759/gif_lib.h:63:9`!) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) {
118 return false;
119 }
120 if (EGifPutExtensionBlock(gf, 11, nsle) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) {
121 //gif_push_error();
122 //i_push_error(0, "writing loop extension");
123 return false;
124 }
125 subblock[0] = 1;
126 subblock[2] = loop_count % 256;
127 subblock[1] = loop_count / 256;
128 //if (EGifPutExtension(gf, 0, 3, subblock) == GIF_ERROR) {
•129 if (EGifPutExtensionTrailer(gf) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) {
130 //gif_push_error();
131 //i_push_error(0, "writing loop extention sub-block");
132 return false;
133 }
134 #if 0
135 if (EGifPutExtension(gf, 0, 0, subblock) == GIF_ERROR) {
136 gif_push_error();
137 i_push_error(0, "writing loop extension terminator");
138 return false;
139 }
140 #endif
141 }
142 return true;
143 }
144
145
146 bool GifWrappercxx . . $ GifWrapper#::Savecxx . . $ GifWrapper#Save(c5f7da30cbc0f4e9).(const char* filename){
147 if (framescxx . . $ frames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()==0) return false;
148
149
•150 GifFileType *GifFile = EGifOpenFileName(filename, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
151
152 if (!GifFile) return false;
153
154 if (EGifPutScreenDesc(
155 GifFile,
156 gifsxcxx . . $ gifsx., gifsycxx . . $ gifsy., 8, 0,
157 outputPalettecxx . . $ outputPalette.
158 ) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) return false;
159
160 if (!AddLoopcxx . . $ AddLoop(efe6cffacfdecff5).(GifFile)) return false;
161
•162 for (int ni=0; ni < (int)framescxx . . $ frames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ni++) {
163
164 static unsigned char
165 ExtStr[4] = { 0x04, 0x00, 0x00, 0xff };
166
167
168 ExtStr[0] = (false) ? 0x06 : 0x04;
169 ExtStr[1] = delaycxx . . $ delay.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).ni] % 256;
170 ExtStr[2] = delaycxx . . $ delay.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).ni] / 256;
171
172 /* Dump graphics control block. */
173 EGifPutExtension(GifFile, GRAPHICS_EXT_FUNC_CODEcxx . . $ `<external>/10551564925796585759/gif_lib.h:61:9`!, 4, ExtStr);
174
175
176 if (EGifPutImageDesc(
177 GifFile,
•178 0, 0, gifsxcxx . . $ gifsx., gifsycxx . . $ gifsy., 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!
179 ) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) return false;
180
181
182 for (int y = 0, j=(gifsycxx . . $ gifsy.-1)*gifsxcxx . . $ gifsx.; y < gifsycxx . . $ gifsy.; y++, j-=gifsxcxx . . $ gifsx.) {
183 if (EGifPutLine(GifFile, &(framescxx . . $ frames.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).ni][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j]), gifsxcxx . . $ gifsx.) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) return false;
184 }
185 }
186
•187 if (EGifCloseFile(GifFile, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) == GIF_ERRORcxx . . $ `<external>/10551564925796585759/gif_lib.h:20:9`!) return false;
188
•189 mode_t mask = umask(0);
190 umask(mask);
191 chmod(filename, mask ^ 0666);
192
193 return true;
194 }
195
196