/******************************************************************************* operator(QImage) ********************************************************************************/ QImage GaussFilter::operator () ( QImage input ) { const int w = w_scale, l = l_scale; const int width = input.width(); const int height = input.height(); bMatrixDouble w_red_mat( width, height ), // 用橫向 縱向的filter來處理 加速用. w_green_mat( width, height ), w_blue_mat( width, height ); bMatrixDouble l_red_mat( width, height ), l_green_mat( width, height ), l_blue_mat( width, height ); int i, j, x, y, r, g, b; double dsum_r, dsum_g, dsum_b; // 橫向的filter for( i = 0; i < width; i++ ) for( j = 0; j < height; j++ ) { // 對每一個pixel的位置做橫向的filter dsum_r = 0; dsum_g = 0; dsum_b = 0; for( x = -w; x <= w; x++ ) { if( i+x < 0 || i+x >= width ) continue; dsum_r += filter_w(x) * input.red_channel( i+x, j ); dsum_g += filter_w(x) * input.green_channel( i+x, j ); dsum_b += filter_w(x) * input.blue_channel( i+x, j ); } w_red_mat(i,j) = dsum_r; w_green_mat(i,j) = dsum_g; w_blue_mat(i,j) = dsum_b; } // 進行縱向的filter for( i = 0; i < width; i++ ) for( j = 0; j < height; j++ ) { // 對wimg做縱向的filter dsum_r = 0; dsum_g = 0; dsum_b = 0; for( y = -l; y <= l; y++ ) { if( j+y < 0 || j+y >= height ) continue; dsum_r += filter_l(y) * input.red_channel( i, j+y ); dsum_g += filter_l(y) * input.green_channel( i, j+y ); dsum_b += filter_l(y) * input.blue_channel( i, j+y ); } l_red_mat(i,j) = dsum_r; l_green_mat(i,j) = dsum_g; l_blue_mat(i,j) = dsum_b; } // result output QImage &result = input; for( i = 0; i < width; i++ ) for( j = 0; j < height; j++ ) { r = l_red_mat(i,j); g = l_green_mat(i,j); b = l_blue_mat(i,j); result.rgb_channel( i, j, r, g, b ); } return result; }