~ubuntu-branches/ubuntu/karmic/emacs-snapshot/karmic

« back to all changes in this revision

Viewing changes to src/image.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-04-05 09:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090405091430-nw07lynn2arotjbe
Tags: upstream-20090320
ImportĀ upstreamĀ versionĀ 20090320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Functions for image support on window system.
2
2
   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3
 
                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 
3
                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4
4
                 Free Software Foundation, Inc.
5
5
 
6
6
This file is part of GNU Emacs.
79
79
#define FRAME_X_VISUAL(f) FRAME_X_DISPLAY_INFO (f)->visual
80
80
#define x_defined_color w32_defined_color
81
81
#define DefaultDepthOfScreen(screen) (one_w32_display_info.n_cbits)
 
82
 
 
83
/* Functions from w32term.c that depend on XColor (so can't go in w32term.h
 
84
   without modifying lots of files).  */
 
85
extern void x_query_colors (struct frame *f, XColor *colors, int ncolors);
 
86
extern void x_query_color (struct frame *f, XColor *color);
82
87
#endif /* HAVE_NTGUI */
83
88
 
84
89
#ifdef HAVE_NS
1622
1627
    {
1623
1628
      Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap);
1624
1629
      img->pixmap = NO_PIXMAP;
1625
 
#ifdef HAVE_NS
1626
 
      if (img->background_valid)
1627
 
        ns_free_indexed_color(img->background, f);
1628
 
#endif
 
1630
      /* NOTE (HAVE_NS): background color is NOT an indexed color! */
1629
1631
      img->background_valid = 0;
1630
1632
    }
1631
1633
 
2990
2992
    }
2991
2993
 
2992
2994
  if (!check_image_size (f, *width, *height))
2993
 
    goto failure;
 
2995
    {
 
2996
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
 
2997
      goto failure;
 
2998
    }
2994
2999
  else if (data == NULL)
2995
3000
    goto success;
2996
3001
 
4200
4205
 
4201
4206
  if (!check_image_size (f, width, height))
4202
4207
    {
4203
 
      image_error ("Invalid image size", Qnil, Qnil);
 
4208
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
4204
4209
      goto failure;
4205
4210
    }
4206
4211
 
4786
4791
    {
4787
4792
      XColor *row = p;
4788
4793
 
4789
 
#ifdef HAVE_X_WINDOWS
 
4794
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
4790
4795
      for (x = 0; x < img->width; ++x, ++p)
4791
 
        p->pixel = XGetPixel (ximg, x, y);
 
4796
        p->pixel = GET_PIXEL (ximg, x, y);
4792
4797
      if (rgb_p)
4793
4798
        x_query_colors (f, row, img->width);
4794
4799
 
4800
4805
          p->pixel = GET_PIXEL (ximg, x, y);
4801
4806
          if (rgb_p)
4802
4807
            {
4803
 
#if defined (HAVE_NS)
4804
4808
              p->red = RED16_FROM_ULONG (p->pixel);
4805
4809
              p->green = GREEN16_FROM_ULONG (p->pixel);
4806
4810
              p->blue = BLUE16_FROM_ULONG (p->pixel);
4807
 
#endif  /* HAVE_NS */
4808
 
#ifdef HAVE_NTGUI
4809
 
              p->red = 256 * GetRValue (p->pixel);
4810
 
              p->green = 256 * GetGValue (p->pixel);
4811
 
              p->blue = 256 * GetBValue (p->pixel);
4812
 
#endif /* HAVE_NTGUI */
4813
4811
            }
4814
4812
        }
4815
4813
#endif /* HAVE_X_WINDOWS */
5548
5546
 
5549
5547
  if (!check_image_size (f, width, height))
5550
5548
    {
5551
 
      image_error ("Invalid image size", Qnil, Qnil);
 
5549
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
5552
5550
      goto error;
5553
5551
    }
5554
5552
 
6084
6082
                   &interlace_type, NULL, NULL);
6085
6083
 
6086
6084
  if (!check_image_size (f, width, height))
6087
 
    goto error;
6088
 
 
 
6085
    {
 
6086
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
 
6087
      goto error;
 
6088
    }
6089
6089
  /* If image contains simply transparency data, we prefer to
6090
6090
     construct a clipping mask.  */
6091
6091
  if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
6123
6123
      if (STRINGP (specified_bg))
6124
6124
        /* The user specified `:background', use that.  */
6125
6125
        {
6126
 
          /* W32 version incorrectly used COLORREF here!!  ++kfs */
6127
6126
          XColor color;
6128
6127
          if (x_defined_color (f, SDATA (specified_bg), &color, 0))
6129
6128
            {
6142
6141
        {
6143
6142
          /* We use the current frame background, ignoring any default
6144
6143
             background color set by the image.  */
6145
 
#ifdef HAVE_X_WINDOWS
 
6144
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
6146
6145
          XColor color;
6147
6146
          png_color_16 frame_background;
6148
6147
 
6155
6154
          frame_background.blue = color.blue >> shift;
6156
6155
#endif /* HAVE_X_WINDOWS */
6157
6156
 
6158
 
#ifdef HAVE_NTGUI
6159
 
          COLORREF color;
6160
 
          png_color_16 frame_background;
6161
 
          color = FRAME_BACKGROUND_PIXEL (f);
6162
 
#if 0 /* W32 TODO : Colormap support.  */
6163
 
          x_query_color (f, &color);
6164
 
#endif
6165
 
          bzero (&frame_background, sizeof frame_background);
6166
 
          frame_background.red = GetRValue (color);
6167
 
          frame_background.green = GetGValue (color);
6168
 
          frame_background.blue = GetBValue (color);
6169
 
#endif /* HAVE_NTGUI */
6170
 
 
6171
6157
          fn_png_set_background (png_ptr, &frame_background,
6172
6158
                                 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
6173
6159
        }
6806
6792
 
6807
6793
  if (!check_image_size (f, width, height))
6808
6794
    {
6809
 
      image_error ("Invalid image size", Qnil, Qnil);
 
6795
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
6810
6796
      longjmp (mgr.setjmp_buffer, 2);
6811
6797
    }
6812
6798
 
7257
7243
 
7258
7244
  if (!check_image_size (f, width, height))
7259
7245
    {
7260
 
      image_error ("Invalid image size", Qnil, Qnil);
 
7246
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7261
7247
      fn_TIFFClose (tiff);
7262
7248
      UNGCPRO;
7263
7249
      return 0;
7596
7582
  /* Before reading entire contents, check the declared image size. */
7597
7583
  if (!check_image_size (f, gif->SWidth, gif->SHeight))
7598
7584
    {
7599
 
      image_error ("Invalid image size", Qnil, Qnil);
 
7585
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7600
7586
      fn_DGifCloseFile (gif);
7601
7587
      UNGCPRO;
7602
7588
      return 0;
7639
7625
 
7640
7626
  if (!check_image_size (f, width, height))
7641
7627
    {
7642
 
      image_error ("Invalid image size", Qnil, Qnil);
 
7628
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7643
7629
      fn_DGifCloseFile (gif);
7644
7630
      UNGCPRO;
7645
7631
      return 0;
7901
7887
DEF_IMGLIB_FN (g_object_unref);
7902
7888
DEF_IMGLIB_FN (g_error_free);
7903
7889
 
7904
 
Lisp_Object Qgdk_pixbuf, Qglib;
 
7890
Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
7905
7891
 
7906
7892
static int
7907
7893
init_svg_functions (Lisp_Object libraries)
7908
7894
{
7909
 
  HMODULE library, gdklib, glib;
 
7895
  HMODULE library, gdklib, glib, gobject;
7910
7896
 
7911
7897
  if (!(glib = w32_delayed_load (libraries, Qglib))
 
7898
      || !(gobject = w32_delayed_load (libraries, Qgobject))
7912
7899
      || !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf))
7913
7900
      || !(library = w32_delayed_load (libraries, Qsvg)))
7914
7901
    return 0;
7929
7916
  LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_has_alpha);
7930
7917
  LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_bits_per_sample);
7931
7918
 
7932
 
  LOAD_IMGLIB_FN (glib, g_type_init);
7933
 
  LOAD_IMGLIB_FN (glib, g_object_unref);
 
7919
  LOAD_IMGLIB_FN (gobject, g_type_init);
 
7920
  LOAD_IMGLIB_FN (gobject, g_object_unref);
7934
7921
  LOAD_IMGLIB_FN (glib, g_error_free);
 
7922
 
7935
7923
  return 1;
7936
7924
}
7937
7925
 
8051
8039
     gnome type library functions.  */
8052
8040
  fn_g_type_init ();
8053
8041
  /* Make a handle to a new rsvg object.  */
8054
 
  rsvg_handle = fn_rsvg_handle_new ();
 
8042
  rsvg_handle = (RsvgHandle *) fn_rsvg_handle_new ();
8055
8043
 
8056
8044
  /* Parse the contents argument and fill in the rsvg_handle.  */
8057
8045
  fn_rsvg_handle_write (rsvg_handle, contents, size, &error);
8064
8052
 
8065
8053
  fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
8066
8054
  if (! check_image_size (f, dimension_data.width, dimension_data.height))
8067
 
    goto rsvg_error;
 
8055
    {
 
8056
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
 
8057
      goto rsvg_error;
 
8058
    }
8068
8059
 
8069
8060
  /* We can now get a valid pixel buffer from the svg file, if all
8070
8061
     went ok.  */
8071
 
  pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle);
 
8062
  pixbuf = (GdkPixbuf *) fn_rsvg_handle_get_pixbuf (rsvg_handle);
8072
8063
  if (!pixbuf) goto rsvg_error;
8073
8064
  fn_g_object_unref (rsvg_handle);
8074
8065
 
8075
8066
  /* Extract some meta data from the svg handle.  */
8076
8067
  width     = fn_gdk_pixbuf_get_width (pixbuf);
8077
8068
  height    = fn_gdk_pixbuf_get_height (pixbuf);
8078
 
  pixels    = fn_gdk_pixbuf_get_pixels (pixbuf);
 
8069
  pixels    = (const guint8 *) fn_gdk_pixbuf_get_pixels (pixbuf);
8079
8070
  rowstride = fn_gdk_pixbuf_get_rowstride (pixbuf);
8080
8071
 
8081
8072
  /* Validate the svg meta data.  */
8096
8087
  /* Handle alpha channel by combining the image with a background
8097
8088
     color.  */
8098
8089
  specified_bg = image_spec_value (img->spec, QCbackground, NULL);
8099
 
  if (STRINGP (specified_bg)
8100
 
      && x_defined_color (f, SDATA (specified_bg), &background, 0))
8101
 
    {
8102
 
      background.red   >>= 8;
8103
 
      background.green >>= 8;
8104
 
      background.blue  >>= 8;
8105
 
    }
8106
 
  else
8107
 
    {
8108
 
#ifdef HAVE_X_WINDOWS
8109
 
      background.pixel = FRAME_BACKGROUND_PIXEL (f);
8110
 
      x_query_color (f, &background);
8111
 
 
8112
 
      /* SVG pixmaps specify transparency in the last byte, so right
8113
 
         shift 8 bits to get rid of it, since emacs doesn't support
8114
 
         transparency.  */
8115
 
      background.red   >>= 8;
8116
 
      background.green >>= 8;
8117
 
      background.blue  >>= 8;
8118
 
#elif defined (HAVE_NTGUI)
8119
 
      background.pixel = FRAME_BACKGROUND_PIXEL (f);
8120
 
#if 0 /* W32 TODO : Colormap support.  */
8121
 
      x_query_color (f, &background);
8122
 
#endif
8123
 
 
8124
 
      /* SVG pixmaps specify transparency in the last byte, so right
8125
 
         shift 8 bits to get rid of it, since emacs doesn't support
8126
 
         transparency.  */
8127
 
      background.red   >>= 8;
8128
 
      background.green >>= 8;
8129
 
      background.blue  >>= 8;
8130
 
#else /* not HAVE_X_WINDOWS*/
8131
 
#error FIXME
8132
 
#endif
8133
 
    }
 
8090
  if (!STRINGP (specified_bg)
 
8091
      || !x_defined_color (f, SDATA (specified_bg), &background, 0))
 
8092
    {
 
8093
#ifndef HAVE_NS
 
8094
      background.pixel = FRAME_BACKGROUND_PIXEL (f);
 
8095
      x_query_color (f, &background);
 
8096
#else
 
8097
      ns_query_color(FRAME_BACKGROUND_COLOR (f), &background, 1);
 
8098
#endif
 
8099
    }
 
8100
 
 
8101
  /* SVG pixmaps specify transparency in the last byte, so right
 
8102
     shift 8 bits to get rid of it, since emacs doesn't support
 
8103
     transparency.  */
 
8104
  background.red   >>= 8;
 
8105
  background.green >>= 8;
 
8106
  background.blue  >>= 8;
8134
8107
 
8135
8108
  /* This loop handles opacity values, since Emacs assumes
8136
8109
     non-transparent images.  Each pixel must be "flattened" by
8355
8328
 
8356
8329
  if (!check_image_size (f, img->width, img->height))
8357
8330
    {
8358
 
      image_error ("Invalid image size", Qnil, Qnil);
 
8331
      image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
8359
8332
      return 0;
8360
8333
    }
8361
8334
 
8745
8718
  staticpro (&Qsvg);
8746
8719
  ADD_IMAGE_TYPE (Qsvg);
8747
8720
#ifdef HAVE_NTGUI
 
8721
  /* Other libraries used directly by svg code.  */
8748
8722
  Qgdk_pixbuf = intern ("gdk-pixbuf");
8749
8723
  staticpro (&Qgdk_pixbuf);
8750
8724
  Qglib = intern ("glib");
8751
8725
  staticpro (&Qglib);
 
8726
  Qgobject = intern ("gobject");
 
8727
  staticpro (&Qgobject);
8752
8728
#endif /* HAVE_NTGUI  */
8753
8729
#endif /* HAVE_RSVG  */
8754
8730