~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/FreeImage/PluginGIF.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        std::vector<size_t> comment_extension_offsets;
53
53
        std::vector<size_t> graphic_control_extension_offsets;
54
54
        std::vector<size_t> image_descriptor_offsets;
 
55
 
 
56
        GIFinfo() : read(0), global_color_table_offset(0), global_color_table_size(0), background_color(0)
 
57
        {
 
58
        }
55
59
};
56
60
 
57
61
struct PageInfo {
352
356
        }
353
357
 
354
358
        m_bufferSize = 0;
355
 
        *len = bufpos - buf;
 
359
        *len = (int)(bufpos - buf);
356
360
 
357
361
        return true;
358
362
}
374
378
 
375
379
                        if( code > m_nextCode || (m_nextCode == MAX_LZW_CODE && code != m_clearCode) || code == m_endCode ) {
376
380
                                m_done = true;
377
 
                                *len = bufpos - buf;
 
381
                                *len = (int)(bufpos - buf);
378
382
                                return true;
379
383
                        }
380
384
                        if( code == m_clearCode ) {
393
397
                                m_partialSize += m_codeSize;
394
398
                                m_partial |= code;
395
399
                                m_bufferPos++;
396
 
                                *len = bufpos - buf;
 
400
                                *len = (int)(bufpos - buf);
397
401
                                return true;
398
402
                        }
399
403
 
416
420
        }
417
421
 
418
422
        m_bufferSize = 0;
419
 
        *len = bufpos - buf;
 
423
        *len = (int)(bufpos - buf);
420
424
 
421
425
        return true;
422
426
}
524
528
        if( info == NULL ) {
525
529
                return NULL;
526
530
        }
527
 
        memset(info, 0, sizeof(GIFinfo));
 
531
 
 
532
        // 25/02/2008 MDA:      Not safe to memset GIFinfo structure with VS 2008 (safe iterators),
 
533
        //                                      perform initialization in constructor instead.
 
534
        // memset(info, 0, sizeof(GIFinfo));
528
535
 
529
536
        info->read = read;
530
537
        if( read ) {
531
538
                try {
532
539
                        //Header
533
540
                        if( !Validate(io, handle) ) {
534
 
                                throw "Not a GIF file";
 
541
                                throw FI_MSG_ERROR_MAGIC_NUMBER;
535
542
                        }
536
543
                        io->seek_proc(handle, 6, SEEK_CUR);
537
544
 
646
653
        }
647
654
        GIFinfo *info = (GIFinfo *)data;
648
655
 
649
 
        return info->image_descriptor_offsets.size();
 
656
        return (int) info->image_descriptor_offsets.size();
650
657
}
651
658
 
652
659
static FIBITMAP * DLL_CALLCONV 
685
692
                        //set the background color with 0 alpha
686
693
                        RGBQUAD background;
687
694
                        if( info->global_color_table_offset != 0 && info->background_color < info->global_color_table_size ) {
688
 
                                io->seek_proc(handle, info->global_color_table_offset + (info->background_color * 3), SEEK_SET);
 
695
                                io->seek_proc(handle, (long)(info->global_color_table_offset + (info->background_color * 3)), SEEK_SET);
689
696
                                io->read_proc(&background.rgbRed, 1, 1, handle);
690
697
                                io->read_proc(&background.rgbGreen, 1, 1, handle);
691
698
                                io->read_proc(&background.rgbBlue, 1, 1, handle);
699
706
                        //allocate entire logical area
700
707
                        dib = FreeImage_Allocate(logicalwidth, logicalheight, 32);
701
708
                        if( dib == NULL ) {
702
 
                                throw "DIB allocated failed";
 
709
                                throw FI_MSG_ERROR_DIB_MEMORY;
703
710
                        }
704
711
 
705
712
                        //fill with background color to start
717
724
                        int start = page, end = page;
718
725
                        while( start >= 0 ) {
719
726
                                //Graphic Control Extension
720
 
                                io->seek_proc(handle, info->graphic_control_extension_offsets[start] + 1, SEEK_SET);
 
727
                                io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[start] + 1), SEEK_SET);
721
728
                                io->read_proc(&packed, 1, 1, handle);
722
729
                                have_transparent = (packed & GIF_PACKED_GCE_HAVETRANS) ? true : false;
723
730
                                disposal_method = (packed & GIF_PACKED_GCE_DISPOSAL) >> 2;
724
731
                                //Image Descriptor
725
 
                                io->seek_proc(handle, info->image_descriptor_offsets[start], SEEK_SET);
 
732
                                io->seek_proc(handle, (long)(info->image_descriptor_offsets[start]), SEEK_SET);
726
733
                                io->read_proc(&left, 2, 1, handle);
727
734
                                io->read_proc(&top, 2, 1, handle);
728
735
                                io->read_proc(&width, 2, 1, handle);
756
763
                        }
757
764
 
758
765
                        //draw each page into the logical area
 
766
                        delay_time = 0;
759
767
                        for( page = start; page <= end; page++ ) {
760
768
                                PageInfo &info = pageinfo[end - page];
761
769
                                //things we can skip having to decode
770
778
                                                                *scanline++ = background;
771
779
                                                        }
772
780
                                                }
 
781
                                                continue;
773
782
                                        }
774
783
                                }
775
784
 
802
811
                                                        pageline++;
803
812
                                                }
804
813
                                        }
 
814
                                        //copy frame time
 
815
                                        if( page == end ) {
 
816
                                                FITAG *tag;
 
817
                                                if( FreeImage_GetMetadataEx(FIMD_ANIMATION, pagedib, "FrameTime", FIDT_LONG, &tag) ) {
 
818
                                                        delay_time = *(LONG *)FreeImage_GetTagValue(tag);
 
819
                                                }
 
820
                                        }
805
821
                                        FreeImage_Unload(pagedib);
806
822
                                }
807
823
                        }
808
824
 
 
825
                        //setup frame time
 
826
                        FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", ANIMTAG_FRAMETIME, FIDT_LONG, 1, 4, &delay_time);
809
827
                        return dib;
810
828
                }
811
829
 
812
830
                //get the actual frame image data for a single frame
813
831
 
814
832
                //Image Descriptor
815
 
                io->seek_proc(handle, info->image_descriptor_offsets[page], SEEK_SET);
 
833
                io->seek_proc(handle, (long)info->image_descriptor_offsets[page], SEEK_SET);
816
834
                io->read_proc(&left, 2, 1, handle);
817
835
                io->read_proc(&top, 2, 1, handle);
818
836
                io->read_proc(&width, 2, 1, handle);
840
858
                }
841
859
                dib = FreeImage_Allocate(width, height, bpp);
842
860
                if( dib == NULL ) {
843
 
                        throw "DIB allocated failed";
 
861
                        throw FI_MSG_ERROR_DIB_MEMORY;
844
862
                }
845
863
 
846
864
                FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", ANIMTAG_FRAMELEFT, FIDT_SHORT, 1, 2, &left);
864
882
                        }
865
883
                } else if( info->global_color_table_offset != 0 ) {
866
884
                        long pos = io->tell_proc(handle);
867
 
                        io->seek_proc(handle, info->global_color_table_offset, SEEK_SET);
 
885
                        io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET);
868
886
 
869
887
                        int i = 0;
870
888
                        while( i < info->global_color_table_size ) {
947
965
                        //Global Color Table
948
966
                        if( info->global_color_table_offset != 0 ) {
949
967
                                RGBQUAD globalpalette[256];
950
 
                                io->seek_proc(handle, info->global_color_table_offset, SEEK_SET);
 
968
                                io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET);
951
969
                                int i = 0;
952
970
                                while( i < info->global_color_table_size ) {
953
971
                                        io->read_proc(&globalpalette[i].rgbRed, 1, 1, handle);
966
984
                        //Application Extension
967
985
                        LONG loop = 1; //If no AE with a loop count is found, the default must be 1
968
986
                        for( idx = 0; idx < info->application_extension_offsets.size(); idx++ ) {
969
 
                                io->seek_proc(handle, info->application_extension_offsets[idx], SEEK_SET);
 
987
                                io->seek_proc(handle, (long)info->application_extension_offsets[idx], SEEK_SET);
970
988
                                io->read_proc(&b, 1, 1, handle);
971
989
                                if( b == 11 ) { //All AEs start with an 11 byte sub-block to determine what type of AE it is
972
990
                                        char buf[11];
990
1008
 
991
1009
                        //Comment Extension
992
1010
                        for( idx = 0; idx < info->comment_extension_offsets.size(); idx++ ) {
993
 
                                io->seek_proc(handle, info->comment_extension_offsets[idx], SEEK_SET);
 
1011
                                io->seek_proc(handle, (long)info->comment_extension_offsets[idx], SEEK_SET);
994
1012
                                std::string comment;
995
1013
                                char buf[255];
996
1014
                                io->read_proc(&b, 1, 1, handle);
1001
1019
                                }
1002
1020
                                comment.append(1, '\0');
1003
1021
                                sprintf(buf, "Comment%d", idx);
1004
 
                                FreeImage_SetMetadataEx(FIMD_COMMENTS, dib, buf, 1, FIDT_ASCII, comment.size(), comment.size(), comment.c_str());
 
1022
                                DWORD comment_size = (DWORD)comment.size();
 
1023
                                FreeImage_SetMetadataEx(FIMD_COMMENTS, dib, buf, 1, FIDT_ASCII, comment_size, comment_size, comment.c_str());
1005
1024
                        }
1006
1025
                }
1007
1026
 
1008
1027
                //Graphic Control Extension
1009
1028
                if( info->graphic_control_extension_offsets[page] != 0 ) {
1010
 
                        io->seek_proc(handle, info->graphic_control_extension_offsets[page] + 1, SEEK_SET);
 
1029
                        io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[page] + 1), SEEK_SET);
1011
1030
                        io->read_proc(&packed, 1, 1, handle);
1012
1031
                        io->read_proc(&w, 2, 1, handle);
1013
1032
#ifdef FREEIMAGE_BIGENDIAN
1305
1324
                                        size = sizeof(buf);
1306
1325
                                        bufptr = buf;
1307
1326
                                } else {
1308
 
                                        size = sizeof(buf) - (bufptr - buf);
 
1327
                                        size = (int)(sizeof(buf) - (bufptr - buf));
1309
1328
                                }
1310
1329
                        }
1311
1330
                        if( interlaced ) {
1317
1336
                                y++;
1318
1337
                        }
1319
1338
                }
1320
 
                size = bufptr - buf;
 
1339
                size = (int)(bufptr - buf);
1321
1340
                BYTE last[4];
1322
1341
                w = (WORD)stringtable->CompressEnd(last);
1323
1342
                if( size + w >= sizeof(buf) ) {