1 /*
2 * gfx3.cc
3 * Graphics routines
4 * AYM 1999-06-06
5 */
6
7
8 /*
9 This file is part of Yadex.
10
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in
12 1994 by Rapha�l Quinet and Brendon Wyber.
13
14 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
15
16 This program is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any later
19 version.
20
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License along with
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
27 Place, Suite 330, Boston, MA 02111-1307, USA.
28 */
29
30
31 #include "yadex.h"
32 #include <X11/Xlib.h>
33 #include "colour.h"
34 #include "gfx.h"
35 #include "gfx3.h"
36 #include "rgbbmp.h"
37
38
39 /*
40 * window_to_rgbbmp
41 * Grab a rectangle from the window or screen into an
42 * Rgbbmp, in a portable fashion.
43 */
window_to_rgbbmp(int x,int y,int width,int height,Rgbbmp & b)44 void window_to_rgbbmp (int x, int y, int width, int height, Rgbbmp &b)
45 {
46 #if defined Y_X11
47 b.resize (width, height);
48 // FIXME
49 for (int y = 0; y < b.height (); y++)
50 for (int x = 0; x < b.width (); x++)
51 b.set_r (x, y, 255 * (b.height () - y) / b.height ());
52 for (int y = 0; y < b.height (); y++)
53 for (int x = 0; x < b.width (); x++)
54 b.set_g (x, y, 255 * (b.width () - x) / b.width ());
55 for (int y = 0; y < b.height (); y++)
56 for (int x = 0; x < b.width (); x++)
57 b.set_b (x, y, 255 * (x + y) / (b.width () + b.height ()));
58 #elif defined Y_BGI
59 printf ("window_to_rgb: unimplemented\n");
60 return 0;
61 #endif
62 }
63
64
65 /*
66 * rgbbmp_to_rawppm
67 * Return 0 on success, non-zero on failure.
68 */
rgbbmp_to_rawppm(const Rgbbmp & b,const char * file_name)69 int rgbbmp_to_rawppm (const Rgbbmp &b, const char *file_name)
70 {
71 FILE *fd;
72 fd = fopen (file_name, "wb");
73 if (fd == 0)
74 {
75 fflush (stdout);
76 fprintf (stderr, "Can't open \"%s\" for writing (%s)\n",
77 file_name, strerror (errno));
78 fflush (stderr);
79 return 1;
80 }
81 fprintf (fd, "P6\n"
82 "# Created by Yadex %s\n"
83 "%d %d\n"
84 "255\n", yadex_version, b.width (), b.height ());
85 for (int y = 0; y < b.height (); y++)
86 for (int x = 0; x < b.width (); x++)
87 {
88 putc (b.get_r (x, y), fd);
89 putc (b.get_g (x, y), fd);
90 putc (b.get_b (x, y), fd);
91 }
92 if (fclose (fd))
93 {
94 fflush (stdout);
95 fprintf (stderr, "Write error in \"%s\"\n", file_name);
96 fflush (stderr);
97 return 1;
98 }
99 return 0;
100 }
101
102
103