00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <filters/filter.h>
00025
00026 #include <core/exceptions/software.h>
00027 #include <cstdlib>
00028 #include <cstring>
00029
00030 using namespace fawkes;
00031
00032 namespace firevision {
00033 #if 0
00034 }
00035 #endif
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 Filter::Filter(const char *name, unsigned int max_num_buffers)
00055 {
00056 if ( max_num_buffers == 0 ) {
00057 throw OutOfBoundsException("Need to set at least one buffer", 0, 1, 0xFFFFFFFF);
00058 }
00059
00060 _name = strdup(name);
00061 _max_num_buffers = max_num_buffers;
00062
00063 src = (unsigned char **)malloc(_max_num_buffers * sizeof(unsigned char *));
00064 memset(src, 0, _max_num_buffers * sizeof(unsigned char *));
00065
00066 src_roi = (ROI **)malloc(_max_num_buffers * sizeof(ROI *));
00067 memset(src_roi, 0, _max_num_buffers * sizeof(ROI *));
00068
00069 ori = (orientation_t *)malloc(_max_num_buffers * sizeof(orientation_t));
00070 memset(ori, 0, _max_num_buffers * sizeof(orientation_t));
00071 }
00072
00073
00074
00075 Filter::~Filter()
00076 {
00077 free(_name);
00078 free(src);
00079 free(src_roi);
00080 free(ori);
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 void
00093 Filter::set_src_buffer(unsigned char *buf,
00094 ROI *roi,
00095 orientation_t ori,
00096 unsigned int buffer_num)
00097 {
00098 if ( buffer_num >= _max_num_buffers ) {
00099 throw OutOfBoundsException("Invalid buffer number", buffer_num, 0, _max_num_buffers);
00100 }
00101
00102 src[buffer_num] = buf;
00103 src_roi[buffer_num] = roi;
00104 this->ori[buffer_num] = ori;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114 void
00115 Filter::set_src_buffer(unsigned char *buf,
00116 ROI *roi,
00117 unsigned int buffer_num)
00118 {
00119 if ( buffer_num >= _max_num_buffers ) {
00120 throw OutOfBoundsException("Invalid buffer number", buffer_num, 0, _max_num_buffers);
00121 }
00122
00123 src[buffer_num] = buf;
00124 src_roi[buffer_num] = roi;
00125 ori[buffer_num] = ORI_HORIZONTAL;
00126 }
00127
00128
00129
00130
00131
00132
00133 void
00134 Filter::set_dst_buffer(unsigned char *buf, ROI *roi)
00135 {
00136 dst = buf;
00137 dst_roi = roi;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 void
00147 Filter::set_orientation(orientation_t ori, unsigned int buffer_num)
00148 {
00149 if ( buffer_num >= _max_num_buffers ) {
00150 throw OutOfBoundsException("Invalid buffer number", buffer_num, 0, _max_num_buffers);
00151 }
00152
00153 this->ori[buffer_num] = ORI_HORIZONTAL;
00154 }
00155
00156
00157
00158
00159
00160 const char *
00161 Filter::name()
00162 {
00163 return _name;
00164 }
00165
00166
00167
00168
00169
00170
00171 void
00172 Filter::shrink_region(ROI *r, unsigned int n)
00173 {
00174 if (r->start.x < (n/2)) {
00175 r->start.x = n/2;
00176 }
00177 if (r->start.y < (n/2)) {
00178 r->start.y = n/2;
00179 }
00180 if ( (r->start.x + r->width) >= (r->image_width - (n/2)) ) {
00181 r->width -= (r->start.x + r->width) - (r->image_width - (n/2));
00182 }
00183 if ( (r->start.y + r->height) >= (r->image_height - (n/2)) ) {
00184 r->height -= (r->start.y + r->height) - (r->image_height - (n/2));
00185 }
00186 }
00187
00188 }