2 fbv -- simple image viewer for the linux framebuffer
3 Copyright (C) 2000, 2001, 2003 Mateusz Golicz
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 unsigned char * simple_resize(unsigned char * orgin
,int ox
,int oy
,int dx
,int dy
)
25 unsigned char *cr
,*p
,*l
;
27 assert(cr
= (unsigned char*) malloc(dx
*dy
*3));
30 for(j
=0;j
<dy
;j
++,l
+=dx
*3)
32 p
=orgin
+(j
*oy
/dy
*ox
*3);
33 for(i
=0,k
=0;i
<dx
;i
++,k
+=3)
44 unsigned char * alpha_resize(unsigned char * alpha
,int ox
,int oy
,int dx
,int dy
)
46 unsigned char *cr
,*p
,*l
;
48 cr
=(unsigned char*) malloc(dx
*dy
); l
=cr
;
50 for(j
=0;j
<dy
;j
++,l
+=dx
)
52 p
= alpha
+(j
*oy
/dy
*ox
);
60 unsigned char * color_average_resize(unsigned char * orgin
,int ox
,int oy
,int dx
,int dy
)
62 unsigned char *cr
,*p
,*q
;
63 int i
,j
,k
,l
,xa
,xb
,ya
,yb
;
65 assert(cr
=(unsigned char*) malloc(dx
*dy
*3)); p
=cr
;
69 for(i
=0;i
<dx
;i
++,p
+=3)
73 xb
=(i
+1)*ox
/dx
; if(xb
>=ox
) xb
=ox
-1;
74 yb
=(j
+1)*oy
/dy
; if(yb
>=oy
) yb
=oy
-1;
75 for(l
=ya
,r
=0,g
=0,b
=0,sq
=0;l
<=yb
;l
++)
77 q
=orgin
+((l
*ox
+xa
)*3);
78 for(k
=xa
;k
<=xb
;k
++,q
+=3,sq
++)
80 r
+=q
[0]; g
+=q
[1]; b
+=q
[2];
83 p
[0]=r
/sq
; p
[1]=g
/sq
; p
[2]=b
/sq
;
89 unsigned char * rotate(unsigned char *i
, int ox
, int oy
, int rot
)
91 unsigned char * n
, * p
;
93 assert(n
= (unsigned char*) malloc(ox
* oy
* 3));
97 case 1: /* 90 deg right */
99 for(y
= 0; y
<oy
; y
++, p
-= 3)
101 unsigned char * r
= p
;
102 for(x
= 0; x
<ox
; x
++, r
+= oy
* 3)
110 case 2: /* 180 deg */
111 i
+= ox
* oy
* 3; p
= n
;
112 for(y
= ox
* oy
; y
> 0; y
--)
121 case 3: /* 90 deg left */
123 for(y
= 0; y
<oy
; y
++, p
+= 3)
125 unsigned char * r
= p
+ ((ox
* 3) * oy
);
126 for(x
= 0; x
<ox
; x
++)
139 unsigned char * alpha_rotate(unsigned char *i
, int ox
, int oy
, int rot
)
141 unsigned char * n
, * p
;
143 assert(n
= (unsigned char*) malloc(ox
* oy
));
147 case 1: /* 90 deg right */
149 for(y
= 0; y
<oy
; y
++, p
--)
151 unsigned char * r
= p
;
152 for(x
= 0; x
<ox
; x
++, r
+= oy
)
156 case 2: /* 180 deg */
158 for(y
= ox
* oy
; y
> 0; y
--)
161 case 3: /* 90 deg left */
163 for(y
= 0; y
<oy
; y
++, p
++)
165 unsigned char * r
= p
+ (ox
* oy
);
166 for(x
= 0; x
<ox
; x
++)