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

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

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

  1 /**@(#) **/
  2 #include <stdio.h>
  3 #ifdef __STRICT_ANSI__
  4 #include <stdlib.h>
  5 #endif
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 #include <tina/math.h>
  9 #include <tina/tv.h>
 10 #include <tina/tv_screen.h>
 11 
 12 extern int tv_screen_check_width(Tv_screen * tv_screen);
 13 extern int tv_screen_check_height(Tv_screen * tv_screen);
 14 extern int tv_screen_check_depth(Tv_screen * tv_screen);
 15 
 16 static char dump_command[256] = "lpr -Plw";
 17 static char dumpfile[128] = "JUNK";
 18 
 19 Ipos    ipos();
 20 
 21 void    dump_file_set(char *fname)
 22 {
 23     strcpy(dumpfile, fname);
 24 }
 25 
 26 char   *dump_file_get(void)
 27 {
 28     return (dumpfile);
 29 }
 30 
 31 void    dump_command_set(char *command)
 32 {
 33     (void) strcpy(dump_command, command);
 34 }
 35 
 36 char   *dump_command_get(void)
 37 {
 38     return dump_command;
 39 }
 40 
 41 void    tv_screen_print_data(FILE * fp, Tv_screen * tv_screen)
 42 {
 43     int     i, j, width, height;
 44     int     count = 0;
 45     XImage *ximage;
 46     int     shade[256], bkgrndpix;
 47     Tina_pixel *lut;
 48 
 49     if (tv_screen == NULL || tv_screen->tv == NULL)
 50         return;
 51 
 52     width = tv_screen_check_width(tv_screen);
 53     height = tv_screen_check_height(tv_screen);
 54 
 55     /* ximage checked for NULL JB 7/3/93 */
 56     if ((ximage = XGetImage(tv_screen->display, tv_screen->window,
 57                             0, 0, width, height, AllPlanes, ZPixmap)))
 58     {
 59         lut = tv_screen->tv->cmap_data_visible->std_lut;
 60 
 61         for (i = 0; i < 256; i++)
 62         {
 63             XColor  color;
 64             int     r, g, b;
 65 
 66             color.pixel = i;
 67             XQueryColor(tv_screen->display, tv_screen->colormap, &color);
 68             r = color.red >> 8;
 69             g = color.green >> 8;
 70             b = color.blue >> 8;
 71             if (r == g && g == b)
 72                 shade[i] = r;   /** grey **/
 73             else
 74                 shade[i] = 255 - MAX3(r, g, b); /** brighter colors drawn blacker **/
 75         }
 76         bkgrndpix = (int) lut[bkgrnd];
 77 
 78         count = 0;
 79         for (i = 0; i < height; i++)
 80         {
 81             for (j = 0; j < width; j++)
 82             {
 83                 unsigned long c, g;
 84 
 85                 c = XGetPixel(ximage, j, i);    /* X pixel value */
 86                 if (c == bkgrndpix)
 87                     g = 255;
 88                 else
 89                     g = shade[c];
 90                 (void) fprintf(fp, "%2.2x", g);
 91                 if ((++count % 64) == 0)
 92                     (void) fprintf(fp, "\n");
 93             }
 94         }
 95         /* HP warns: 'Argument #1 is not the correct type' */
 96         /* But ximage IS correct for XDestroyImage */
 97         XDestroyImage(ximage);
 98     }
 99 }
100 
101 
102 /* tv_push_screen creates a new image on the top of the
103    image stack that is a copy of the current tv's
104    display contents. most of this code comes directly
105    from the tv_screen_print_data procedure 
106 
107    modified this to remove the stack_push call.
108    it now returns asn Imrect and the calling function
109    is expected to do the pushing.  
110    renamed to tv_screen2imrect
111 */
112 Imrect  *tv_screen2imrect(void)
113 {
114   Tv          *tv = (Tv *)tv_get_next();
115   Tv_screen   *tv_screen = NULL;
116   int          i, j, width, height;
117   XImage      *ximage;
118   Tina_pixel  *lut;
119   int          bkgrndpix;
120   XColor       color;
121   int          r, g, b;
122   unsigned long c,grey;
123   Imrect      *stack_image = NULL;
124 
125   if (tv && (tv_screen=(Tv_screen *)tv->tv_screen))
126     {
127       width = tv_screen_check_width(tv_screen);
128       height = tv_screen_check_height(tv_screen);
129 
130       stack_image = im_alloc(height, width, NULL, int_v);
131 
132       if ((ximage = XGetImage(tv_screen->display, tv_screen->window,
133                               0, 0, width, height, AllPlanes, ZPixmap)))
134       {
135           lut = tv_screen->tv->cmap_data_visible->std_lut;
136           bkgrndpix = (int)lut[bkgrnd];
137 
138           for (i = 0; i < height; i++)
139             {
140               for (j = 0; j < width; j++)
141                 {
142                   c = XGetPixel(ximage, j, i);
143                   if ((int)c == bkgrndpix)
144                     IM_INT(stack_image, i, j) = 255;
145                   else
146                   {
147                      color.pixel = c;
148                      XQueryColor(tv_screen->display, tv_screen->colormap, &color);
149                      r = color.red >> 8;
150                      g = color.green >> 8;
151                      b = color.blue >> 8;
152                      if (r == g && g == b)
153                         grey = r;
154                      else
155                         grey = MAX3(r, g, b);
156 
157                      IM_INT(stack_image, i, j) = grey;
158                   }
159                 }
160             }
161           XDestroyImage(ximage);
162         }
163     }
164     return (stack_image);
165 }
166 
167 
168 /* ARGSUSED quieten lint */
169 void    tv_screen_dump(Tv_screen * tv_screen, double draw_width, double draw_height, int darkest, int lightest)
170 {
171     FILE   *fp = fopen(dumpfile, "w");
172     int     width, height, depth;
173     float   totsize, border = 0.05;
174     char    system_call[256];
175 
176     (void) string_append(system_call, dump_command, " ", dumpfile, NULL);
177 
178     (void) fprintf(fp, "%%!\n");
179     (void) fprintf(fp, "72 72 translate\n");
180     (void) fprintf(fp, "%f %f scale\n", draw_width * 72.0, draw_height * 72.0);
181 
182     totsize = 1.0 + 2.0 * border;
183     (void) fprintf(fp, "newpath\n");
184     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
185     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
186     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
187     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
188     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
189     (void) fprintf(fp, "closepath\n");
190     (void) fprintf(fp, "0.005 setlinewidth\n");
191     (void) fprintf(fp, "stroke\n");
192 
193     width = tv_screen_check_width(tv_screen);
194     height = tv_screen_check_height(tv_screen);
195     depth = tv_screen_check_depth(tv_screen);
196 
197     (void) fprintf(fp, "/picstr %d string def\n", width);
198     (void) fprintf(fp, "%d %d %d\n", width, height, depth);
199     (void) fprintf(fp, "[%d %d %d %d %d %d]\n", width, 0, 0, -height, 0, height);
200     (void) fprintf(fp, "{\n");
201     (void) fprintf(fp, "currentfile picstr readhexstring pop\n");
202     (void) fprintf(fp, "} image\n");
203     tv_screen_print_data(fp, tv_screen);
204     (void) fprintf(fp, "\nshowpage\n");
205     (void) fclose(fp);
206     if (!strcmp(dumpfile, "JUNK"))
207     {
208         (void) system(system_call);
209         (void) unlink(dumpfile);
210     }
211 }
212 

~ [ 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.