Fawkes API  Fawkes Development Version
or.cpp
1 
2 /***************************************************************************
3  * or.cpp - Implementation for "or'ing" images together
4  *
5  * Created: Fri May 13 14:57:10 2005
6  * Copyright 2005-2012 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21  */
22 
23 #include <core/exception.h>
24 #include <fvfilters/or.h>
25 
26 #include <cstddef>
27 
28 #ifdef HAVE_IPP
29 # include <ippi.h>
30 #elif defined(HAVE_OPENCV)
31 # if CV_MAJOR_VERSION < 2 || (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION < 4)
32 # include <opencv/cv.h>
33 # endif
34 # include <opencv/cv.hpp>
35 #else
36 # error "Neither IPP nor OpenCV available"
37 #endif
38 
39 namespace firevision {
40 
41 /** @class FilterOr <fvfilters/or.h>
42  * Or filter.
43  * @author Tim Niemueller
44  */
45 
46 /** Constructor. */
47 FilterOr::FilterOr() : Filter("FilterOr", 2)
48 {
49 }
50 
51 void
53 {
54 #ifdef HAVE_IPP
55  IppiSize size;
56  size.width = src_roi[0]->width;
57  size.height = src_roi[0]->height;
58 
59  IppStatus status;
60 
61  if ((dst == NULL) || (dst == src[1])) {
62  // In-place
63  status = ippiOr_8u_C1IR(src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
64  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
65  src_roi[0]->line_step,
66  src[1] + (src_roi[1]->start.y * src_roi[1]->line_step)
67  + (src_roi[1]->start.x * src_roi[1]->pixel_step),
68  src_roi[1]->line_step,
69  size);
70 
71  } else {
72  status = ippiOr_8u_C1R(src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
73  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
74  src_roi[0]->line_step,
75  src[1] + (src_roi[1]->start.y * src_roi[1]->line_step)
76  + (src_roi[1]->start.x * src_roi[1]->pixel_step),
77  src_roi[1]->line_step,
81  size);
82  }
83 
84  if (status != ippStsNoErr) {
85  throw fawkes::Exception("Or filter failed with %i\n", status);
86  }
87 #elif defined(HAVE_OPENCV)
88 
89  if ((dst == NULL) || (dst == src[0])) {
90  throw fawkes::Exception("OpenCV-based OR filter cannot be in-place");
91  }
92 
93  cv::Mat srcm_0(src_roi[0]->height,
94  src_roi[0]->width,
95  CV_8UC1,
96  src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
97  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
98  src_roi[0]->line_step);
99 
100  cv::Mat srcm_1(src_roi[1]->height,
101  src_roi[1]->width,
102  CV_8UC1,
103  src[1] + (src_roi[1]->start.y * src_roi[1]->line_step)
104  + (src_roi[1]->start.x * src_roi[1]->pixel_step),
105  src_roi[1]->line_step);
106 
107  cv::Mat dstm(dst_roi->height,
108  dst_roi->width,
109  CV_8UC1,
111  + (dst_roi->start.x * dst_roi->pixel_step),
112  dst_roi->line_step);
113 
114  cv::bitwise_or(srcm_0, srcm_1, dstm);
115 
116 #endif
117 }
118 
119 } // end namespace firevision
firevision::ROI::width
unsigned int width
ROI width.
Definition: roi.h:117
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
firevision::FilterOr::FilterOr
FilterOr()
Constructor.
Definition: or.cpp:47
firevision::ROI::height
unsigned int height
ROI height.
Definition: roi.h:119
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
firevision::FilterOr::apply
virtual void apply()
Apply the filter.
Definition: or.cpp:52
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition: types.h:37
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition: roi.h:127
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
firevision::ROI::line_step
unsigned int line_step
line step
Definition: roi.h:125
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition: types.h:36
firevision::Filter
Filter interface.
Definition: filter.h:33
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:63
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36