6358 |
DEF_IMGLIB_FN (jpeg_destroy_decompress); |
DEF_IMGLIB_FN (jpeg_destroy_decompress); |
6359 |
DEF_IMGLIB_FN (jpeg_read_header); |
DEF_IMGLIB_FN (jpeg_read_header); |
6360 |
DEF_IMGLIB_FN (jpeg_read_scanlines); |
DEF_IMGLIB_FN (jpeg_read_scanlines); |
|
DEF_IMGLIB_FN (jpeg_stdio_src); |
|
6361 |
DEF_IMGLIB_FN (jpeg_std_error); |
DEF_IMGLIB_FN (jpeg_std_error); |
6362 |
DEF_IMGLIB_FN (jpeg_resync_to_restart); |
DEF_IMGLIB_FN (jpeg_resync_to_restart); |
6363 |
|
|
6373 |
LOAD_IMGLIB_FN (library, jpeg_read_scanlines); |
LOAD_IMGLIB_FN (library, jpeg_read_scanlines); |
6374 |
LOAD_IMGLIB_FN (library, jpeg_start_decompress); |
LOAD_IMGLIB_FN (library, jpeg_start_decompress); |
6375 |
LOAD_IMGLIB_FN (library, jpeg_read_header); |
LOAD_IMGLIB_FN (library, jpeg_read_header); |
|
LOAD_IMGLIB_FN (library, jpeg_stdio_src); |
|
6376 |
LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); |
LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); |
6377 |
LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); |
LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); |
6378 |
LOAD_IMGLIB_FN (library, jpeg_std_error); |
LOAD_IMGLIB_FN (library, jpeg_std_error); |
6398 |
#define fn_jpeg_destroy_decompress jpeg_destroy_decompress |
#define fn_jpeg_destroy_decompress jpeg_destroy_decompress |
6399 |
#define fn_jpeg_read_header jpeg_read_header |
#define fn_jpeg_read_header jpeg_read_header |
6400 |
#define fn_jpeg_read_scanlines jpeg_read_scanlines |
#define fn_jpeg_read_scanlines jpeg_read_scanlines |
|
#define fn_jpeg_stdio_src jpeg_stdio_src |
|
6401 |
#define fn_jpeg_std_error jpeg_std_error |
#define fn_jpeg_std_error jpeg_std_error |
6402 |
#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart |
#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart |
6403 |
|
|
6424 |
libjpeg.doc from the JPEG lib distribution. */ |
libjpeg.doc from the JPEG lib distribution. */ |
6425 |
|
|
6426 |
static void |
static void |
6427 |
our_init_source (cinfo) |
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) |
6438 |
j_decompress_ptr cinfo; |
j_decompress_ptr cinfo; |
6439 |
{ |
{ |
6440 |
} |
} |
6445 |
so this only adds a fake end of input marker at the end. */ |
so this only adds a fake end of input marker at the end. */ |
6446 |
|
|
6447 |
static boolean |
static boolean |
6448 |
our_fill_input_buffer (cinfo) |
our_memory_fill_input_buffer (cinfo) |
6449 |
j_decompress_ptr cinfo; |
j_decompress_ptr cinfo; |
6450 |
{ |
{ |
6451 |
/* Insert a fake EOI marker. */ |
/* Insert a fake EOI marker. */ |
6465 |
is the JPEG data source manager. */ |
is the JPEG data source manager. */ |
6466 |
|
|
6467 |
static void |
static void |
6468 |
our_skip_input_data (cinfo, num_bytes) |
our_memory_skip_input_data (cinfo, num_bytes) |
6469 |
j_decompress_ptr cinfo; |
j_decompress_ptr cinfo; |
6470 |
long num_bytes; |
long num_bytes; |
6471 |
{ |
{ |
6482 |
} |
} |
6483 |
|
|
6484 |
|
|
|
/* Method to terminate data source. Called by |
|
|
jpeg_finish_decompress() after all data has been processed. */ |
|
|
|
|
|
static void |
|
|
our_term_source (cinfo) |
|
|
j_decompress_ptr cinfo; |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
6485 |
/* Set up the JPEG lib for reading an image from DATA which contains |
/* Set up the JPEG lib for reading an image from DATA which contains |
6486 |
LEN bytes. CINFO is the decompression info structure created for |
LEN bytes. CINFO is the decompression info structure created for |
6487 |
reading the image. */ |
reading the image. */ |
6505 |
} |
} |
6506 |
|
|
6507 |
src = (struct jpeg_source_mgr *) cinfo->src; |
src = (struct jpeg_source_mgr *) cinfo->src; |
6508 |
src->init_source = our_init_source; |
src->init_source = our_common_init_source; |
6509 |
src->fill_input_buffer = our_fill_input_buffer; |
src->fill_input_buffer = our_memory_fill_input_buffer; |
6510 |
src->skip_input_data = our_skip_input_data; |
src->skip_input_data = our_memory_skip_input_data; |
6511 |
src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ |
src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ |
6512 |
src->term_source = our_term_source; |
src->term_source = our_common_term_source; |
6513 |
src->bytes_in_buffer = len; |
src->bytes_in_buffer = len; |
6514 |
src->next_input_byte = data; |
src->next_input_byte = data; |
6515 |
} |
} |
6516 |
|
|
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 |
|
|
6632 |
/* Load image IMG for use on frame F. Patterned after example.c |
/* Load image IMG for use on frame F. Patterned after example.c |
6633 |
from the JPEG lib. */ |
from the JPEG lib. */ |
6634 |
|
|
6712 |
fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); |
fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); |
6713 |
|
|
6714 |
if (NILP (specified_data)) |
if (NILP (specified_data)) |
6715 |
fn_jpeg_stdio_src (&cinfo, (FILE *) fp); |
jpeg_file_src (&cinfo, (FILE *) fp); |
6716 |
else |
else |
6717 |
jpeg_memory_src (&cinfo, SDATA (specified_data), |
jpeg_memory_src (&cinfo, SDATA (specified_data), |
6718 |
SBYTES (specified_data)); |
SBYTES (specified_data)); |