/[oroborus]/oroborus/src/pixmap.c
ViewVC logotype

Diff of /oroborus/src/pixmap.c

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

revision 1.5 by dreamind, Sun Jul 7 03:17:41 2002 UTC revision 1.6 by dreamind, Mon Jul 15 08:23:08 2002 UTC
# Line 29  Line 29 
29    
30  int  int
31  loadPixmap (Display * dpy, MyPixmap * pm, char *dir, char *file,  loadPixmap (Display * dpy, MyPixmap * pm, char *dir, char *file,
32              XpmColorSymbol * cs, int n)                                                  XpmColorSymbol * cs, int n)
33  {  {
34    char filename[512];          char filename[512];
35    XpmAttributes attr;          XpmAttributes attr;
36    
37  #ifdef DEBUG  #ifdef DEBUG
38    printf ("entering loadPixmap\n");          printf ("entering loadPixmap\n");
39  #endif  #endif
40    
41    pm->pixmap = None;          pm->pixmap = None;
42    pm->mask = None;          pm->mask = None;
43    pm->width = 1;          pm->width = 1;
44    pm->height = 1;          pm->height = 1;
45    snprintf (filename, sizeof (filename), "%s/%s", dir, file);          snprintf (filename, sizeof (filename), "%s/%s", dir, file);
46    attr.colorsymbols = cs;          attr.colorsymbols = cs;
47    attr.numsymbols = n;          attr.numsymbols = n;
48    attr.valuemask = XpmSize;          attr.valuemask = XpmSize;
49    if (n > 0 && cs)          if (n > 0 && cs)
50      attr.valuemask = attr.valuemask | XpmColorSymbols;                  attr.valuemask = attr.valuemask | XpmColorSymbols;
51    if (XpmReadFileToPixmap          if (XpmReadFileToPixmap
52        (dpy, XDefaultRootWindow (dpy), filename, &pm->pixmap, &pm->mask,                          (dpy, XDefaultRootWindow (dpy), filename, &pm->pixmap, &pm->mask,
53         &attr))                           &attr))
54      return False;                  return False;
55    pm->width = attr.width;          pm->width = attr.width;
56    pm->height = attr.height;          pm->height = attr.height;
57    XpmFreeAttributes (&attr);          XpmFreeAttributes (&attr);
58    return True;          return True;
59  }  }
60    
61  void  void
62  freePixmap (Display * dpy, MyPixmap * pm)  freePixmap (Display * dpy, MyPixmap * pm)
63  {  {
64  #ifdef DEBUG  #ifdef DEBUG
65    printf ("entering freePixmap\n");          printf ("entering freePixmap\n");
66  #endif  #endif
67    
68    if (pm->pixmap != None)          if (pm->pixmap != None)
69      XFreePixmap (dpy, pm->pixmap);                  XFreePixmap (dpy, pm->pixmap);
70    if (pm->mask != None)          if (pm->mask != None)
71      XFreePixmap (dpy, pm->mask);                  XFreePixmap (dpy, pm->mask);
72  }  }
73    
74  void  void
75  scalePixmap (Display * dpy, MyPixmap * src, MyPixmap * dst, int width,  scalePixmap (Display * dpy, MyPixmap * src, MyPixmap * dst, int width,
76               int height)                                                   int height)
77  {  {
78    XpmImage xi_src, xi_dst;          XpmImage xi_src, xi_dst;
79    int x, y, sx, sy, *src_data, *dst_data;          int x, y, sx, sy, *src_data, *dst_data;
80    
81  #ifdef DEBUG  #ifdef DEBUG
82    printf ("entering scalePixmap\n");          printf ("entering scalePixmap\n");
83  #endif  #endif
84    
85    /* don't ask me why but sometimes this function gets _REALLY_ big imagesizes          /* don't ask me why but sometimes this function gets _REALLY_ big imagesizes
86     * so there must be something totally wrong somewhere... */           * so there must be something totally wrong somewhere... */
87    if (width > 20000)          if (width > 20000)
88      return;                  return;
89    if (height > 20000)          if (height > 20000)
90      return;                  return;
91    if (width < 1)          if (width < 1)
92      return;                  return;
93    if (height < 1)          if (height < 1)
94      return;                  return;
95    /* I currently don't know exactly but it _IS_ a bug in here */          /* I currently don't know exactly but it _IS_ a bug in here */
96    
97    XpmCreateXpmImageFromPixmap (dpy, src->pixmap, src->mask, &xi_src, NULL);          XpmCreateXpmImageFromPixmap (dpy, src->pixmap, src->mask, &xi_src, NULL);
98    dst->width = width;          dst->width = width;
99    dst->height = height;          dst->height = height;
100    xi_dst.width = width;          xi_dst.width = width;
101    xi_dst.height = height;          xi_dst.height = height;
102    xi_dst.cpp = xi_src.cpp;          xi_dst.cpp = xi_src.cpp;
103    xi_dst.ncolors = xi_src.ncolors;          xi_dst.ncolors = xi_src.ncolors;
104    xi_dst.colorTable = xi_src.colorTable;          xi_dst.colorTable = xi_src.colorTable;
105    xi_dst.data = xmalloc (sizeof (int) * (xi_dst.width * xi_dst.height));          xi_dst.data = xmalloc (sizeof (int) * (xi_dst.width * xi_dst.height));
106    dst_data = xi_dst.data;          dst_data = xi_dst.data;
107    src_data = xi_src.data;          src_data = xi_src.data;
108  #ifdef DEBUG  #ifdef DEBUG
109    printf ("xi_dst.width %i\n", xi_dst.width);          printf ("xi_dst.width %i\n", xi_dst.width);
110    printf ("xi_dst.height %i\n", xi_dst.height);          printf ("xi_dst.height %i\n", xi_dst.height);
111    printf ("xi_src.width %i\n", xi_src.width);          printf ("xi_src.width %i\n", xi_src.width);
112    printf ("xi_src.height %i\n", xi_src.height);          printf ("xi_src.height %i\n", xi_src.height);
113  #endif  #endif
114    for (y = 0; y < xi_dst.height; y++)          for (y = 0; y < xi_dst.height; y++)
115      {                  {
116        dst_data = xi_dst.data + (y * xi_dst.width);                          dst_data = xi_dst.data + (y * xi_dst.width);
117        for (x = 0; x < xi_dst.width; x++)                          for (x = 0; x < xi_dst.width; x++)
118          {                                  {
119            sx = (x * xi_src.width) / xi_dst.width;                                          sx = (x * xi_src.width) / xi_dst.width;
120            sy = (y * xi_src.height) / xi_dst.height;                                          sy = (y * xi_src.height) / xi_dst.height;
121            *dst_data = *(src_data + sx + (sy * xi_src.width));                                          *dst_data = *(src_data + sx + (sy * xi_src.width));
122            dst_data++;                                          dst_data++;
123          }                                  }
124      }                  }
125    XpmCreatePixmapFromXpmImage (dpy, DefaultRootWindow (dpy), &xi_dst,          XpmCreatePixmapFromXpmImage (dpy, DefaultRootWindow (dpy), &xi_dst,
126                                 &dst->pixmap, &dst->mask, NULL);                                                                                                                           &dst->pixmap, &dst->mask, NULL);
127    free (xi_dst.data);          free (xi_dst.data);
128    XpmFreeXpmImage (&xi_src);          XpmFreeXpmImage (&xi_src);
129  }  }
130    
131  /**This must remain at the end of the file.**********  /**This must remain at the end of the file.**********
132   * vim600:set sw=2 ts=8:                            *   * vim600:set sw=2 ts=2:                            *
133   * vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: *   * vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: *
134   * vim600:set foldmethod=marker:                    *   * vim600:set foldmethod=marker:                    *
135   ****************************************************/   ****************************************************/

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

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