Rev 692 | Rev 694 | Go to most recent revision | Details | Compare with Previous | 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; |
||
693 | giacomo | 42 | int wx; |
43 | int wy; |
||
44 | int bytesperpixel; |
||
45 | void *buff; |
||
46 | } sslot[16] = {{0, 0, 0, 0, NULL}, |
||
47 | {0, 0, 0, 0, NULL}, |
||
48 | {0, 0, 0, 0, NULL}, |
||
49 | {0, 0, 0, 0, NULL}, |
||
50 | {0, 0, 0, 0, NULL}, |
||
51 | {0, 0, 0, 0, NULL}, |
||
52 | {0, 0, 0, 0, NULL}, |
||
53 | {0, 0, 0, 0, NULL}, |
||
54 | {0, 0, 0, 0, NULL}, |
||
55 | {0, 0, 0, 0, NULL}, |
||
56 | {0, 0, 0, 0, NULL}, |
||
57 | {0, 0, 0, 0, NULL}, |
||
58 | {0, 0, 0, 0, NULL}, |
||
59 | {0, 0, 0, 0, NULL}, |
||
60 | {0, 0, 0, 0, NULL}, |
||
61 | {0, 0, 0, 0, NULL}}; |
||
692 | mauro | 62 | |
693 | giacomo | 63 | void *snapshot_getslot(int nbuff, int wx, int wy, int bytesperpixel) |
692 | mauro | 64 | { |
693 | giacomo | 65 | void* tmp; |
692 | mauro | 66 | |
693 | giacomo | 67 | if ((wx<=0) || (wy<=0) || (nbuff<=0) || (nbuff>15)){ |
692 | mauro | 68 | return NULL; |
69 | } |
||
70 | |||
693 | giacomo | 71 | if (sslot[nbuff].used) |
692 | mauro | 72 | return NULL; |
73 | |||
693 | giacomo | 74 | /* Allocate memory. */ |
75 | tmp = (void *)kern_alloc(wx * wy * bytesperpixel); |
||
76 | if (!tmp) return NULL; |
||
692 | mauro | 77 | |
78 | sslot[nbuff].used = 1; |
||
693 | giacomo | 79 | sslot[nbuff].wx = wx; |
80 | sslot[nbuff].wy = wy; |
||
81 | sslot[nbuff].bytesperpixel = bytesperpixel; |
||
692 | mauro | 82 | sslot[nbuff].buff = tmp; |
83 | return tmp; |
||
84 | } |
||
85 | |||
86 | void snapshot_freeslot(int nbuff) |
||
87 | { |
||
693 | giacomo | 88 | if (sslot[nbuff].used == 0) return; |
89 | kern_free(sslot[nbuff].buff, sslot[nbuff].wx * sslot[nbuff].wy * sslot[nbuff].bytesperpixel); |
||
90 | sslot[nbuff].used = 0; |
||
692 | mauro | 91 | } |
92 | |||
93 | void snapshot_grab(int nbuff) |
||
94 | { |
||
693 | giacomo | 95 | int i; |
96 | SYS_FLAGS f; |
||
692 | mauro | 97 | |
693 | giacomo | 98 | f = kern_fsave(); |
99 | for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++) |
||
100 | *(int *)(sslot[nbuff].buff + i*2)= (int)grx_getpixel(i % sslot[nbuff].wx,i / sslot[nbuff].wx); |
||
101 | kern_frestore(f); |
||
102 | |||
692 | mauro | 103 | } |
104 | |||
105 | int snapshot_save_pgm(int nbuff, char *fname) |
||
106 | { |
||
107 | char out_st[40]; |
||
693 | giacomo | 108 | register int i; |
109 | unsigned char tmp; |
||
692 | mauro | 110 | DOS_FILE *outf; |
111 | |||
112 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
113 | return -1; |
||
114 | } else { |
||
693 | giacomo | 115 | sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255); |
692 | mauro | 116 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
117 | cprintf(out_st); |
||
118 | |||
693 | giacomo | 119 | for (i = 0; i < sslot[nbuff].wy * sslot[nbuff].wx; i++) { |
120 | tmp = (unsigned char)(*(int *)(sslot[nbuff].buff + i * 2)); |
||
121 | DOS_fwrite(&tmp, 1, 1, outf); |
||
692 | mauro | 122 | } |
123 | DOS_fclose(outf); |
||
124 | } |
||
125 | return 0; |
||
126 | } |
||
127 | |||
128 | int snapshot_save_ppm(int nbuff, char *fname) |
||
129 | { |
||
130 | char out_st[40]; |
||
693 | giacomo | 131 | register int i; |
692 | mauro | 132 | int col_r, col_g, col_b; |
133 | DOS_FILE *outf; |
||
134 | |||
135 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
136 | return -1; |
||
137 | } else { |
||
693 | giacomo | 138 | sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255); |
692 | mauro | 139 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
140 | cprintf(out_st); |
||
141 | |||
693 | giacomo | 142 | for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++) { |
143 | col_r = ((*(int *)(sslot[nbuff].buff + i*2) & 0xF800) >> 11) * 4; |
||
144 | col_g = ((*(int *)(sslot[nbuff].buff + i*2) & 0x07E0) >> 5) * 2; |
||
145 | col_b = (*(int *)(sslot[nbuff].buff + i*2) & 0x001F) * 4; |
||
146 | sprintf(out_st, "%d %d %d ", col_r, col_g, col_b); |
||
147 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
||
692 | mauro | 148 | } |
149 | DOS_fclose(outf); |
||
150 | } |
||
151 | return 0; |
||
152 | } |