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

Linux Cross Reference
Tina5/tina-tools/tinatool/gphx/x11/gphxX11_dump.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/gphx/x11/gphxX11_dump.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: gphxX11_dump.c,v 1.4 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  * 
 45  *
 46  *********
 47 */
 48 
 49 #if HAVE_CONFIG_H
 50   #include <config.h>
 51 #endif
 52 
 53 #include <stdlib.h>
 54 #include <unistd.h>
 55 
 56 #include "gphxX11_dump.h"
 57 
 58 #include <tina/image/imgGen_alloc.h>
 59 #include <tinatool/gphx/x11/gphxX11_size.h>
 60 #include <tinatool/draw/drawTv_next.h>
 61 
 62 static char dump_command[256] = "lpr -Plw";
 63 static char dumpfile[128] = "JUNK";
 64 
 65 Ipos    ipos();
 66 
 67 void    dump_file_set(char *fname)
 68 {
 69     strcpy(dumpfile, fname);
 70 }
 71 
 72 char   *dump_file_get(void)
 73 {
 74     return (dumpfile);
 75 }
 76 
 77 void    dump_command_set(char *command)
 78 {
 79     (void) strcpy(dump_command, command);
 80 }
 81 
 82 char   *dump_command_get(void)
 83 {
 84     return dump_command;
 85 }
 86 
 87 void    tv_screen_print_data(FILE * fp, Tv_screen * tv_screen)
 88 {
 89     int     i, j, width, height;
 90     int     count = 0;
 91     XImage *ximage;
 92     int     shade[256], bkgrndpix;
 93     Tina_pixel *lut;
 94 
 95     if (tv_screen == NULL || tv_screen->tv == NULL)
 96         return;
 97 
 98     width = tv_screen_check_width(tv_screen);
 99     height = tv_screen_check_height(tv_screen);
100 
101     /* ximage checked for NULL JB 7/3/93 */
102     if ((ximage = XGetImage(tv_screen->display, tv_screen->window,
103                             0, 0, width, height, AllPlanes, ZPixmap)))
104     {
105         lut = tv_screen->tv->cmap_data_visible->std_lut;
106 
107         for (i = 0; i < 256; i++)
108         {
109             XColor  color;
110             int     r, g, b;
111 
112             color.pixel = i;
113             XQueryColor(tv_screen->display, tv_screen->colormap, &color);
114             r = color.red >> 8;
115             g = color.green >> 8;
116             b = color.blue >> 8;
117             if (r == g && g == b)
118                 shade[i] = r;   /** grey **/
119             else
120                 shade[i] = 255 - MAX3(r, g, b); /** brighter colors drawn blacker **/
121         }
122         bkgrndpix = (int) lut[bkgrnd];
123 
124         count = 0;
125         for (i = 0; i < height; i++)
126         {
127             for (j = 0; j < width; j++)
128             {
129                 unsigned long c, g;
130 
131                 c = XGetPixel(ximage, j, i);    /* X pixel value */
132                 if (c == bkgrndpix)
133                     g = 255;
134                 else
135                     g = shade[c];
136                 (void) fprintf(fp, "%2.2x", g);
137                 if ((++count % 64) == 0)
138                     (void) fprintf(fp, "\n");
139             }
140         }
141         /* HP warns: 'Argument #1 is not the correct type' */
142         /* But ximage IS correct for XDestroyImage */
143         XDestroyImage(ximage);
144     }
145 }
146 
147 
148 /* tv_push_screen creates a new image on the top of the
149    image stack that is a copy of the current tv's
150    display contents. most of this code comes directly
151    from the tv_screen_print_data procedure 
152 
153    modified this to remove the stack_push call.
154    it now returns asn Imrect and the calling function
155    is expected to do the pushing.  
156    renamed to tv_screen2imrect
157 */
158 Imrect  *tv_screen2imrect(void)
159 {
160   Tv          *tv = (Tv *)tv_get_next();
161   Tv_screen   *tv_screen = NULL;
162   int          i, j, width, height;
163   XImage      *ximage;
164   Tina_pixel  *lut;
165   int          bkgrndpix;
166   XColor       color;
167   int          r, g, b;
168   unsigned long c,grey;
169   Imrect      *stack_image = NULL;
170 
171   if (tv && (tv_screen=(Tv_screen *)tv->tv_screen))
172     {
173       width = tv_screen_check_width(tv_screen);
174       height = tv_screen_check_height(tv_screen);
175 
176       stack_image = im_alloc(height, width, NULL, int_v);
177 
178       if ((ximage = XGetImage(tv_screen->display, tv_screen->window,
179                               0, 0, width, height, AllPlanes, ZPixmap)))
180       {
181           lut = tv_screen->tv->cmap_data_visible->std_lut;
182           bkgrndpix = (int)lut[bkgrnd];
183 
184           for (i = 0; i < height; i++)
185             {
186               for (j = 0; j < width; j++)
187                 {
188                   c = XGetPixel(ximage, j, i);
189                   if ((int)c == bkgrndpix)
190                     IM_INT(stack_image, i, j) = 255;
191                   else
192                   {
193                      color.pixel = c;
194                      XQueryColor(tv_screen->display, tv_screen->colormap, &color);
195                      r = color.red >> 8;
196                      g = color.green >> 8;
197                      b = color.blue >> 8;
198                      if (r == g && g == b)
199                         grey = r;
200                      else
201                         grey = MAX3(r, g, b);
202 
203                      IM_INT(stack_image, i, j) = grey;
204                   }
205                 }
206             }
207           XDestroyImage(ximage);
208         }
209     }
210     return (stack_image);
211 }
212 
213 
214 /* ARGSUSED quieten lint */
215 void    tv_screen_dump(Tv_screen * tv_screen, double draw_width, double draw_height, int darkest, int lightest)
216 {
217     FILE   *fp = fopen(dumpfile, "w");
218     int     width, height, depth;
219     float   totsize, border = 0.05;
220     char    system_call[256];
221 
222     (void) string_append(system_call, dump_command, " ", dumpfile, NULL);
223 
224     (void) fprintf(fp, "%%!\n");
225     (void) fprintf(fp, "72 72 translate\n");
226     (void) fprintf(fp, "%f %f scale\n", draw_width * 72.0, draw_height * 72.0);
227 
228     totsize = 1.0 + 2.0 * border;
229     (void) fprintf(fp, "newpath\n");
230     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
231     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
232     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
233     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
234     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
235     (void) fprintf(fp, "closepath\n");
236     (void) fprintf(fp, "0.005 setlinewidth\n");
237     (void) fprintf(fp, "stroke\n");
238 
239     width = tv_screen_check_width(tv_screen);
240     height = tv_screen_check_height(tv_screen);
241     depth = tv_screen_check_depth(tv_screen);
242 
243     (void) fprintf(fp, "/picstr %d string def\n", width);
244     (void) fprintf(fp, "%d %d %d\n", width, height, depth);
245     (void) fprintf(fp, "[%d %d %d %d %d %d]\n", width, 0, 0, -height, 0, height);
246     (void) fprintf(fp, "{\n");
247     (void) fprintf(fp, "currentfile picstr readhexstring pop\n");
248     (void) fprintf(fp, "} image\n");
249     tv_screen_print_data(fp, tv_screen);
250     (void) fprintf(fp, "\nshowpage\n");
251     (void) fclose(fp);
252     if (!strcmp(dumpfile, "JUNK"))
253     {
254         (void) system(system_call);
255         (void) unlink(dumpfile);
256     }
257 }
258 

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