Stefan Schuermans commited on 2016-12-18 21:02:47
Showing 1 changed files, with 33 additions and 9 deletions.
... | ... |
@@ -200,7 +200,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename) |
200 | 200 |
{ |
201 | 201 |
GifFileType *gif; |
202 | 202 |
int frameCnt, height, width, channels, maxval, channels_new, maxval_new, |
203 |
- colors, r, g, b, i, frame, y, x, c, y1, x1, y2, x2, v, ret; |
|
203 |
+ r, g, b, i, frame, y, x, c, y1, x1, y2, x2, v, ret; |
|
204 | 204 |
unsigned int delay; |
205 | 205 |
stBlinkenMovie *pOutMovie; |
206 | 206 |
stBlinkenFrame *pFrame, *pLast; |
... | ... |
@@ -223,10 +223,10 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename) |
223 | 223 |
else |
224 | 224 |
channels_new = channels; |
225 | 225 |
switch (channels) { |
226 |
- case 1: maxval_new = 255; colors = 256; break; |
|
227 |
- case 2: maxval_new = 15; colors = 256; break; |
|
228 |
- case 3: maxval_new = 5; colors = 216; break; |
|
229 |
- default: maxval_new = 255; colors = 255; break; |
|
226 |
+ case 1: maxval_new = 255; break; |
|
227 |
+ case 2: maxval_new = 15; break; |
|
228 |
+ case 3: maxval_new = 5; break; |
|
229 |
+ default: maxval_new = 255; break; |
|
230 | 230 |
} |
231 | 231 |
pOutMovie = BlinkenMovieClone(pMovie); |
232 | 232 |
if (pOutMovie == NULL) |
... | ... |
@@ -247,7 +247,7 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename) |
247 | 247 |
// set global GIF config |
248 | 248 |
gif->SWidth = width; |
249 | 249 |
gif->SHeight = height; |
250 |
- gif->SColorResolution = colors; |
|
250 |
+ gif->SColorResolution = 256; |
|
251 | 251 |
gif->SBackGroundColor = 0; |
252 | 252 |
gif->SColorMap = NULL; |
253 | 253 |
gif->ImageCount = frameCnt; |
... | ... |
@@ -266,15 +266,39 @@ int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename) |
266 | 266 |
BlinkenMovieFree(pOutMovie); |
267 | 267 |
return -1; // error |
268 | 268 |
} |
269 |
- for (b = 0, i = 0; b <= maxval && i < colors; ++b) { |
|
270 |
- for (g = 0; g <= maxval && i < colors; ++g) { |
|
271 |
- for (r = 0; r <= maxval && i < colors; ++r, ++i) { |
|
269 |
+ i = 0; |
|
270 |
+ switch (channels) { |
|
271 |
+ case 1: |
|
272 |
+ for (r = 0; r <= maxval; ++r) { |
|
273 |
+ gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval; |
|
274 |
+ gif->SColorMap->Colors[i].Green = gif->SColorMap->Colors[i].Red; |
|
275 |
+ gif->SColorMap->Colors[i].Blue = gif->SColorMap->Colors[i].Red; |
|
276 |
+ ++i; |
|
277 |
+ } |
|
278 |
+ break; |
|
279 |
+ case 2: |
|
280 |
+ for (g = 0; g <= maxval; ++g) { |
|
281 |
+ for (r = 0; r <= maxval; ++r) { |
|
282 |
+ gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval; |
|
283 |
+ gif->SColorMap->Colors[i].Green = ((int)g * 255 + maxval / 2) / maxval; |
|
284 |
+ gif->SColorMap->Colors[i].Blue = gif->SColorMap->Colors[i].Green; |
|
285 |
+ ++i; |
|
286 |
+ } |
|
287 |
+ } |
|
288 |
+ break; |
|
289 |
+ case 3: |
|
290 |
+ for (b = 0; b <= maxval; ++b) { |
|
291 |
+ for (g = 0; g <= maxval; ++g) { |
|
292 |
+ for (r = 0; r <= maxval; ++r) { |
|
272 | 293 |
gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval; |
273 | 294 |
gif->SColorMap->Colors[i].Green = ((int)g * 255 + maxval / 2) / maxval; |
274 | 295 |
gif->SColorMap->Colors[i].Blue = ((int)b * 255 + maxval / 2) / maxval; |
296 |
+ ++i; |
|
275 | 297 |
} |
276 | 298 |
} |
277 | 299 |
} |
300 |
+ break; |
|
301 |
+ } // switch channels |
|
278 | 302 |
for (; i < 256; ++i) { |
279 | 303 |
gif->SColorMap->Colors[i].Red = 0; |
280 | 304 |
gif->SColorMap->Colors[i].Green = 0; |
281 | 305 |