Fawkes API  Fawkes Development Version
or.cpp
00001 
00002 /***************************************************************************
00003  *  or.cpp - Implementation for "or'ing" images together
00004  *
00005  *  Created: Fri May 13 14:57:10 2005
00006  *  Copyright  2005-2012  Tim Niemueller [www.niemueller.de]
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version. A runtime exception applies to
00013  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00021  */
00022 
00023 #include <fvfilters/or.h>
00024 
00025 #include <core/exception.h>
00026 
00027 #include <cstddef>
00028 
00029 #ifdef HAVE_IPP
00030 #  include <ippi.h>
00031 #elif defined(HAVE_OPENCV)
00032 #  include <cv.h>
00033 #else
00034 #  error "Neither IPP nor OpenCV available"
00035 #endif
00036 
00037 namespace firevision {
00038 #if 0 /* just to make Emacs auto-indent happy */
00039 }
00040 #endif
00041 
00042 /** @class FilterOr <fvfilters/or.h>
00043  * Or filter.
00044  * @author Tim Niemueller
00045  */
00046 
00047 /** Constructor. */
00048 FilterOr::FilterOr()
00049   : Filter("FilterOr", 2)
00050 {
00051 }
00052 
00053 
00054 void
00055 FilterOr::apply()
00056 {
00057 #ifdef HAVE_IPP
00058   IppiSize size;
00059   size.width = src_roi[0]->width;
00060   size.height = src_roi[0]->height;
00061 
00062   IppStatus status;
00063 
00064   if ( (dst == NULL) || (dst == src[1]) ) {
00065     // In-place
00066     status = ippiOr_8u_C1IR(src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step),
00067                             src_roi[0]->line_step,
00068                             src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step),
00069                             src_roi[1]->line_step,
00070                             size);
00071     
00072   } else {
00073     status = ippiOr_8u_C1R(src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step),
00074                            src_roi[0]->line_step,
00075                            src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step),
00076                            src_roi[1]->line_step,
00077                            dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step),
00078                            dst_roi->line_step,
00079                            size);
00080   }
00081 
00082   if ( status != ippStsNoErr ) {
00083     throw fawkes::Exception("Or filter failed with %i\n", status);
00084   }
00085 #elif defined(HAVE_OPENCV)
00086 
00087   if ((dst == NULL) || (dst == src[0])) {
00088     throw fawkes::Exception("OpenCV-based OR filter cannot be in-place");
00089   }
00090 
00091   cv::Mat srcm_0(src_roi[0]->height, src_roi[0]->width, CV_8UC1,
00092                  src[0] +
00093                    (src_roi[0]->start.y * src_roi[0]->line_step) +
00094                    (src_roi[0]->start.x * src_roi[0]->pixel_step),
00095                  src_roi[0]->line_step);
00096 
00097   cv::Mat srcm_1(src_roi[1]->height, src_roi[1]->width, CV_8UC1,
00098                  src[1] +
00099                    (src_roi[1]->start.y * src_roi[1]->line_step) +
00100                    (src_roi[1]->start.x * src_roi[1]->pixel_step),
00101                  src_roi[1]->line_step);
00102 
00103   cv::Mat dstm(dst_roi->height, dst_roi->width, CV_8UC1,
00104                dst +
00105                  (dst_roi->start.y * dst_roi->line_step) +
00106                  (dst_roi->start.x * dst_roi->pixel_step),
00107                dst_roi->line_step);
00108 
00109   cv::bitwise_or(srcm_0, srcm_1, dstm);
00110 
00111 #endif
00112 }
00113 
00114 } // end namespace firevision