Rev 693 | 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 | |
694 | 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 | { |
||
694 | giacomo | 95 | extern void *video_memory; |
692 | mauro | 96 | |
694 | giacomo | 97 | memcpy(sslot[nbuff].buff,video_memory,sslot[nbuff].wx * sslot[nbuff].wy * sslot[nbuff].bytesperpixel); |
693 | giacomo | 98 | |
692 | mauro | 99 | } |
100 | |||
101 | int snapshot_save_pgm(int nbuff, char *fname) |
||
102 | { |
||
103 | char out_st[40]; |
||
693 | giacomo | 104 | register int i; |
105 | unsigned char tmp; |
||
692 | mauro | 106 | DOS_FILE *outf; |
107 | |||
108 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
109 | return -1; |
||
110 | } else { |
||
693 | giacomo | 111 | sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255); |
692 | mauro | 112 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
113 | cprintf(out_st); |
||
114 | |||
693 | giacomo | 115 | for (i = 0; i < sslot[nbuff].wy * sslot[nbuff].wx; i++) { |
116 | tmp = (unsigned char)(*(int *)(sslot[nbuff].buff + i * 2)); |
||
117 | DOS_fwrite(&tmp, 1, 1, outf); |
||
692 | mauro | 118 | } |
119 | DOS_fclose(outf); |
||
120 | } |
||
121 | return 0; |
||
122 | } |
||
123 | |||
124 | int snapshot_save_ppm(int nbuff, char *fname) |
||
125 | { |
||
126 | char out_st[40]; |
||
693 | giacomo | 127 | register int i; |
692 | mauro | 128 | int col_r, col_g, col_b; |
129 | DOS_FILE *outf; |
||
130 | |||
131 | if ((outf = DOS_fopen(fname, "w")) == NULL) { |
||
132 | return -1; |
||
133 | } else { |
||
693 | giacomo | 134 | sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255); |
692 | mauro | 135 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
136 | cprintf(out_st); |
||
137 | |||
693 | giacomo | 138 | for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++) { |
694 | giacomo | 139 | col_r = ((*(int *)(sslot[nbuff].buff + i*2) & 0xF800) >> 11) << 3; |
140 | col_g = ((*(int *)(sslot[nbuff].buff + i*2) & 0x07E0) >> 5) << 2; |
||
141 | col_b = (*(int *)(sslot[nbuff].buff + i*2) & 0x001F) << 3; |
||
693 | giacomo | 142 | sprintf(out_st, "%d %d %d ", col_r, col_g, col_b); |
143 | DOS_fwrite(out_st, strlen(out_st), 1, outf); |
||
692 | mauro | 144 | } |
145 | DOS_fclose(outf); |
||
146 | } |
||
147 | return 0; |
||
148 | } |