1 // Copyright 2002, 2003, 2004 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * image_bayer_ale_real.h: Bayer-patterned image represented by an array of ale_reals
25 #ifndef __image_bayer_ale_real_h__
26 #define __image_bayer_ale_real_h__
28 #include "exposure/exposure.h"
31 #include "image_ale_real.h"
33 class image_bayer_ale_real
: public image
{
39 * X offset of 'R' element
41 unsigned int r_x_offset() const {
46 * Y offset of 'R' element
48 unsigned int r_y_offset() const {
49 return (bayer
& 0x2) >> 1;
54 * Return the color of a given pixel.
56 unsigned int bayer_color(unsigned int i
, unsigned int j
) const {
57 return (i
+ r_y_offset()) % 2 + (j
+ r_x_offset()) % 2;
61 void trigger(pixel multiplier
) {
62 for (unsigned int i
= 0; i
< _dimy
; i
++)
63 for (unsigned int j
= 0; j
< _dimx
; j
++)
64 _p
[i
* _dimx
+ j
] *= multiplier
[bayer_color(i
, j
)];
68 image_bayer_ale_real (unsigned int dimy
, unsigned int dimx
, unsigned int depth
,
69 unsigned int bayer
, char *name
= "anonymous", exposure
*exp
= NULL
)
70 : image(dimy
, dimx
, depth
, name
, exp
, bayer
) {
72 assert (bayer
== IMAGE_BAYER_BGRG
73 || bayer
== IMAGE_BAYER_GBGR
74 || bayer
== IMAGE_BAYER_GRGB
75 || bayer
== IMAGE_BAYER_RGBG
);
77 _p
= new ale_real
[dimx
* dimy
];
82 fprintf(stderr
, "Could not allocate memory for image data.\n");
87 virtual ~image_bayer_ale_real() {
91 ale_real
&chan(unsigned int y
, unsigned int x
, unsigned int k
) {
92 assert (k
== bayer_color(y
, x
));
93 return _p
[y
* _dimx
+ x
];
96 const ale_real
&chan(unsigned int y
, unsigned int x
, unsigned int k
) const {
97 assert (k
== bayer_color(y
, x
));
98 return _p
[y
* _dimx
+ x
];
101 spixel
&pix(unsigned int y
, unsigned int x
) {
108 const spixel
&pix(unsigned int y
, unsigned int x
) const {
109 static spixel foo
= get_pixel(y
, x
);
114 * This method throws away data not stored at this pixel
117 void set_pixel(unsigned int y
, unsigned int x
, spixel p
) {
118 chan(y
, x
, bayer_color(y
, x
)) = p
[bayer_color(y
, x
)];
122 * This method uses bilinear interpolation.
124 pixel
get_pixel(unsigned int y
, unsigned int x
) const {
126 unsigned int k
= bayer_color(y
, x
);
130 result
[k
] = chan(y
, x
, k
);
133 unsigned int k1
= bayer_color(y
+ 1, x
);
134 unsigned int k2
= 2 - k1
;
138 sum
+= chan(y
- 1, x
, k1
);
142 sum
+= chan(y
+ 1, x
, k1
);
146 result
[k1
] = sum
/ num
;
150 sum
+= chan(y
, x
- 1, k2
);
154 sum
+= chan(y
, x
+ 1, k2
);
158 result
[k2
] = sum
/ num
;
165 sum
+= chan(y
- 1, x
, 1);
169 sum
+= chan(y
, x
- 1, 1);
173 sum
+= chan(y
+ 1, x
, 1);
177 sum
+= chan(y
, x
+ 1, 1);
181 result
[1] = sum
/ num
;
184 if (y
> 0 && x
> 0) {
185 sum
+= chan(y
- 1, x
- 1, 2 - k
);
188 if (y
> 0 && x
< _dimx
- 1) {
189 sum
+= chan(y
- 1, x
+ 1, 2 - k
);
192 if (y
< _dimy
- 1 && x
> 0) {
193 sum
+= chan(y
+ 1, x
- 1, 2 - k
);
196 if (y
< _dimy
- 1 && x
< _dimx
- 1) {
197 sum
+= chan(y
+ 1, x
+ 1, 2 - k
);
200 result
[2 - k
] = sum
/num
;
206 * Make a new image suitable for receiving scaled values.
208 virtual image
*scale_generator(int height
, int width
, int depth
, char *name
) const {
209 return new image_ale_real(height
, width
, depth
, name
, _exp
);
213 * Extend the image area to the top, bottom, left, and right,
214 * initializing the new image areas with black pixels.
216 void extend(int top
, int bottom
, int left
, int right
) {
218 * Bayer-patterned images should always represent inputs,
219 * which should not ever be extended.