Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1655 | giacomo | 1 | /* |
2 | * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Gerardo Lamastra <gerardo@sssup.it> |
||
6 | * |
||
7 | * Authors : Luca Abeni <luca@hartik.sssup.it> |
||
8 | * Massimiliano Giorgi <massy@hartik.sssup.it> |
||
9 | * (see authors.txt for full list of hartik's authors) |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://hartik.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Copyright (C) 1999 Luca Abeni and Massimiliano Giorgi |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
37 | /* |
||
38 | * CVS : $Id: gphoto.ok,v 1.1.1.1 2004-05-24 18:03:44 giacomo Exp $ |
||
39 | * |
||
40 | * File: $File$ |
||
41 | * Revision: $Revision: 1.1.1.1 $ |
||
42 | * Last update: $Date: 2004-05-24 18:03:44 $ |
||
43 | */ |
||
44 | |||
45 | #include "config.h" |
||
46 | |||
47 | #include <kernel/func.h> |
||
48 | #include <kernel/model.h> |
||
49 | #include <kernel/const.h> |
||
50 | |||
51 | #include <drivers/glib.h> |
||
52 | |||
53 | #include <unistd.h> |
||
54 | #include <stdlib.h> |
||
55 | #include <fcntl.h> |
||
56 | |||
57 | #include "mutex.h" |
||
58 | #include "gphoto.h" |
||
59 | |||
60 | #ifdef FULLCOLOR |
||
61 | |||
62 | /* 16bits format 5:6:5 */ |
||
63 | /* 24bits format 8:8:8 */ |
||
64 | static void down24to16(WORD *dst, BYTE *src, int dx, int dy) |
||
65 | { |
||
66 | int x,y; |
||
67 | /* row must be multiple of 4!!! (there are 3 bytes per pixel!)*/ |
||
68 | dst+=dx*(dy+1); |
||
69 | for (y=0;y<dy;y++) { |
||
70 | dst-=dx*2; |
||
71 | for (x=0;x<dx;x++,src+=3,dst++) |
||
72 | /* blue green red */ |
||
73 | *dst=((src[0]&0xf8)>>3)|((src[1]&0xfc)<<3)|((src[2]&0xf8)<<8); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | #define downscaleimage(x,y,z,k) down24to16((WORD*)x,y,z,k) |
||
78 | |||
79 | #else |
||
80 | |||
81 | static void down24to8(BYTE *dst, BYTE *src, int dx, int dy) |
||
82 | { |
||
83 | int x,y; |
||
84 | |||
85 | dst+=dx*(dy+1); |
||
86 | for (y=0;y<dy;y++) { |
||
87 | dst-=dx*2; |
||
88 | for (x=0;x<dx;x++,src+=3,dst++) |
||
89 | *dst=(((int)src[0])*11+((int)src[1])*59+((int)src[2])*30)/100; |
||
90 | } |
||
91 | } |
||
92 | |||
93 | #define downscaleimage(x,y,z,k) down24to8(x,y,z,k) |
||
94 | |||
95 | #endif |
||
96 | |||
97 | /* |
||
98 | * |
||
99 | */ |
||
100 | |||
101 | extern void draw_frame(int x, int y, int dx, int dy); |
||
102 | |||
103 | int gphoto_show(char *pathname, int x, int y) |
||
104 | { |
||
105 | struct BITMAPFILEHEADER *bf; |
||
106 | struct BITMAPINFOHEADER *bi; |
||
107 | BYTE *src,*dst; |
||
108 | long l; |
||
109 | int h,n; |
||
110 | int dx,dy; |
||
111 | |||
112 | bf=(struct BITMAPFILEHEADER *)malloc(sizeof(struct BITMAPFILEHEADER)); |
||
113 | bi=(struct BITMAPINFOHEADER *)malloc(sizeof(struct BITMAPINFOHEADER)); |
||
114 | |||
115 | if (bf==NULL||bi==NULL) return -1; |
||
116 | |||
117 | h=open(pathname,O_RDONLY); |
||
118 | if (h==-1) { |
||
119 | free(bf); |
||
120 | free(bi); |
||
121 | return -2; |
||
122 | } |
||
123 | |||
124 | n=read(h,bf,sizeof(struct BITMAPFILEHEADER)); |
||
125 | if (n!=sizeof(struct BITMAPFILEHEADER)) { |
||
126 | close(h); |
||
127 | free(bf); |
||
128 | free(bi); |
||
129 | return -4; |
||
130 | } |
||
131 | |||
132 | n=read(h,bi,sizeof(struct BITMAPINFOHEADER)); |
||
133 | if (n!=sizeof(struct BITMAPINFOHEADER)) { |
||
134 | close(h); |
||
135 | free(bf); |
||
136 | free(bi); |
||
137 | return -4; |
||
138 | } |
||
139 | |||
140 | //grx_close(); |
||
141 | |||
142 | /* |
||
143 | cprintf("type: %c %c\n",bf->bfType&0xff,bf->bfType>>8); |
||
144 | cprintf("size: %li\n",bf->bfSize); |
||
145 | cprintf("tell: %li\n\n",bf->bfOffBits); |
||
146 | |||
147 | cprintf("bitcoutn: %i\n",bi->biBitCount); |
||
148 | cprintf("compress: %li\n",bi->biCompression); |
||
149 | cprintf("dx: %li\n",bi->biWidth); |
||
150 | cprintf("dy: %li\n",bi->biHeight); |
||
151 | */ |
||
152 | |||
153 | //sys_end(); |
||
154 | //return 0; |
||
155 | |||
156 | if (bf->bfType!='B'+256*'M'|| |
||
157 | bi->biBitCount!=24|| |
||
158 | bi->biCompression!=0|| |
||
159 | bi->biWidth%4!=0) { |
||
160 | close(h); |
||
161 | free(bf); |
||
162 | free(bi); |
||
163 | return -5; |
||
164 | } |
||
165 | |||
166 | dx=bi->biWidth; |
||
167 | dy=bi->biHeight; |
||
168 | |||
169 | src=(BYTE*)malloc(dx*dy*3); |
||
170 | if (src==NULL) { |
||
171 | close(h); |
||
172 | free(bf); |
||
173 | free(bi); |
||
174 | return -6; |
||
175 | } |
||
176 | |||
177 | dst=(BYTE*)malloc(dx*dy*2); |
||
178 | if (dst==NULL) { |
||
179 | free(src); |
||
180 | close(h); |
||
181 | free(bf); |
||
182 | free(bi); |
||
183 | return -6; |
||
184 | } |
||
185 | |||
186 | l=lseek(h,bf->bfOffBits,SEEK_SET); |
||
187 | if (l!=bf->bfOffBits) { |
||
188 | free(dst); |
||
189 | free(src); |
||
190 | close(h); |
||
191 | free(bf); |
||
192 | free(bi); |
||
193 | return -7; |
||
194 | } |
||
195 | |||
196 | n=read(h,src,dx*dy*3); |
||
197 | if (n!=dx*dy*3) { |
||
198 | free(dst); |
||
199 | free(src); |
||
200 | close(h); |
||
201 | free(bf); |
||
202 | free(bi); |
||
203 | return -8; |
||
204 | } |
||
205 | |||
206 | downscaleimage(dst,src,dx,dy); |
||
207 | |||
208 | #ifndef NOGRX |
||
209 | draw_frame(x,y,dx,dy); |
||
210 | grxlock(); |
||
211 | grx_putimage(x, y, x+dx-1, y+dy-1, dst); |
||
212 | grxunlock(); |
||
213 | #endif |
||
214 | |||
215 | free(dst); |
||
216 | free(src); |
||
217 | close(h); |
||
218 | free(bi); |
||
219 | free(bf); |
||
220 | |||
221 | return 0; |
||
222 | } |