Mercurial > hg > xemacs-beta
comparison src/glyphs-eimage.c @ 647:b39c14581166
[xemacs-hg @ 2001-08-13 04:45:47 by ben]
removal of unsigned, size_t, etc.
author | ben |
---|---|
date | Mon, 13 Aug 2001 04:46:48 +0000 |
parents | 373ced43e288 |
children | fdefd0186b75 |
comparison
equal
deleted
inserted
replaced
646:00c54252fe4f | 647:b39c14581166 |
---|---|
62 | 62 |
63 #ifdef HAVE_PNG | 63 #ifdef HAVE_PNG |
64 #ifdef __cplusplus | 64 #ifdef __cplusplus |
65 extern "C" { | 65 extern "C" { |
66 #endif | 66 #endif |
67 #define message message_ /* Yuck */ | |
67 #include <png.h> | 68 #include <png.h> |
69 #undef message | |
68 #ifdef __cplusplus | 70 #ifdef __cplusplus |
69 } | 71 } |
70 #endif | 72 #endif |
71 #else | 73 #else |
72 #include <setjmp.h> | 74 #include <setjmp.h> |
230 struct jpeg_source_mgr *src = NULL; | 232 struct jpeg_source_mgr *src = NULL; |
231 | 233 |
232 src = (struct jpeg_source_mgr *) cinfo->src; | 234 src = (struct jpeg_source_mgr *) cinfo->src; |
233 | 235 |
234 if (!src) | 236 if (!src) |
237 return; | |
238 else if (num_bytes > (long) src->bytes_in_buffer) | |
235 { | 239 { |
236 return; | 240 ERREXIT (cinfo, JERR_INPUT_EOF); |
237 } else if (num_bytes > src->bytes_in_buffer) | 241 /*NOTREACHED*/ |
238 { | 242 } |
239 ERREXIT(cinfo, JERR_INPUT_EOF); | |
240 /*NOTREACHED*/ | |
241 } | |
242 | 243 |
243 src->bytes_in_buffer -= num_bytes; | 244 src->bytes_in_buffer -= num_bytes; |
244 src->next_input_byte += num_bytes; | 245 src->next_input_byte += num_bytes; |
245 } | 246 } |
246 | 247 |
257 { | 258 { |
258 struct jpeg_source_mgr pub; | 259 struct jpeg_source_mgr pub; |
259 } our_jpeg_source_mgr; | 260 } our_jpeg_source_mgr; |
260 | 261 |
261 static void | 262 static void |
262 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len) | 263 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, Memory_Count len) |
263 { | 264 { |
264 struct jpeg_source_mgr *src; | 265 struct jpeg_source_mgr *src; |
265 | 266 |
266 if (cinfo->src == NULL) | 267 if (cinfo->src == NULL) |
267 { /* first time for this JPEG object? */ | 268 { /* first time for this JPEG object? */ |
372 | 373 |
373 /* Step 2: specify data source (eg, a file) */ | 374 /* Step 2: specify data source (eg, a file) */ |
374 | 375 |
375 { | 376 { |
376 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 377 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
377 const Extbyte *bytes; | 378 const UChar_Binary *bytes; |
378 Extcount len; | 379 Memory_Count len; |
379 | 380 |
380 /* #### This is a definite problem under Mule due to the amount of | 381 /* #### This is a definite problem under Mule due to the amount of |
381 stack data it might allocate. Need to be able to convert and | 382 stack data it might allocate. Need to be able to convert and |
382 write out to a file. */ | 383 write out to a file. */ |
383 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary); | 384 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary); |
450 * Here the array is only one element long, but you could ask for | 451 * Here the array is only one element long, but you could ask for |
451 * more than one scanline at a time if that's more convenient. | 452 * more than one scanline at a time if that's more convenient. |
452 */ | 453 */ |
453 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); | 454 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); |
454 jp = row_buffer[0]; | 455 jp = row_buffer[0]; |
455 for (i = 0; i < cinfo.output_width; i++) | 456 for (i = 0; i < (int) cinfo.output_width; i++) |
456 { | 457 { |
457 int clr; | 458 int clr; |
458 if (jpeg_gray) | 459 if (jpeg_gray) |
459 { | 460 { |
460 unsigned char val; | 461 unsigned char val; |
461 #if (BITS_IN_JSAMPLE == 8) | 462 #if (BITS_IN_JSAMPLE == 8) |
462 val = (unsigned char)*jp++; | 463 val = (unsigned char) *jp++; |
463 #else /* other option is 12 */ | 464 #else /* other option is 12 */ |
464 val = (unsigned char)(*jp++ >> 4); | 465 val = (unsigned char) (*jp++ >> 4); |
465 #endif | 466 #endif |
466 for (clr = 0; clr < 3; clr++) /* copy the same value into RGB */ | 467 for (clr = 0; clr < 3; clr++) /* copy the same value into RGB */ |
467 *op++ = val; | 468 *op++ = val; |
468 } | 469 } |
469 else | 470 else |
549 if (data->giffile) | 550 if (data->giffile) |
550 { | 551 { |
551 DGifCloseFile (data->giffile); | 552 DGifCloseFile (data->giffile); |
552 GifFree(data->giffile); | 553 GifFree(data->giffile); |
553 } | 554 } |
554 if (data->eimage) xfree(data->eimage); | 555 if (data->eimage) |
556 xfree (data->eimage); | |
555 | 557 |
556 return Qnil; | 558 return Qnil; |
557 } | 559 } |
558 | 560 |
559 typedef struct gif_memory_storage | 561 typedef struct gif_memory_storage |
560 { | 562 { |
561 Extbyte *bytes; /* The data */ | 563 UChar_Binary *bytes; /* The data */ |
562 Extcount len; /* How big is it? */ | 564 Memory_Count len; /* How big is it? */ |
563 int index; /* Where are we? */ | 565 Memory_Count index; /* Where are we? */ |
564 } gif_memory_storage; | 566 } gif_memory_storage; |
565 | 567 |
566 static size_t | 568 static Memory_Count |
567 gif_read_from_memory(GifByteType *buf, size_t size, VoidPtr data) | 569 gif_read_from_memory (GifByteType *buf, Memory_Count size, VoidPtr data) |
568 { | 570 { |
569 gif_memory_storage *mem = (gif_memory_storage*)data; | 571 gif_memory_storage *mem = (gif_memory_storage *) data; |
570 | 572 |
571 if (size > (mem->len - mem->index)) | 573 if (size > (mem->len - mem->index)) |
572 return (size_t) -1; | 574 return -1; |
573 memcpy(buf, mem->bytes + mem->index, size); | 575 memcpy (buf, mem->bytes + mem->index, size); |
574 mem->index = mem->index + size; | 576 mem->index = mem->index + size; |
575 return size; | 577 return size; |
576 } | 578 } |
577 | 579 |
578 static int | 580 static int |
579 gif_memory_close(VoidPtr data) | 581 gif_memory_close (VoidPtr data) |
580 { | 582 { |
581 return 0; | 583 return 0; |
582 } | 584 } |
583 | 585 |
584 struct gif_error_struct | 586 struct gif_error_struct |
586 const char *err_str; /* return the error string */ | 588 const char *err_str; /* return the error string */ |
587 jmp_buf setjmp_buffer; /* for return to caller */ | 589 jmp_buf setjmp_buffer; /* for return to caller */ |
588 }; | 590 }; |
589 | 591 |
590 static void | 592 static void |
591 gif_error_func(const char *err_str, VoidPtr error_ptr) | 593 gif_error_func (const char *err_str, VoidPtr error_ptr) |
592 { | 594 { |
593 struct gif_error_struct *error_data = (struct gif_error_struct*)error_ptr; | 595 struct gif_error_struct *error_data = (struct gif_error_struct *) error_ptr; |
594 | 596 |
595 /* return to setjmp point */ | 597 /* return to setjmp point */ |
596 error_data->err_str = err_str; | 598 error_data->err_str = err_str; |
597 longjmp (error_data->setjmp_buffer, 1); | 599 longjmp (error_data->setjmp_buffer, 1); |
598 } | 600 } |
608 stack frame is still valid. */ | 610 stack frame is still valid. */ |
609 struct gif_unwind_data unwind; | 611 struct gif_unwind_data unwind; |
610 int speccount = specpdl_depth (); | 612 int speccount = specpdl_depth (); |
611 gif_memory_storage mem_struct; | 613 gif_memory_storage mem_struct; |
612 struct gif_error_struct gif_err; | 614 struct gif_error_struct gif_err; |
613 Extbyte *bytes; | 615 UChar_Binary *bytes; |
614 Extcount len; | 616 Memory_Count len; |
615 int height = 0; | 617 int height = 0; |
616 int width = 0; | 618 int width = 0; |
617 | 619 |
618 xzero (unwind); | 620 xzero (unwind); |
619 record_unwind_protect (gif_instantiate_unwind, make_opaque_ptr (&unwind)); | 621 record_unwind_protect (gif_instantiate_unwind, make_opaque_ptr (&unwind)); |
771 return IMAGE_COLOR_PIXMAP_MASK; | 773 return IMAGE_COLOR_PIXMAP_MASK; |
772 } | 774 } |
773 | 775 |
774 struct png_memory_storage | 776 struct png_memory_storage |
775 { | 777 { |
776 const Extbyte *bytes; /* The data */ | 778 const UChar_Binary *bytes; /* The data */ |
777 Extcount len; /* How big is it? */ | 779 Memory_Count len; /* How big is it? */ |
778 int index; /* Where are we? */ | 780 Memory_Count index; /* Where are we? */ |
779 }; | 781 }; |
780 | 782 |
781 static void | 783 static void |
782 png_read_from_memory(png_structp png_ptr, png_bytep data, | 784 png_read_from_memory (png_structp png_ptr, png_bytep data, |
783 png_size_t length) | 785 png_size_t length) |
784 { | 786 { |
785 struct png_memory_storage *tbr = | 787 struct png_memory_storage *tbr = |
786 (struct png_memory_storage *) png_get_io_ptr (png_ptr); | 788 (struct png_memory_storage *) png_get_io_ptr (png_ptr); |
787 | 789 |
788 if (length > (tbr->len - tbr->index)) | 790 if ((Memory_Count) length > (tbr->len - tbr->index)) |
789 png_error (png_ptr, (png_const_charp) "Read Error"); | 791 png_error (png_ptr, (png_const_charp) "Read Error"); |
790 memcpy (data,tbr->bytes + tbr->index,length); | 792 memcpy (data, tbr->bytes + tbr->index,length); |
791 tbr->index = tbr->index + length; | 793 tbr->index = tbr->index + length; |
792 } | 794 } |
793 | 795 |
794 struct png_error_struct | 796 struct png_error_struct |
795 { | 797 { |
895 } | 897 } |
896 | 898 |
897 /* Initialize the IO layer and read in header information */ | 899 /* Initialize the IO layer and read in header information */ |
898 { | 900 { |
899 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 901 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
900 const Extbyte *bytes; | 902 const UChar_Binary *bytes; |
901 Extcount len; | 903 Memory_Count len; |
902 | 904 |
903 assert (!NILP (data)); | 905 assert (!NILP (data)); |
904 | 906 |
905 /* #### This is a definite problem under Mule due to the amount of | 907 /* #### This is a definite problem under Mule due to the amount of |
906 stack data it might allocate. Need to think about using Lstreams */ | 908 stack data it might allocate. Need to think about using Lstreams */ |
1082 return Qnil; | 1084 return Qnil; |
1083 } | 1085 } |
1084 | 1086 |
1085 typedef struct tiff_memory_storage | 1087 typedef struct tiff_memory_storage |
1086 { | 1088 { |
1087 Extbyte *bytes; /* The data */ | 1089 UChar_Binary *bytes; /* The data */ |
1088 Extcount len; /* How big is it? */ | 1090 Memory_Count len; /* How big is it? */ |
1089 int index; /* Where are we? */ | 1091 Memory_Count index; /* Where are we? */ |
1090 } tiff_memory_storage; | 1092 } tiff_memory_storage; |
1091 | 1093 |
1092 static size_t | 1094 static size_t |
1093 tiff_memory_read(thandle_t data, tdata_t buf, tsize_t size) | 1095 tiff_memory_read (thandle_t data, tdata_t buf, tsize_t size) |
1094 { | 1096 { |
1095 tiff_memory_storage *mem = (tiff_memory_storage*)data; | 1097 tiff_memory_storage *mem = (tiff_memory_storage *) data; |
1096 | 1098 |
1097 if (size > (mem->len - mem->index)) | 1099 if ((Memory_Count) size > (mem->len - mem->index)) |
1098 return (size_t) -1; | 1100 return (size_t) -1; |
1099 memcpy(buf, mem->bytes + mem->index, size); | 1101 memcpy (buf, mem->bytes + mem->index, size); |
1100 mem->index = mem->index + size; | 1102 mem->index = mem->index + size; |
1101 return size; | 1103 return size; |
1102 } | 1104 } |
1103 | 1105 |
1104 static size_t tiff_memory_write(thandle_t data, tdata_t buf, tsize_t size) | 1106 static size_t |
1107 tiff_memory_write (thandle_t data, tdata_t buf, tsize_t size) | |
1105 { | 1108 { |
1106 abort(); | 1109 abort(); |
1107 return 0; /* Shut up warnings. */ | 1110 return 0; /* Shut up warnings. */ |
1108 } | 1111 } |
1109 | 1112 |
1110 static toff_t tiff_memory_seek(thandle_t data, toff_t off, int whence) | 1113 static toff_t |
1111 { | 1114 tiff_memory_seek (thandle_t data, toff_t off, int whence) |
1112 tiff_memory_storage *mem = (tiff_memory_storage*)data; | 1115 { |
1116 tiff_memory_storage *mem = (tiff_memory_storage *) data; | |
1113 int newidx; | 1117 int newidx; |
1114 switch(whence) { | 1118 switch(whence) |
1115 case SEEK_SET: | 1119 { |
1116 newidx = off; | 1120 case SEEK_SET: |
1117 break; | 1121 newidx = off; |
1118 case SEEK_END: | 1122 break; |
1119 newidx = mem->len + off; | 1123 case SEEK_END: |
1120 break; | 1124 newidx = mem->len + off; |
1121 case SEEK_CUR: | 1125 break; |
1122 newidx = mem->index + off; | 1126 case SEEK_CUR: |
1123 break; | 1127 newidx = mem->index + off; |
1124 default: | 1128 break; |
1125 fprintf(stderr,"Eh? invalid seek mode in tiff_memory_seek\n"); | 1129 default: |
1126 return (toff_t) -1; | 1130 fprintf (stderr, "Eh? invalid seek mode in tiff_memory_seek\n"); |
1127 } | 1131 return (toff_t) -1; |
1132 } | |
1128 | 1133 |
1129 if ((newidx > mem->len) || (newidx < 0)) | 1134 if ((newidx > mem->len) || (newidx < 0)) |
1130 return (toff_t) -1; | 1135 return (toff_t) -1; |
1131 | 1136 |
1132 mem->index = newidx; | 1137 mem->index = newidx; |
1133 return newidx; | 1138 return newidx; |
1134 } | 1139 } |
1135 | 1140 |
1136 static int | 1141 static int |
1137 tiff_memory_close(thandle_t data) | 1142 tiff_memory_close (thandle_t data) |
1138 { | 1143 { |
1139 return 0; | 1144 return 0; |
1140 } | 1145 } |
1141 | 1146 |
1142 static int | 1147 static int |
1143 tiff_map_noop(thandle_t data, tdata_t* pbase, toff_t* psize) | 1148 tiff_map_noop (thandle_t data, tdata_t* pbase, toff_t* psize) |
1144 { | 1149 { |
1145 return 0; | 1150 return 0; |
1146 } | 1151 } |
1147 | 1152 |
1148 static void | 1153 static void |
1149 tiff_unmap_noop(thandle_t data, tdata_t pbase, toff_t psize) | 1154 tiff_unmap_noop (thandle_t data, tdata_t pbase, toff_t psize) |
1150 { | 1155 { |
1151 return; | 1156 return; |
1152 } | 1157 } |
1153 | 1158 |
1154 static toff_t | 1159 static toff_t |
1155 tiff_memory_size(thandle_t data) | 1160 tiff_memory_size (thandle_t data) |
1156 { | 1161 { |
1157 tiff_memory_storage *mem = (tiff_memory_storage*)data; | 1162 tiff_memory_storage *mem = (tiff_memory_storage*)data; |
1158 return mem->len; | 1163 return mem->len; |
1159 } | 1164 } |
1160 | 1165 |
1173 have any place to store error func data. This should be rectified | 1178 have any place to store error func data. This should be rectified |
1174 before XEmacs gets threads! */ | 1179 before XEmacs gets threads! */ |
1175 static struct tiff_error_struct tiff_err_data; | 1180 static struct tiff_error_struct tiff_err_data; |
1176 | 1181 |
1177 static void | 1182 static void |
1178 tiff_error_func(const char *module, const char *fmt, ...) | 1183 tiff_error_func (const char *module, const char *fmt, ...) |
1179 { | 1184 { |
1180 va_list vargs; | 1185 va_list vargs; |
1181 | 1186 |
1182 va_start (vargs, fmt); | 1187 va_start (vargs, fmt); |
1183 #ifdef HAVE_VSNPRINTF | 1188 #ifdef HAVE_VSNPRINTF |
1190 /* return to setjmp point */ | 1195 /* return to setjmp point */ |
1191 longjmp (tiff_err_data.setjmp_buffer, 1); | 1196 longjmp (tiff_err_data.setjmp_buffer, 1); |
1192 } | 1197 } |
1193 | 1198 |
1194 static void | 1199 static void |
1195 tiff_warning_func(const char *module, const char *fmt, ...) | 1200 tiff_warning_func (const char *module, const char *fmt, ...) |
1196 { | 1201 { |
1197 va_list vargs; | 1202 va_list vargs; |
1198 #ifdef HAVE_VSNPRINTF | 1203 #ifdef HAVE_VSNPRINTF |
1199 char warn_str[256]; | 1204 char warn_str[256]; |
1200 #else | 1205 #else |
1240 } | 1245 } |
1241 TIFFSetErrorHandler ((TIFFErrorHandler)tiff_error_func); | 1246 TIFFSetErrorHandler ((TIFFErrorHandler)tiff_error_func); |
1242 TIFFSetWarningHandler ((TIFFErrorHandler)tiff_warning_func); | 1247 TIFFSetWarningHandler ((TIFFErrorHandler)tiff_warning_func); |
1243 { | 1248 { |
1244 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 1249 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
1245 Extbyte *bytes; | 1250 UChar_Binary *bytes; |
1246 Extcount len; | 1251 Memory_Count len; |
1247 | 1252 |
1248 uint32 *raster; | 1253 uint32 *raster; |
1249 unsigned char *ep; | 1254 unsigned char *ep; |
1250 | 1255 |
1251 assert (!NILP (data)); | 1256 assert (!NILP (data)); |
1275 It needs to be reimplemented via scanline reads for both memory | 1280 It needs to be reimplemented via scanline reads for both memory |
1276 compactness. */ | 1281 compactness. */ |
1277 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32)); | 1282 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32)); |
1278 if (raster != NULL) | 1283 if (raster != NULL) |
1279 { | 1284 { |
1280 int i,j; | 1285 int i, j; |
1281 uint32 *rp; | 1286 uint32 *rp; |
1282 ep = unwind.eimage; | 1287 ep = unwind.eimage; |
1283 rp = raster; | 1288 rp = raster; |
1284 if (TIFFReadRGBAImage (unwind.tiff, width, height, raster, 0)) | 1289 if (TIFFReadRGBAImage (unwind.tiff, width, height, raster, 0)) |
1285 { | 1290 { |
1286 for (i = height - 1; i >= 0; i--) | 1291 for (i = height - 1; i >= 0; i--) |
1287 { | 1292 { |
1288 /* This is to get around weirdness in the libtiff library where properly | 1293 /* This is to get around weirdness in the libtiff library where properly |
1289 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */ | 1294 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */ |
1290 rp = raster + (i * width); | 1295 rp = raster + (i * width); |
1291 for (j = 0; j < width; j++) | 1296 for (j = 0; j < (int) width; j++) |
1292 { | 1297 { |
1293 *ep++ = (unsigned char)TIFFGetR(*rp); | 1298 *ep++ = (unsigned char)TIFFGetR(*rp); |
1294 *ep++ = (unsigned char)TIFFGetG(*rp); | 1299 *ep++ = (unsigned char)TIFFGetG(*rp); |
1295 *ep++ = (unsigned char)TIFFGetB(*rp); | 1300 *ep++ = (unsigned char)TIFFGetB(*rp); |
1296 rp++; | 1301 rp++; |