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/max.h>
00025
00026 #include <core/exceptions/software.h>
00027 #include <fvutils/color/yuv.h>
00028 #include <cstddef>
00029
00030 using namespace fawkes;
00031
00032 namespace firevision {
00033 #if 0
00034 }
00035 #endif
00036
00037
00038
00039
00040
00041
00042
00043 FilterMax::FilterMax()
00044 : Filter("FilterMax", 2)
00045 {
00046 }
00047
00048 void
00049 FilterMax::apply()
00050 {
00051 if ( src[0] == NULL ) throw NullPointerException("FilterInvert: src buffer 0 is NULL");
00052 if ( src[1] == NULL ) throw NullPointerException("FilterInvert: src buffer 1 is NULL");
00053 if ( src_roi[0] == NULL ) throw NullPointerException("FilterInvert: src ROI 0 is NULL");
00054 if ( src_roi[1] == NULL ) throw NullPointerException("FilterInvert: src ROI 1 is NULL");
00055
00056 register unsigned int h = 0;
00057 register unsigned int w = 0;
00058
00059
00060 register unsigned char *byp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
00061
00062 register unsigned char *bup = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00063 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00064
00065 register unsigned char *bvp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00066 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00067
00068
00069
00070 register unsigned char *fyp = src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step);
00071
00072 register unsigned char *fup = YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00073 + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2) ;
00074
00075 register unsigned char *fvp = YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00076 + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
00077
00078
00079
00080 register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00081
00082 register unsigned char *dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00083 + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
00084
00085 register unsigned char *dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00086 + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
00087
00088
00089 unsigned char *lbyp = byp;
00090 unsigned char *lbup = fup;
00091 unsigned char *lbvp = fvp;
00092 unsigned char *lfyp = fyp;
00093 unsigned char *lfup = fup;
00094 unsigned char *lfvp = fvp;
00095 unsigned char *ldyp = dyp;
00096 unsigned char *ldup = dup;
00097 unsigned char *ldvp = dvp;
00098
00099 unsigned char u1, u2, v1, v2;
00100
00101 for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
00102 for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
00103 if ( *byp > *fyp ) {
00104 *dyp++ = *byp;
00105 u1 = *bup;
00106 v1 = *bvp;
00107 } else {
00108 *dyp++ = *fyp;
00109 u1 = *fup;
00110 v1 = *fvp;
00111 }
00112 ++byp;
00113 ++fyp;
00114
00115 if ( *byp > *fyp ) {
00116 *dyp++ = *byp;
00117 u2 = *bup;
00118 v2 = *bvp;
00119 } else {
00120 *dyp++ = *fyp;
00121 u2 = *fup;
00122 v2 = *fvp;
00123 }
00124 ++byp;
00125 ++fyp;
00126
00127 *dup++ = (u1 + u2) / 2;
00128 *dvp++ = (v1 + v2) / 2;
00129
00130 ++bup;
00131 ++bvp;
00132 ++fup;
00133 ++fvp;
00134 }
00135
00136 lbyp += src_roi[0]->line_step;
00137 lbup += src_roi[0]->line_step / 2;
00138 lbvp += src_roi[0]->line_step / 2;
00139 lfyp += src_roi[1]->line_step;
00140 lfup += src_roi[1]->line_step / 2;
00141 lfvp += src_roi[1]->line_step / 2;
00142 ldyp += dst_roi->line_step;
00143 ldup += dst_roi->line_step / 2;
00144 ldvp += dst_roi->line_step / 2;
00145 byp = lbyp;
00146 bup = lbup;
00147 bvp = lbvp;
00148 fyp = lfyp;
00149 fup = lfup;
00150 fvp = lfvp;
00151 dyp = ldyp;
00152 dup = ldup;
00153 dvp = ldvp;
00154 }
00155
00156 }
00157
00158 }