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