1 // Copyright 2002, 2003, 2004, 2008 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>,
3 // <dhilvert@gmail.com>
5 /* This file is part of the Anti-Lamenessing Engine.
7 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with the Anti-Lamenessing Engine; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * image_accel.h: Image represented by a (possibly accelerated) opaque type.
26 #ifndef __image_accel_h__
27 #define __image_accel_h__
29 #include "exposure/exposure.h"
33 class image_accel
: public image
{
43 image_accel (unsigned int dimy
, unsigned int dimx
, unsigned int
44 depth
, unsigned int bayer
, const char *name
= "anonymous",
46 : image(dimy
, dimx
, depth
, name
, exp
, bayer
) {
53 case IMAGE_BAYER_NONE
:
54 // libale_bayer = ALE_FORMAT_RGB;
56 case IMAGE_BAYER_RGBG
:
57 // libale_bayer = ALE_FORMAT_BAYER_RGBG;
59 case IMAGE_BAYER_GBGR
:
60 // libale_bayer = ALE_FORMAT_BAYER_GBGR;
62 case IMAGE_BAYER_GRGB
:
63 // libale_bayer = ALE_FORMAT_BAYER_GRGB;
65 case IMAGE_BAYER_BGRG
:
66 // libale_bayer = ALE_FORMAT_BAYER_BGRG;
72 // im = ale_new_domain_2d(accel::context(), libale_bayer, ALE_TYPE_FLOAT_32, dimy, dimx);
77 fprintf(stderr
, "Could not allocate image data.\n");
82 image_accel (const image
*source
) : image(source
, 0) {
89 case IMAGE_BAYER_NONE
:
90 // libale_bayer = ALE_FORMAT_RGB;
92 case IMAGE_BAYER_RGBG
:
93 // libale_bayer = ALE_FORMAT_BAYER_RGBG;
95 case IMAGE_BAYER_GBGR
:
96 // libale_bayer = ALE_FORMAT_BAYER_GBGR;
98 case IMAGE_BAYER_GRGB
:
99 // libale_bayer = ALE_FORMAT_BAYER_GRGB;
101 case IMAGE_BAYER_BGRG
:
102 // libale_bayer = ALE_FORMAT_BAYER_BGRG;
108 // im = ale_new_domain_2d(accel::context(), libale_bayer, ALE_TYPE_FLOAT_32, _dimy, _dimx);
111 fprintf(stderr
, "Could not allocate Libale domain.\n");
121 if (bayer
== IMAGE_BAYER_NONE
) {
122 data
= (float *) malloc(_dimy
* _dimx
* _depth
* sizeof(float));
125 fprintf(stderr
, "Could not allocate image data.\n");
129 for (unsigned int i
= 0; i
< _dimy
; i
++)
130 for (unsigned int j
= 0; j
< _dimx
; j
++)
131 for (unsigned int k
= 0; k
< _depth
; k
++)
132 data
[i
* _dimx
* _depth
+ j
* _depth
+ k
] = source
->get_chan(i
, j
, k
);
135 data
= (float *) malloc(_dimy
* _dimx
* sizeof(float));
138 fprintf(stderr
, "Could not allocate image data.\n");
142 for (unsigned int i
= 0; i
< _dimy
; i
++)
143 for (unsigned int j
= 0; j
< _dimx
; j
++)
144 data
[i
* _dimx
+ j
] = source
->get_chan(i
, j
, source
->bayer_color(i
, j
));
147 // ale_load_into_domain(im, data);
152 virtual ~image_accel() {
153 // ale_delete_domain_2d(im);
156 virtual int accel_type() {
160 virtual image
*unaccel_equiv() {
162 * XXX: An unaccelerated equivalent should be created here.
170 spixel
get_pixel(unsigned int y
, unsigned int x
) const {
174 void set_pixel(unsigned int y
, unsigned int x
, spixel p
) {
178 void mul_pixel(unsigned int y
, unsigned int x
, spixel p
) {
182 void add_pixel(unsigned int y
, unsigned int x
, pixel p
) {
186 ale_sreal
get_chan(unsigned int y
, unsigned int x
, unsigned int k
) const {
190 void set_chan(unsigned int y
, unsigned int x
, unsigned int k
, ale_sreal c
) {
194 void div_chan(unsigned int y
, unsigned int x
, unsigned int k
, ale_sreal c
) {
199 * Make a new image suitable for receiving scaled values.
201 virtual image
*scale_generator(int height
, int width
, int depth
, const char *name
) const {
202 return new image_accel(height
, width
, depth
, IMAGE_BAYER_NONE
, name
, _exp
);
206 * Extend the image area to the top, bottom, left, and right,
207 * initializing the new image areas with black pixels. Negative values
210 image
*_extend(int top
, int bottom
, int left
, int right
) {
212 image
*is
= new image_accel (
213 height() + top
+ bottom
,
214 width() + left
+ right
, depth(), bayer
, name
, _exp
);
218 unsigned int min_i
= (-top
> 0)
222 unsigned int min_j
= (-left
> 0)
226 unsigned int max_i
= (height() < is
->height() - top
)
228 : is
->height() - top
;
230 unsigned int max_j
= (width() < is
->width() - left
)
232 : is
->width() - left
;
234 for (unsigned int i
= min_i
; i
< max_i
; i
++)
235 for (unsigned int j
= min_j
; j
< max_j
; j
++)
236 is
->set_pixel(i
+ top
, j
+ left
, get_pixel(i
, j
));
238 is
->set_offset(_offset
[0] - top
, _offset
[1] - left
);
244 void trigger(pixel multiplier
) {
245 for (unsigned int i
= 0; i
< height(); i
++)
246 for (unsigned int j
= 0; j
< width(); j
++) {
247 mul_pixel(i
, j
, multiplier
);