~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/gfli/fli.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
18
 *
19
19
 */
20
 
 
 
20
 
21
21
/*
22
22
 * This code can be used to read and write FLI movies. It is currently
23
23
 * only used for the GIMP fli plug-in, but it can be used for other
24
24
 * programs, too.
25
25
 */
26
 
 
 
26
 
 
27
#include "config.h"
 
28
 
 
29
#include <string.h>
27
30
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#include <string.h>
30
31
 
31
32
#include "fli.h"
32
33
 
160
161
                        if (chunk.size & 1) chunk.size++;
161
162
                        fseek(f,chunkpos+chunk.size,SEEK_SET);
162
163
                }
163
 
        } /* else: unknown, skip */ 
 
164
        } /* else: unknown, skip */
164
165
        fseek(f, framepos+fli_frame.size, SEEK_SET);
165
166
}
166
167
 
180
181
        fli_frame.magic=FRAME;
181
182
        fli_frame.chunks=0;
182
183
 
183
 
        /* 
184
 
         * create color chunk 
 
184
        /*
 
185
         * create color chunk
185
186
         */
186
187
        if (fli_header->magic == HEADER_FLI) {
187
188
                if (fli_write_color(f, fli_header, old_cmap, cmap)) fli_frame.chunks++;
208
209
                fli_write_lc(f, fli_header, old_framebuf, framebuf);
209
210
        }
210
211
        fli_frame.chunks++;
211
 
        
 
212
 
212
213
        frameend=ftell(f);
213
214
        fli_frame.size=frameend-framepos;
214
215
        fseek(f, framepos, SEEK_SET);
254
255
{
255
256
        unsigned long chunkpos;
256
257
        unsigned short num_packets;
257
 
        s_fli_chunk chunk; 
 
258
        s_fli_chunk chunk;
258
259
        chunkpos=ftell(f);
259
260
        fseek(f, chunkpos+8, SEEK_SET);
260
261
        num_packets=0;
270
271
                unsigned short num_packets, cnt_skip, cnt_col, col_pos, col_start;
271
272
                num_packets=0; col_pos=0;
272
273
                do {
273
 
                        cnt_skip=0; 
 
274
                        cnt_skip=0;
274
275
                        while ((col_pos<256) && (old_cmap[col_pos*3+0]==cmap[col_pos*3+0]) && (old_cmap[col_pos*3+1]==cmap[col_pos*3+1]) && (old_cmap[col_pos*3+2]==cmap[col_pos*3+2])) {
275
276
                                cnt_skip++; col_pos++;
276
277
                        }
277
278
                        col_start=col_pos;
278
 
                        cnt_col=0; 
 
279
                        cnt_col=0;
279
280
                        while ((col_pos<256) && !((old_cmap[col_pos*3+0]==cmap[col_pos*3+0]) && (old_cmap[col_pos*3+1]==cmap[col_pos*3+1]) && (old_cmap[col_pos*3+2]==cmap[col_pos*3+2]))) {
280
281
                                cnt_col++; col_pos++;
281
282
                        }
327
328
                                cmap[col_pos]=fli_read_char(f);
328
329
                        }
329
330
                        return;
330
 
                } 
 
331
                }
331
332
                for (col_cnt=skip_col; (col_cnt>0) && (col_pos<768); col_cnt--) {
332
333
                        cmap[col_pos]=old_cmap[col_pos];col_pos++;
333
334
                        cmap[col_pos]=old_cmap[col_pos];col_pos++;
334
335
                        cmap[col_pos]=old_cmap[col_pos];col_pos++;
335
336
                }
336
337
                for (col_cnt=num_col; (col_cnt>0) && (col_pos<768); col_cnt--) {
337
 
                        cmap[col_pos++]=fli_read_char(f);                               
 
338
                        cmap[col_pos++]=fli_read_char(f);
338
339
                        cmap[col_pos++]=fli_read_char(f);
339
340
                        cmap[col_pos++]=fli_read_char(f);
340
341
                }
345
346
{
346
347
        unsigned long chunkpos;
347
348
        unsigned short num_packets;
348
 
        s_fli_chunk chunk; 
 
349
        s_fli_chunk chunk;
349
350
        chunkpos=ftell(f);
350
351
        fseek(f, chunkpos+8, SEEK_SET);
351
352
        num_packets=0;
361
362
                unsigned short num_packets, cnt_skip, cnt_col, col_pos, col_start;
362
363
                num_packets=0; col_pos=0;
363
364
                do {
364
 
                        cnt_skip=0; 
 
365
                        cnt_skip=0;
365
366
                        while ((col_pos<256) && (old_cmap[col_pos*3+0]==cmap[col_pos*3+0]) && (old_cmap[col_pos*3+1]==cmap[col_pos*3+1]) && (old_cmap[col_pos*3+2]==cmap[col_pos*3+2])) {
366
367
                                cnt_skip++; col_pos++;
367
368
                        }
368
369
                        col_start=col_pos;
369
 
                        cnt_col=0; 
 
370
                        cnt_col=0;
370
371
                        while ((col_pos<256) && !((old_cmap[col_pos*3+0]==cmap[col_pos*3+0]) && (old_cmap[col_pos*3+1]==cmap[col_pos*3+1]) && (old_cmap[col_pos*3+2]==cmap[col_pos*3+2]))) {
371
372
                                cnt_col++; col_pos++;
372
373
                        }
410
411
 
411
412
void fli_write_black(FILE *f, s_fli_header *fli_header, unsigned char *framebuf)
412
413
{
413
 
        s_fli_chunk chunk; 
 
414
        s_fli_chunk chunk;
414
415
 
415
416
        chunk.size=6;
416
417
        chunk.magic=FLI_BLACK;
429
430
 
430
431
void fli_write_copy(FILE *f, s_fli_header *fli_header, unsigned char *framebuf)
431
432
{
432
 
        
 
433
 
433
434
        unsigned long chunkpos;
434
 
        s_fli_chunk chunk; 
 
435
        s_fli_chunk chunk;
435
436
        chunkpos=ftell(f);
436
437
        fseek(f, chunkpos+6, SEEK_SET);
437
438
        fwrite(framebuf, fli_header->width, fli_header->height, f);
441
442
        fseek(f, chunkpos, SEEK_SET);
442
443
        fli_write_long(f, chunk.size);
443
444
        fli_write_short(f, chunk.magic);
444
 
        
 
445
 
445
446
        if (chunk.size & 1) chunk.size++;
446
447
        fseek(f,chunkpos+chunk.size,SEEK_SET);
447
448
}
462
463
                        unsigned short ps;
463
464
                        ps=fli_read_char(f);
464
465
                        if (ps & 0x80) {
465
 
                                unsigned short len; 
 
466
                                unsigned short len;
466
467
                                for (len=-(signed char)ps; len>0; len--) {
467
468
                                        pos[xc++]=fli_read_char(f);
468
 
                                } 
 
469
                                }
469
470
                        } else {
470
471
                                unsigned char val;
471
472
                                val=fli_read_char(f);
473
474
                                xc+=ps;
474
475
                        }
475
476
                }
476
 
        } 
 
477
        }
477
478
}
478
479
 
479
480
void fli_write_brun(FILE *f, s_fli_header *fli_header, unsigned char *framebuf)
480
481
{
481
482
        unsigned long chunkpos;
482
 
        s_fli_chunk chunk; 
 
483
        s_fli_chunk chunk;
483
484
        unsigned short yc;
484
485
        unsigned char *linebuf;
485
 
        
 
486
 
486
487
        chunkpos=ftell(f);
487
488
        fseek(f, chunkpos+6, SEEK_SET);
488
489
 
496
497
                while (xc < fli_header->width) {
497
498
                        pc=1;
498
499
                        while ((pc<120) && ((xc+pc)<fli_header->width) && (linebuf[xc+pc] == linebuf[xc])) {
499
 
                                pc++; 
 
500
                                pc++;
500
501
                        }
501
502
                        if (pc>2) {
502
503
                                if (tc>0) {
527
528
                        fwrite(linebuf+t1, 1, tc, f);
528
529
                        tc=0;
529
530
                }
530
 
                lineend=ftell(f); 
 
531
                lineend=ftell(f);
531
532
                fseek(f, linepos, SEEK_SET);
532
533
                fli_write_char(f, bc);
533
534
                fseek(f, lineend, SEEK_SET);
539
540
        fseek(f, chunkpos, SEEK_SET);
540
541
        fli_write_long(f, chunk.size);
541
542
        fli_write_short(f, chunk.magic);
542
 
        
 
543
 
543
544
        if (chunk.size & 1) chunk.size++;
544
545
        fseek(f,chunkpos+chunk.size,SEEK_SET);
545
546
}
546
547
 
547
548
/*
548
 
 * This is the delta-compression method from the classic Autodesk Animator. 
 
549
 * This is the delta-compression method from the classic Autodesk Animator.
549
550
 * It's basically the RLE method from above, but it allows to skip unchanged
550
551
 * lines at the beginning and end of an image, and unchanged pixels in a line
551
552
 * This chunk is used in FLI files.
578
579
                                xc+=ps;
579
580
                        }
580
581
                }
581
 
        } 
 
582
        }
582
583
}
583
584
 
584
585
void fli_write_lc(FILE *f, s_fli_header *fli_header, unsigned char *old_framebuf, unsigned char *framebuf)
585
586
{
586
587
        unsigned long chunkpos;
587
 
        s_fli_chunk chunk; 
 
588
        s_fli_chunk chunk;
588
589
        unsigned short yc, firstline, numline, lastline;
589
590
        unsigned char *linebuf, *old_linebuf;
590
 
        
 
591
 
591
592
        chunkpos=ftell(f);
592
593
        fseek(f, chunkpos+6, SEEK_SET);
593
594
 
594
595
        /* first check, how many lines are unchanged at the beginning */
595
596
        firstline=0;
596
597
        while ((memcmp(old_framebuf+(firstline*fli_header->width), framebuf+(firstline*fli_header->width), fli_header->width)==0) && (firstline<fli_header->height)) firstline++;
597
 
        
 
598
 
598
599
        /* then check from the end, how many lines are unchanged */
599
600
        if (firstline<fli_header->height) {
600
601
                lastline=fli_header->height-1;
601
602
                while ((memcmp(old_framebuf+(lastline*fli_header->width), framebuf+(lastline*fli_header->width), fli_header->width)==0) && (lastline>firstline)) lastline--;
602
603
                numline=(lastline-firstline)+1;
603
604
        } else {
604
 
                numline=0; 
 
605
                numline=0;
605
606
        }
606
607
        if (numline==0) firstline=0;
607
608
 
651
652
                                xc+=tc;
652
653
                        }
653
654
                }
654
 
                lineend=ftell(f); 
 
655
                lineend=ftell(f);
655
656
                fseek(f, linepos, SEEK_SET);
656
657
                fli_write_char(f, bc);
657
658
                fseek(f, lineend, SEEK_SET);
663
664
        fseek(f, chunkpos, SEEK_SET);
664
665
        fli_write_long(f, chunk.size);
665
666
        fli_write_short(f, chunk.magic);
666
 
        
 
667
 
667
668
        if (chunk.size & 1) chunk.size++;
668
669
        fseek(f,chunkpos+chunk.size,SEEK_SET);
669
670
}
717
718
                }
718
719
                if (lpf) pos[xc]=lpn;
719
720
                yc++;
720
 
        } 
 
721
        }
721
722
}