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

Linux Cross Reference
Tina6/tina-tools/tinatool/gphx/gdk2/gphxGdk_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/gdk2/gphxGdk_dump.c,v $
 37  * Date    :  $Date: 2008/12/02 22:04:19 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: gphxGdk_dump.c,v 1.3 2008/12/02 22:04:19 paul Exp $
 40  *
 41 * Author  :  paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  gphxGdk_dump.c
 47  *  @brief Grab the image displayed on-screen in a Tv to an Imrect.
 48  *
 49  *  Note: the only function in this file that is used in the libraries is tv_screen2imrect:
 50  *  the rest are never called.  It would be sensible to deprecate them; however, they may 
 51  *  be used in a toolkit somewhere.  This is relevant because I have changed the Tv_picture
 52  *  structure to use a GdkPixbuf instead of a GdkImage: I have tested the tv_screen2imrect
 53  *  function but not the others. PAB 11/11/2010.
 54  *
 55  *  Note: the functions in this file are duplicated for each graphics lib (x11, GDK, etc ...).
 56  *
 57  *  The xview and motif code uses the max of r,g,b and a comparison to the TINA background 
 58  *  color in these functions. The former may cause problems with some colors and the latter 
 59  *  requires an awkward colormap conversion from TINA to GtkRGB.  Therefore, i have changed
 60  *  the convention such that the intensity of the pixel is used (i.e. the I field of an HSI
 61  *  conversion of the RGB) and the output is based solely on the GtkRGB color map.  Since the
 62  *  TINA Tv's automatically scale the dynamic range of the images, regardless of the highest
 63  *  image intensity, this should provide a more WYSIWYG style of output. PAB 03/12/2007 
 64  *
 65  */
 66 
 67 
 68 #if HAVE_CONFIG_H
 69   #include <config.h>
 70 #endif
 71 
 72 #include <stdlib.h>
 73 #include <unistd.h>
 74 #include <string.h>
 75 
 76 #include "gphxGdk_dump.h"
 77 
 78 #include <tina/image/imgGen_alloc.h>
 79 #include <tinatool/gphx/gdk2/gphxGdk_picture.h>
 80 #include <tinatool/gphx/gdk2/gphxGdk_size.h>
 81 #include <tinatool/draw/drawTv_next.h>
 82 
 83 static char dump_command[256] = "lpr -Plw";
 84 static char dumpfile[128] = "JUNK";
 85 
 86 Ipos    ipos();
 87 
 88 
 89 /**
 90  * @brief This function is deprecated, and should not be used in newly written code.
 91  *
 92 */
 93 void    dump_file_set(char *fname)
 94 {
 95     strcpy(dumpfile, fname);
 96 }
 97 
 98 
 99 /**
100  * @brief This function is deprecated, and should not be used in newly written code.
101  *
102 */
103 char   *dump_file_get(void)
104 {
105     return (dumpfile);
106 }
107 
108 
109 /**
110  * @brief This function is deprecated, and should not be used in newly written code.
111  *
112 */
113 void    dump_command_set(char *command)
114 {
115     (void) strcpy(dump_command, command);
116 }
117 
118 
119 /**
120  * @brief This function is deprecated, and should not be used in newly written code.
121  *
122 */
123 char   *dump_command_get(void)
124 {
125     return dump_command;
126 }
127 
128 
129 /**
130  * @brief This function is deprecated, and should not be used in newly written code.
131  *
132  * Notes: fixed to compile with the new definition of Tv_picture (containing a 
133  * GdkPixbuf instead of a GdkImage) but untested.  PAB 12/11/2010.
134  *
135 */
136 void    tv_screen_print_data(FILE * fp, Tv_screen * tv_screen)
137 {
138     Tv_picture *picture=NULL;
139     GdkPixbuf   *pbuf;
140     guchar *pixels=NULL, *src=NULL;
141     guint width, height, channel, src_stride;
142     unsigned int grey;
143     int x, y, r, g, b, count=0;
144 
145     if (tv_screen == NULL || tv_screen->tv == NULL) return;
146 
147     picture = tv_screen_get_picture(tv_screen);
148     pbuf = (GdkPixbuf *)picture->pbuf;
149     if(pbuf==NULL) return;
150 
151     width = gdk_pixbuf_get_width(pbuf);
152     height = gdk_pixbuf_get_height(pbuf);
153     channel = gdk_pixbuf_get_n_channels(pbuf);
154     pixels = gdk_pixbuf_get_pixels(pbuf);
155     src_stride = gdk_pixbuf_get_rowstride (pbuf);
156 
157     for (y = 0; y < height; y++, pixels += src_stride)
158     {
159         src = pixels;
160         for (x = 0; x < width; x++, src += channel)
161         {
162             r = src[0];
163             g = src[1];
164             b = src[2];
165 
166             grey = 255 - (r+g+b)/3;  /** brighter colors drawn blacker **/
167             (void) fprintf(fp, "%2.2x", grey);
168             if ((++count % 64) == 0) (void) fprintf(fp, "\n");
169             if ((++count % 64) == 0) (void) fprintf(fp, "\n");
170         }
171     }
172     picture_free(picture);
173 }
174 
175 
176 /**
177  * @brief Return an Imrect of the image displayed on-screen in the current Tv.
178  * @return Imrect The image displayed on-screen in the current Tv
179  *
180 */
181 Imrect  *tv_screen2imrect(void)
182 {
183     Tv *tv = (Tv *)tv_get_next();
184     Tv_screen *tv_screen = NULL;
185     Tv_picture *picture=NULL;
186     GdkPixbuf   *pbuf;
187     guchar *pixels=NULL, *src=NULL;
188     guint width, height, channel, src_stride;
189     Imrect *stack_image=NULL;
190     unsigned long grey;
191     int x, y, r, g, b;
192 
193     if (tv && (tv_screen=(Tv_screen *)tv->tv_screen))
194     {
195         picture = tv_screen_get_picture(tv_screen);
196         pbuf = (GdkPixbuf *)picture->pbuf;
197         if(pbuf==NULL) return NULL;
198 
199         width = gdk_pixbuf_get_width(pbuf);
200         height = gdk_pixbuf_get_height(pbuf);
201         channel = gdk_pixbuf_get_n_channels(pbuf);
202         pixels = gdk_pixbuf_get_pixels(pbuf);
203         src_stride = gdk_pixbuf_get_rowstride (pbuf);
204 
205         stack_image = im_alloc(height, width, NULL, int_v);
206 
207         for (y = 0; y < height; y++, pixels += src_stride)
208         {
209             src = pixels;
210             for (x = 0; x < width; x++, src += channel)
211             {
212                 r = src[0];
213                 g = src[1];
214                 b = src[2];
215 
216                 grey = (r+g+b)/3;
217                 IM_INT(stack_image, y, x) = grey;
218             }
219         }
220         picture_free(picture); 
221     }
222     return (stack_image);
223 }
224 
225 
226 
227 /**
228  * @brief This function is deprecated, and should not be used in newly written code.
229  *
230 */
231 void    tv_screen_dump(Tv_screen * tv_screen, double draw_width, double draw_height, int darkest, int lightest)
232 {
233     FILE   *fp = fopen(dumpfile, "w");
234     int     width, height, depth;
235     float   totsize, border = 0.05;
236     char    system_call[256];
237 
238     (void) string_append(system_call, dump_command, " ", dumpfile, NULL);
239 
240     (void) fprintf(fp, "%%!\n");
241     (void) fprintf(fp, "72 72 translate\n");
242     (void) fprintf(fp, "%f %f scale\n", draw_width * 72.0, draw_height * 72.0);
243 
244     totsize = 1.0 + 2.0 * border;
245     (void) fprintf(fp, "newpath\n");
246     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
247     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
248     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
249     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
250     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
251     (void) fprintf(fp, "closepath\n");
252     (void) fprintf(fp, "0.005 setlinewidth\n");
253     (void) fprintf(fp, "stroke\n");
254 
255     width = tv_screen_check_width(tv_screen);
256     height = tv_screen_check_height(tv_screen);
257     depth = tv_screen_check_depth(tv_screen);
258 
259     (void) fprintf(fp, "/picstr %d string def\n", width);
260     (void) fprintf(fp, "%d %d %d\n", width, height, depth);
261     (void) fprintf(fp, "[%d %d %d %d %d %d]\n", width, 0, 0, -height, 0, height);
262     (void) fprintf(fp, "{\n");
263     (void) fprintf(fp, "currentfile picstr readhexstring pop\n");
264     (void) fprintf(fp, "} image\n");
265     tv_screen_print_data(fp, tv_screen);
266     (void) fprintf(fp, "\nshowpage\n");
267     (void) fclose(fp);
268     if (!strcmp(dumpfile, "JUNK"))
269     {
270         (void) system(system_call);
271         (void) unlink(dumpfile);
272     }
273 }
274 

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