diff options
| author | Juanma Barranquero | 2005-10-11 08:25:27 +0000 |
|---|---|---|
| committer | Juanma Barranquero | 2005-10-11 08:25:27 +0000 |
| commit | b25a72ab313708c70b4219916fe875fbfc20b59d (patch) | |
| tree | ef8b3adb0207a1ff276d34c010a62d85437c8f03 /src/image.c | |
| parent | bf0b151d474697b409a122d5eb24c9e2df81c41e (diff) | |
| download | emacs-b25a72ab313708c70b4219916fe875fbfc20b59d.tar.gz emacs-b25a72ab313708c70b4219916fe875fbfc20b59d.zip | |
(fn_jpeg_stdio_src): Don't define it.
(init_jpeg_functions): Don't initialize `fn_jpeg_stdio_src'.
(our_common_init_source): Rename from `our_init_source'.
(our_common_term_source): Rename from `our_term_source'.
(our_memory_fill_input_buffer): Rename from `our_fill_input_buffer'.
(our_memory_skip_input_data): Rename from `our_skip_input_data'.
(jpeg_memory_src): Use the new names.
(struct jpeg_stdio_mgr): New struct.
(JPEG_STDIO_BUFFER_SIZE): New constant.
(our_stdio_fill_input_buffer, our_stdio_skip_input_data, jpeg_file_src): New
functions.
(jpeg_load): Use `jpeg_file_src' instead of `fn_jpeg_stdio_src'.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 153 |
1 files changed, 132 insertions, 21 deletions
diff --git a/src/image.c b/src/image.c index 3b6969b0c28..2463c24a33a 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -6358,7 +6358,6 @@ DEF_IMGLIB_FN (jpeg_finish_decompress); | |||
| 6358 | DEF_IMGLIB_FN (jpeg_destroy_decompress); | 6358 | DEF_IMGLIB_FN (jpeg_destroy_decompress); |
| 6359 | DEF_IMGLIB_FN (jpeg_read_header); | 6359 | DEF_IMGLIB_FN (jpeg_read_header); |
| 6360 | DEF_IMGLIB_FN (jpeg_read_scanlines); | 6360 | DEF_IMGLIB_FN (jpeg_read_scanlines); |
| 6361 | DEF_IMGLIB_FN (jpeg_stdio_src); | ||
| 6362 | DEF_IMGLIB_FN (jpeg_std_error); | 6361 | DEF_IMGLIB_FN (jpeg_std_error); |
| 6363 | DEF_IMGLIB_FN (jpeg_resync_to_restart); | 6362 | DEF_IMGLIB_FN (jpeg_resync_to_restart); |
| 6364 | 6363 | ||
| @@ -6374,7 +6373,6 @@ init_jpeg_functions (Lisp_Object libraries) | |||
| 6374 | LOAD_IMGLIB_FN (library, jpeg_read_scanlines); | 6373 | LOAD_IMGLIB_FN (library, jpeg_read_scanlines); |
| 6375 | LOAD_IMGLIB_FN (library, jpeg_start_decompress); | 6374 | LOAD_IMGLIB_FN (library, jpeg_start_decompress); |
| 6376 | LOAD_IMGLIB_FN (library, jpeg_read_header); | 6375 | LOAD_IMGLIB_FN (library, jpeg_read_header); |
| 6377 | LOAD_IMGLIB_FN (library, jpeg_stdio_src); | ||
| 6378 | LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); | 6376 | LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); |
| 6379 | LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); | 6377 | LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); |
| 6380 | LOAD_IMGLIB_FN (library, jpeg_std_error); | 6378 | LOAD_IMGLIB_FN (library, jpeg_std_error); |
| @@ -6400,7 +6398,6 @@ jpeg_resync_to_restart_wrapper(cinfo, desired) | |||
| 6400 | #define fn_jpeg_destroy_decompress jpeg_destroy_decompress | 6398 | #define fn_jpeg_destroy_decompress jpeg_destroy_decompress |
| 6401 | #define fn_jpeg_read_header jpeg_read_header | 6399 | #define fn_jpeg_read_header jpeg_read_header |
| 6402 | #define fn_jpeg_read_scanlines jpeg_read_scanlines | 6400 | #define fn_jpeg_read_scanlines jpeg_read_scanlines |
| 6403 | #define fn_jpeg_stdio_src jpeg_stdio_src | ||
| 6404 | #define fn_jpeg_std_error jpeg_std_error | 6401 | #define fn_jpeg_std_error jpeg_std_error |
| 6405 | #define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart | 6402 | #define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart |
| 6406 | 6403 | ||
| @@ -6427,7 +6424,17 @@ my_error_exit (cinfo) | |||
| 6427 | libjpeg.doc from the JPEG lib distribution. */ | 6424 | libjpeg.doc from the JPEG lib distribution. */ |
| 6428 | 6425 | ||
| 6429 | static void | 6426 | static void |
| 6430 | our_init_source (cinfo) | 6427 | our_common_init_source (cinfo) |
| 6428 | j_decompress_ptr cinfo; | ||
| 6429 | { | ||
| 6430 | } | ||
| 6431 | |||
| 6432 | |||
| 6433 | /* Method to terminate data source. Called by | ||
| 6434 | jpeg_finish_decompress() after all data has been processed. */ | ||
| 6435 | |||
| 6436 | static void | ||
| 6437 | our_common_term_source (cinfo) | ||
| 6431 | j_decompress_ptr cinfo; | 6438 | j_decompress_ptr cinfo; |
| 6432 | { | 6439 | { |
| 6433 | } | 6440 | } |
| @@ -6438,7 +6445,7 @@ our_init_source (cinfo) | |||
| 6438 | so this only adds a fake end of input marker at the end. */ | 6445 | so this only adds a fake end of input marker at the end. */ |
| 6439 | 6446 | ||
| 6440 | static boolean | 6447 | static boolean |
| 6441 | our_fill_input_buffer (cinfo) | 6448 | our_memory_fill_input_buffer (cinfo) |
| 6442 | j_decompress_ptr cinfo; | 6449 | j_decompress_ptr cinfo; |
| 6443 | { | 6450 | { |
| 6444 | /* Insert a fake EOI marker. */ | 6451 | /* Insert a fake EOI marker. */ |
| @@ -6458,7 +6465,7 @@ our_fill_input_buffer (cinfo) | |||
| 6458 | is the JPEG data source manager. */ | 6465 | is the JPEG data source manager. */ |
| 6459 | 6466 | ||
| 6460 | static void | 6467 | static void |
| 6461 | our_skip_input_data (cinfo, num_bytes) | 6468 | our_memory_skip_input_data (cinfo, num_bytes) |
| 6462 | j_decompress_ptr cinfo; | 6469 | j_decompress_ptr cinfo; |
| 6463 | long num_bytes; | 6470 | long num_bytes; |
| 6464 | { | 6471 | { |
| @@ -6475,16 +6482,6 @@ our_skip_input_data (cinfo, num_bytes) | |||
| 6475 | } | 6482 | } |
| 6476 | 6483 | ||
| 6477 | 6484 | ||
| 6478 | /* Method to terminate data source. Called by | ||
| 6479 | jpeg_finish_decompress() after all data has been processed. */ | ||
| 6480 | |||
| 6481 | static void | ||
| 6482 | our_term_source (cinfo) | ||
| 6483 | j_decompress_ptr cinfo; | ||
| 6484 | { | ||
| 6485 | } | ||
| 6486 | |||
| 6487 | |||
| 6488 | /* Set up the JPEG lib for reading an image from DATA which contains | 6485 | /* Set up the JPEG lib for reading an image from DATA which contains |
| 6489 | LEN bytes. CINFO is the decompression info structure created for | 6486 | LEN bytes. CINFO is the decompression info structure created for |
| 6490 | reading the image. */ | 6487 | reading the image. */ |
| @@ -6508,16 +6505,130 @@ jpeg_memory_src (cinfo, data, len) | |||
| 6508 | } | 6505 | } |
| 6509 | 6506 | ||
| 6510 | src = (struct jpeg_source_mgr *) cinfo->src; | 6507 | src = (struct jpeg_source_mgr *) cinfo->src; |
| 6511 | src->init_source = our_init_source; | 6508 | src->init_source = our_common_init_source; |
| 6512 | src->fill_input_buffer = our_fill_input_buffer; | 6509 | src->fill_input_buffer = our_memory_fill_input_buffer; |
| 6513 | src->skip_input_data = our_skip_input_data; | 6510 | src->skip_input_data = our_memory_skip_input_data; |
| 6514 | src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ | 6511 | src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ |
| 6515 | src->term_source = our_term_source; | 6512 | src->term_source = our_common_term_source; |
| 6516 | src->bytes_in_buffer = len; | 6513 | src->bytes_in_buffer = len; |
| 6517 | src->next_input_byte = data; | 6514 | src->next_input_byte = data; |
| 6518 | } | 6515 | } |
| 6519 | 6516 | ||
| 6520 | 6517 | ||
| 6518 | struct jpeg_stdio_mgr | ||
| 6519 | { | ||
| 6520 | struct jpeg_source_mgr mgr; | ||
| 6521 | boolean finished; | ||
| 6522 | FILE *file; | ||
| 6523 | JOCTET *buffer; | ||
| 6524 | }; | ||
| 6525 | |||
| 6526 | |||
| 6527 | /* Size of buffer to read JPEG from file. | ||
| 6528 | Not too big, as we want to use alloc_small. */ | ||
| 6529 | #define JPEG_STDIO_BUFFER_SIZE 8192 | ||
| 6530 | |||
| 6531 | |||
| 6532 | /* Fill input buffer method for JPEG data source manager. Called | ||
| 6533 | whenever more data is needed. The data is read from a FILE *. */ | ||
| 6534 | |||
| 6535 | static boolean | ||
| 6536 | our_stdio_fill_input_buffer (cinfo) | ||
| 6537 | j_decompress_ptr cinfo; | ||
| 6538 | { | ||
| 6539 | struct jpeg_stdio_mgr *src; | ||
| 6540 | |||
| 6541 | src = (struct jpeg_stdio_mgr *) cinfo->src; | ||
| 6542 | if (!src->finished) | ||
| 6543 | { | ||
| 6544 | size_t bytes; | ||
| 6545 | |||
| 6546 | bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); | ||
| 6547 | if (bytes > 0) | ||
| 6548 | src->mgr.bytes_in_buffer = bytes; | ||
| 6549 | else | ||
| 6550 | { | ||
| 6551 | WARNMS (cinfo, JWRN_JPEG_EOF); | ||
| 6552 | src->finished = 1; | ||
| 6553 | src->buffer[0] = (JOCTET) 0xFF; | ||
| 6554 | src->buffer[1] = (JOCTET) JPEG_EOI; | ||
| 6555 | src->mgr.bytes_in_buffer = 2; | ||
| 6556 | } | ||
| 6557 | src->mgr.next_input_byte = src->buffer; | ||
| 6558 | } | ||
| 6559 | |||
| 6560 | return 1; | ||
| 6561 | } | ||
| 6562 | |||
| 6563 | |||
| 6564 | /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src | ||
| 6565 | is the JPEG data source manager. */ | ||
| 6566 | |||
| 6567 | static void | ||
| 6568 | our_stdio_skip_input_data (cinfo, num_bytes) | ||
| 6569 | j_decompress_ptr cinfo; | ||
| 6570 | long num_bytes; | ||
| 6571 | { | ||
| 6572 | struct jpeg_stdio_mgr *src; | ||
| 6573 | src = (struct jpeg_stdio_mgr *) cinfo->src; | ||
| 6574 | |||
| 6575 | while (num_bytes > 0 && !src->finished) | ||
| 6576 | { | ||
| 6577 | if (num_bytes <= src->mgr.bytes_in_buffer) | ||
| 6578 | { | ||
| 6579 | src->mgr.bytes_in_buffer -= num_bytes; | ||
| 6580 | src->mgr.next_input_byte += num_bytes; | ||
| 6581 | break; | ||
| 6582 | } | ||
| 6583 | else | ||
| 6584 | { | ||
| 6585 | num_bytes -= src->mgr.bytes_in_buffer; | ||
| 6586 | src->mgr.bytes_in_buffer = 0; | ||
| 6587 | src->mgr.next_input_byte = NULL; | ||
| 6588 | |||
| 6589 | our_stdio_fill_input_buffer (cinfo); | ||
| 6590 | } | ||
| 6591 | } | ||
| 6592 | } | ||
| 6593 | |||
| 6594 | |||
| 6595 | /* Set up the JPEG lib for reading an image from a FILE *. | ||
| 6596 | CINFO is the decompression info structure created for | ||
| 6597 | reading the image. */ | ||
| 6598 | |||
| 6599 | static void | ||
| 6600 | jpeg_file_src (cinfo, fp) | ||
| 6601 | j_decompress_ptr cinfo; | ||
| 6602 | FILE *fp; | ||
| 6603 | { | ||
| 6604 | struct jpeg_stdio_mgr *src; | ||
| 6605 | |||
| 6606 | if (cinfo->src != NULL) | ||
| 6607 | src = (struct jpeg_stdio_mgr *) cinfo->src; | ||
| 6608 | else | ||
| 6609 | { | ||
| 6610 | /* First time for this JPEG object? */ | ||
| 6611 | cinfo->src = (struct jpeg_source_mgr *) | ||
| 6612 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | ||
| 6613 | sizeof (struct jpeg_stdio_mgr)); | ||
| 6614 | src = (struct jpeg_stdio_mgr *) cinfo->src; | ||
| 6615 | src->buffer = (JOCTET *) | ||
| 6616 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | ||
| 6617 | JPEG_STDIO_BUFFER_SIZE); | ||
| 6618 | } | ||
| 6619 | |||
| 6620 | src->file = fp; | ||
| 6621 | src->finished = 0; | ||
| 6622 | src->mgr.init_source = our_common_init_source; | ||
| 6623 | src->mgr.fill_input_buffer = our_stdio_fill_input_buffer; | ||
| 6624 | src->mgr.skip_input_data = our_stdio_skip_input_data; | ||
| 6625 | src->mgr.resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ | ||
| 6626 | src->mgr.term_source = our_common_term_source; | ||
| 6627 | src->mgr.bytes_in_buffer = 0; | ||
| 6628 | src->mgr.next_input_byte = NULL; | ||
| 6629 | } | ||
| 6630 | |||
| 6631 | |||
| 6521 | /* Load image IMG for use on frame F. Patterned after example.c | 6632 | /* Load image IMG for use on frame F. Patterned after example.c |
| 6522 | from the JPEG lib. */ | 6633 | from the JPEG lib. */ |
| 6523 | 6634 | ||
| @@ -6601,7 +6712,7 @@ jpeg_load (f, img) | |||
| 6601 | fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); | 6712 | fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); |
| 6602 | 6713 | ||
| 6603 | if (NILP (specified_data)) | 6714 | if (NILP (specified_data)) |
| 6604 | fn_jpeg_stdio_src (&cinfo, (FILE *) fp); | 6715 | jpeg_file_src (&cinfo, (FILE *) fp); |
| 6605 | else | 6716 | else |
| 6606 | jpeg_memory_src (&cinfo, SDATA (specified_data), | 6717 | jpeg_memory_src (&cinfo, SDATA (specified_data), |
| 6607 | SBYTES (specified_data)); | 6718 | SBYTES (specified_data)); |