equal
deleted
inserted
replaced
708 */ |
708 */ |
709 static int |
709 static int |
710 __decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize) |
710 __decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize) |
711 { |
711 { |
712 register unsigned code; |
712 register unsigned code; |
|
713 // #define GIF_PREFIX_SUFFIX_SIZE 4096 |
|
714 #define GIF_PREFIX_SUFFIX_SIZE (4096*2) |
713 unsigned short *prefix; |
715 unsigned short *prefix; |
714 unsigned short *suffix; |
716 unsigned short *suffix; |
715 unsigned short *outCode; |
717 unsigned short *outCode; |
716 int outCount; |
718 int outCount; |
717 unsigned maxCode, oldCode, fin, inCode, curCode; |
719 unsigned maxCode, oldCode, fin, inCode, curCode; |
733 if (@global(InfoPrinting) == true) { |
735 if (@global(InfoPrinting) == true) { |
734 console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n"); |
736 console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n"); |
735 } |
737 } |
736 return 0; |
738 return 0; |
737 } |
739 } |
738 prefix = (unsigned short *)malloc(sizeof(short) * 4096); |
740 prefix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
739 if (! prefix) return 0; |
741 if (! prefix) return 0; |
740 suffix = (unsigned short *)malloc(sizeof(short) * 4096); |
742 suffix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
741 if (! suffix) { |
743 if (! suffix) { |
742 free(prefix); |
744 free(prefix); |
743 return 0; |
745 return 0; |
744 } |
746 } |
745 outCode = (unsigned short *)malloc(sizeof(short) * 4096); |
747 outCode = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
746 if (! outCode) { |
748 if (! outCode) { |
747 free(prefix); |
749 free(prefix); |
748 free(suffix); |
750 free(suffix); |
749 return 0; |
751 return 0; |
750 } |
752 } |
812 if (outCount > 1024) { |
814 if (outCount > 1024) { |
813 goto out; |
815 goto out; |
814 } |
816 } |
815 |
817 |
816 /* debugging and protecting myself from overwrites */ |
818 /* debugging and protecting myself from overwrites */ |
817 if (curCode >= 4096) { |
819 if (curCode > (GIF_PREFIX_SUFFIX_SIZE-1)) { |
818 if (@global(InfoPrinting) == true) { |
820 if (@global(InfoPrinting) == true) { |
819 console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > 4095)\n"); |
821 console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1)); |
820 } |
822 } |
821 ret = 0; |
823 ret = 0; |
822 break; |
824 break; |
823 } |
825 } |
824 outCode[outCount++] = suffix[curCode]; |
826 outCode[outCount++] = suffix[curCode]; |
848 *to++ = outCode[i]; |
850 *to++ = outCode[i]; |
849 } |
851 } |
850 outCount = 0; |
852 outCount = 0; |
851 |
853 |
852 /* debugging and protecting myself from overwrites */ |
854 /* debugging and protecting myself from overwrites */ |
853 if (freeCode >= 4096) { |
855 if (freeCode > (GIF_PREFIX_SUFFIX_SIZE-1)) { |
854 if (@global(InfoPrinting) == true) { |
856 if (@global(InfoPrinting) == true) { |
855 console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > 4095)\n"); |
857 console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1)); |
856 } |
858 } |
857 ret = 0; |
859 ret = 0; |
858 break; |
860 break; |
859 } |
861 } |
860 |
862 |
1673 !ImageReader class methodsFor:'image writing'! |
1675 !ImageReader class methodsFor:'image writing'! |
1674 |
1676 |
1675 save:anImage onFile:aFileName |
1677 save:anImage onFile:aFileName |
1676 "save the image in my format on aFileName. |
1678 "save the image in my format on aFileName. |
1677 Returns the imageReader instance (bad name; is a writer). |
1679 Returns the imageReader instance (bad name; is a writer). |
1678 May raise Image cannotRepresentImageSignal, |
1680 May raise Image cannotRepresentImageSignal, |
1679 if the image cannot be represented in that format, |
1681 if the image cannot be represented in that format, |
1680 or it is not support" |
1682 or it is not support" |
1681 |
1683 |
1682 ^ (self basicNew) save:anImage onFile:aFileName |
1684 ^ (self basicNew) save:anImage onFile:aFileName |
1683 |
1685 |
1688 save:anImage onFile:aFileName quality:qualityPercent |
1690 save:anImage onFile:aFileName quality:qualityPercent |
1689 "save the image in my format on aFileName. |
1691 "save the image in my format on aFileName. |
1690 The qualityPercent argument is ignored by all lossless formats. |
1692 The qualityPercent argument is ignored by all lossless formats. |
1691 (however, JPG does care for it.) |
1693 (however, JPG does care for it.) |
1692 Returns the imageReader instance (bad name; is a writer). |
1694 Returns the imageReader instance (bad name; is a writer). |
1693 May raise Image cannotRepresentImageSignal, |
1695 May raise Image cannotRepresentImageSignal, |
1694 if the image cannot be represented in that format, |
1696 if the image cannot be represented in that format, |
1695 or it is not support" |
1697 or it is not support" |
1696 |
1698 |
1697 ^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent |
1699 ^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent |
1698 |
1700 |
1701 ! |
1703 ! |
1702 |
1704 |
1703 save:anImage onStream:aStream |
1705 save:anImage onStream:aStream |
1704 "save the image in my format on aStream. |
1706 "save the image in my format on aStream. |
1705 Returns the imageReader instance (bad name; is a writer). |
1707 Returns the imageReader instance (bad name; is a writer). |
1706 May raise Image cannotRepresentImageSignal, |
1708 May raise Image cannotRepresentImageSignal, |
1707 if the image cannot be represented in that format, |
1709 if the image cannot be represented in that format, |
1708 or it is not support" |
1710 or it is not support" |
1709 |
1711 |
1710 ^ (self basicNew) save:anImage onStream:aStream |
1712 ^ (self basicNew) save:anImage onStream:aStream |
1711 |
1713 |
1716 save:anImage onStream:aStream quality:qualityPercent |
1718 save:anImage onStream:aStream quality:qualityPercent |
1717 "save the image in my format on a Stream. |
1719 "save the image in my format on a Stream. |
1718 The qualityPercent argument is ignored by all lossless formats. |
1720 The qualityPercent argument is ignored by all lossless formats. |
1719 (however, JPG does care for it.) |
1721 (however, JPG does care for it.) |
1720 Returns the imageReader instance (bad name; is a writer). |
1722 Returns the imageReader instance (bad name; is a writer). |
1721 May raise Image cannotRepresentImageSignal, |
1723 May raise Image cannotRepresentImageSignal, |
1722 if the image cannot be represented in that format, |
1724 if the image cannot be represented in that format, |
1723 or it is not support" |
1725 or it is not support" |
1724 |
1726 |
1725 ^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent |
1727 ^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent |
1726 |
1728 |
2160 "helper for save image" |
2162 "helper for save image" |
2161 |
2163 |
2162 |stream| |
2164 |stream| |
2163 |
2165 |
2164 [ |
2166 [ |
2165 stream := aFileName asFilename newReadWriteStream. |
2167 stream := aFileName asFilename newReadWriteStream. |
2166 ] on:FileStream openErrorSignal do:[:ex| |
2168 ] on:FileStream openErrorSignal do:[:ex| |
2167 ^ Image fileCreationErrorSignal |
2169 ^ Image fileCreationErrorSignal |
2168 raiseWith:something |
2170 raiseWith:something |
2169 errorString:('file creation error: ' , aFileName asString). |
2171 errorString:('file creation error: ' , aFileName asString). |
2170 ]. |
2172 ]. |
2171 |
2173 |
2172 [ |
2174 [ |
2173 [ |
2175 [ |
2174 aBlock value: stream |
2176 aBlock value: stream |
2175 ] ensure:[ |
2177 ] ensure:[ |
2176 stream close. |
2178 stream close. |
2177 ]. |
2179 ]. |
2178 ] ifCurtailed:[ |
2180 ] ifCurtailed:[ |
2179 OsError catch:[ |
2181 OsError catch:[ |
2180 aFileName asFilename delete. |
2182 aFileName asFilename delete. |
2181 ] |
2183 ] |
2182 ]. |
2184 ]. |
2183 ! ! |
2185 ! ! |
2184 |
2186 |
2185 !ImageReader methodsFor:'initialization'! |
2187 !ImageReader methodsFor:'initialization'! |
2186 |
2188 |
2244 ! |
2246 ! |
2245 |
2247 |
2246 version_CVS |
2248 version_CVS |
2247 ^ '$Header$' |
2249 ^ '$Header$' |
2248 ! ! |
2250 ! ! |
2249 |
|