Rev 693 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
692 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Mauro Marinoni <mauro.marinoni@unipv.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License as published by |
||
22 | * the Free Software Foundation; either version 2 of the License, or |
||
23 | * (at your option) any later version. |
||
24 | * |
||
25 | * This program is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * You should have received a copy of the GNU General Public License |
||
31 | * along with this program; if not, write to the Free Software |
||
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
33 | */ |
||
34 | |||
35 | #include "kernel/kern.h" |
||
36 | #include "string.h" |
||
37 | #include "drivers/shark_fb26.h" |
||
38 | #include "snapshot.h" |
||
39 | |||
40 | struct SNAP_SLOT{ |
||
41 | char used; |
||
42 | int x; |
||
43 | int y; |
||
44 | int** buff; |
||
45 | } sslot[16]; |
||
46 | |||
47 | int** snapshot_getslot(int nbuff, int sx, int sy) |
||
48 | { |
||
49 | int i; |
||
50 | int** tmp; |
||
51 | |||
52 | if ((sx<=0) || (sy<=0) || (nbuff<=0) || (nbuff>15)){ |
||
53 | return NULL; |
||
54 | } |
||
55 | if (sslot[nbuff].used) |
||
56 | return NULL; |
||
57 | |||
58 | /* Allocate pointers to rows. */ |
||
59 | tmp = (int **) kern_alloc((unsigned) (sy)*sizeof(int*)); |
||
60 | if (!tmp) |
||
61 | return NULL; |
||
62 | |||
63 | /* Allocate rows and set pointers to them. */ |
||
64 | for (i = 0; i < sy; i++){ |
||
65 | tmp[i] = (int *) kern_alloc((unsigned) (sx)*sizeof(int)); |
||
66 | if (!tmp[i]) |
||
67 | return NULL; |
||
68 | } |
||
69 | |||
70 | sslot[nbuff].used = 1; |
||
71 | sslot[nbuff].x = sx; |
||
72 | sslot[nbuff].y = sy; |
||
73 | sslot[nbuff].buff = tmp; |
||
74 | return tmp; |
||
75 | } |
||
76 | |||
77 | void snapshot_freeslot(int nbuff) |
||
78 | { |
||
79 | int i; |
||
80 | |||
81 | if (sslot[nbuff].used){ |
||
82 | for (i = 0; i < sslot[nbuff].y; i++) |
||
83 | kern_free(sslot[nbuff].buff[i], (unsigned) (sslot[nbuff].x)*sizeof(int)); |
||
84 | kern_free(sslot[nbuff].buff, (unsigned) (sslot[nbuff].y)*sizeof(int*)); |
||
85 | sslot[nbuff].used = 0; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | void snapshot_grab(int nbuff) |
||
90 | { |
||
91 | int i, j; |
||
92 | |||
93 | for (i = 0; i < sslot[nbuff].x; i++) |
||
94 | for (j = 0; j < sslot[nbuff].x; j++) |
||
95 | sslot[nbuff].buff[i][j] = grx_getpixel(i,j); |
||
96 | } |
||
97 | |||
98 | int snapshot_save_pgm(int nbuff, char *fname) |
||
99 | { |
||
100 | char out_st[40]; |
||
101 | register int i, j; |
||
102 | DOS_FILE *outf; |
||
103 | |||
104 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
105 | return -1; |
||
106 | } else { |
||
107 | sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].x, sslot[nbuff].y, 255); |
||
108 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
||
109 | cprintf(out_st); |
||
110 | |||
111 | for (j = 0; j < sslot[nbuff].y; j++) { |
||
112 | for (i = 0; i < sslot[nbuff].x; i++) { |
||
113 | DOS_fwrite(&(sslot[nbuff].buff[i][j]), 1, 1, outf); |
||
114 | } |
||
115 | } |
||
116 | DOS_fclose(outf); |
||
117 | } |
||
118 | return 0; |
||
119 | } |
||
120 | |||
121 | int snapshot_save_ppm(int nbuff, char *fname) |
||
122 | { |
||
123 | char out_st[40]; |
||
124 | register int i, j; |
||
125 | int col_r, col_g, col_b; |
||
126 | DOS_FILE *outf; |
||
127 | |||
128 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
129 | return -1; |
||
130 | } else { |
||
131 | sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].x, sslot[nbuff].y, 255); |
||
132 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
||
133 | cprintf(out_st); |
||
134 | |||
135 | for (j = 0; j < sslot[nbuff].y; j++) { |
||
136 | for (i = 0; i < sslot[nbuff].x; i++) { |
||
137 | col_r = ((sslot[nbuff].buff[i][j] & 0xF800) >> 11) * 4; |
||
138 | col_g = ((sslot[nbuff].buff[i][j] & 0x07E0) >> 5) * 2; |
||
139 | col_b = (sslot[nbuff].buff[i][j] & 0x001F) * 4; |
||
140 | sprintf(out_st, "%d %d %d ", col_r, col_g, col_b); |
||
141 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
||
142 | } |
||
143 | } |
||
144 | DOS_fclose(outf); |
||
145 | } |
||
146 | return 0; |
||
147 | } |