Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jun 2012 21:52:10 +1000
From:      "Robert McKenzie" <vk7rb@internode.on.net>
To:        <gnome@FreeBSD.org>
Subject:   imlib
Message-ID:  <EADD3B1DE3E746758BAA9A9101AD56A8@Doctor>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------=_NextPart_000_01ED_01CD4E65.C77EC5D0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Sir,

I have done a butchers job to try and fix a problem that I had in that =
kuickshow-kde4 would not build because of an error where PrintGifError =
was missing which I fixed after finding a patch that I was not sure how =
to apply properly so imported it manually, made adjustments as required =
until it worked and then after building and installing imlib, built =
kuickshow-kde4 which then built successfully.

The two files are the diff file that I generated and the modified load.c =
which I hope will prove useful.

Regards,
Robert McKenzie.

------=_NextPart_000_01ED_01CD4E65.C77EC5D0
Content-Type: application/octet-stream;
	name="load.c.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="load.c.diff"

432,433c432,446=0A=
< unsigned char      *=0A=
< _LoadGIF(ImlibData * id, FILE *f, int *w, int *h, int *t)=0A=
---=0A=
> =0A=
>   static void=0A=
>   PrintGifError(void)=0A=
> {=0A=
>   char *Err =3D GifErrorString();=0A=
> =0A=
>   if (Err !=3D NULL)=0A=
>      fprintf(stderr, "\nGIF-LIB error: %s.\n", Err);=0A=
>   else=0A=
>   fprintf(stderr, "\nGIF-LIB undefined error %d.\n", GifError());=0A=
> }=0A=
> =0A=
>   unsigned char *=0A=
>   _LoadGIF(ImlibData * id, FILE *f, int *w, int *h, int *t)=0A=
> =0A=

------=_NextPart_000_01ED_01CD4E65.C77EC5D0
Content-Type: application/octet-stream;
	name="load.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="load.c"

#define _GNU_SOURCE=0A=
#include <config.h>=0A=
#include "Imlib.h"=0A=
#include "Imlib_private.h"=0A=
#include <setjmp.h>=0A=
=0A=
#define G_MAXINT ((int) 0x7fffffff)=0A=
=0A=
/*      Split the ID - damages input    */=0A=
=0A=
static char        *=0A=
_SplitID(char *file)=0A=
{=0A=
#ifndef __EMX__=0A=
  char *p =3D strrchr(file, ':');=0A=
#else=0A=
  char *p =3D strrchr(file, ';');=0A=
#endif=0A=
=0A=
  if (p =3D=3D NULL)=0A=
    return "";=0A=
  else=0A=
    {=0A=
      *p++ =3D 0;=0A=
      return p;=0A=
    }=0A=
}=0A=
=0A=
/*=0A=
 * *     Doesn't damage the input=0A=
 */=0A=
=0A=
char               *=0A=
_GetExtension(char *file)=0A=
{=0A=
  char               *p =3D strrchr(file, '.');=0A=
=0A=
  if (p =3D=3D NULL)=0A=
    return "";=0A=
  else=0A=
    return p + 1;=0A=
}=0A=
=0A=
/*=0A=
 *     Make sure we don't wrap on our memory allocations=0A=
 *     we check G_MAXINT/4 because rend.c malloc's w * h * bpp=0A=
 *     + 3 is safety margin=0A=
 */=0A=
=0A=
void * _imlib_malloc_image(unsigned int w, unsigned int h)=0A=
{=0A=
       if (w <=3D 0 || w > 32767 ||=0A=
           h <=3D 0 || h > 32767 ||=0A=
           h >=3D (G_MAXINT/4 - 1) / w)=0A=
                return NULL;=0A=
       return malloc(w * h * 3 + 3);=0A=
}=0A=
=0A=
#ifdef HAVE_LIBJPEG=0A=
=0A=
/** =0A=
 *  * This error handling is broken beyond belief, but oh well it works=0A=
 *  **/=0A=
=0A=
struct ImLib_JPEG_error_mgr=0A=
{=0A=
  struct jpeg_error_mgr pub;=0A=
  sigjmp_buf          setjmp_buffer;=0A=
};=0A=
=0A=
typedef struct ImLib_JPEG_error_mgr *emptr;=0A=
=0A=
void=0A=
_JPEGFatalErrorHandler(j_common_ptr cinfo)=0A=
{=0A=
  /* =0A=
   * FIXME:=0A=
   * We should somehow signal what error occurred to the caller so the=0A=
   * caller can handle the error message =0A=
   */=0A=
  emptr               errmgr;=0A=
=0A=
  errmgr =3D (emptr) cinfo->err;=0A=
  cinfo->err->output_message(cinfo);=0A=
  siglongjmp(errmgr->setjmp_buffer, 1);=0A=
  return;=0A=
}=0A=
=0A=
unsigned char      *=0A=
_LoadJPEG(ImlibData * id, FILE * f, int *w, int *h)=0A=
{=0A=
  struct jpeg_decompress_struct cinfo;=0A=
  struct ImLib_JPEG_error_mgr jerr;=0A=
  unsigned char      *data, *line[16], *ptr;=0A=
  int                 x, y, i;=0A=
=0A=
  cinfo.err =3D jpeg_std_error(&(jerr.pub));=0A=
  jerr.pub.error_exit =3D _JPEGFatalErrorHandler;=0A=
=0A=
  /* error handler to longjmp to, we want to preserve signals */=0A=
  if (sigsetjmp(jerr.setjmp_buffer, 1))=0A=
    {=0A=
      /* Whoops there was a jpeg error */=0A=
      jpeg_destroy_decompress(&cinfo);=0A=
      return NULL;=0A=
    }=0A=
=0A=
  jpeg_create_decompress(&cinfo);=0A=
  jpeg_stdio_src(&cinfo, f);=0A=
  jpeg_read_header(&cinfo, TRUE);=0A=
  cinfo.do_fancy_upsampling =3D FALSE;=0A=
  cinfo.do_block_smoothing =3D FALSE;=0A=
  jpeg_start_decompress(&cinfo);=0A=
  *w =3D cinfo.output_width;=0A=
  *h =3D cinfo.output_height;=0A=
  data =3D _imlib_malloc_image(*w, *h);=0A=
  if (!data)=0A=
    {=0A=
      jpeg_destroy_decompress(&cinfo);=0A=
      return NULL;=0A=
    }=0A=
  ptr =3D data;=0A=
=0A=
  if (cinfo.rec_outbuf_height > 16)=0A=
    {=0A=
      fprintf(stderr, "Imlib ERROR: JPEG uses line buffers > 16. Cannot =
load.\n");=0A=
      return NULL;=0A=
    }=0A=
  if (cinfo.output_components =3D=3D 3)=0A=
    {=0A=
      for (y =3D 0; y < *h; y +=3D cinfo.rec_outbuf_height)=0A=
	{=0A=
	  for (i =3D 0; i < cinfo.rec_outbuf_height; i++)=0A=
	    {=0A=
	      line[i] =3D ptr;=0A=
	      ptr +=3D *w * 3;=0A=
	    }=0A=
	  jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);=0A=
	}=0A=
    }=0A=
  else if (cinfo.output_components =3D=3D 1)=0A=
    {=0A=
      for (i =3D 0; i < cinfo.rec_outbuf_height; i++)=0A=
	{=0A=
	  if ((line[i] =3D malloc(*w)) =3D=3D NULL)=0A=
	    {=0A=
	      int                 t =3D 0;=0A=
=0A=
	      for (t =3D 0; t < i; t++)=0A=
		free(line[t]);=0A=
	      jpeg_destroy_decompress(&cinfo);=0A=
	      return NULL;=0A=
	    }=0A=
	}=0A=
      for (y =3D 0; y < *h; y +=3D cinfo.rec_outbuf_height)=0A=
	{=0A=
	  jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);=0A=
	  for (i =3D 0; i < cinfo.rec_outbuf_height; i++)=0A=
	    {=0A=
	      for (x =3D 0; x < *w; x++)=0A=
		{=0A=
		  *ptr++ =3D line[i][x];=0A=
		  *ptr++ =3D line[i][x];=0A=
		  *ptr++ =3D line[i][x];=0A=
		}=0A=
	    }=0A=
	}=0A=
      for (i =3D 0; i < cinfo.rec_outbuf_height; i++)=0A=
	free(line[i]);=0A=
    }=0A=
  jpeg_finish_decompress(&cinfo);=0A=
  jpeg_destroy_decompress(&cinfo);=0A=
=0A=
  return data;=0A=
}=0A=
#endif /* HAVE_LIBJPEG */=0A=
=0A=
#ifdef HAVE_LIBPNG=0A=
#include <pngpriv.h>=0A=
unsigned char      *=0A=
_LoadPNG(ImlibData * id, FILE * f, int *w, int *h, int *t)=0A=
{=0A=
  png_structp         png_ptr;=0A=
  png_infop           info_ptr;=0A=
  unsigned char      *data, *ptr, **lines, *ptr2, r, g, b, a;=0A=
  int                 i, x, y, transp, bit_depth, color_type, =
interlace_type;=0A=
  png_uint_32         ww, hh;=0A=
=0A=
  /* Init PNG Reader */=0A=
  transp =3D 0;=0A=
=0A=
  png_ptr =3D png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, =
NULL);=0A=
  if (!png_ptr)=0A=
    return NULL;=0A=
  info_ptr =3D png_create_info_struct(png_ptr);=0A=
  if (!info_ptr)=0A=
    {=0A=
      png_destroy_read_struct(&png_ptr, NULL, NULL);=0A=
      return NULL;=0A=
    }=0A=
  if (setjmp(png_jmpbuf(png_ptr)))=0A=
    {=0A=
      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
      return NULL;=0A=
    }=0A=
  if (info_ptr->color_type =3D=3D PNG_COLOR_TYPE_RGB_ALPHA)=0A=
    {=0A=
      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
      return NULL;=0A=
    }=0A=
  png_init_io(png_ptr, f);=0A=
=0A=
  /* Read Header */=0A=
  png_read_info(png_ptr, info_ptr);=0A=
  png_get_IHDR(png_ptr, info_ptr, &ww, &hh, =0A=
	       &bit_depth, &color_type, &interlace_type, NULL, NULL);=0A=
  *w =3D ww;=0A=
  *h =3D hh;=0A=
=0A=
  /* Setup Translators */=0A=
  if ((color_type =3D=3D PNG_COLOR_TYPE_PALETTE) ||=0A=
      (color_type =3D=3D PNG_COLOR_TYPE_GRAY))=0A=
    png_set_expand(png_ptr);=0A=
  png_set_strip_16(png_ptr);=0A=
  png_set_packing(png_ptr);=0A=
  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))=0A=
    png_set_expand(png_ptr);=0A=
  png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);=0A=
  data =3D _imlib_malloc_image(*w, *h);=0A=
  if (!data)=0A=
    {=0A=
      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
      return NULL;=0A=
    }=0A=
    /* This malloc is fine, _imlib_malloc_image will fail first */=0A=
  lines =3D (unsigned char **)malloc(*h * sizeof(unsigned char *));=0A=
=0A=
  if (lines =3D=3D NULL)=0A=
    {=0A=
      free(data);=0A=
      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
      return NULL;=0A=
    }=0A=
=0A=
  for (i =3D 0; i < *h; i++)=0A=
    {=0A=
     /* Safe as well for the same reason as above */=0A=
      if ((lines[i] =3D malloc(*w * (sizeof(unsigned char) * 4))) =3D=3D =
NULL)=0A=
	{=0A=
	  int                 n;=0A=
=0A=
	  free(data);=0A=
	  for (n =3D 0; n < i; n++)=0A=
	    free(lines[n]);=0A=
	  free(lines);=0A=
	  png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
	  return NULL;=0A=
	}=0A=
    }=0A=
=0A=
  png_read_image(png_ptr, lines);=0A=
  png_destroy_read_struct(&png_ptr, &info_ptr, NULL);=0A=
  ptr =3D data;=0A=
  if (color_type =3D=3D PNG_COLOR_TYPE_GRAY_ALPHA)=0A=
    {=0A=
      for (y =3D 0; y < *h; y++)=0A=
	{=0A=
	  ptr2 =3D lines[y];=0A=
	  for (x =3D 0; x < *w; x++)=0A=
	    {=0A=
	      r =3D *ptr2++;=0A=
	      a =3D *ptr2++;=0A=
	      if (a < 128)=0A=
		{=0A=
		  *ptr++ =3D 255;=0A=
		  *ptr++ =3D 0;=0A=
		  *ptr++ =3D 255;=0A=
		  transp =3D 1;=0A=
		}=0A=
	      else=0A=
		{=0A=
		  *ptr++ =3D r;=0A=
		  *ptr++ =3D r;=0A=
		  *ptr++ =3D r;=0A=
		}=0A=
	    }=0A=
	}=0A=
    }=0A=
  else if (color_type =3D=3D PNG_COLOR_TYPE_GRAY)=0A=
    {=0A=
      for (y =3D 0; y < *h; y++)=0A=
	{=0A=
	  ptr2 =3D lines[y];=0A=
	  for (x =3D 0; x < *w; x++)=0A=
	    {=0A=
	      r =3D *ptr2++;=0A=
              ptr2++;=0A=
	      *ptr++ =3D r;=0A=
	      *ptr++ =3D r;=0A=
	      *ptr++ =3D r;=0A=
	    }=0A=
	}=0A=
    }=0A=
  else=0A=
    {=0A=
      for (y =3D 0; y < *h; y++)=0A=
	{=0A=
	  ptr2 =3D lines[y];=0A=
	  for (x =3D 0; x < *w; x++)=0A=
	    {=0A=
	      r =3D *ptr2++;=0A=
	      g =3D *ptr2++;=0A=
	      b =3D *ptr2++;=0A=
	      a =3D *ptr2++;=0A=
	      if (a < 128)=0A=
		{=0A=
		  *ptr++ =3D 255;=0A=
		  *ptr++ =3D 0;=0A=
		  *ptr++ =3D 255;=0A=
		  transp =3D 1;=0A=
		}=0A=
	      else=0A=
		{=0A=
		  if ((r =3D=3D 255) && (g =3D=3D 0) && (b =3D=3D 255))=0A=
		    r =3D 254;=0A=
		  *ptr++ =3D r;=0A=
		  *ptr++ =3D g;=0A=
		  *ptr++ =3D b;=0A=
		}=0A=
	    }=0A=
	}=0A=
    }=0A=
  for (i =3D 0; i < *h; i++)=0A=
    free(lines[i]);=0A=
  free(lines);=0A=
  *t =3D transp;=0A=
  return data;=0A=
}=0A=
#endif /* HAVE_LIBPNG */=0A=
=0A=
#ifdef HAVE_LIBTIFF=0A=
unsigned char      *=0A=
_LoadTIFF(ImlibData * id, FILE *f, char *file, int *w, int *h, int *t)=0A=
{=0A=
  TIFF               *tif;=0A=
  unsigned char      *data, *ptr, r, g, b, a;=0A=
  int                 x, y;=0A=
  uint32              ww, hh, *rast, *tptr;=0A=
  size_t              npix;=0A=
  int                 istransp;=0A=
  int                 fd;=0A=
=0A=
  istransp =3D 0;=0A=
  if (!f)=0A=
    return NULL;=0A=
=0A=
  fd =3D fileno(f);=0A=
  /* Apparently rewind(f) isn't sufficient */=0A=
  lseek(fd, (long) 0, 0);=0A=
  /* So why does libtif need a filename here ??? */=0A=
  tif =3D TIFFFdOpen(fd, file, "r");=0A=
=0A=
  if (!tif)=0A=
    return NULL;=0A=
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &ww);=0A=
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &hh);=0A=
  npix =3D ww * hh;=0A=
  *w =3D (int)ww;=0A=
  *h =3D (int)hh;=0A=
  if (ww <=3D 0 || ww > 32767 ||=0A=
      hh <=3D 0 || hh > 32767 ||=0A=
      hh >=3D (G_MAXINT/sizeof(uint32)) / ww)=0A=
    {=0A=
       TIFFClose(tif);=0A=
       return NULL;=0A=
    }=0A=
  rast =3D (uint32 *) _TIFFmalloc(npix * sizeof(uint32));=0A=
  if (!rast)=0A=
    {=0A=
      TIFFClose(tif);=0A=
      return NULL;=0A=
    }=0A=
  data =3D NULL;=0A=
  if (TIFFReadRGBAImage(tif, ww, hh, rast, 0))=0A=
    {=0A=
      data =3D (unsigned char *)malloc(*w ** h * 3);=0A=
      if (!data)=0A=
	{=0A=
	  _TIFFfree(rast);=0A=
	  TIFFClose(tif);=0A=
	  return NULL;=0A=
	}=0A=
      ptr =3D data;=0A=
      for (y =3D 0; y < *h; y++)=0A=
	{=0A=
	  tptr =3D rast;=0A=
	  tptr +=3D ((*h - y - 1) ** w);=0A=
	  for (x =3D 0; x < *w; x++)=0A=
	    {=0A=
	      a =3D TIFFGetA(*tptr);=0A=
	      b =3D TIFFGetB(*tptr);=0A=
	      g =3D TIFFGetG(*tptr);=0A=
	      r =3D TIFFGetR(*tptr);=0A=
	      tptr++;=0A=
	      if (a < 128)=0A=
		{=0A=
		  *ptr++ =3D 255;=0A=
		  *ptr++ =3D 0;=0A=
		  *ptr++ =3D 255;=0A=
		  istransp =3D 1;=0A=
		}=0A=
	      else=0A=
		{=0A=
		  if ((r =3D=3D 255) && (g =3D=3D 0) && (b =3D=3D 255))=0A=
		    r =3D 254;=0A=
		  *ptr++ =3D r;=0A=
		  *ptr++ =3D g;=0A=
		  *ptr++ =3D b;=0A=
		}=0A=
	    }=0A=
	}=0A=
    }=0A=
  _TIFFfree(rast);=0A=
  TIFFClose(tif);=0A=
  *t =3D istransp;=0A=
  return data;=0A=
}=0A=
=0A=
#endif /* HAVE_LIBTIFF */=0A=
=0A=
#ifdef HAVE_LIBGIF=0A=
=0A=
  static void=0A=
  PrintGifError(void)=0A=
{=0A=
  char *Err =3D GifErrorString();=0A=
=0A=
  if (Err !=3D NULL)=0A=
     fprintf(stderr, "\nGIF-LIB error: %s.\n", Err);=0A=
  else=0A=
  fprintf(stderr, "\nGIF-LIB undefined error %d.\n", GifError());=0A=
}=0A=
=0A=
  unsigned char *=0A=
  _LoadGIF(ImlibData * id, FILE *f, int *w, int *h, int *t)=0A=
=0A=
{=0A=
  unsigned char      *data, *ptr;=0A=
  GifFileType        *gif;=0A=
  GifRowType         *rows;=0A=
  GifRecordType       rec;=0A=
  ColorMapObject     *cmap;=0A=
  int                 i, j, done, bg, csize, r, g, b;=0A=
  int                 intoffset[] =3D {0, 4, 2, 1};=0A=
  int                 intjump[] =3D {8, 8, 4, 2};=0A=
  int                 istransp, transp;=0A=
  int                 fd;=0A=
=0A=
  done =3D 0;=0A=
  istransp =3D 0;=0A=
  data =3D NULL;=0A=
  rows =3D NULL;=0A=
  transp =3D -1;=0A=
=0A=
  fd =3D fileno(f);=0A=
  /* Apparently rewind(f) isn't sufficient */=0A=
  lseek(fd, (long) 0, 0);=0A=
  gif =3D DGifOpenFileHandle(fd);=0A=
=0A=
  if (!gif)=0A=
    return NULL;=0A=
  do=0A=
    {=0A=
      if (DGifGetRecordType(gif, &rec) =3D=3D GIF_ERROR)=0A=
	{=0A=
	  PrintGifError();=0A=
	  rec =3D TERMINATE_RECORD_TYPE;=0A=
	}=0A=
      if ((rec =3D=3D IMAGE_DESC_RECORD_TYPE) && (!done))=0A=
	{=0A=
	  if (DGifGetImageDesc(gif) =3D=3D GIF_ERROR)=0A=
	    {=0A=
	      PrintGifError();=0A=
	      rec =3D TERMINATE_RECORD_TYPE;=0A=
	    }=0A=
	  *w =3D gif->Image.Width;=0A=
	  *h =3D gif->Image.Height;=0A=
	  if (*h <=3D 0 || *h > 32767 || *w <=3D 0 || *w > 32767)=0A=
	    {=0A=
	       return NULL;=0A=
	    }=0A=
	  rows =3D malloc(*h * sizeof(GifRowType *));=0A=
	  if (!rows)=0A=
	    {=0A=
	      DGifCloseFile(gif);=0A=
	      return NULL;=0A=
	    }=0A=
	  data =3D _imlib_malloc_image(*w, *h);=0A=
	  if (!data)=0A=
	    {=0A=
	      DGifCloseFile(gif);=0A=
	      free(rows);=0A=
	      return NULL;=0A=
	    }=0A=
	  for (i =3D 0; i < *h; i++)=0A=
	    rows[i] =3D NULL;=0A=
	  for (i =3D 0; i < *h; i++)=0A=
	    {=0A=
	      rows[i] =3D malloc(*w * sizeof(GifPixelType));=0A=
	      if (!rows[i])=0A=
		{=0A=
		  DGifCloseFile(gif);=0A=
		  for (i =3D 0; i < *h; i++)=0A=
		    if (rows[i])=0A=
		      free(rows[i]);=0A=
		  free(rows);=0A=
		  free(data);=0A=
		  return NULL;=0A=
		}=0A=
	    }=0A=
	  if (gif->Image.Interlace)=0A=
	    {=0A=
	      for (i =3D 0; i < 4; i++)=0A=
		{=0A=
		  for (j =3D intoffset[i]; j < *h; j +=3D intjump[i])=0A=
		    DGifGetLine(gif, rows[j], *w);=0A=
		}=0A=
	    }=0A=
	  else=0A=
	    {=0A=
	      for (i =3D 0; i < *h; i++)=0A=
		DGifGetLine(gif, rows[i], *w);=0A=
	    }=0A=
	  done =3D 1;=0A=
	}=0A=
      else if (rec =3D=3D EXTENSION_RECORD_TYPE)=0A=
	{=0A=
	  int                 ext_code;=0A=
	  GifByteType        *ext;=0A=
=0A=
	  ext =3D NULL;=0A=
	  DGifGetExtension(gif, &ext_code, &ext);=0A=
	  while (ext)=0A=
	    {=0A=
	      if ((ext_code =3D=3D 0xf9) && (ext[1] & 1) && (transp < 0))=0A=
		{=0A=
		  istransp =3D 1;=0A=
		  transp =3D (int)ext[4];=0A=
		}=0A=
	      ext =3D NULL;=0A=
	      DGifGetExtensionNext(gif, &ext);=0A=
	    }=0A=
	}=0A=
    }=0A=
  while (rec !=3D TERMINATE_RECORD_TYPE);=0A=
  bg =3D gif->SBackGroundColor;=0A=
  cmap =3D (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap);=0A=
  csize =3D cmap->ColorCount;=0A=
  ptr =3D data;=0A=
  if (!istransp)=0A=
    {=0A=
      for (i =3D 0; i < *h; i++)=0A=
	{=0A=
	  for (j =3D 0; j < *w; j++)=0A=
	    {=0A=
	      r =3D cmap->Colors[rows[i][j]].Red;=0A=
	      g =3D cmap->Colors[rows[i][j]].Green;=0A=
	      b =3D cmap->Colors[rows[i][j]].Blue;=0A=
	      *ptr++ =3D r;=0A=
	      *ptr++ =3D g;=0A=
	      *ptr++ =3D b;=0A=
	    }=0A=
	}=0A=
    }=0A=
  else=0A=
    {=0A=
      for (i =3D 0; i < *h; i++)=0A=
	{=0A=
	  for (j =3D 0; j < *w; j++)=0A=
	    {=0A=
	      if (rows[i][j] =3D=3D transp)=0A=
		{=0A=
		  *ptr++ =3D 255;=0A=
		  *ptr++ =3D 0;=0A=
		  *ptr++ =3D 255;=0A=
		}=0A=
	      else=0A=
		{=0A=
		  r =3D cmap->Colors[rows[i][j]].Red;=0A=
		  g =3D cmap->Colors[rows[i][j]].Green;=0A=
		  b =3D cmap->Colors[rows[i][j]].Blue;=0A=
		  if ((r =3D=3D 255) && (g =3D=3D 0) && (b =3D=3D 255))=0A=
		    r =3D 254;=0A=
		  *ptr++ =3D r;=0A=
		  *ptr++ =3D g;=0A=
		  *ptr++ =3D b;=0A=
		}=0A=
	    }=0A=
	}=0A=
    }=0A=
  DGifCloseFile(gif);=0A=
  for (i =3D 0; i < *h; i++)=0A=
    free(rows[i]);=0A=
  free(rows);=0A=
  *t =3D istransp;=0A=
  return data;=0A=
}=0A=
=0A=
#endif /* HAVE_LIBGIF */=0A=
=0A=
unsigned char      *=0A=
_LoadBMP(ImlibData * id, FILE *file, int *w, int *h, int *t)=0A=
{=0A=
  unsigned char      *data, *ptr;=0A=
  int                 done, i, bpp, planes, comp, ncolors, line, column,=0A=
                      linesize, linepos, rshift, gshift, bshift, size;=0A=
  unsigned char       byte;=0A=
  short int           word;=0A=
  long int            dbuf[4], dword, rmask, gmask, bmask, offset;=0A=
  signed char         bbuf[4];=0A=
  struct _cmap=0A=
    {=0A=
      unsigned char       r, g, b;=0A=
    }=0A=
                     *cmap;=0A=
=0A=
#define BI_RGB       0=0A=
#define BI_RLE8      1=0A=
#define BI_RLE4      2=0A=
#define BI_BITFIELDS 3=0A=
=0A=
  rshift =3D 0;=0A=
  gshift =3D 0;=0A=
  bshift =3D 0;=0A=
  rmask =3D 0xff;=0A=
  gmask =3D 0xff;=0A=
  bmask =3D 0xff;=0A=
  if (!file)=0A=
    return NULL;=0A=
=0A=
  done =3D 0;=0A=
  /* =0A=
   * reading the bmp header =0A=
   */=0A=
=0A=
  fread(bbuf, 1, 2, file);=0A=
=0A=
  fread(dbuf, 4, 4, file);=0A=
=0A=
  size =3D dbuf[0];=0A=
  offset =3D dbuf[2];=0A=
=0A=
  fread(dbuf, 4, 2, file);=0A=
  *w =3D (int)dbuf[0];=0A=
  *h =3D (int)dbuf[1];=0A=
  if ((*w > 32767) || (*w < 0))=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for =
file\n");=0A=
      return NULL;=0A=
    }=0A=
  if ((*h > 32767) || (*h < 0))=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for =
file\n");=0A=
      return NULL;=0A=
    }=0A=
  fread(&word, 2, 1, file);=0A=
  planes =3D (int)word;=0A=
  fread(&word, 2, 1, file);=0A=
  bpp =3D (int)word;=0A=
  if (bpp !=3D 1 && bpp !=3D 4 && bpp !=3D 8 && bpp && 16 && bpp !=3D 24 =
&& bpp !=3D 32)=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: unknown bitdepth in file\n");=0A=
      return NULL;=0A=
    }=0A=
  fread(dbuf, 4, 4, file);=0A=
  comp =3D (int)dbuf[0];=0A=
  if (comp !=3D BI_RGB && comp !=3D BI_RLE4 && comp !=3D BI_RLE8 && comp =
!=3D BI_BITFIELDS)=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: unknown encoding in Windows BMP =
file\n");=0A=
      return NULL;=0A=
    }=0A=
  fread(dbuf, 4, 2, file);=0A=
  ncolors =3D (int)dbuf[0];=0A=
  if ((ncolors > (1 << bpp)) || (ncolors < 0))=0A=
    ncolors =3D 1 << bpp;=0A=
  if ((ncolors < 0) || (ncolors > (1 << bpp)))=0A=
    ncolors =3D 1 << bpp;=0A=
=0A=
  /* some more sanity checks */=0A=
  if (((comp =3D=3D BI_RLE4) && (bpp !=3D 4)) || ((comp =3D=3D BI_RLE8) =
&& (bpp !=3D 8)) || ((comp =3D=3D BI_BITFIELDS) && (bpp !=3D 16 && bpp =
!=3D 32)))=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: encoding of BMP doesn't match =
bitdepth\n");=0A=
      return NULL;=0A=
    }=0A=
  if (bpp < 16)=0A=
    {=0A=
      cmap =3D (struct _cmap *)malloc(sizeof(struct _cmap) * ncolors);=0A=
=0A=
      if (!cmap)=0A=
	{=0A=
	  fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for color map in =
BMP file\n");=0A=
	  return NULL;=0A=
	}=0A=
    }=0A=
  else=0A=
    cmap =3D NULL;=0A=
  ptr =3D (unsigned char *)_imlib_malloc_image(*w, *h);=0A=
  if (!ptr)=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for RGB data in =
file\n");=0A=
      if (cmap)=0A=
	free(cmap);=0A=
      return NULL;=0A=
    }=0A=
=0A=
  /*=0A=
   * Reading the palette, if it exists.=0A=
   */=0A=
  if (bpp < 16 && ncolors !=3D 0)=0A=
    {=0A=
      for (i =3D 0; i < ncolors; i++)=0A=
	{=0A=
	  fread(bbuf, 1, 4, file);=0A=
	  cmap[i].b =3D bbuf[0];=0A=
	  cmap[i].g =3D bbuf[1];=0A=
	  cmap[i].r =3D bbuf[2];=0A=
	}=0A=
    }=0A=
  else if (bpp =3D=3D 16 || bpp =3D=3D 32)=0A=
    {=0A=
      if (comp =3D=3D BI_BITFIELDS)=0A=
	{=0A=
	  int                 bit =3D 0;=0A=
=0A=
	  fread(dbuf, 4, 3, file);=0A=
	  bmask =3D dbuf[0];=0A=
	  gmask =3D dbuf[1];=0A=
	  rmask =3D dbuf[2];=0A=
	  /* find shift amount.. ugly, but i can't think of a better way */=0A=
	  for (bit =3D 0; bit < bpp; bit++)=0A=
	    {=0A=
	      if (bmask & (1 << bit))=0A=
		bshift =3D bit;=0A=
	      if (gmask & (1 << bit))=0A=
		gshift =3D bit;=0A=
	      if (rmask & (1 << bit))=0A=
		rshift =3D bit;=0A=
	    }=0A=
	}=0A=
      else if (bpp =3D=3D 16)=0A=
	{=0A=
	  rmask =3D 0x7C00;=0A=
	  gmask =3D 0x03E0;=0A=
	  bmask =3D 0x001F;=0A=
	  rshift =3D 10;=0A=
	  gshift =3D 5;=0A=
	  bshift =3D 0;=0A=
	}=0A=
      else if (bpp =3D=3D 32)=0A=
	{=0A=
	  rmask =3D 0x00FF0000;=0A=
	  gmask =3D 0x0000FF00;=0A=
	  bmask =3D 0x000000FF;=0A=
	  rshift =3D 16;=0A=
	  gshift =3D 8;=0A=
	  bshift =3D 0;=0A=
	}=0A=
    }=0A=
=0A=
  /*=0A=
   * Reading the image data=0A=
   */=0A=
  fseek(file, offset, SEEK_SET);=0A=
  data =3D ptr;=0A=
=0A=
  /* set the whole image to the background color */=0A=
  if (bpp < 16 && (comp =3D=3D BI_RLE4 || comp =3D=3D BI_RLE8))=0A=
    {=0A=
      for (i =3D 0; i < *w * *h; i++)=0A=
	{=0A=
	  *ptr++ =3D cmap[0].r;=0A=
	  *ptr++ =3D cmap[0].g;=0A=
	  *ptr++ =3D cmap[0].b;=0A=
	}=0A=
      ptr =3D data;=0A=
    }=0A=
  line =3D 0;=0A=
  column =3D 0;=0A=
#define poffset (line * *w * 3 + column * 3)=0A=
=0A=
  /*=0A=
   * BMPs are stored upside down... hmmmmmmmmmm....=0A=
   */=0A=
=0A=
  linesize =3D ((*w * bpp + 31) / 32) * 4;=0A=
  for (line =3D (*h - 1); line >=3D 0; line--)=0A=
    {=0A=
      linepos =3D 0;=0A=
      for (column =3D 0; column < *w;)=0A=
	{=0A=
	  if (bpp < 16)=0A=
	    {=0A=
	      int                 index;=0A=
=0A=
	      linepos++;=0A=
	      byte =3D getc(file);=0A=
	      if (bpp =3D=3D 1)=0A=
		{=0A=
		  int                 bit =3D 0;=0A=
=0A=
		  for (bit =3D 0; bit < 8; bit++)=0A=
		    {=0A=
		      index =3D ((byte & (0x80 >> bit)) ? 1 : 0);=0A=
		      /* possibly corrupted file? */=0A=
		      if (index < ncolors && poffset < *w * *h * 3)=0A=
			{=0A=
			  ptr[poffset] =3D cmap[index].r;=0A=
			  ptr[poffset + 1] =3D cmap[index].g;=0A=
			  ptr[poffset + 2] =3D cmap[index].b;=0A=
			}=0A=
		      column++;=0A=
		    }=0A=
		}=0A=
	      else if (bpp =3D=3D 4)=0A=
		{=0A=
		  if (comp =3D=3D BI_RLE4)=0A=
		    {=0A=
		      fprintf(stderr, "can't deal with 4bit encoded yet.\n");=0A=
		      free(data);=0A=
		      free(cmap);=0A=
		      return NULL;=0A=
		    }=0A=
		  else=0A=
		    {=0A=
		      int                 nibble =3D 0;=0A=
=0A=
		      for (nibble =3D 0; nibble < 2; nibble++)=0A=
			{=0A=
			  index =3D ((byte & (0xF0 >> nibble * 4)) >> (!nibble * 4));=0A=
			  if (index >=3D 16)=0A=
			    index =3D 15;=0A=
			  /* possibly corrupted file? */=0A=
			  if (index < ncolors && poffset < *w * *h * 3)=0A=
			    {=0A=
			      ptr[poffset] =3D cmap[index].r;=0A=
			      ptr[poffset + 1] =3D cmap[index].g;=0A=
			      ptr[poffset + 2] =3D cmap[index].b;=0A=
			    }=0A=
			  column++;=0A=
			}=0A=
		    }=0A=
		}=0A=
	      else if (bpp =3D=3D 8)=0A=
		{=0A=
		  if (comp =3D=3D BI_RLE8)=0A=
		    {=0A=
		      unsigned char       first =3D byte;=0A=
=0A=
		      byte =3D getc(file);=0A=
		      if (first =3D=3D 0)=0A=
			{=0A=
			  if (byte =3D=3D 0)=0A=
			    {=0A=
			      /*   column =3D *w; */=0A=
			    }=0A=
			  else if (byte =3D=3D 1)=0A=
			    {=0A=
			      column =3D *w;=0A=
			      line =3D -1;=0A=
			    }=0A=
			  else if (byte =3D=3D 2)=0A=
			    {=0A=
			      byte =3D getc(file);=0A=
			      column +=3D byte;=0A=
			      linepos =3D column * bpp / 8;=0A=
			      byte =3D getc(file);=0A=
			      line +=3D byte;=0A=
			    }=0A=
			  else=0A=
			    {=0A=
			      int                 absolute =3D byte;=0A=
=0A=
			      for (i =3D 0; i < absolute; i++)=0A=
				{=0A=
				  linepos++;=0A=
				  byte =3D getc(file);=0A=
				  /* possibly corrupted file? */=0A=
				  if (byte < ncolors && poffset < *w * *h * 3)=0A=
				    {=0A=
				      ptr[poffset] =3D cmap[byte].r;=0A=
				      ptr[poffset + 1] =3D cmap[byte].g;=0A=
				      ptr[poffset + 2] =3D cmap[byte].b;=0A=
				    }=0A=
				  column++;=0A=
				}=0A=
			      if (absolute & 0x01)=0A=
				byte =3D getc(file);=0A=
			    }=0A=
			}=0A=
		      else=0A=
			{=0A=
			  for (i =3D 0; i < first; i++)=0A=
			    {=0A=
			      /* possibly corrupted file? */=0A=
			      if (byte < ncolors && poffset < *w * *h * 3)=0A=
				{=0A=
				  ptr[poffset] =3D cmap[byte].r;=0A=
				  ptr[poffset + 1] =3D cmap[byte].g;=0A=
				  ptr[poffset + 2] =3D cmap[byte].b;=0A=
				}=0A=
			      column++;=0A=
			      linepos++;=0A=
			    }=0A=
			}=0A=
		    }=0A=
		  else=0A=
		    {=0A=
		      /* possibly corrupted file? */=0A=
		      if (byte < ncolors && poffset < *w * *h * 3)=0A=
			{=0A=
			  ptr[poffset] =3D cmap[byte].r;=0A=
			  ptr[poffset + 1] =3D cmap[byte].g;=0A=
			  ptr[poffset + 2] =3D cmap[byte].b;=0A=
			}=0A=
		      column++;=0A=
		    }=0A=
		}=0A=
	    }=0A=
	  else if (bpp =3D=3D 24)=0A=
	    {=0A=
	      linepos +=3D fread(bbuf, 1, 3, file);=0A=
	      /* possibly corrupted file? */=0A=
	      if (poffset < *w * *h * 3)=0A=
		{=0A=
		  ptr[poffset] =3D (unsigned char)bbuf[2];=0A=
		  ptr[poffset + 1] =3D (unsigned char)bbuf[1];=0A=
		  ptr[poffset + 2] =3D (unsigned char)bbuf[0];=0A=
		}=0A=
	      column++;=0A=
	    }=0A=
	  else if (bpp =3D=3D 16)=0A=
	    {=0A=
	      unsigned char       temp;=0A=
=0A=
	      linepos +=3D fread(&word, 2, 1, file);=0A=
	      /* possibly corrupted file? */=0A=
	      if (poffset < *w * *h * 3)=0A=
		{=0A=
		  temp =3D (word & rmask) >> rshift;=0A=
		  ptr[poffset] =3D temp;=0A=
		  temp =3D (word & gmask) >> gshift;=0A=
		  ptr[poffset + 1] =3D temp;=0A=
		  temp =3D (word & bmask) >> gshift;=0A=
		  ptr[poffset + 2] =3D temp;=0A=
		}=0A=
	      column++;=0A=
	    }=0A=
	  else=0A=
	    {=0A=
	      unsigned char       temp;=0A=
=0A=
	      linepos +=3D fread(&dword, 4, 1, file);=0A=
	      /* possibly corrupted file? */=0A=
	      if (poffset < *w * *h * 3)=0A=
		{=0A=
		  temp =3D (dword & rmask) >> rshift;=0A=
		  ptr[poffset] =3D temp;=0A=
		  temp =3D (dword & gmask) >> gshift;=0A=
		  ptr[poffset + 1] =3D temp;=0A=
		  temp =3D (dword & bmask) >> bshift;=0A=
		  ptr[poffset + 2] =3D temp;=0A=
		}=0A=
	      column++;=0A=
	    }=0A=
	}=0A=
      while ((linepos < linesize) && (comp !=3D 1) && (comp !=3D 2))=0A=
	{=0A=
	  int                 temp =3D fread(&byte, 1, 1, file);=0A=
=0A=
	  linepos +=3D temp;=0A=
	  if (!temp)=0A=
	    break;=0A=
	}=0A=
    }=0A=
  if (cmap)=0A=
    free(cmap);=0A=
  *t =3D 0;=0A=
  return data;=0A=
}=0A=
=0A=
unsigned char      *=0A=
_LoadXPM(ImlibData * id, FILE *file, int *w, int *h, int *t)=0A=
{=0A=
  unsigned char      *data, *ptr, *end;=0A=
  int                 pc, c, i, j, k, ncolors, cpp, comment, transp, =
quote,=0A=
                      context, len, done;=0A=
  char                *line, s[256], tok[128], col[256];=0A=
  XColor              xcol;=0A=
  int                 lsz =3D 256;=0A=
  struct _cmap=0A=
    {=0A=
      unsigned char       str[6];=0A=
      unsigned char       transp;=0A=
      short                 r, g, b;=0A=
    }=0A=
                     *cmap;=0A=
  short                 lookup[128 - 32][128 - 32];=0A=
=0A=
  transp =3D 0;=0A=
  done =3D 0;=0A=
  if (!file)=0A=
    return NULL;=0A=
  i =3D 0;=0A=
  j =3D 0;=0A=
  cmap =3D NULL;=0A=
  *w =3D 10;=0A=
  *h =3D 10;=0A=
  ptr =3D NULL;=0A=
  data =3D NULL;=0A=
  end =3D NULL;=0A=
  c =3D ' ';=0A=
  comment =3D 0;=0A=
  quote =3D 0;=0A=
  context =3D 0;=0A=
  memset(lookup, 0, sizeof(lookup));=0A=
=0A=
  line =3D malloc(lsz);=0A=
  if (!line)=0A=
    return NULL;=0A=
=0A=
  while (!done)=0A=
    {=0A=
      pc =3D c;=0A=
      c =3D fgetc(file);=0A=
      if (c =3D=3D EOF)=0A=
	break;=0A=
      if (!quote)=0A=
	{=0A=
	  if ((pc =3D=3D '/') && (c =3D=3D '*'))=0A=
	    comment =3D 1;=0A=
	  else if ((pc =3D=3D '*') && (c =3D=3D '/') && (comment))=0A=
	    comment =3D 0;=0A=
	}=0A=
      if (!comment)=0A=
	{=0A=
	  if ((!quote) && (c =3D=3D '"'))=0A=
	    {=0A=
	      quote =3D 1;=0A=
	      i =3D 0;=0A=
	    }=0A=
	  else if ((quote) && (c =3D=3D '"'))=0A=
	    {=0A=
	      line[i] =3D 0;=0A=
	      quote =3D 0;=0A=
	      if (context =3D=3D 0)=0A=
		{=0A=
		  /* Header */=0A=
		  sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp);=0A=
                  if (ncolors <=3D 0 || ncolors > 32766)=0A=
		    {=0A=
		      fprintf(stderr, "IMLIB ERROR: XPM files wth colors > 32766 not =
supported\n");=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		  if (cpp <=3D 0 || cpp > 5)=0A=
		    {=0A=
		      fprintf(stderr, "IMLIB ERROR: XPM files with characters per =
pixel > 5 not supported\n");=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		  if (*w <=3D 0 || *w > 32767)=0A=
		    {=0A=
		      fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for =
file\n");=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		  if (*h <=3D 0 || *h > 32767)=0A=
		    {=0A=
		      fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for =
file\n");=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		  cmap =3D malloc(sizeof(struct _cmap) * ncolors);=0A=
=0A=
		  if (!cmap)=0A=
		    {=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		    /* SAFE -- Check for w,h in earlier code */=0A=
		  data =3D malloc(*w ** h * 3);=0A=
		  if (!data)=0A=
		    {=0A=
		      free(cmap);=0A=
		      free(line);=0A=
		      return NULL;=0A=
		    }=0A=
		  ptr =3D data;=0A=
		  end =3D ptr + (*w ** h * 3);=0A=
		  j =3D 0;=0A=
		  context++;=0A=
		}=0A=
	      else if (context =3D=3D 1)=0A=
		{=0A=
		  /* Color Table */=0A=
		  if (j < ncolors)=0A=
		    {=0A=
		      int                 slen;=0A=
		      int                 hascolor, iscolor;=0A=
		      int                 space;=0A=
=0A=
		      iscolor =3D 0;=0A=
		      hascolor =3D 0;=0A=
		      tok[0] =3D 0;=0A=
		      col[0] =3D 0;=0A=
		      space =3D sizeof(col) - 1;=0A=
		      s[0] =3D 0;=0A=
		      len =3D strlen(line);=0A=
		      strncpy(cmap[j].str, line, cpp);=0A=
		      cmap[j].str[cpp] =3D 0;=0A=
		      cmap[j].r =3D -1;=0A=
		      cmap[j].transp =3D 0;=0A=
		      for (k =3D cpp; k < len; k++)=0A=
			{=0A=
			  if (line[k] !=3D ' ')=0A=
			    {=0A=
			      s[0] =3D 0;=0A=
			      sscanf(&line[k], "%256s", s);=0A=
			      slen =3D strlen(s);=0A=
			      k +=3D slen;=0A=
			      if (!strcmp(s, "c"))=0A=
				iscolor =3D 1;=0A=
			      if ((!strcmp(s, "m")) || (!strcmp(s, "s")) ||=0A=
				  (!strcmp(s, "g4")) || (!strcmp(s, "g")) ||=0A=
				  (!strcmp(s, "c")) || (k >=3D len))=0A=
				{=0A=
				  if (k >=3D len)=0A=
				    {=0A=
				      if (col[0] && space > 0)=0A=
					strcat(col, " "), space -=3D 1;=0A=
                                      if (slen <=3D space)=0A=
					strcat(col, s), space -=3D slen;=0A=
				    }=0A=
				  if (col[0])=0A=
				    {=0A=
				      if (!strcasecmp(col, "none"))=0A=
					{=0A=
					  transp =3D 1;=0A=
					  cmap[j].transp =3D 1;=0A=
					}=0A=
				      else=0A=
					{=0A=
					  if ((((cmap[j].r < 0) ||=0A=
						(!strcmp(tok, "c"))) &&=0A=
					       (!hascolor)))=0A=
					    {=0A=
					      XParseColor(id->x.disp,=0A=
							  id->x.root_cmap,=0A=
							  col, &xcol);=0A=
					      cmap[j].r =3D xcol.red >> 8;=0A=
					      cmap[j].g =3D xcol.green >> 8;=0A=
					      cmap[j].b =3D xcol.blue >> 8;=0A=
					      if ((cmap[j].r =3D=3D 255) &&=0A=
						  (cmap[j].g =3D=3D 0) &&=0A=
						  (cmap[j].b =3D=3D 255))=0A=
						cmap[j].r =3D 254;=0A=
					      if (iscolor)=0A=
						hascolor =3D 1;=0A=
					    }=0A=
					}=0A=
				    }=0A=
				  if (slen < sizeof(tok));=0A=
				    strcpy(tok, s);=0A=
				  col[0] =3D 0;=0A=
				  space =3D sizeof(col) - 1;=0A=
				}=0A=
			      else=0A=
				{=0A=
				  if (col[0] && space > 0)=0A=
				    strcat(col, " "), space -=3D1;=0A=
				  if (slen <=3D space)=0A=
				    strcat(col, s), space -=3D slen;=0A=
				}=0A=
			    }=0A=
			}=0A=
		    }=0A=
		  j++;=0A=
		  if (j >=3D ncolors)=0A=
		    {=0A=
		      if (cpp =3D=3D 1)=0A=
			for (i =3D 0; i < ncolors; i++)=0A=
			  lookup[(int)cmap[i].str[0] - 32][0] =3D i;=0A=
		      if (cpp =3D=3D 2)=0A=
			for (i =3D 0; i < ncolors; i++)=0A=
			  lookup[(int)cmap[i].str[0] - 32][(int)cmap[i].str[1] - 32] =3D i;=0A=
		      context++;=0A=
		    }=0A=
		}=0A=
	      else=0A=
		{=0A=
		  /* Image Data */=0A=
		  i =3D 0;=0A=
		  if (cpp =3D=3D 0)=0A=
		    {=0A=
		      /* Chars per pixel =3D 0? well u never know */=0A=
		    }=0A=
		  if (cpp =3D=3D 1)=0A=
		    {=0A=
		      if (transp)=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      col[0] =3D line[i];=0A=
			      if (cmap[lookup[(int)col[0] - 32][0]].transp)=0A=
				{=0A=
				  *ptr++ =3D 255;=0A=
				  *ptr++ =3D 0;=0A=
				  *ptr++ =3D 255;=0A=
				}=0A=
			      else=0A=
				{=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r;=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g;=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b;=0A=
				}=0A=
			    }=0A=
			}=0A=
		      else=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      col[0] =3D line[i];=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r;=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g;=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b;=0A=
			    }=0A=
			}=0A=
		    }=0A=
		  else if (cpp =3D=3D 2)=0A=
		    {=0A=
		      if (transp)=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      col[0] =3D line[i++];=0A=
			      col[1] =3D line[i];=0A=
			      if (cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].transp)=0A=
				{=0A=
				  *ptr++ =3D 255;=0A=
				  *ptr++ =3D 0;=0A=
				  *ptr++ =3D 255;=0A=
				}=0A=
			      else=0A=
				{=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].r;=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].g;=0A=
				  *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].b;=0A=
				}=0A=
			    }=0A=
			}=0A=
		      else=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      col[0] =3D line[i++];=0A=
			      col[1] =3D line[i];=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].r;=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].g;=0A=
			      *ptr++ =3D (unsigned char)cmap[lookup[(int)col[0] - =
32][(int)col[1] - 32]].b;=0A=
			    }=0A=
			}=0A=
		    }=0A=
		  else=0A=
		    {=0A=
		      if (transp)=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      for (j =3D 0; j < cpp; j++, i++)=0A=
				{=0A=
				  col[j] =3D line[i];=0A=
				}=0A=
			      col[j] =3D 0;=0A=
			      i--;=0A=
			      for (j =3D 0; j < ncolors; j++)=0A=
				{=0A=
				  if (!strcmp(col, cmap[j].str))=0A=
				    {=0A=
				      if (cmap[j].transp)=0A=
					{=0A=
					  *ptr++ =3D 255;=0A=
					  *ptr++ =3D 0;=0A=
					  *ptr++ =3D 255;=0A=
					}=0A=
				      else=0A=
					{=0A=
					  *ptr++ =3D (unsigned char)cmap[j].r;=0A=
					  *ptr++ =3D (unsigned char)cmap[j].g;=0A=
					  *ptr++ =3D (unsigned char)cmap[j].b;=0A=
					}=0A=
				      j =3D ncolors;=0A=
				    }=0A=
				}=0A=
			    }=0A=
			}=0A=
		      else=0A=
			{=0A=
			  for (i =3D 0; ((i < 65536) && (ptr < end) && (line[i])); i++)=0A=
			    {=0A=
			      for (j =3D 0; j < cpp; j++, i++)=0A=
				{=0A=
				  col[j] =3D line[i];=0A=
				}=0A=
			      col[j] =3D 0;=0A=
			      i--;=0A=
			      for (j =3D 0; j < ncolors; j++)=0A=
				{=0A=
				  if (!strcmp(col, cmap[j].str))=0A=
				    {=0A=
				      *ptr++ =3D (unsigned char)cmap[j].r;=0A=
				      *ptr++ =3D (unsigned char)cmap[j].g;=0A=
				      *ptr++ =3D (unsigned char)cmap[j].b;=0A=
				      j =3D ncolors;=0A=
				    }=0A=
				}=0A=
			    }=0A=
			}=0A=
		    }=0A=
		}=0A=
	    }=0A=
	}=0A=
      /* Scan in line from XPM file */=0A=
      if ((!comment) && (quote) && (c !=3D '"'))=0A=
	{=0A=
	  if (c < 32)=0A=
	    c =3D 32;=0A=
	  else if (c > 127)=0A=
	    c =3D 127;=0A=
	  line[i++] =3D c;=0A=
	}=0A=
      if (i >=3D lsz)=0A=
	{=0A=
	  lsz +=3D 256;=0A=
	  line =3D realloc(line, lsz);=0A=
	  if(line =3D=3D NULL)=0A=
	    {=0A=
	    	free(cmap);=0A=
	    	return NULL;=0A=
	    }=0A=
	}=0A=
      if ((ptr) && ((ptr - data) >=3D *w ** h * 3))=0A=
	done =3D 1;=0A=
    }=0A=
  if (transp)=0A=
    *t =3D 1;=0A=
  else=0A=
    *t =3D 0;=0A=
  free(cmap);=0A=
  free(line);=0A=
  return data;=0A=
}=0A=
=0A=
unsigned char      *=0A=
_LoadPPM(ImlibData * id, FILE * f, int *w, int *h)=0A=
{=0A=
  int                 done;=0A=
  unsigned char      *ptr;=0A=
  unsigned char       chr;=0A=
  char                s[256];=0A=
  int                 a, b, i, j;=0A=
  int                 color, scale, ascii, bw;=0A=
=0A=
  a =3D b =3D scale =3D ascii =3D bw =3D color =3D 0;=0A=
  fgets(s, 256, f);=0A=
  s[2] =3D 0;=0A=
  if (!strcmp(s, "P6"))=0A=
    color =3D 1;=0A=
  else if (!strcmp(s, "P5"))=0A=
    color =3D 0;=0A=
  else if (!strcmp(s, "P4"))=0A=
    bw =3D 1;=0A=
  else if (!strcmp(s, "P3"))=0A=
    {=0A=
      color =3D 1;=0A=
      ascii =3D 1;=0A=
    }=0A=
  else if (!strcmp(s, "P2"))=0A=
    {=0A=
      ascii =3D 1;=0A=
    }=0A=
  else if (!strcmp(s, "P1"))=0A=
    {=0A=
      ascii =3D 1;=0A=
      bw =3D 1;=0A=
    }=0A=
  else=0A=
    return NULL;=0A=
  done =3D 1;=0A=
  ptr =3D NULL;=0A=
  while (done)=0A=
    {=0A=
      if (fgets(s, 256, f) =3D=3D NULL)=0A=
	break;=0A=
=0A=
      if (s[0] !=3D '#')=0A=
	{=0A=
	  done =3D 0;=0A=
	  sscanf(s, "%i %i", w, h);=0A=
	  a =3D *w;=0A=
	  b =3D *h;=0A=
	  if (a <=3D 0 || a > 32767)=0A=
	    {=0A=
	      fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for =
file\n");=0A=
	      return NULL;=0A=
	    }=0A=
	  if (b <=3D 0 || b > 32767)=0A=
	    {=0A=
	      fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for =
file\n");=0A=
	      return NULL;=0A=
	    }=0A=
	  if (!bw)=0A=
	    {=0A=
	      fgets(s, 256, f);=0A=
	      sscanf(s, "%i", &scale);=0A=
	    }=0A=
	  else=0A=
	    scale =3D 99999;=0A=
	  ptr =3D (unsigned char *)_imlib_malloc_image(a, b);=0A=
	  if (!ptr)=0A=
	    {=0A=
	      fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for RGB data in =
file");=0A=
	      return ptr;=0A=
	    }=0A=
	  if ((color) && (!ascii) && (!bw))=0A=
	    {=0A=
	      fread(ptr, a * b * 3, 1, f);=0A=
	    }=0A=
	  else if ((!color) && (!ascii) && (!bw))=0A=
	    {=0A=
	      b =3D (a * b * 3);=0A=
	      a =3D 0;=0A=
	      while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		{=0A=
		  ptr[a++] =3D chr;=0A=
		  ptr[a++] =3D chr;=0A=
		  ptr[a++] =3D chr;=0A=
		}=0A=
	    }=0A=
	  else if ((!color) && (!ascii) && (bw))=0A=
	    {=0A=
	      b =3D (a * b * 3);=0A=
	      a =3D 0;=0A=
	      j =3D 0;=0A=
	      while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		{=0A=
		  for (i =3D 7; i >=3D 0; i--)=0A=
		    {=0A=
		      j++;=0A=
		      if (j <=3D *w)=0A=
			{=0A=
			  if (chr & (1 << i))=0A=
			    {=0A=
			      ptr[a++] =3D 0;=0A=
			      ptr[a++] =3D 0;=0A=
			      ptr[a++] =3D 0;=0A=
			    }=0A=
			  else=0A=
			    {=0A=
			      ptr[a++] =3D 255;=0A=
			      ptr[a++] =3D 255;=0A=
			      ptr[a++] =3D 255;=0A=
			    }=0A=
			}=0A=
		    }=0A=
		  if (j >=3D *w)=0A=
		    j =3D 0;=0A=
		}=0A=
	    }=0A=
	  else if ((color) && (ascii) && (!bw))=0A=
	    {=0A=
	      b =3D (a * b * 3);=0A=
	      a =3D 0;=0A=
	      i =3D 0;=0A=
	      if (scale !=3D 255)=0A=
		{=0A=
		  while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		    {=0A=
		      s[i++] =3D chr;=0A=
		      if (!isdigit(chr))=0A=
			{=0A=
			  s[i - 1] =3D 0;=0A=
			  if ((i > 1) && (isdigit(s[i - 2])))=0A=
			    {=0A=
			      ptr[a++] =3D ((atoi(s)) * 255) / scale;=0A=
			    }=0A=
			  i =3D 0;=0A=
			}=0A=
		    }=0A=
		}=0A=
	      else=0A=
		{=0A=
		  while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		    {=0A=
		      s[i++] =3D chr;=0A=
		      if (!isdigit(chr))=0A=
			{=0A=
			  s[i - 1] =3D 0;=0A=
			  if ((i > 1) && (isdigit(s[i - 2])))=0A=
			    {=0A=
			      ptr[a++] =3D atoi(s);=0A=
			    }=0A=
			  i =3D 0;=0A=
			}=0A=
		    }=0A=
		}=0A=
=0A=
	    }=0A=
	  else if ((!color) && (ascii) && (!bw))=0A=
	    {=0A=
	      b =3D (a * b * 3);=0A=
	      a =3D 0;=0A=
	      i =3D 0;=0A=
	      if (scale !=3D 255)=0A=
		{=0A=
		  while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		    {=0A=
		      s[i++] =3D chr;=0A=
		      if (!isdigit(chr))=0A=
			{=0A=
			  s[i - 1] =3D 0;=0A=
			  if ((i > 1) && (isdigit(s[i - 2])))=0A=
			    {=0A=
			      ptr[a++] =3D ((atoi(s)) * 255) / scale;=0A=
			      ptr[a++] =3D ptr[a - 1];=0A=
			      ptr[a++] =3D ptr[a - 1];=0A=
			    }=0A=
			  i =3D 0;=0A=
			}=0A=
		    }=0A=
		}=0A=
	      else=0A=
		{=0A=
		  while ((fread(&chr, 1, 1, f)) && (a < b))=0A=
		    {=0A=
		      s[i++] =3D chr;=0A=
		      if (!isdigit(chr))=0A=
			{=0A=
			  s[i - 1] =3D 0;=0A=
			  if ((i > 1) && (isdigit(s[i - 2])))=0A=
			    {=0A=
			      ptr[a++] =3D atoi(s);=0A=
			      ptr[a++] =3D ptr[a - 1];=0A=
			      ptr[a++] =3D ptr[a - 1];=0A=
			    }=0A=
			  i =3D 0;=0A=
			}=0A=
		    }=0A=
		}=0A=
	    }=0A=
	  else if ((!color) && (ascii) && (bw))=0A=
	    {=0A=
	    }=0A=
	}=0A=
    }=0A=
  if (!ptr)=0A=
    return NULL;=0A=
  if (scale =3D=3D 0)=0A=
    {=0A=
      free(ptr);=0A=
      return NULL;=0A=
    }=0A=
  if ((scale < 255) && (!ascii))=0A=
    {=0A=
      int                 rot;=0A=
      unsigned char      *po;=0A=
=0A=
      if (scale <=3D 1)=0A=
	rot =3D 7;=0A=
      else if (scale <=3D 3)=0A=
	rot =3D 6;=0A=
      else if (scale <=3D 7)=0A=
	rot =3D 5;=0A=
      else if (scale <=3D 15)=0A=
	rot =3D 4;=0A=
      else if (scale <=3D 31)=0A=
	rot =3D 3;=0A=
      else if (scale <=3D 63)=0A=
	rot =3D 2;=0A=
      else=0A=
	rot =3D 1;=0A=
=0A=
      if (rot > 0)=0A=
	{=0A=
	  po =3D ptr;=0A=
	  while (po < (ptr + (*w ** h * 3)))=0A=
	    {=0A=
	      *po++ <<=3D rot;=0A=
	      *po++ <<=3D rot;=0A=
	      *po++ <<=3D rot;=0A=
	    }=0A=
	}=0A=
    }=0A=
  return ptr;=0A=
}=0A=
=0A=
int=0A=
ispnm(FILE *f)=0A=
{=0A=
  char                buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fgets(buf, 8, f);=0A=
  rewind(f);=0A=
  if (!strcmp("P6", buf))=0A=
    return 1;=0A=
  if (!strcmp("P5", buf))=0A=
    return 1;=0A=
  if (!strcmp("P4", buf))=0A=
    return 1;=0A=
  if (!strcmp("P3", buf))=0A=
    return 1;=0A=
  if (!strcmp("P2", buf))=0A=
    return 1;=0A=
  if (!strcmp("P1", buf))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
isjpeg(FILE *f)=0A=
{=0A=
  unsigned char       buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 2, f);=0A=
  rewind(f);=0A=
  if ((buf[0] =3D=3D 0xff) && (buf[1] =3D=3D 0xd8))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
ispng(FILE *f)=0A=
{=0A=
#ifdef HAVE_LIBPNG=0A=
  unsigned char       buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 8, f);=0A=
  rewind(f);=0A=
  return (int)!png_sig_cmp(buf, 0, 8);=0A=
#else=0A=
  return 0;=0A=
#endif=0A=
}=0A=
=0A=
int=0A=
istiff(FILE *f)=0A=
{=0A=
  char                buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fgets(buf, 5, f);=0A=
  rewind(f);=0A=
  if ((buf[0] =3D=3D 'M') && (buf[1] =3D=3D 'M') && (buf[2] =3D=3D 0x00) =
&& (buf[3] =3D=3D 0x2a))=0A=
    return 1;=0A=
  if ((buf[0] =3D=3D 'I') && (buf[1] =3D=3D 'I') && (buf[2] =3D=3D 0x2a) =
&& (buf[3] =3D=3D 0x00))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
iseim(FILE *f)=0A=
{=0A=
  char                buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 4, f);=0A=
  rewind(f);=0A=
  buf[4] =3D 0;=0A=
  if (!strncmp("EIM ", buf, 4))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
isgif(FILE *f)=0A=
{=0A=
  char                buf[8];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 4, f);=0A=
  rewind(f);=0A=
  buf[4] =3D 0;=0A=
  if (!strcmp("GIF8", buf))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
isxpm(FILE *f)=0A=
{=0A=
  char                buf[11];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 9, f);=0A=
  rewind(f);=0A=
  buf[9] =3D 0;=0A=
  if (!strcmp("/* XPM */", buf))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
int=0A=
isbmp(FILE *f)=0A=
{=0A=
  char                buf[3];=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
  fread(buf, 1, 2, f);=0A=
  rewind(f);=0A=
  buf[2] =3D 0;=0A=
  if (!strcmp("BM", buf))=0A=
    return 1;=0A=
  return 0;=0A=
}=0A=
=0A=
ImlibImage         *=0A=
Imlib_load_image(ImlibData * id, char *file)=0A=
{=0A=
  int                 w, h;=0A=
  unsigned char      *data;=0A=
  ImlibImage         *im;=0A=
  char                s[4096];=0A=
  char                fil[4096];=0A=
  char               *iden;=0A=
  char               *e;=0A=
  char                cmd[4096];=0A=
  FILE               *p;=0A=
  int                 eim;=0A=
  int                 fmt;=0A=
  int                 trans;=0A=
=0A=
  eim =3D 0;=0A=
  fmt =3D 0;=0A=
  data =3D NULL;=0A=
=0A=
  if (!file)=0A=
    return NULL;=0A=
  if (id->cache.on_image)=0A=
    if ((im =3D find_image(id, file)))=0A=
      {=0A=
        if (im->rgb_width =3D=3D 0 || im->rgb_height =3D=3D 0)=0A=
          {=0A=
            Imlib_destroy_image(id, im);=0A=
            return NULL;=0A=
          }=0A=
        else=0A=
          return im;=0A=
      }=0A=
  if (!strcmp(file,"-")) {=0A=
  	p =3D stdin;=0A=
  }=0A=
  else {=0A=
  	p =3D fopen(file, "rb");=0A=
  }=0A=
  if (!p)=0A=
	return NULL;=0A=
  strncpy(fil, file, sizeof(fil));=0A=
  iden =3D _SplitID(fil);=0A=
  e =3D _GetExtension(fil);=0A=
=0A=
  if (ispnm(p))=0A=
    {=0A=
      fmt =3D 0;=0A=
    }=0A=
  else if (isjpeg(p))=0A=
    {=0A=
      fmt =3D 2;=0A=
    }=0A=
  else if (istiff(p))=0A=
    {=0A=
      fmt =3D 3;=0A=
    }=0A=
  else if (iseim(p))=0A=
    {=0A=
      eim =3D 1;=0A=
      fmt =3D 9999;=0A=
    }=0A=
  else if (isxpm(p))=0A=
    {=0A=
      fmt =3D 5;=0A=
    }=0A=
  else if (ispng(p))=0A=
    {=0A=
      fmt =3D 1;=0A=
    }=0A=
  else if (isgif(p))=0A=
    {=0A=
      fmt =3D 4;=0A=
    }=0A=
  else if (isbmp(p))=0A=
    {=0A=
      fmt =3D 6;=0A=
    }=0A=
=0A=
  trans =3D 0;=0A=
  if ((!eim) && (!data))=0A=
    {=0A=
      switch (fmt)=0A=
	{=0A=
	case 6:=0A=
	  data =3D _LoadBMP(id, p, &w, &h, &trans);=0A=
	  break;=0A=
	case 5:=0A=
	  data =3D _LoadXPM(id, p, &w, &h, &trans);=0A=
	  break;=0A=
#ifdef HAVE_LIBGIF=0A=
	case 4:=0A=
	  data =3D _LoadGIF(id, p, &w, &h, &trans);=0A=
	  break;=0A=
#endif=0A=
#ifdef HAVE_LIBTIFF=0A=
	case 3:=0A=
	  data =3D _LoadTIFF(id, p, file, &w, &h, &trans);=0A=
	  break;=0A=
#endif=0A=
#ifdef HAVE_LIBJPEG=0A=
	case 2:=0A=
	    data =3D _LoadJPEG(id, p, &w, &h);=0A=
	  break;=0A=
#endif=0A=
#ifdef HAVE_LIBPNG=0A=
	case 1:=0A=
	    data =3D _LoadPNG(id, p, &w, &h, &trans);=0A=
	  break;=0A=
#endif=0A=
	default:=0A=
	    data =3D _LoadPPM(id, p, &w, &h);=0A=
	  break;=0A=
	}=0A=
    }=0A=
=0A=
    if (p !=3D stdin) =0A=
      fclose(p);=0A=
=0A=
  if ((!eim) && (!data))=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: Cannot load image: %s\n"=0A=
      		      "All fallbacks failed.\n", fil);=0A=
      return NULL;=0A=
    }=0A=
    =0A=
  if (!w || !h)=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: zero image\n" );=0A=
      if(data)=0A=
        free(data);=0A=
      return NULL;=0A=
    }=0A=
    =0A=
  im =3D (ImlibImage *) malloc(sizeof(ImlibImage));=0A=
  if (!im)=0A=
    {=0A=
      fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for image =
structure\n");=0A=
      if (data)=0A=
	free(data);=0A=
      return NULL;=0A=
    }=0A=
  im->alpha_data =3D NULL;=0A=
  if (trans)=0A=
    {=0A=
      im->shape_color.r =3D 255;=0A=
      im->shape_color.g =3D 0;=0A=
      im->shape_color.b =3D 255;=0A=
    }=0A=
  else=0A=
    {=0A=
      im->shape_color.r =3D -1;=0A=
      im->shape_color.g =3D -1;=0A=
      im->shape_color.b =3D -1;=0A=
    }=0A=
  im->border.left =3D 0;=0A=
  im->border.right =3D 0;=0A=
  im->border.top =3D 0;=0A=
  im->border.bottom =3D 0;=0A=
  im->cache =3D 1;=0A=
  im->rgb_data =3D data;=0A=
  im->rgb_width =3D w;=0A=
  im->rgb_height =3D h;=0A=
  im->pixmap =3D 0;=0A=
  im->shape_mask =3D 0;=0A=
  if (eim)=0A=
    {=0A=
      char                s1[256], s2[256];=0A=
      int                 num, size;=0A=
      int                 r, g, b;=0A=
      int                 br, bl, bt, bb;=0A=
=0A=
      /* Load Native-as-can-be EIM format (Enlightenment IMlib format) */=0A=
      if (!strcmp(file,"-"))=0A=
        p =3D stdin;=0A=
      else {=0A=
#ifndef __EMX__=0A=
	p =3D fopen(file, "r");=0A=
#else=0A=
	p =3D fopen(file, "rt");=0A=
#endif=0A=
	  }=0A=
=0A=
      if (!p)=0A=
	{=0A=
	  free(im);=0A=
	  return NULL;=0A=
	}=0A=
      fgets(s, 4096, p);=0A=
      if ((s[0] !=3D 'E') && (s[1] !=3D 'I') && (s[2] !=3D 'M') && (s[3] =
!=3D ' '))=0A=
	{=0A=
	  fclose(p);=0A=
	  free(im);=0A=
	  return NULL;=0A=
	}=0A=
      sscanf(s, "%256s %i", s1, &num);=0A=
      if (num <=3D 0)=0A=
	{=0A=
	  fclose(p);=0A=
	  free(im);=0A=
	  return NULL;=0A=
	}=0A=
      while (fgets(s, 4096, p))=0A=
	{=0A=
	  sscanf(s, "%256s", s1);=0A=
	  if (!strcmp("IMAGE", s1))=0A=
	    {=0A=
	      sscanf(s, "%256s %i %256s %i %i %i %i %i %i %i %i %i", s1, &size,=0A=
		     s2, &w, &h, &r, &g, &b, &bl, &br, &bt, &bb);=0A=
	      if (!iden[0])=0A=
		break;=0A=
	      else if (!strcmp(iden, s2))=0A=
		break;=0A=
	      if (size > 0)=0A=
		fseek(p, size, SEEK_CUR);=0A=
	    }=0A=
	}=0A=
      im->rgb_data =3D _imlib_malloc_image(w, h);=0A=
      if (!im->rgb_data)=0A=
	{=0A=
	  fclose(p);=0A=
	  free(im);=0A=
	  return NULL;=0A=
	}=0A=
      im->shape_color.r =3D r;=0A=
      im->shape_color.g =3D g;=0A=
      im->shape_color.b =3D b;=0A=
      im->rgb_width =3D w;=0A=
      im->rgb_height =3D h;=0A=
      im->border.left =3D bl;=0A=
      im->border.right =3D br;=0A=
      im->border.top =3D bt;=0A=
      im->border.bottom =3D bb;=0A=
      fread(im->rgb_data, 1, w * h * 3, p);=0A=
      fclose(p);=0A=
      if (iden[0])=0A=
	{=0A=
#ifndef __EMX__=0A=
	  strncat(fil, ":", sizeof(fil) - strlen(fil));=0A=
#else=0A=
	  strncat(fil, ";", sizeof(fil) - strlen(fil));=0A=
#endif=0A=
	  strncat(fil, iden, sizeof(fil) - strlen(fil));=0A=
	}=0A=
    }=0A=
  im->mod.gamma =3D id->mod.gamma;=0A=
  im->mod.brightness =3D id->mod.brightness;=0A=
  im->mod.contrast =3D id->mod.contrast;=0A=
  im->rmod.gamma =3D id->rmod.gamma;=0A=
  im->rmod.brightness =3D id->rmod.brightness;=0A=
  im->rmod.contrast =3D id->rmod.contrast;=0A=
  im->gmod.gamma =3D id->gmod.gamma;=0A=
  im->gmod.brightness =3D id->gmod.brightness;=0A=
  im->gmod.contrast =3D id->gmod.contrast;=0A=
  im->bmod.gamma =3D id->bmod.gamma;=0A=
  im->bmod.brightness =3D id->bmod.brightness;=0A=
  im->bmod.contrast =3D id->bmod.contrast;=0A=
  im->filename =3D malloc(strlen(file) + 1);=0A=
  if (im->filename)=0A=
    strcpy(im->filename, file);=0A=
  if ((id->cache.on_image) && (im))=0A=
    add_image(id, im, fil);=0A=
  calc_map_tables(id, im);=0A=
  return im;=0A=
}=0A=
=0A=
int=0A=
Imlib_save_image_to_eim(ImlibData * id, ImlibImage * im, char *file)=0A=
{=0A=
  char                fil[4096];=0A=
  char               *iden;=0A=
  FILE               *f;=0A=
  int                 size;=0A=
=0A=
  if ((!id) || (!im) || (!file))=0A=
    return 0;=0A=
  strncpy(fil, file, sizeof(fil));=0A=
  iden =3D _SplitID(fil);=0A=
  if (!iden[0])=0A=
    iden =3D "default";=0A=
  f =3D fopen(fil, "w");=0A=
  if (!f)=0A=
    return 0;=0A=
=0A=
  size =3D im->rgb_width * im->rgb_height * 3;=0A=
  fprintf(f, "EIM 1\n");=0A=
  fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n",=0A=
	  size,=0A=
	  iden,=0A=
	  im->rgb_width,=0A=
	  im->rgb_height,=0A=
	  im->shape_color.r,=0A=
	  im->shape_color.g,=0A=
	  im->shape_color.b,=0A=
	  im->border.left,=0A=
	  im->border.right,=0A=
	  im->border.top,=0A=
	  im->border.bottom);=0A=
  if (fwrite(im->rgb_data, size, 1, f) !=3D 1)=0A=
    {=0A=
      fclose(f);=0A=
      return 0;=0A=
    }=0A=
  fclose(f);=0A=
  return 1;=0A=
}=0A=
=0A=
int=0A=
Imlib_add_image_to_eim(ImlibData * id, ImlibImage * im, char *file)=0A=
{=0A=
  char                fil[4096];=0A=
  char               *iden;=0A=
  FILE               *f;=0A=
  int                 size;=0A=
=0A=
  if ((!id) || (!im) || (!file))=0A=
    return 0;=0A=
  strncpy(fil, file, sizeof(fil));=0A=
=0A=
  iden =3D _SplitID(file);=0A=
  if (!iden[0])=0A=
    strcpy(iden, "default");=0A=
=0A=
  f =3D fopen(fil, "a");=0A=
  if (!f)=0A=
    return 0;=0A=
=0A=
  size =3D im->rgb_width * im->rgb_height * 3;=0A=
  fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n",=0A=
	  size,=0A=
	  iden,=0A=
	  im->rgb_width,=0A=
	  im->rgb_height,=0A=
	  im->shape_color.r,=0A=
	  im->shape_color.g,=0A=
	  im->shape_color.b,=0A=
	  im->border.left,=0A=
	  im->border.right,=0A=
	  im->border.top,=0A=
	  im->border.bottom);=0A=
=0A=
  if (fwrite(im->rgb_data, size, 1, f) !=3D 1)=0A=
    {=0A=
      fclose(f);=0A=
      return 0;=0A=
    }=0A=
  fclose(f);=0A=
  return 1;=0A=
}=0A=
=0A=
int=0A=
Imlib_save_image_to_ppm(ImlibData * id, ImlibImage * im, char *file)=0A=
{=0A=
  FILE               *f;=0A=
=0A=
  if ((!id) || (!im) || (!file))=0A=
    return 0;=0A=
#ifndef __EMX__=0A=
  f =3D fopen(file, "w");=0A=
#else=0A=
  f =3D fopen(file, "wb");=0A=
#endif=0A=
=0A=
  if (!f)=0A=
    return 0;=0A=
=0A=
  fprintf(f, "P6\n");=0A=
  fprintf(f, "%i %i\n255\n",=0A=
	  im->rgb_width,=0A=
	  im->rgb_height);=0A=
  if (fwrite(im->rgb_data, im->rgb_width * im->rgb_height * 3, 1, f) =
!=3D 1)=0A=
    {=0A=
      fclose(f);=0A=
      return 0;=0A=
    }=0A=
  fclose(f);=0A=
  return 1;=0A=
}=0A=

------=_NextPart_000_01ED_01CD4E65.C77EC5D0--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?EADD3B1DE3E746758BAA9A9101AD56A8>