Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 <fvfilters/or.h>
24 
25 #include <core/exception.h>
26 
27 #include <cstddef>
28 
29 #ifdef HAVE_IPP
30 # include <ippi.h>
31 #elif defined(HAVE_OPENCV)
32 # include <cv.h>
33 #else
34 # error "Neither IPP nor OpenCV available"
35 #endif
36 
37 namespace firevision {
38 #if 0 /* just to make Emacs auto-indent happy */
39 }
40 #endif
41 
42 /** @class FilterOr <fvfilters/or.h>
43  * Or filter.
44  * @author Tim Niemueller
45  */
46 
47 /** Constructor. */
48 FilterOr::FilterOr()
49  : Filter("FilterOr", 2)
50 {
51 }
52 
53 
54 void
56 {
57 #ifdef HAVE_IPP
58  IppiSize size;
59  size.width = src_roi[0]->width;
60  size.height = src_roi[0]->height;
61 
62  IppStatus status;
63 
64  if ( (dst == NULL) || (dst == src[1]) ) {
65  // In-place
66  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),
67  src_roi[0]->line_step,
68  src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step),
69  src_roi[1]->line_step,
70  size);
71 
72  } else {
73  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),
74  src_roi[0]->line_step,
75  src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step),
76  src_roi[1]->line_step,
79  size);
80  }
81 
82  if ( status != ippStsNoErr ) {
83  throw fawkes::Exception("Or filter failed with %i\n", status);
84  }
85 #elif defined(HAVE_OPENCV)
86 
87  if ((dst == NULL) || (dst == src[0])) {
88  throw fawkes::Exception("OpenCV-based OR filter cannot be in-place");
89  }
90 
91  cv::Mat srcm_0(src_roi[0]->height, src_roi[0]->width, CV_8UC1,
92  src[0] +
93  (src_roi[0]->start.y * src_roi[0]->line_step) +
94  (src_roi[0]->start.x * src_roi[0]->pixel_step),
95  src_roi[0]->line_step);
96 
97  cv::Mat srcm_1(src_roi[1]->height, src_roi[1]->width, CV_8UC1,
98  src[1] +
99  (src_roi[1]->start.y * src_roi[1]->line_step) +
100  (src_roi[1]->start.x * src_roi[1]->pixel_step),
101  src_roi[1]->line_step);
102 
103  cv::Mat dstm(dst_roi->height, dst_roi->width, CV_8UC1,
104  dst +
107  dst_roi->line_step);
108 
109  cv::bitwise_or(srcm_0, srcm_1, dstm);
110 
111 #endif
112 }
113 
114 } // end namespace firevision
virtual void apply()
Apply the filter.
Definition: or.cpp:55
fawkes::point_t start
ROI start.
Definition: roi.h:118
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:120
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
Base class for exceptions in Fawkes.
Definition: exception.h:36
Filter interface.
Definition: filter.h:35
unsigned int y
y coordinate
Definition: types.h:36
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
unsigned int height
ROI height.
Definition: roi.h:122
unsigned int line_step
line step
Definition: roi.h:128
unsigned char * dst
Destination buffer.
Definition: filter.h:67
unsigned int pixel_step
pixel step
Definition: roi.h:130
ROI * dst_roi
Destination ROI.
Definition: filter.h:72