/[emacs]/emacs/src/w32fns.c
ViewVC logotype

Diff of /emacs/src/w32fns.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.165 by jasonr, Sat Mar 23 00:35:23 2002 UTC revision 1.166 by jasonr, Sun Mar 24 15:49:44 2002 UTC
# Line 9507  slurp_file (file, size) Line 9507  slurp_file (file, size)
9507                                XBM images                                XBM images
9508   ***********************************************************************/   ***********************************************************************/
9509    
9510    static int xbm_scan P_ ((char **, char *, char *, int *));
9511  static int xbm_load P_ ((struct frame *f, struct image *img));  static int xbm_load P_ ((struct frame *f, struct image *img));
9512  static int xbm_load_image_from_file P_ ((struct frame *f, struct image *img,  static int xbm_load_image P_ ((struct frame *f, struct image *img,
9513                                           Lisp_Object file));                                 char *, char *));
9514  static int xbm_image_p P_ ((Lisp_Object object));  static int xbm_image_p P_ ((Lisp_Object object));
9515  static int xbm_read_bitmap_file_data P_ ((char *, int *, int *,  static int xbm_read_bitmap_data P_ ((char *, char *, int *, int *,
9516                                            unsigned char **));                                       unsigned char **));
9517    static int xbm_file_p P_ ((Lisp_Object));
9518    
9519    
9520  /* Indices of image specification fields in xbm_format, below.  */  /* Indices of image specification fields in xbm_format, below.  */
# Line 9545  static struct image_keyword xbm_format[X Line 9547  static struct image_keyword xbm_format[X
9547    {":width",            IMAGE_POSITIVE_INTEGER_VALUE,           0},    {":width",            IMAGE_POSITIVE_INTEGER_VALUE,           0},
9548    {":height",           IMAGE_POSITIVE_INTEGER_VALUE,           0},    {":height",           IMAGE_POSITIVE_INTEGER_VALUE,           0},
9549    {":data",             IMAGE_DONT_CHECK_VALUE_TYPE,            0},    {":data",             IMAGE_DONT_CHECK_VALUE_TYPE,            0},
9550    {":foreground",       IMAGE_STRING_OR_NIL_VALUE,                      0},    {":foreground",       IMAGE_STRING_OR_NIL_VALUE,              0},
9551    {":background",       IMAGE_STRING_OR_NIL_VALUE,                      0},    {":background",       IMAGE_STRING_OR_NIL_VALUE,              0},
9552    {":ascent",           IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},    {":ascent",           IMAGE_ASCENT_VALUE,                     0},
9553    {":margin",           IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},    {":margin",           IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
9554    {":relief",           IMAGE_INTEGER_VALUE,                    0},    {":relief",           IMAGE_INTEGER_VALUE,                    0},
9555    {":conversion",       IMAGE_DONT_CHECK_VALUE_TYPE,            0},    {":conversion",       IMAGE_DONT_CHECK_VALUE_TYPE,            0},
9556    {":heuristic-mask",   IMAGE_DONT_CHECK_VALUE_TYPE,            0}    {":heuristic-mask",   IMAGE_DONT_CHECK_VALUE_TYPE,            0},
9557      {":mask",             IMAGE_DONT_CHECK_VALUE_TYPE,            0}
9558  };  };
9559    
9560  /* Structure describing the image type XBM.  */  /* Structure describing the image type XBM.  */
# Line 9594  enum xbm_token Line 9597  enum xbm_token
9597     3. a vector of strings or bool-vectors, one for each line of the     3. a vector of strings or bool-vectors, one for each line of the
9598     bitmap.     bitmap.
9599    
9600       4. A string containing an in-memory XBM file.  WIDTH and HEIGHT
9601       may not be specified in this case because they are defined in the
9602       XBM file.
9603    
9604     Both the file and data forms may contain the additional entries     Both the file and data forms may contain the additional entries
9605     `:background COLOR' and `:foreground COLOR'.  If not present,     `:background COLOR' and `:foreground COLOR'.  If not present,
9606     foreground and background of the frame on which the image is     foreground and background of the frame on which the image is
9607     displayed, is used.  */     displayed is used.  */
9608    
9609  static int  static int
9610  xbm_image_p (object)  xbm_image_p (object)
# Line 9616  xbm_image_p (object) Line 9623  xbm_image_p (object)
9623        if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count)        if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_DATA].count)
9624          return 0;          return 0;
9625      }      }
9626      else if (kw[XBM_DATA].count && xbm_file_p (kw[XBM_DATA].value))
9627        {
9628          /* In-memory XBM file.  */
9629          if (kw[XBM_WIDTH].count || kw[XBM_HEIGHT].count || kw[XBM_FILE].count)
9630            return 0;
9631        }
9632    else    else
9633      {      {
9634        Lisp_Object data;        Lisp_Object data;
# Line 9677  xbm_image_p (object) Line 9690  xbm_image_p (object)
9690          return 0;          return 0;
9691      }      }
9692    
   /* Baseline must be a value between 0 and 100 (a percentage).  */  
   if (kw[XBM_ASCENT].count  
       && XFASTINT (kw[XBM_ASCENT].value) > 100)  
     return 0;  
     
9693    return 1;    return 1;
9694  }  }
9695    
# Line 9780  xbm_scan (s, end, sval, ival) Line 9788  xbm_scan (s, end, sval, ival)
9788  }  }
9789    
9790    
9791    /* XBM bits seem to be backward within bytes compared with how
9792       Windows does things.  */
9793    static unsigned char reflect_byte (unsigned char orig)
9794    {
9795      int i;
9796      unsigned char reflected = 0x00;
9797      for (i = 0; i < 8; i++)
9798        {
9799          if (orig & (0x01 << i))
9800            reflected |= 0x80 >> i;
9801        }
9802      return reflected;
9803    }
9804    
9805    
9806  /* Replacement for XReadBitmapFileData which isn't available under old  /* Replacement for XReadBitmapFileData which isn't available under old
9807     X versions.  CONTENTS is a pointer to a buffer to parse; END is the     X versions.  CONTENTS is a pointer to a buffer to parse; END is the
9808     buffer's end.  Set *WIDTH and *HEIGHT to the width and height of     buffer's end.  Set *WIDTH and *HEIGHT to the width and height of
# Line 9797  xbm_read_bitmap_data (contents, end, wid Line 9820  xbm_read_bitmap_data (contents, end, wid
9820    char buffer[BUFSIZ];    char buffer[BUFSIZ];
9821    int padding_p = 0;    int padding_p = 0;
9822    int v10 = 0;    int v10 = 0;
9823    int bytes_per_line, i, nbytes;    int bytes_in_per_line, bytes_out_per_line, i, nbytes;
9824    unsigned char *p;    unsigned char *p;
9825    int value;    int value;
9826    int LA1;    int LA1;
9827    
9828  #define match() \  #define match() \
9829       LA1 = xbm_scan (contents, end, buffer, &value)       LA1 = xbm_scan (&s, end, buffer, &value)
9830    
9831  #define expect(TOKEN)           \  #define expect(TOKEN)           \
9832       if (LA1 != (TOKEN))        \       if (LA1 != (TOKEN))        \
# Line 9850  xbm_read_bitmap_data (contents, end, wid Line 9873  xbm_read_bitmap_data (contents, end, wid
9873    expect_ident ("static");    expect_ident ("static");
9874    if (LA1 == XBM_TK_IDENT)    if (LA1 == XBM_TK_IDENT)
9875      {      {
9876          /* On Windows, all images need padding to 16 bit boundaries.  */
9877          if (*width % 16 && *width % 16 < 9)
9878            padding_p = 1;
9879    
9880        if (strcmp (buffer, "unsigned") == 0)        if (strcmp (buffer, "unsigned") == 0)
9881          {          {
9882            match ();            match ();
# Line 9859  xbm_read_bitmap_data (contents, end, wid Line 9886  xbm_read_bitmap_data (contents, end, wid
9886          {          {
9887            match ();            match ();
9888            v10 = 1;            v10 = 1;
           if (*width % 16 && *width % 16 < 9)  
             padding_p = 1;  
9889          }          }
9890        else if (strcmp (buffer, "char") == 0)        else if (strcmp (buffer, "char") == 0)
9891          match ();          match ();
# Line 9876  xbm_read_bitmap_data (contents, end, wid Line 9901  xbm_read_bitmap_data (contents, end, wid
9901    expect ('=');    expect ('=');
9902    expect ('{');    expect ('{');
9903    
9904    bytes_per_line = (*width + 7) / 8 + padding_p;    /* Bytes per line on input.  Only count padding for v10 XBMs.  */
9905    nbytes = bytes_per_line * *height;    bytes_in_per_line = (*width + 7) / 8 + (v10 ? padding_p : 0);
9906    p = *data = (char *) xmalloc (nbytes);    bytes_out_per_line = (*width + 7) / 8 + padding_p;
9907    
9908      nbytes = bytes_in_per_line * *height;
9909      p = *data = (char *) xmalloc (bytes_out_per_line * *height);
9910    
9911    if (v10)    if (v10)
9912      {      {
         
9913        for (i = 0; i < nbytes; i += 2)        for (i = 0; i < nbytes; i += 2)
9914          {          {
9915            int val = value;            int val = value;
9916            expect (XBM_TK_NUMBER);            expect (XBM_TK_NUMBER);
9917    
9918            *p++ = val;            *p++ = reflect_byte (val);
9919            if (!padding_p || ((i + 2) % bytes_per_line))            if (!padding_p || ((i + 2) % bytes_in_per_line))
9920              *p++ = value >> 8;              *p++ = reflect_byte (value >> 8);
9921                        
9922            if (LA1 == ',' || LA1 == '}')            if (LA1 == ',' || LA1 == '}')
9923              match ();              match ();
# Line 9905  xbm_read_bitmap_data (contents, end, wid Line 9932  xbm_read_bitmap_data (contents, end, wid
9932            int val = value;            int val = value;
9933            expect (XBM_TK_NUMBER);            expect (XBM_TK_NUMBER);
9934                        
9935            *p++ = val;            *p++ = reflect_byte (val);
9936                        if (padding_p && ((i + 1) % bytes_in_per_line) == 0)
9937                *p++ = 0;
9938    
9939            if (LA1 == ',' || LA1 == '}')            if (LA1 == ',' || LA1 == '}')
9940              match ();              match ();
9941            else            else
# Line 9949  xbm_load_image (f, img, contents, end) Line 9978  xbm_load_image (f, img, contents, end)
9978    rc = xbm_read_bitmap_data (contents, end, &img->width, &img->height, &data);    rc = xbm_read_bitmap_data (contents, end, &img->width, &img->height, &data);
9979    if (rc)    if (rc)
9980      {      {
       int depth = one_w32_display_info.n_cbits;  
       int planes = one_w32_display_info.n_planes;  
   
9981        unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);        unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
9982        unsigned long background = FRAME_BACKGROUND_PIXEL (f);        unsigned long background = FRAME_BACKGROUND_PIXEL (f);
9983        Lisp_Object value;        Lisp_Object value;
# Line 9970  xbm_load_image (f, img, contents, end) Line 9996  xbm_load_image (f, img, contents, end)
9996            img->background_valid = 1;            img->background_valid = 1;
9997          }          }
9998        img->pixmap        img->pixmap
9999          = CreateBitmap (img->width, img->height, planes, depth, data);          = CreateBitmap (img->width, img->height, 1, 1, data);
10000    
10001        xfree (data);        xfree (data);
10002    
# Line 10061  xbm_load (f, img) Line 10087  xbm_load (f, img)
10087        data = image_spec_value (img->spec, QCdata, NULL);        data = image_spec_value (img->spec, QCdata, NULL);
10088        in_memory_file_p = xbm_file_p (data);        in_memory_file_p = xbm_file_p (data);
10089    
10090        /* Parse the list specification.  */        /* Parse the image specification.  */
10091        bcopy (xbm_format, fmt, sizeof fmt);        bcopy (xbm_format, fmt, sizeof fmt);
10092        parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);        parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
10093        xassert (parsed_p);        xassert (parsed_p);
# Line 10073  xbm_load (f, img) Line 10099  xbm_load (f, img)
10099            img->height = XFASTINT (fmt[XBM_HEIGHT].value);            img->height = XFASTINT (fmt[XBM_HEIGHT].value);
10100            xassert (img->width > 0 && img->height > 0);            xassert (img->width > 0 && img->height > 0);
10101          }          }
10102    
10103        /* Get foreground and background colors, maybe allocate colors.  */        /* Get foreground and background colors, maybe allocate colors.  */
10104        if (fmt[XBM_FOREGROUND].count        if (fmt[XBM_FOREGROUND].count
10105            && STRINGP (fmt[XBM_FOREGROUND].value))            && STRINGP (fmt[XBM_FOREGROUND].value))
# Line 10109  xbm_load (f, img) Line 10136  xbm_load (f, img)
10136              bits = XSTRING (data)->data;              bits = XSTRING (data)->data;
10137            else            else
10138              bits = XBOOL_VECTOR (data)->data;              bits = XBOOL_VECTOR (data)->data;
10139  #ifdef TODO /* image support.  */  #ifdef TODO /* full image support.  */
10140            /* Create the pixmap.  */            /* Create the pixmap.  */
10141            depth = one_w32_display_info.n_cbits;            depth = one_w32_display_info.n_cbits;
10142            img->pixmap            img->pixmap
# Line 11012  x_build_heuristic_mask (f, img, how) Line 11039  x_build_heuristic_mask (f, img, how)
11039    return 0;    return 0;
11040  #endif  #endif
11041  }  }
11042    
11043    
11044  /***********************************************************************  /***********************************************************************
11045                         PBM (mono, gray, color)                         PBM (mono, gray, color)
# Line 15339  init_xfns () Line 15367  init_xfns ()
15367    Vimage_types = Qnil;    Vimage_types = Qnil;
15368    
15369    define_image_type (&pbm_type);    define_image_type (&pbm_type);
   
 #if 0 /* TODO : Image support for W32 */  
15370    define_image_type (&xbm_type);    define_image_type (&xbm_type);
15371    #if 0 /* TODO : Image support for W32 */
15372    define_image_type (&gs_type);    define_image_type (&gs_type);
15373  #endif  #endif
15374        

Legend:
Removed from v.1.165  
changed lines
  Added in v.1.166

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26