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

Linux Cross Reference
Tina4/src/PCwin/epsf_dump.cpp

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

  1 /* Create Encapsulated PostScript Files */
  2 
  3 #include <dibapi.h>
  4 
  5 #ifdef __cplusplus
  6 extern "C" {
  7 #endif  /* __cplusplus */
  8 #include <tina/sys.h>
  9 #include <tina/math.h>
 10 #include <tina/vision.h>
 11 #include <tina/tv.h>
 12 #include <tina/tvfuncs.h>
 13 #include <tina/file.h>
 14 #include <tina/draw.h>
 15 #include <tina/tv_screen.h>
 16 #ifdef __cplusplus
 17 }
 18 #endif  /* __cplusplus */
 19 
 20 extern void (*screen_text) (char *);
 21 #define Print(x)  if(screen_text!=NULL) screen_text(x)
 22 
 23 extern "C" int tv_screen_check_width(Tv_screen *);
 24 extern "C" int tv_screen_check_height(Tv_screen *);
 25 extern "C" int tv_screen_check_depth(Tv_screen *);
 26 
 27 static void tv_screen_epsf_dump_bw(Tv_screen *, char *);
 28 static void tv_screen_epsf_dump_1bpp(Tv_screen *, char *);
 29 static void tv_screen_epsf_dump_color(Tv_screen *, char *);
 30 static void (*epsf_dump) (Tv_screen *, char *) = tv_screen_epsf_dump_color;
 31 static int no_of_bytes_written = 0;
 32 
 33 static void set_epsf_dump_type(Dump_type type)
 34 {
 35     switch (type)
 36     {
 37         case DT_BW:
 38         epsf_dump = tv_screen_epsf_dump_bw;
 39         break;
 40     case DT_COLOR:
 41         epsf_dump = tv_screen_epsf_dump_color;
 42         break;
 43     case DT_ONE_BIT_PER_PIXEL:
 44         epsf_dump = tv_screen_epsf_dump_1bpp;
 45         break;
 46     }
 47 }
 48 
 49 static void write_byte(FILE * out, int byte)
 50 {
 51 
 52     (void) fprintf(out, "%2.2x", byte);
 53     no_of_bytes_written++;
 54     if ((no_of_bytes_written % 72) == 0)
 55     {
 56         (void) fprintf(out, "\n");
 57         no_of_bytes_written = 0;
 58     }
 59 }
 60 
 61 static void tv_screen_print_data_1bpp(FILE * fp, Tv_screen * tv_screen)
 62 {
 63     int     width, height;
 64 
 65     Print("tv_screen_print_data_1bpp?");
 66     width = tv_screen_check_width(tv_screen);
 67     height = tv_screen_check_height(tv_screen);
 68 }
 69 
 70 
 71 
 72 static void tv_screen_epsf_dump_1bpp(Tv_screen * tv_screen, char *epsf_dump_file)
 73 {
 74     FILE   *fp = fopen(epsf_dump_file, "w");
 75     int     width, height, depth, bytes, pixwidth, pixheight, bitsperpixel;
 76     float   totsize, border = (float)0.05;
 77 
 78     width = tv_screen_check_width(tv_screen);
 79     height = tv_screen_check_height(tv_screen);
 80     depth = tv_screen_check_depth(tv_screen);
 81     pixwidth = width;           /* scale setting in PSpoint */
 82     pixheight = height;
 83     bitsperpixel = 1;
 84     bytes = width / 8;          /* size of string for image routine */
 85     if (width % 8)
 86         bytes++;
 87     totsize = (float)(1.0 + 2.0 * border);
 88 
 89     (void) fprintf(fp, "%%!PS-Adobe-2.0 EPFS-2.0\n");
 90     (void) fprintf(fp, "%%%%BoundingBox: %f %f %f %f\n", -border * pixwidth, -border * pixheight, width + border * pixwidth, height + border * pixheight);
 91     /* NB linethickness too ! */
 92     (void) fprintf(fp, "%%%%Creator: TINA epsf_dump\n");
 93     (void) fprintf(fp, "%%%%EndComments\n");
 94 
 95     (void) fprintf(fp, "/bytes %d def\n", bytes);
 96     (void) fprintf(fp, "/width %d def\n", width);
 97     (void) fprintf(fp, "/height %d def\n", height);
 98     (void) fprintf(fp, "/pixwidth %d def\n", pixwidth);
 99     (void) fprintf(fp, "/pixheight %d def\n", pixheight);
100     (void) fprintf(fp, "/bitsperpixel %d def\n", bitsperpixel);
101 
102     (void) fprintf(fp, "/picstr bytes string def\n");
103     (void) fprintf(fp, "/dopic {\n");
104     (void) fprintf(fp, "gsave width height bitsperpixel\n");
105     (void) fprintf(fp, "[width 0 0 height neg 0 height]\n");
106     (void) fprintf(fp, "{currentfile picstr readhexstring pop}\n");
107     (void) fprintf(fp, "image grestore} def\n");
108 
109     (void) fprintf(fp, "0 0 translate pixwidth pixheight scale\n");
110     (void) fprintf(fp, "newpath\n");
111     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
112     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
113     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
114     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
115     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
116     (void) fprintf(fp, "closepath\n");
117     (void) fprintf(fp, "0.005 setlinewidth\n");
118     (void) fprintf(fp, "stroke\n");
119 
120     (void) fprintf(fp, "dopic\n");
121 
122     tv_screen_print_data_1bpp(fp, tv_screen);
123 
124     (void) fprintf(fp, "\nshowpage\n");
125     (void) fprintf(fp, "%%%%Trailer\n");
126     fclose(fp);
127 }
128 
129 
130 static void tv_screen_print_data_bw(FILE * fp, Tv_screen * tv_screen)
131 {
132     int width, height;
133 
134     Print("tv_screen_print_data_bw?");
135     width = tv_screen_check_width(tv_screen);
136     height = tv_screen_check_height(tv_screen);
137 }
138 
139 static void tv_screen_epsf_dump_bw(Tv_screen * tv_screen, char *epsf_dump_file)
140 {
141     FILE   *fp = fopen(epsf_dump_file, "w");
142     int     width, height, depth, bytes, pixwidth, pixheight, bitsperpixel;
143     float   totsize, border = (float)0.05;
144 
145     width = tv_screen_check_width(tv_screen);
146     height = tv_screen_check_height(tv_screen);
147     depth = tv_screen_check_depth(tv_screen);
148     pixwidth = width;           /* scale setting in PSpoint */
149     pixheight = height;
150     bitsperpixel = 8;
151     bytes = width;              /* size of string for image routine */
152     totsize = (float)(1.0 + 2.0 * border);
153 
154     (void) fprintf(fp, "%%!PS-Adobe-2.0 EPFS-2.0\n");
155     (void) fprintf(fp, "%%%%BoundingBox: %f %f %f %f\n", -border * pixwidth, -border * pixheight, width + border * pixwidth, height + border * pixheight);
156     /* NB linethickness too ! */
157     (void) fprintf(fp, "%%%%Creator: TINA epsf_dump\n");
158     (void) fprintf(fp, "%%%%EndComments\n");
159 
160     (void) fprintf(fp, "/bytes %d def\n", bytes);
161     (void) fprintf(fp, "/width %d def\n", width);
162     (void) fprintf(fp, "/height %d def\n", height);
163     (void) fprintf(fp, "/pixwidth %d def\n", pixwidth);
164     (void) fprintf(fp, "/pixheight %d def\n", pixheight);
165     (void) fprintf(fp, "/bitsperpixel %d def\n", bitsperpixel);
166 
167     (void) fprintf(fp, "/picstr bytes string def\n");
168     (void) fprintf(fp, "/dopic {\n");
169     (void) fprintf(fp, "gsave width height bitsperpixel\n");
170     (void) fprintf(fp, "[width 0 0 height neg 0 height]\n");
171     (void) fprintf(fp, "{currentfile picstr readhexstring pop}\n");
172     (void) fprintf(fp, "image grestore} def\n");
173 
174     (void) fprintf(fp, "0 0 translate pixwidth pixheight scale\n");
175     (void) fprintf(fp, "newpath\n");
176     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
177     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
178     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
179     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
180     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
181     (void) fprintf(fp, "closepath\n");
182     (void) fprintf(fp, "0.005 setlinewidth\n");
183     (void) fprintf(fp, "stroke\n");
184 
185     (void) fprintf(fp, "dopic\n");
186 
187     tv_screen_print_data_bw(fp, tv_screen);
188 
189     (void) fprintf(fp, "\nshowpage\n");
190     (void) fprintf(fp, "%%%%Trailer\n");
191     fclose(fp);
192 }
193 
194 /* This awaits a Level 2 postscript to be tested! */
195 static void tv_screen_print_color_map(FILE * fp, Tv_screen * tv_screen)
196 {
197     Print("tv_screen_print_color_map?");
198     if (tv_screen == NULL || tv_screen->tv == NULL)
199         return;
200 
201     /* write out color map */
202 }
203 
204 static void tv_screen_print_data_color(FILE * fp, Tv_screen * tv_screen)
205 {
206     Print("tv_screen_print_data_color?");
207     if (tv_screen == NULL || tv_screen->tv == NULL)
208         return;
209 
210     /* get colour map */
211 }
212 
213 static void tv_screen_epsf_dump_color(Tv_screen * tv_screen, char *epsf_dump_file)
214 {
215     FILE   *fp = fopen(epsf_dump_file, "w");
216     int     width, height, depth, pixwidth, pixheight;
217     float   totsize, border = (float)0.05;
218 
219     width = tv_screen_check_width(tv_screen);
220     height = tv_screen_check_height(tv_screen);
221     depth = tv_screen_check_depth(tv_screen);
222     pixwidth = width;           /* scale setting in PSpoint */
223     pixheight = height;
224     totsize = (float)(1.0 + 2.0 * border);
225 
226     (void) fprintf(fp, "%%!PS-Adobe-2.0 EPFS-2.0\n");
227     (void) fprintf(fp, "%%%%BoundingBox: %f %f %f %f\n", -border * pixwidth, -border * pixheight, width + border * pixwidth, height + border * pixheight);
228     (void) fprintf(fp, "%%%%Creator: TINA epsf_dump\n");
229     (void) fprintf(fp, "%%%%EndComments\n");
230 
231     /* do border */
232     (void) fprintf(fp, "0 0 translate %d %d scale\n", pixwidth, pixheight);
233     (void) fprintf(fp, "newpath\n");
234     (void) fprintf(fp, "%f %f moveto\n", -border, -border);
235     (void) fprintf(fp, "%f %f rlineto\n", 0.0, totsize);
236     (void) fprintf(fp, "%f %f rlineto\n", totsize, 0.0);
237     (void) fprintf(fp, "%f %f rlineto\n", 0.0, -totsize);
238     (void) fprintf(fp, "%f %f rlineto\n", -totsize, 0.0);
239     (void) fprintf(fp, "closepath\n");
240     (void) fprintf(fp, "0.005 setlinewidth\n");
241     (void) fprintf(fp, "stroke\n");
242 
243     (void) fprintf(fp, "/picstr %d string def\n", 3 * width);
244     (void) fprintf(fp, "%d %d 8\n", width, height);
245     (void) fprintf(fp, "[%d 0 0 -%d 0 %d]\n", width, height, height);
246     (void) fprintf(fp, "{currentfile picstr readhexstring pop}\n");
247     (void) fprintf(fp, "false 3\n");
248     (void) fprintf(fp, "colorimage\n");
249 
250     tv_screen_print_data_color(fp, tv_screen);
251 
252     (void) fprintf(fp, "\nshowpage\n");
253     (void) fprintf(fp, "%%%%Trailer\n");
254     fclose(fp);
255 }
256 
257 extern "C" void tv_screen_epsf_dump(Dump_type type, Tv_screen * tv_screen, 
258 char *filename)
259 {
260     if (tv_screen == NULL || tv_screen->tv == NULL)
261         return;
262     set_epsf_dump_type(type);
263     (*epsf_dump) (tv_screen, filename);
264 }
265 

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