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