diff options
| author | Jason Rumney | 2003-01-26 01:21:25 +0000 |
|---|---|---|
| committer | Jason Rumney | 2003-01-26 01:21:25 +0000 |
| commit | afc390dc508524bae2fc43801a44b7c5b522af73 (patch) | |
| tree | 0e8f45a6fe01566d7b21891595d4fcdbfb94d218 | |
| parent | e7a0095207bd9bdddc4250f7d06bbd1930ad74df (diff) | |
| download | emacs-afc390dc508524bae2fc43801a44b7c5b522af73.tar.gz emacs-afc390dc508524bae2fc43801a44b7c5b522af73.zip | |
(init_jpeg_functions, jpeg_resync_to_restart_wrapper):
New functions.
(jpeg_load): Sync with xfns.c version. Adjust colors for Windows.
Disable color table lookups. Call jpeg library functions
through pointers determined at runtime.
(init_external_image_libraries): Try to load jpeg.dll.
| -rw-r--r-- | src/w32fns.c | 157 |
1 files changed, 103 insertions, 54 deletions
diff --git a/src/w32fns.c b/src/w32fns.c index 4eeb08c4a53..0747e4b9e52 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -12217,6 +12217,44 @@ static struct image_type jpeg_type = | |||
| 12217 | }; | 12217 | }; |
| 12218 | 12218 | ||
| 12219 | 12219 | ||
| 12220 | /* JPEG library details. */ | ||
| 12221 | DEF_IMGLIB_FN (jpeg_CreateDecompress); | ||
| 12222 | DEF_IMGLIB_FN (jpeg_start_decompress); | ||
| 12223 | DEF_IMGLIB_FN (jpeg_finish_decompress); | ||
| 12224 | DEF_IMGLIB_FN (jpeg_destroy_decompress); | ||
| 12225 | DEF_IMGLIB_FN (jpeg_read_header); | ||
| 12226 | DEF_IMGLIB_FN (jpeg_read_scanlines); | ||
| 12227 | DEF_IMGLIB_FN (jpeg_stdio_src); | ||
| 12228 | DEF_IMGLIB_FN (jpeg_std_error); | ||
| 12229 | DEF_IMGLIB_FN (jpeg_resync_to_restart); | ||
| 12230 | |||
| 12231 | static int | ||
| 12232 | init_jpeg_functions (library) | ||
| 12233 | HMODULE library; | ||
| 12234 | { | ||
| 12235 | LOAD_IMGLIB_FN (library, jpeg_finish_decompress); | ||
| 12236 | LOAD_IMGLIB_FN (library, jpeg_read_scanlines); | ||
| 12237 | LOAD_IMGLIB_FN (library, jpeg_start_decompress); | ||
| 12238 | LOAD_IMGLIB_FN (library, jpeg_read_header); | ||
| 12239 | LOAD_IMGLIB_FN (library, jpeg_stdio_src); | ||
| 12240 | LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); | ||
| 12241 | LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); | ||
| 12242 | LOAD_IMGLIB_FN (library, jpeg_std_error); | ||
| 12243 | LOAD_IMGLIB_FN (library, jpeg_resync_to_restart); | ||
| 12244 | return 1; | ||
| 12245 | } | ||
| 12246 | |||
| 12247 | /* Wrapper since we can't directly assign the function pointer | ||
| 12248 | to another function pointer that was declared more completely easily. */ | ||
| 12249 | static boolean | ||
| 12250 | jpeg_resync_to_restart_wrapper(cinfo, desired) | ||
| 12251 | j_decompress_ptr cinfo; | ||
| 12252 | int desired; | ||
| 12253 | { | ||
| 12254 | return fn_jpeg_resync_to_restart (cinfo, desired); | ||
| 12255 | } | ||
| 12256 | |||
| 12257 | |||
| 12220 | /* Return non-zero if OBJECT is a valid JPEG image specification. */ | 12258 | /* Return non-zero if OBJECT is a valid JPEG image specification. */ |
| 12221 | 12259 | ||
| 12222 | static int | 12260 | static int |
| @@ -12224,9 +12262,9 @@ jpeg_image_p (object) | |||
| 12224 | Lisp_Object object; | 12262 | Lisp_Object object; |
| 12225 | { | 12263 | { |
| 12226 | struct image_keyword fmt[JPEG_LAST]; | 12264 | struct image_keyword fmt[JPEG_LAST]; |
| 12227 | 12265 | ||
| 12228 | bcopy (jpeg_format, fmt, sizeof fmt); | 12266 | bcopy (jpeg_format, fmt, sizeof fmt); |
| 12229 | 12267 | ||
| 12230 | if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg)) | 12268 | if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg)) |
| 12231 | return 0; | 12269 | return 0; |
| 12232 | 12270 | ||
| @@ -12241,6 +12279,7 @@ struct my_jpeg_error_mgr | |||
| 12241 | jmp_buf setjmp_buffer; | 12279 | jmp_buf setjmp_buffer; |
| 12242 | }; | 12280 | }; |
| 12243 | 12281 | ||
| 12282 | |||
| 12244 | static void | 12283 | static void |
| 12245 | my_error_exit (cinfo) | 12284 | my_error_exit (cinfo) |
| 12246 | j_common_ptr cinfo; | 12285 | j_common_ptr cinfo; |
| @@ -12249,6 +12288,7 @@ my_error_exit (cinfo) | |||
| 12249 | longjmp (mgr->setjmp_buffer, 1); | 12288 | longjmp (mgr->setjmp_buffer, 1); |
| 12250 | } | 12289 | } |
| 12251 | 12290 | ||
| 12291 | |||
| 12252 | /* Init source method for JPEG data source manager. Called by | 12292 | /* Init source method for JPEG data source manager. Called by |
| 12253 | jpeg_read_header() before any data is actually read. See | 12293 | jpeg_read_header() before any data is actually read. See |
| 12254 | libjpeg.doc from the JPEG lib distribution. */ | 12294 | libjpeg.doc from the JPEG lib distribution. */ |
| @@ -12295,7 +12335,7 @@ our_skip_input_data (cinfo, num_bytes) | |||
| 12295 | { | 12335 | { |
| 12296 | if (num_bytes > src->bytes_in_buffer) | 12336 | if (num_bytes > src->bytes_in_buffer) |
| 12297 | ERREXIT (cinfo, JERR_INPUT_EOF); | 12337 | ERREXIT (cinfo, JERR_INPUT_EOF); |
| 12298 | 12338 | ||
| 12299 | src->bytes_in_buffer -= num_bytes; | 12339 | src->bytes_in_buffer -= num_bytes; |
| 12300 | src->next_input_byte += num_bytes; | 12340 | src->next_input_byte += num_bytes; |
| 12301 | } | 12341 | } |
| @@ -12333,12 +12373,12 @@ jpeg_memory_src (cinfo, data, len) | |||
| 12333 | src = (struct jpeg_source_mgr *) cinfo->src; | 12373 | src = (struct jpeg_source_mgr *) cinfo->src; |
| 12334 | src->next_input_byte = data; | 12374 | src->next_input_byte = data; |
| 12335 | } | 12375 | } |
| 12336 | 12376 | ||
| 12337 | src = (struct jpeg_source_mgr *) cinfo->src; | 12377 | src = (struct jpeg_source_mgr *) cinfo->src; |
| 12338 | src->init_source = our_init_source; | 12378 | src->init_source = our_init_source; |
| 12339 | src->fill_input_buffer = our_fill_input_buffer; | 12379 | src->fill_input_buffer = our_fill_input_buffer; |
| 12340 | src->skip_input_data = our_skip_input_data; | 12380 | src->skip_input_data = our_skip_input_data; |
| 12341 | src->resync_to_restart = jpeg_resync_to_restart; /* Use default method. */ | 12381 | src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ |
| 12342 | src->term_source = our_term_source; | 12382 | src->term_source = our_term_source; |
| 12343 | src->bytes_in_buffer = len; | 12383 | src->bytes_in_buffer = len; |
| 12344 | src->next_input_byte = data; | 12384 | src->next_input_byte = data; |
| @@ -12348,7 +12388,7 @@ jpeg_memory_src (cinfo, data, len) | |||
| 12348 | /* Load image IMG for use on frame F. Patterned after example.c | 12388 | /* Load image IMG for use on frame F. Patterned after example.c |
| 12349 | from the JPEG lib. */ | 12389 | from the JPEG lib. */ |
| 12350 | 12390 | ||
| 12351 | static int | 12391 | static int |
| 12352 | jpeg_load (f, img) | 12392 | jpeg_load (f, img) |
| 12353 | struct frame *f; | 12393 | struct frame *f; |
| 12354 | struct image *img; | 12394 | struct image *img; |
| @@ -12376,26 +12416,26 @@ jpeg_load (f, img) | |||
| 12376 | { | 12416 | { |
| 12377 | file = x_find_image_file (specified_file); | 12417 | file = x_find_image_file (specified_file); |
| 12378 | if (!STRINGP (file)) | 12418 | if (!STRINGP (file)) |
| 12379 | { | 12419 | { |
| 12380 | image_error ("Cannot find image file `%s'", specified_file, Qnil); | 12420 | image_error ("Cannot find image file `%s'", specified_file, Qnil); |
| 12381 | UNGCPRO; | 12421 | UNGCPRO; |
| 12382 | return 0; | 12422 | return 0; |
| 12383 | } | 12423 | } |
| 12384 | 12424 | ||
| 12385 | fp = fopen (SDATA (file), "r"); | 12425 | fp = fopen (SDATA (file), "r"); |
| 12386 | if (fp == NULL) | 12426 | if (fp == NULL) |
| 12387 | { | 12427 | { |
| 12388 | image_error ("Cannot open `%s'", file, Qnil); | 12428 | image_error ("Cannot open `%s'", file, Qnil); |
| 12389 | UNGCPRO; | 12429 | UNGCPRO; |
| 12390 | return 0; | 12430 | return 0; |
| 12391 | } | 12431 | } |
| 12392 | } | 12432 | } |
| 12393 | 12433 | ||
| 12394 | /* Customize libjpeg's error handling to call my_error_exit when an | 12434 | /* Customize libjpeg's error handling to call my_error_exit when an |
| 12395 | error is detected. This function will perform a longjmp. */ | 12435 | error is detected. This function will perform a longjmp. */ |
| 12396 | cinfo.err = jpeg_std_error (&mgr.pub); | 12436 | cinfo.err = fn_jpeg_std_error (&mgr.pub); |
| 12397 | mgr.pub.error_exit = my_error_exit; | 12437 | mgr.pub.error_exit = my_error_exit; |
| 12398 | 12438 | ||
| 12399 | if ((rc = setjmp (mgr.setjmp_buffer)) != 0) | 12439 | if ((rc = setjmp (mgr.setjmp_buffer)) != 0) |
| 12400 | { | 12440 | { |
| 12401 | if (rc == 1) | 12441 | if (rc == 1) |
| @@ -12406,44 +12446,43 @@ jpeg_load (f, img) | |||
| 12406 | image_error ("Error reading JPEG image `%s': %s", img->spec, | 12446 | image_error ("Error reading JPEG image `%s': %s", img->spec, |
| 12407 | build_string (buffer)); | 12447 | build_string (buffer)); |
| 12408 | } | 12448 | } |
| 12409 | 12449 | ||
| 12410 | /* Close the input file and destroy the JPEG object. */ | 12450 | /* Close the input file and destroy the JPEG object. */ |
| 12411 | if (fp) | 12451 | if (fp) |
| 12412 | fclose (fp); | 12452 | fclose ((FILE *) fp); |
| 12413 | jpeg_destroy_decompress (&cinfo); | 12453 | fn_jpeg_destroy_decompress (&cinfo); |
| 12414 | 12454 | ||
| 12415 | /* If we already have an XImage, free that. */ | 12455 | /* If we already have an XImage, free that. */ |
| 12416 | x_destroy_x_image (ximg); | 12456 | x_destroy_x_image (ximg); |
| 12417 | 12457 | ||
| 12418 | /* Free pixmap and colors. */ | 12458 | /* Free pixmap and colors. */ |
| 12419 | x_clear_image (f, img); | 12459 | x_clear_image (f, img); |
| 12420 | 12460 | ||
| 12421 | UNGCPRO; | 12461 | UNGCPRO; |
| 12422 | return 0; | 12462 | return 0; |
| 12423 | } | 12463 | } |
| 12424 | 12464 | ||
| 12425 | /* Create the JPEG decompression object. Let it read from fp. | 12465 | /* Create the JPEG decompression object. Let it read from fp. |
| 12426 | Read the JPEG image header. */ | 12466 | Read the JPEG image header. */ |
| 12427 | jpeg_create_decompress (&cinfo); | 12467 | fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); |
| 12428 | 12468 | ||
| 12429 | if (NILP (specified_data)) | 12469 | if (NILP (specified_data)) |
| 12430 | jpeg_stdio_src (&cinfo, fp); | 12470 | fn_jpeg_stdio_src (&cinfo, (FILE *) fp); |
| 12431 | else | 12471 | else |
| 12432 | jpeg_memory_src (&cinfo, SDATA (specified_data), | 12472 | jpeg_memory_src (&cinfo, SDATA (specified_data), |
| 12433 | SBYTES (specified_data)); | 12473 | SBYTES (specified_data)); |
| 12434 | 12474 | ||
| 12435 | jpeg_read_header (&cinfo, TRUE); | 12475 | fn_jpeg_read_header (&cinfo, TRUE); |
| 12436 | 12476 | ||
| 12437 | /* Customize decompression so that color quantization will be used. | 12477 | /* Customize decompression so that color quantization will be used. |
| 12438 | Start decompression. */ | 12478 | Start decompression. */ |
| 12439 | cinfo.quantize_colors = TRUE; | 12479 | cinfo.quantize_colors = TRUE; |
| 12440 | jpeg_start_decompress (&cinfo); | 12480 | fn_jpeg_start_decompress (&cinfo); |
| 12441 | width = img->width = cinfo.output_width; | 12481 | width = img->width = cinfo.output_width; |
| 12442 | height = img->height = cinfo.output_height; | 12482 | height = img->height = cinfo.output_height; |
| 12443 | 12483 | ||
| 12444 | /* Create X image and pixmap. */ | 12484 | /* Create X image and pixmap. */ |
| 12445 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, | 12485 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
| 12446 | &img->pixmap)) | ||
| 12447 | longjmp (mgr.setjmp_buffer, 2); | 12486 | longjmp (mgr.setjmp_buffer, 2); |
| 12448 | 12487 | ||
| 12449 | /* Allocate colors. When color quantization is used, | 12488 | /* Allocate colors. When color quantization is used, |
| @@ -12461,27 +12500,33 @@ jpeg_load (f, img) | |||
| 12461 | else | 12500 | else |
| 12462 | ir = 0, ig = 0, ib = 0; | 12501 | ir = 0, ig = 0, ib = 0; |
| 12463 | 12502 | ||
| 12503 | #if 0 /* TODO: Color tables. */ | ||
| 12464 | /* Use the color table mechanism because it handles colors that | 12504 | /* Use the color table mechanism because it handles colors that |
| 12465 | cannot be allocated nicely. Such colors will be replaced with | 12505 | cannot be allocated nicely. Such colors will be replaced with |
| 12466 | a default color, and we don't have to care about which colors | 12506 | a default color, and we don't have to care about which colors |
| 12467 | can be freed safely, and which can't. */ | 12507 | can be freed safely, and which can't. */ |
| 12468 | init_color_table (); | 12508 | init_color_table (); |
| 12509 | #endif | ||
| 12469 | colors = (unsigned long *) alloca (cinfo.actual_number_of_colors | 12510 | colors = (unsigned long *) alloca (cinfo.actual_number_of_colors |
| 12470 | * sizeof *colors); | 12511 | * sizeof *colors); |
| 12471 | 12512 | ||
| 12472 | for (i = 0; i < cinfo.actual_number_of_colors; ++i) | 12513 | for (i = 0; i < cinfo.actual_number_of_colors; ++i) |
| 12473 | { | 12514 | { |
| 12474 | /* Multiply RGB values with 255 because X expects RGB values | 12515 | int r = cinfo.colormap[ir][i]; |
| 12475 | in the range 0..0xffff. */ | 12516 | int g = cinfo.colormap[ig][i]; |
| 12476 | int r = cinfo.colormap[ir][i] << 8; | 12517 | int b = cinfo.colormap[ib][i]; |
| 12477 | int g = cinfo.colormap[ig][i] << 8; | 12518 | #if 0 /* TODO: Color tables. */ |
| 12478 | int b = cinfo.colormap[ib][i] << 8; | ||
| 12479 | colors[i] = lookup_rgb_color (f, r, g, b); | 12519 | colors[i] = lookup_rgb_color (f, r, g, b); |
| 12520 | #else | ||
| 12521 | colors[i] = PALETTERGB (r, g, b); | ||
| 12522 | #endif | ||
| 12480 | } | 12523 | } |
| 12481 | 12524 | ||
| 12525 | #if 0 /* TODO: Color tables. */ | ||
| 12482 | /* Remember those colors actually allocated. */ | 12526 | /* Remember those colors actually allocated. */ |
| 12483 | img->colors = colors_in_color_table (&img->ncolors); | 12527 | img->colors = colors_in_color_table (&img->ncolors); |
| 12484 | free_color_table (); | 12528 | free_color_table (); |
| 12529 | #endif | ||
| 12485 | } | 12530 | } |
| 12486 | 12531 | ||
| 12487 | /* Read pixels. */ | 12532 | /* Read pixels. */ |
| @@ -12490,25 +12535,24 @@ jpeg_load (f, img) | |||
| 12490 | row_stride, 1); | 12535 | row_stride, 1); |
| 12491 | for (y = 0; y < height; ++y) | 12536 | for (y = 0; y < height; ++y) |
| 12492 | { | 12537 | { |
| 12493 | jpeg_read_scanlines (&cinfo, buffer, 1); | 12538 | fn_jpeg_read_scanlines (&cinfo, buffer, 1); |
| 12494 | for (x = 0; x < cinfo.output_width; ++x) | 12539 | for (x = 0; x < cinfo.output_width; ++x) |
| 12495 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); | 12540 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); |
| 12496 | } | 12541 | } |
| 12497 | 12542 | ||
| 12498 | /* Clean up. */ | 12543 | /* Clean up. */ |
| 12499 | jpeg_finish_decompress (&cinfo); | 12544 | fn_jpeg_finish_decompress (&cinfo); |
| 12500 | jpeg_destroy_decompress (&cinfo); | 12545 | fn_jpeg_destroy_decompress (&cinfo); |
| 12501 | if (fp) | 12546 | if (fp) |
| 12502 | fclose (fp); | 12547 | fclose ((FILE *) fp); |
| 12503 | 12548 | ||
| 12504 | /* Maybe fill in the background field while we have ximg handy. */ | 12549 | /* Maybe fill in the background field while we have ximg handy. */ |
| 12505 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | 12550 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) |
| 12506 | IMAGE_BACKGROUND (img, f, ximg); | 12551 | IMAGE_BACKGROUND (img, f, ximg); |
| 12507 | 12552 | ||
| 12508 | /* Put the image into the pixmap. */ | 12553 | /* Put the image into the pixmap. */ |
| 12509 | x_put_x_image (f, ximg, img->pixmap, width, height); | 12554 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| 12510 | x_destroy_x_image (ximg); | 12555 | x_destroy_x_image (ximg); |
| 12511 | UNBLOCK_INPUT; | ||
| 12512 | UNGCPRO; | 12556 | UNGCPRO; |
| 12513 | return 1; | 12557 | return 1; |
| 12514 | } | 12558 | } |
| @@ -15022,8 +15066,8 @@ If the underlying system call fails, value is nil. */) | |||
| 15022 | void | 15066 | void |
| 15023 | syms_of_w32fns () | 15067 | syms_of_w32fns () |
| 15024 | { | 15068 | { |
| 15025 | globals_of_w32fns (); | 15069 | globals_of_w32fns (); |
| 15026 | /* This is zero if not using MS-Windows. */ | 15070 | /* This is zero if not using MS-Windows. */ |
| 15027 | w32_in_use = 0; | 15071 | w32_in_use = 0; |
| 15028 | track_mouse_window = NULL; | 15072 | track_mouse_window = NULL; |
| 15029 | 15073 | ||
| @@ -15628,14 +15672,19 @@ void globals_of_w32fns () | |||
| 15628 | static void | 15672 | static void |
| 15629 | init_external_image_libraries () | 15673 | init_external_image_libraries () |
| 15630 | { | 15674 | { |
| 15631 | HINSTANCE png_lib; | 15675 | HINSTANCE library; |
| 15632 | 15676 | ||
| 15633 | #if HAVE_XPM | 15677 | #if HAVE_XPM |
| 15634 | define_image_type (&xpm_type); | 15678 | define_image_type (&xpm_type); |
| 15635 | #endif | 15679 | #endif |
| 15636 | 15680 | ||
| 15637 | #if HAVE_JPEG | 15681 | #if HAVE_JPEG |
| 15638 | define_image_type (&jpeg_type); | 15682 | /* Try loading jpeg library under probable names. */ |
| 15683 | if (library = LoadLibrary ("jpeg.dll")) | ||
| 15684 | { | ||
| 15685 | if (init_jpeg_functions (library)) | ||
| 15686 | define_image_type (&jpeg_type); | ||
| 15687 | } | ||
| 15639 | #endif | 15688 | #endif |
| 15640 | 15689 | ||
| 15641 | #if HAVE_TIFF | 15690 | #if HAVE_TIFF |
| @@ -15652,13 +15701,13 @@ init_external_image_libraries () | |||
| 15652 | LoadLibrary ("zlib.dll"); | 15701 | LoadLibrary ("zlib.dll"); |
| 15653 | 15702 | ||
| 15654 | /* Try loading libpng under probable names. */ | 15703 | /* Try loading libpng under probable names. */ |
| 15655 | if ((png_lib = LoadLibrary ("libpng13d.dll")) | 15704 | if ((library = LoadLibrary ("libpng13d.dll")) |
| 15656 | || (png_lib = LoadLibrary ("libpng13.dll")) | 15705 | || (library = LoadLibrary ("libpng13.dll")) |
| 15657 | || (png_lib = LoadLibrary ("libpng12d.dll")) | 15706 | || (library = LoadLibrary ("libpng12d.dll")) |
| 15658 | || (png_lib = LoadLibrary ("libpng12.dll")) | 15707 | || (library = LoadLibrary ("libpng12.dll")) |
| 15659 | || (png_lib = LoadLibrary ("libpng.dll"))) | 15708 | || (library = LoadLibrary ("libpng.dll"))) |
| 15660 | { | 15709 | { |
| 15661 | if (init_png_functions (png_lib)) | 15710 | if (init_png_functions (library)) |
| 15662 | define_image_type (&png_type); | 15711 | define_image_type (&png_type); |
| 15663 | } | 15712 | } |
| 15664 | #endif | 15713 | #endif |