Lines 1048-1053
Link Here
|
1048 |
Bool new_image = True ; |
1048 |
Bool new_image = True ; |
1049 |
START_TIME(started); |
1049 |
START_TIME(started); |
1050 |
int cmap_size = 1; |
1050 |
int cmap_size = 1; |
|
|
1051 |
#if (GIFLIB_MAJOR>=5) |
1052 |
int errcode; |
1053 |
#endif |
1051 |
#define GIF_NETSCAPE_EXT_BYTES 3 |
1054 |
#define GIF_NETSCAPE_EXT_BYTES 3 |
1052 |
unsigned char netscape_ext_bytes[GIF_NETSCAPE_EXT_BYTES] = { 0x1, 0x0, 0x0}; |
1055 |
unsigned char netscape_ext_bytes[GIF_NETSCAPE_EXT_BYTES] = { 0x1, 0x0, 0x0}; |
1053 |
#define GIF_GCE_BYTES 4 |
1056 |
#define GIF_GCE_BYTES 4 |
Lines 1086-1095
Link Here
|
1086 |
|
1089 |
|
1087 |
while( cmap_size < 256 && cmap_size < (int)cmap.count+(gce_bytes[0]&0x01) ) |
1090 |
while( cmap_size < 256 && cmap_size < (int)cmap.count+(gce_bytes[0]&0x01) ) |
1088 |
cmap_size = cmap_size<<1 ; |
1091 |
cmap_size = cmap_size<<1 ; |
|
|
1092 |
#if (GIFLIB_MAJOR>=5) |
1093 |
if( (gif_cmap = GifMakeMapObject(cmap_size, NULL )) == NULL ) |
1094 |
#else |
1089 |
if( (gif_cmap = MakeMapObject(cmap_size, NULL )) == NULL ) |
1095 |
if( (gif_cmap = MakeMapObject(cmap_size, NULL )) == NULL ) |
|
|
1096 |
#endif |
1090 |
{ |
1097 |
{ |
1091 |
free( mapped_im ); |
1098 |
free( mapped_im ); |
|
|
1099 |
#if (GIFLIB_MAJOR>=5) |
1100 |
ASIM_PrintGifError(E_GIF_ERR_NOT_ENOUGH_MEM); |
1101 |
#else |
1092 |
ASIM_PrintGifError(); |
1102 |
ASIM_PrintGifError(); |
|
|
1103 |
#endif |
1093 |
return False; |
1104 |
return False; |
1094 |
} |
1105 |
} |
1095 |
memcpy( &(gif_cmap->Colors[0]), &(cmap.entries[0]), MIN(cmap.count,(unsigned int)cmap_size)*3 ); |
1106 |
memcpy( &(gif_cmap->Colors[0]), &(cmap.entries[0]), MIN(cmap.count,(unsigned int)cmap_size)*3 ); |
Lines 1101-1113
Link Here
|
1101 |
SavedImage *images = NULL ; |
1112 |
SavedImage *images = NULL ; |
1102 |
int count = 0 ; |
1113 |
int count = 0 ; |
1103 |
/* TODO: do something about multiimage files !!! */ |
1114 |
/* TODO: do something about multiimage files !!! */ |
|
|
1115 |
#if (GIFLIB_MAJOR>=5) |
1116 |
gif = open_gif_read(infile, &errcode); |
1117 |
#else |
1104 |
gif = open_gif_read(infile); |
1118 |
gif = open_gif_read(infile); |
|
|
1119 |
#endif |
1105 |
if( gif == NULL || get_gif_saved_images(gif, -1, &images, &count) == GIF_ERROR) |
1120 |
if( gif == NULL || get_gif_saved_images(gif, -1, &images, &count) == GIF_ERROR) |
1106 |
{ |
1121 |
{ |
|
|
1122 |
#if (GIFLIB_MAJOR>=5) |
1123 |
ASIM_PrintGifError(errcode); |
1124 |
#else |
1107 |
ASIM_PrintGifError(); |
1125 |
ASIM_PrintGifError(); |
|
|
1126 |
#endif |
1108 |
if( gif ) |
1127 |
if( gif ) |
1109 |
{ |
1128 |
{ |
|
|
1129 |
#if (GIFLIB_MAJOR>=5) |
1130 |
DGifCloseFile(gif, &errcode); |
1131 |
#else |
1110 |
DGifCloseFile(gif); |
1132 |
DGifCloseFile(gif); |
|
|
1133 |
#endif |
1111 |
gif = NULL ; |
1134 |
gif = NULL ; |
1112 |
} |
1135 |
} |
1113 |
if (infile) |
1136 |
if (infile) |
Lines 1123-1136
Link Here
|
1123 |
gif_src = *gif ; |
1146 |
gif_src = *gif ; |
1124 |
gif->SColorMap = NULL ; |
1147 |
gif->SColorMap = NULL ; |
1125 |
gif->Image.ColorMap = NULL ; |
1148 |
gif->Image.ColorMap = NULL ; |
|
|
1149 |
#if (GIFLIB_MAJOR>=5) |
1150 |
DGifCloseFile(gif, &errcode); |
1151 |
#else |
1126 |
DGifCloseFile(gif); |
1152 |
DGifCloseFile(gif); |
|
|
1153 |
#endif |
1127 |
gif = NULL; |
1154 |
gif = NULL; |
1128 |
fclose (infile); |
1155 |
fclose (infile); |
1129 |
infile = NULL; |
1156 |
infile = NULL; |
1130 |
outfile = open_writeable_image_file( path ); |
1157 |
outfile = open_writeable_image_file( path ); |
1131 |
|
1158 |
|
1132 |
if (outfile) |
1159 |
if (outfile) |
|
|
1160 |
#if (GIFLIB_MAJOR>=5) |
1161 |
gif = EGifOpenFileHandle(fileno(outfile), &errcode); |
1162 |
#else |
1133 |
gif = EGifOpenFileHandle(fileno(outfile)); |
1163 |
gif = EGifOpenFileHandle(fileno(outfile)); |
|
|
1164 |
#endif |
1134 |
|
1165 |
|
1135 |
if (gif) |
1166 |
if (gif) |
1136 |
{ |
1167 |
{ |
Lines 1141-1166
Link Here
|
1141 |
gif_src.SColorMap )) == GIF_OK ) |
1172 |
gif_src.SColorMap )) == GIF_OK ) |
1142 |
status = write_gif_saved_images( gif, images, count ); |
1173 |
status = write_gif_saved_images( gif, images, count ); |
1143 |
if( status != GIF_OK ) |
1174 |
if( status != GIF_OK ) |
|
|
1175 |
#if (GIFLIB_MAJOR>=5) |
1176 |
ASIM_PrintGifError(status); |
1177 |
#else |
1144 |
ASIM_PrintGifError(); |
1178 |
ASIM_PrintGifError(); |
|
|
1179 |
#endif |
1145 |
} |
1180 |
} |
1146 |
if (gif_src.SColorMap) |
1181 |
if (gif_src.SColorMap) |
1147 |
{ /* we only want to save private colormap if it is any different from |
1182 |
{ /* we only want to save private colormap if it is any different from |
1148 |
* screen colormap ( saves us 768 bytes per image ) */ |
1183 |
* screen colormap ( saves us 768 bytes per image ) */ |
1149 |
if( gif_cmap->ColorCount == gif_src.SColorMap->ColorCount ) |
1184 |
if( gif_cmap->ColorCount == gif_src.SColorMap->ColorCount ) |
1150 |
dont_save_cmap = ( memcmp( gif_cmap->Colors, gif_src.SColorMap->Colors, gif_cmap->ColorCount*sizeof(GifColorType)) == 0 ); |
1185 |
dont_save_cmap = ( memcmp( gif_cmap->Colors, gif_src.SColorMap->Colors, gif_cmap->ColorCount*sizeof(GifColorType)) == 0 ); |
|
|
1186 |
#if (GIFLIB_MAJOR>=5) |
1187 |
GifFreeMapObject(gif_src.SColorMap); |
1188 |
#else |
1151 |
FreeMapObject(gif_src.SColorMap); |
1189 |
FreeMapObject(gif_src.SColorMap); |
|
|
1190 |
#endif |
1152 |
} |
1191 |
} |
1153 |
if (gif) |
1192 |
if (gif) |
1154 |
{ |
1193 |
{ |
1155 |
EGifPutExtension(gif, GRAPHICS_EXT_FUNC_CODE, GIF_GCE_BYTES, &(gce_bytes[0])); |
1194 |
EGifPutExtension(gif, GRAPHICS_EXT_FUNC_CODE, GIF_GCE_BYTES, &(gce_bytes[0])); |
1156 |
if( get_flags( params->gif.flags, EXPORT_ANIMATION_REPEATS ) ) |
1195 |
if( get_flags( params->gif.flags, EXPORT_ANIMATION_REPEATS ) ) |
1157 |
{ |
1196 |
{ |
|
|
1197 |
#if (GIFLIB_MAJOR>=5) |
1198 |
EGifPutExtensionLeader(gif, APPLICATION_EXT_FUNC_CODE); |
1199 |
EGifPutExtensionBlock(gif, 11, "NETSCAPE2.0"); |
1200 |
EGifPutExtensionBlock(gif, GIF_NETSCAPE_EXT_BYTES, &(netscape_ext_bytes[0])); |
1201 |
EGifPutExtensionTrailer(gif); |
1202 |
#else |
1158 |
EGifPutExtensionFirst(gif, APPLICATION_EXT_FUNC_CODE, 11, "NETSCAPE2.0"); |
1203 |
EGifPutExtensionFirst(gif, APPLICATION_EXT_FUNC_CODE, 11, "NETSCAPE2.0"); |
1159 |
EGifPutExtensionLast(gif, 0, GIF_NETSCAPE_EXT_BYTES, &(netscape_ext_bytes[0])); |
1204 |
EGifPutExtensionLast(gif, 0, GIF_NETSCAPE_EXT_BYTES, &(netscape_ext_bytes[0])); |
|
|
1205 |
#endif |
1160 |
} |
1206 |
} |
1161 |
|
1207 |
|
|
|
1208 |
#if (GIFLIB_MAJOR>=5) |
1209 |
if( (errcode = EGifPutImageDesc(gif, 0, 0, im->width, im->height, false, (dont_save_cmap)?NULL:gif_cmap )) == GIF_ERROR ) |
1210 |
ASIM_PrintGifError(errcode); |
1211 |
#else |
1162 |
if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, (dont_save_cmap)?NULL:gif_cmap ) == GIF_ERROR ) |
1212 |
if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, (dont_save_cmap)?NULL:gif_cmap ) == GIF_ERROR ) |
1163 |
ASIM_PrintGifError(); |
1213 |
ASIM_PrintGifError(); |
|
|
1214 |
#endif |
1164 |
} |
1215 |
} |
1165 |
} |
1216 |
} |
1166 |
free_gif_saved_images( images, count ); |
1217 |
free_gif_saved_images( images, count ); |
Lines 1172-1195
Link Here
|
1172 |
outfile = open_writeable_image_file(path); |
1223 |
outfile = open_writeable_image_file(path); |
1173 |
|
1224 |
|
1174 |
if (outfile) |
1225 |
if (outfile) |
|
|
1226 |
{ |
1227 |
#if (GIFLIB_MAJOR>=5) |
1228 |
gif = EGifOpenFileHandle(fileno(outfile), &errcode); |
1229 |
if (errcode != E_GIF_SUCCEEDED) |
1230 |
ASIM_PrintGifError(errcode); |
1231 |
#else |
1175 |
if ((gif = EGifOpenFileHandle(fileno(outfile))) == NULL) |
1232 |
if ((gif = EGifOpenFileHandle(fileno(outfile))) == NULL) |
1176 |
ASIM_PrintGifError(); |
1233 |
ASIM_PrintGifError(); |
|
|
1234 |
#endif |
1235 |
} |
1177 |
} |
1236 |
} |
1178 |
|
1237 |
|
1179 |
if( new_image && gif ) |
1238 |
if( new_image && gif ) |
1180 |
{ |
1239 |
{ |
|
|
1240 |
#if (GIFLIB_MAJOR>=5) |
1241 |
if( (errcode = EGifPutScreenDesc(gif, im->width, im->height, cmap_size, 0, gif_cmap )) == GIF_ERROR ) |
1242 |
ASIM_PrintGifError(errcode); |
1243 |
#else |
1181 |
if( EGifPutScreenDesc(gif, im->width, im->height, cmap_size, 0, gif_cmap ) == GIF_ERROR ) |
1244 |
if( EGifPutScreenDesc(gif, im->width, im->height, cmap_size, 0, gif_cmap ) == GIF_ERROR ) |
1182 |
ASIM_PrintGifError(); |
1245 |
ASIM_PrintGifError(); |
|
|
1246 |
#endif |
1183 |
|
1247 |
|
1184 |
EGifPutExtension(gif, 0xf9, GIF_GCE_BYTES, &(gce_bytes[0])); |
1248 |
EGifPutExtension(gif, 0xf9, GIF_GCE_BYTES, &(gce_bytes[0])); |
1185 |
|
1249 |
|
|
|
1250 |
#if (GIFLIB_MAJOR>=5) |
1251 |
if( (errcode = EGifPutImageDesc(gif, 0, 0, im->width, im->height, false, NULL )) == GIF_ERROR ) |
1252 |
ASIM_PrintGifError(errcode); |
1253 |
#else |
1186 |
if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, NULL ) == GIF_ERROR ) |
1254 |
if( EGifPutImageDesc(gif, 0, 0, im->width, im->height, FALSE, NULL ) == GIF_ERROR ) |
1187 |
ASIM_PrintGifError(); |
1255 |
ASIM_PrintGifError(); |
|
|
1256 |
#endif |
1188 |
} |
1257 |
} |
1189 |
|
1258 |
|
1190 |
if( gif_cmap ) |
1259 |
if( gif_cmap ) |
1191 |
{ |
1260 |
{ |
|
|
1261 |
#if (GIFLIB_MAJOR>=5) |
1262 |
GifFreeMapObject(gif_cmap); |
1263 |
#else |
1192 |
FreeMapObject(gif_cmap); |
1264 |
FreeMapObject(gif_cmap); |
|
|
1265 |
#endif |
1193 |
gif_cmap = NULL ; |
1266 |
gif_cmap = NULL ; |
1194 |
} |
1267 |
} |
1195 |
if( gif ) |
1268 |
if( gif ) |
Lines 1203-1214
Link Here
|
1203 |
register int *src = mapped_im + x*y; |
1276 |
register int *src = mapped_im + x*y; |
1204 |
while( --x >= 0 ) |
1277 |
while( --x >= 0 ) |
1205 |
row_pointer[x] = src[x] ; |
1278 |
row_pointer[x] = src[x] ; |
|
|
1279 |
#if (GIFLIB_MAJOR>=5) |
1280 |
if( (errcode = EGifPutLine(gif, row_pointer, im->width)) == GIF_ERROR) |
1281 |
ASIM_PrintGifError(errcode); |
1282 |
#else |
1206 |
if( EGifPutLine(gif, row_pointer, im->width) == GIF_ERROR) |
1283 |
if( EGifPutLine(gif, row_pointer, im->width) == GIF_ERROR) |
1207 |
ASIM_PrintGifError(); |
1284 |
ASIM_PrintGifError(); |
|
|
1285 |
#endif |
1208 |
} |
1286 |
} |
1209 |
free( row_pointer ); |
1287 |
free( row_pointer ); |
|
|
1288 |
#if (GIFLIB_MAJOR>=5) |
1289 |
EGifCloseFile(gif, &errcode); |
1290 |
if (errcode != E_GIF_SUCCEEDED) |
1291 |
ASIM_PrintGifError(errcode); |
1292 |
#else |
1210 |
if (EGifCloseFile(gif) == GIF_ERROR) |
1293 |
if (EGifCloseFile(gif) == GIF_ERROR) |
1211 |
ASIM_PrintGifError(); |
1294 |
ASIM_PrintGifError(); |
|
|
1295 |
#endif |
1212 |
gif = NULL; |
1296 |
gif = NULL; |
1213 |
} |
1297 |
} |
1214 |
free( mapped_im ); |
1298 |
free( mapped_im ); |