~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/X11/picture.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /**
  4 tv_screen_picture:
  5 A Tv_picture contains the pixmap of a tv_screen plus enough information
  6 to display it. A list of pictures makes a movie.
  7 **/
  8 
  9 #include <signal.h>
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/tv.h>
 14 #include <tina/tv_screen.h>
 15 #include <tina/X11funcs.h>
 16 
 17 Tv_picture *tv_screen_get_picture(Tv_screen * tv_screen)
 18 {
 19     Tv_picture *picture = ts_ralloc(Tv_picture);
 20 
 21     if (tv_screen!=NULL)
 22     {
 23         picture->pixmap = XCreatePixmap(tv_screen->display, tv_screen->window,
 24                    tv_screen->width, tv_screen->height, tv_screen->depth);
 25         picture->tv_screen = tv_screen;
 26         tv_screen_set_op(tv_screen, rop_copy);
 27         XCopyArea(tv_screen->display, tv_screen->window, picture->pixmap, tv_screen->gc,
 28                   0, 0, tv_screen->width, tv_screen->height, 0, 0);
 29     }
 30     return (picture);
 31 }
 32 
 33 void    picture_free(void *s)
 34 {
 35     Tv_picture *picture = (Tv_picture *) s;
 36 
 37     if (picture != NULL)
 38         XFreePixmap(picture->tv_screen->display, picture->pixmap);
 39     rfree((void *) s);
 40 }
 41 
 42 static void ximage_write(FILE * fp, XImage * ximage)
 43 {
 44     if (ximage == NULL)
 45         return;
 46 
 47     (void) fwrite((char *) &ximage->width, sizeof(int), 1, fp);
 48     (void) fwrite((char *) &ximage->height, sizeof(int), 1, fp);
 49     (void) fwrite((char *) &ximage->xoffset, sizeof(int), 1, fp);
 50     (void) fwrite((char *) &ximage->format, sizeof(int), 1, fp);
 51     (void) fwrite((char *) &ximage->byte_order, sizeof(int), 1, fp);
 52     (void) fwrite((char *) &ximage->bitmap_unit, sizeof(int), 1, fp);
 53     (void) fwrite((char *) &ximage->bitmap_bit_order, sizeof(int), 1, fp);
 54     (void) fwrite((char *) &ximage->bitmap_pad, sizeof(int), 1, fp);
 55     (void) fwrite((char *) &ximage->depth, sizeof(int), 1, fp);
 56     (void) fwrite((char *) &ximage->bytes_per_line, sizeof(int), 1, fp);
 57     (void) fwrite((char *) &ximage->bits_per_pixel, sizeof(int), 1, fp);
 58     (void) fwrite((char *) &ximage->red_mask, sizeof(unsigned long), 1, fp);
 59     (void) fwrite((char *) &ximage->green_mask, sizeof(unsigned long), 1, fp);
 60     (void) fwrite((char *) &ximage->blue_mask, sizeof(unsigned long), 1, fp);
 61 
 62     (void) fwrite((char *) ximage->data, ximage->bytes_per_line, ximage->height, fp);
 63 }
 64 
 65 XImage *ximage_read(FILE * fp, Display * display, Visual * visual)
 66 {
 67     XImage *ximage;
 68     int     width;
 69     int     height;
 70     int     xoffset;
 71     int     format;
 72     int     byte_order;
 73     int     bitmap_unit;
 74     int     bitmap_bit_order;
 75     int     bitmap_pad;
 76     int     depth;
 77     int     bytes_per_line;
 78     int     bits_per_pixel;
 79     unsigned long red_mask;
 80     unsigned long green_mask;
 81     unsigned long blue_mask;
 82     char   *data;
 83 
 84     (void) fread((char *) &width, sizeof(int), 1, fp);
 85     (void) fread((char *) &height, sizeof(int), 1, fp);
 86     (void) fread((char *) &xoffset, sizeof(int), 1, fp);
 87     (void) fread((char *) &format, sizeof(int), 1, fp);
 88     (void) fread((char *) &byte_order, sizeof(int), 1, fp);
 89     (void) fread((char *) &bitmap_unit, sizeof(int), 1, fp);
 90     (void) fread((char *) &bitmap_bit_order, sizeof(int), 1, fp);
 91     (void) fread((char *) &bitmap_pad, sizeof(int), 1, fp);
 92     (void) fread((char *) &depth, sizeof(int), 1, fp);
 93     (void) fread((char *) &bytes_per_line, sizeof(int), 1, fp);
 94     (void) fread((char *) &bits_per_pixel, sizeof(int), 1, fp);
 95     (void) fread((char *) &red_mask, sizeof(unsigned long), 1, fp);
 96     (void) fread((char *) &green_mask, sizeof(unsigned long), 1, fp);
 97     (void) fread((char *) &blue_mask, sizeof(unsigned long), 1, fp);
 98     data = (char *) malloc((unsigned) bytes_per_line * height);
 99     (void) fread((char *) data, bytes_per_line, height, fp);
100 
101     ximage = XCreateImage(display, visual,
102                           depth, format, xoffset, data, width, height, bitmap_pad, bytes_per_line);
103 
104     ximage->width = width;
105     ximage->height = height;
106     ximage->xoffset = xoffset;
107     ximage->format = format;
108     ximage->byte_order = byte_order;
109     ximage->bitmap_unit = bitmap_unit;
110     ximage->bitmap_bit_order = bitmap_bit_order;
111     ximage->bitmap_pad = bitmap_pad;
112     ximage->depth = depth;
113     ximage->bytes_per_line = bytes_per_line;
114     ximage->bits_per_pixel = bits_per_pixel;
115     ximage->red_mask = red_mask;
116     ximage->green_mask = green_mask;
117     ximage->blue_mask = blue_mask;
118     ximage->data = data;
119 
120     return (ximage);
121 }
122 
123 void    picture_write(FILE * fp, Tv_picture * picture)
124 {
125     XImage *ximage;
126 
127     if (fp == NULL || picture == NULL)
128         return;
129     ximage = XGetImage(picture->tv_screen->display, picture->pixmap,
130           0, 0, picture->tv_screen->width, picture->tv_screen->height,
131                        AllPlanes, ZPixmap);
132     ximage_write(fp, ximage);
133     /* HP warns: 'Argument #1 is not the correct type' */
134     /* But ximage IS correct for XDestroyImage */
135     XDestroyImage(ximage);
136 }
137 
138 Tv_picture *tv_screen_picture_read(Tv_screen * tv_screen, FILE * fp)
139 {
140     XImage *ximage;
141     XWindowAttributes attr;
142     Tv_picture *picture;
143 
144     if (tv_screen == NULL || fp == NULL || feof(fp))
145         return (NULL);
146 
147     XGetWindowAttributes(tv_screen->display, tv_screen->window, &attr);
148     ximage = ximage_read(fp, tv_screen->display, attr.visual);
149 
150     picture = ts_ralloc(Tv_picture);
151     picture->tv_screen = tv_screen;
152     picture->pixmap = XCreatePixmap(tv_screen->display, tv_screen->window,
153                tv_screen->width, tv_screen->height, tv_screen->depth);
154     XPutImage(tv_screen->display, picture->pixmap, tv_screen->gc, ximage,
155               0, 0, 0, 0, tv_screen->width, tv_screen->height);
156     /* HP warns: 'Argument #1 is not the correct type' */
157     /* But ximage IS correct for XDestroyImage */
158     XDestroyImage(ximage);
159 
160     return (picture);
161 }
162 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.