Copyright (C) 1993, 1994, 1998 Free Software Foundation, Inc.
Copyright (C) 1995 Board of Trustees, University of Illinois.
Copyright (C) 1995 Tinker Systems
- Copyright (C) 1995, 1996 Ben Wing
+ Copyright (C) 1995, 1996, 2005 Ben Wing
Copyright (C) 1995 Sun Microsystems
This file is part of XEmacs.
#include "buffer.h"
#include "frame.h"
#include "opaque.h"
+#include "window.h"
#include "sysfile.h"
#ifdef __cplusplus
extern "C" {
#endif
+
+#ifdef WIN32_NATIVE
+/* #### Yuck! More horrifitude. tiffio.h, below, includes <windows.h>,
+ which defines INT32 and INT16, the former differently and incompatibly
+ from jmorecfg.h, included by jpeglib.h. We can disable the stuff in
+ jmorecfg.h by defining XMD_H (clever, huh?); then we define these
+ typedefs the way that <windows.h> wants them (which is more correct,
+ anyway; jmorecfg.h defines INT32 as `long'). */
+#define XMD_H
+typedef signed int INT32;
+typedef signed short INT16;
+#endif
+
#include <jpeglib.h>
#include <jerror.h>
#ifdef __cplusplus
}
static Lisp_Object
-jpeg_normalize (Lisp_Object inst, Lisp_Object console_type)
+jpeg_normalize (Lisp_Object inst, Lisp_Object console_type,
+ Lisp_Object dest_mask)
{
return simple_image_type_normalize (inst, console_type, Qjpeg);
}
if (!src)
{
return;
- } else if (num_bytes > src->bytes_in_buffer)
+ } else if (num_bytes > (long) src->bytes_in_buffer)
{
ERREXIT(cinfo, JERR_INPUT_EOF);
/*NOTREACHED*/
Lisp_Object pointer_fg, Lisp_Object pointer_bg,
int dest_mask, Lisp_Object domain)
{
- struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
/* It is OK for the unwind data to be local to this function,
because the unwind-protect is always executed when this
stack frame is still valid. */
{
Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
- CONST Extbyte *bytes;
+ const Extbyte *bytes;
Extcount len;
/* #### This is a definite problem under Mule due to the amount of
stack data it might allocate. Need to be able to convert and
write out to a file. */
- GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
+ TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
jpeg_memory_src (&cinfo, (JOCTET *) bytes, len);
}
*/
while (cinfo.output_scanline < cinfo.output_height)
{
- int i;
+ unsigned int i;
/* jpeg_read_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could ask for
/* Step 6.5: Create the pixmap and set up the image instance */
/* now instantiate */
- MAYBE_DEVMETH (XDEVICE (ii->device),
+ MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
init_image_instance_from_eimage,
(ii, cinfo.output_width, cinfo.output_height, 1,
unwind.eimage, dest_mask,
}
static Lisp_Object
-gif_normalize (Lisp_Object inst, Lisp_Object console_type)
+gif_normalize (Lisp_Object inst, Lisp_Object console_type,
+ Lisp_Object dest_mask)
{
return simple_image_type_normalize (inst, console_type, Qgif);
}
{
gif_memory_storage *mem = (gif_memory_storage*)data;
- if (size > (mem->len - mem->index))
+ if ((ssize_t) size > (mem->len - mem->index))
return (size_t) -1;
memcpy(buf, mem->bytes + mem->index, size);
mem->index = mem->index + size;
struct gif_error_struct
{
- CONST char *err_str; /* return the error string */
+ const char *err_str; /* return the error string */
jmp_buf setjmp_buffer; /* for return to caller */
};
static void
-gif_error_func(CONST char *err_str, VoidPtr error_ptr)
+gif_error_func(const char *err_str, VoidPtr error_ptr)
{
struct gif_error_struct *error_data = (struct gif_error_struct*)error_ptr;
Lisp_Object pointer_fg, Lisp_Object pointer_bg,
int dest_mask, Lisp_Object domain)
{
- struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
/* It is OK for the unwind data to be local to this function,
because the unwind-protect is always executed when this
stack frame is still valid. */
assert (!NILP (data));
if (!(unwind.giffile = GifSetup()))
- signal_image_error ("Insufficent memory to instantiate GIF image", instantiator);
+ signal_image_error ("Insufficient memory to instantiate GIF image", instantiator);
/* set up error facilities */
if (setjmp(gif_err.setjmp_buffer))
}
GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err);
- GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
+ TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
mem_struct.bytes = bytes;
mem_struct.len = len;
mem_struct.index = 0;
for (slice = 0; slice < unwind.giffile->ImageCount; slice++)
{
- /* We check here that that the current image covers the full "screen" size. */
+ /* We check here that the current image covers the full "screen" size. */
if (unwind.giffile->SavedImages[slice].ImageDesc.Height != height
|| unwind.giffile->SavedImages[slice].ImageDesc.Width != width
|| unwind.giffile->SavedImages[slice].ImageDesc.Left != 0
}
/* now instantiate */
- MAYBE_DEVMETH (XDEVICE (ii->device),
+ MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
init_image_instance_from_eimage,
(ii, width, height, unwind.giffile->ImageCount, unwind.eimage, dest_mask,
instantiator, domain));
}
static Lisp_Object
-png_normalize (Lisp_Object inst, Lisp_Object console_type)
+png_normalize (Lisp_Object inst, Lisp_Object console_type,
+ Lisp_Object dest_mask)
{
return simple_image_type_normalize (inst, console_type, Qpng);
}
struct png_memory_storage
{
- CONST Extbyte *bytes; /* The data */
+ const Extbyte *bytes; /* The data */
Extcount len; /* How big is it? */
int index; /* Where are we? */
};
struct png_memory_storage *tbr =
(struct png_memory_storage *) png_get_io_ptr (png_ptr);
- if (length > (tbr->len - tbr->index))
+ if ((ssize_t) length > (tbr->len - tbr->index))
png_error (png_ptr, (png_const_charp) "Read Error");
memcpy (data,tbr->bytes + tbr->index,length);
tbr->index = tbr->index + length;
struct png_error_struct
{
- CONST char *err_str;
+ const char *err_str;
jmp_buf setjmp_buffer; /* for return to caller */
};
free_opaque_ptr (unwind_obj);
if (data->png_ptr)
- png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL);
+ {
+ /* ensure we can't get here again */
+ png_structp tmp = data->png_ptr;
+ data->png_ptr = NULL;
+ png_destroy_read_struct (&tmp, &(data->info_ptr), (png_infopp)NULL);
+ }
+
if (data->instream)
fclose (data->instream);
Lisp_Object pointer_fg, Lisp_Object pointer_bg,
int dest_mask, Lisp_Object domain)
{
- struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
struct png_unwind_data unwind;
int speccount = specpdl_depth ();
int height, width;
png_structp png_ptr;
png_infop info_ptr;
+ xzero (unwind);
+ record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
+
+ if (setjmp (png_err_stct.setjmp_buffer))
+ {
+ /* Something blew up:
+ just display the error (cleanup happens in the unwind) */
+ signal_image_error_2 ("Error decoding PNG",
+ build_string(png_err_stct.err_str),
+ instantiator);
+ }
+
/* Initialize all PNG structures */
- png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (void*)&png_err_stct,
+ png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
+ (void *) &png_err_stct,
png_error_func, png_warning_func);
if (!png_ptr)
signal_image_error ("Error obtaining memory for png_read", instantiator);
+ unwind.png_ptr = png_ptr;
+
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
+ unwind.png_ptr = NULL; /* avoid re-calling png_destroy_read_struct
+ when unwinding */
png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
signal_image_error ("Error obtaining memory for png_read", instantiator);
}
-
- xzero (unwind);
- unwind.png_ptr = png_ptr;
unwind.info_ptr = info_ptr;
- record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
-
/* This code is a mixture of stuff from Ben's GIF/JPEG stuff from
this file, example.c from the libpng 0.81 distribution, and the
pngtopnm sources. -WMP-
and is no longer usable for previous versions. jh
*/
- /* Set the jmp_buf return context for png_error ... if this returns !0, then
- we ran into a problem somewhere, and need to clean up after ourselves. */
- if (setjmp (png_err_stct.setjmp_buffer))
- {
- /* Something blew up: just display the error (cleanup happens in the unwind) */
- signal_image_error_2 ("Error decoding PNG",
- build_string(png_err_stct.err_str),
- instantiator);
- }
-
/* Initialize the IO layer and read in header information */
{
Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
- CONST Extbyte *bytes;
+ const Extbyte *bytes;
Extcount len;
assert (!NILP (data));
/* #### This is a definite problem under Mule due to the amount of
stack data it might allocate. Need to think about using Lstreams */
- GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
+ TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
tbr.bytes = bytes;
tbr.len = len;
tbr.index = 0;
{
int y;
unsigned char **row_pointers;
- height = info_ptr->height;
- width = info_ptr->width;
+ height = png_get_image_height (png_ptr, info_ptr) /* info_ptr->height */;
+ width = png_get_image_width (png_ptr, info_ptr) /* info_ptr->width */;
/* Wow, allocate all the memory. Truly, exciting. */
unwind.eimage = xnew_array_and_zero (unsigned char, width * height * 3);
}
else
{
- struct Lisp_Color_Instance *c;
+ Lisp_Color_Instance *c;
Lisp_Object rgblist;
c = XCOLOR_INSTANCE (bkgd);
rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device),
color_instance_rgb_components,
(c));
- my_background.red = XINT (XCAR (rgblist));
- my_background.green = XINT (XCAR (XCDR (rgblist)));
- my_background.blue = XINT (XCAR (XCDR (XCDR (rgblist))));
+ my_background.red = (unsigned short) XINT (XCAR (rgblist));
+ my_background.green = (unsigned short) XINT (XCAR (XCDR (rgblist)));
+ my_background.blue = (unsigned short) XINT (XCAR (XCDR (XCDR (rgblist))));
}
if (png_get_bKGD (png_ptr, info_ptr, &image_background))
/* Now that we're using EImage, ask for 8bit RGB triples for any type
of image*/
/* convert palette images to full RGB */
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_PALETTE)
png_set_expand (png_ptr);
/* send grayscale images to RGB too */
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
/* we can't handle alpha values */
- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha (png_ptr);
/* tell libpng to strip 16 bit depth files down to 8 bits */
- if (info_ptr->bit_depth == 16)
+ if (png_get_bit_depth(png_ptr, info_ptr) /* info_ptr->bit_depth */ == 16)
png_set_strip_16 (png_ptr);
/* if the image is < 8 bits, pad it out */
- if (info_ptr->bit_depth < 8)
+ if (png_get_bit_depth(png_ptr, info_ptr) /* info_ptr->bit_depth */ < 8)
{
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY)
png_set_expand (png_ptr);
else
png_set_packing (png_ptr);
}
/* now instantiate */
- MAYBE_DEVMETH (XDEVICE (ii->device),
+ MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
init_image_instance_from_eimage,
(ii, width, height, 1, unwind.eimage, dest_mask,
instantiator, domain));
}
static Lisp_Object
-tiff_normalize (Lisp_Object inst, Lisp_Object console_type)
+tiff_normalize (Lisp_Object inst, Lisp_Object console_type,
+ Lisp_Object dest_mask)
{
return simple_image_type_normalize (inst, console_type, Qtiff);
}
static size_t tiff_memory_write(thandle_t data, tdata_t buf, tsize_t size)
{
- abort();
+ ABORT();
return 0; /* Shut up warnings. */
}
break;
default:
fprintf(stderr,"Eh? invalid seek mode in tiff_memory_seek\n");
- return -1;
+ return (toff_t) -1;
}
if ((newidx > mem->len) || (newidx < 0))
- return -1;
+ return (toff_t) -1;
mem->index = newidx;
return newidx;
static struct tiff_error_struct tiff_err_data;
static void
-tiff_error_func(CONST char *module, CONST char *fmt, ...)
+tiff_error_func(const char *module, const char *fmt, ...)
{
va_list vargs;
}
static void
-tiff_warning_func(CONST char *module, CONST char *fmt, ...)
+tiff_warning_func(const char *module, const char *fmt, ...)
{
va_list vargs;
#ifdef HAVE_VSNPRINTF
Lisp_Object pointer_fg, Lisp_Object pointer_bg,
int dest_mask, Lisp_Object domain)
{
- struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
tiff_memory_storage mem_struct;
/* It is OK for the unwind data to be local to this function,
because the unwind-protect is always executed when this
/* #### This is a definite problem under Mule due to the amount of
stack data it might allocate. Think about Lstreams... */
- GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len);
+ TO_EXTERNAL_FORMAT (LISP_STRING, data,
+ ALLOCA, (bytes, len),
+ Qbinary);
mem_struct.bytes = bytes;
mem_struct.len = len;
mem_struct.index = 0;
- unwind.tiff = TIFFClientOpen ("memfile", "r", &mem_struct,
+ unwind.tiff = TIFFClientOpen ("memfile", "r", (thandle_t) &mem_struct,
(TIFFReadWriteProc)tiff_memory_read,
(TIFFReadWriteProc)tiff_memory_write,
tiff_memory_seek, tiff_memory_close, tiff_memory_size,
tiff_map_noop, tiff_unmap_noop);
if (!unwind.tiff)
- signal_image_error ("Insufficent memory to instantiate TIFF image", instantiator);
+ signal_image_error ("Insufficient memory to instantiate TIFF image", instantiator);
TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height);
unwind.eimage = (unsigned char *) xmalloc (width * height * 3);
- /* ### This is little more than proof-of-concept/function testing.
+ /* #### This is little more than proof-of-concept/function testing.
It needs to be reimplemented via scanline reads for both memory
compactness. */
raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32));
/* This is to get around weirdness in the libtiff library where properly
made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */
rp = raster + (i * width);
- for (j = 0; j < width; j++)
+ for (j = 0; (uint32) j < width; j++)
{
*ep++ = (unsigned char)TIFFGetR(*rp);
*ep++ = (unsigned char)TIFFGetG(*rp);
}
/* now instantiate */
- MAYBE_DEVMETH (XDEVICE (ii->device),
+ MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
init_image_instance_from_eimage,
(ii, width, height, 1, unwind.eimage, dest_mask,
instantiator, domain));