Fawkes API  Fawkes Development Version
roidraw.cpp
1 
2 /***************************************************************************
3  * roidraw.cpp - Implementation of ROI draw filter
4  *
5  * Created: Thu Jul 14 16:01:37 2005
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvfilters/roidraw.h>
25 #include <fvutils/color/color_object_map.h>
26 #include <fvutils/draw/drawer.h>
27 
28 #include <cstddef>
29 
30 namespace firevision {
31 
32 /** @class FilterROIDraw <fvfilters/roidraw.h>
33  * ROI Drawing filter.
34  * This filter visually marks the given region of interest.
35  * @author Tim Niemueller
36  */
37 
38 /** Constructor.
39  * @param rois optional list of ROIs to draw additionally to the dst_roi
40  * @param style optional border style (default is INVERTED)
41  */
42 FilterROIDraw::FilterROIDraw(const std::list<ROI> *rois, border_style_t style)
43 : Filter("FilterROIDraw"), rois_(rois), border_style_(style)
44 {
45  drawer_ = new Drawer;
46 }
47 
48 /** Destructor */
50 {
51  delete drawer_;
52 }
53 
54 void
55 FilterROIDraw::draw_roi(const ROI *roi)
56 {
57  if (border_style_ == DASHED_HINT) {
58  YUV_t hint_color = ColorObjectMap::get_color(roi->color);
59  drawer_->set_buffer(dst, roi->image_width, roi->image_height);
60  bool draw_black = false;
61  fawkes::upoint_t end;
62  end.x = std::min(roi->image_width - 1, roi->start.x + roi->width);
63  end.y = std::min(roi->image_height - 1, roi->start.y + roi->height);
64 
65  //Top and bottom line
66  for (unsigned int x = roi->start.x; x <= end.x; ++x) {
67  if (!(x % 2)) {
68  drawer_->set_color(draw_black ? YUV_t::black() : hint_color);
69  draw_black = !draw_black;
70  }
71 
72  drawer_->color_point(x, roi->start.y);
73  drawer_->color_point(x, end.y);
74  }
75 
76  //Side lines
77  for (unsigned int y = roi->start.y; y <= end.y; ++y) {
78  if (!(y % 2)) {
79  drawer_->set_color(draw_black ? YUV_t::black() : hint_color);
80  draw_black = !draw_black;
81  }
82 
83  drawer_->color_point(roi->start.x, y);
84  drawer_->color_point(end.x, y);
85  }
86  } else {
87  // destination y-plane
88  unsigned char *dyp = dst + (roi->start.y * roi->line_step) + (roi->start.x * roi->pixel_step);
89 
90  // line starts
91  unsigned char *ldyp = dyp; // destination y-plane
92 
93  // top border
94  for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
95  *dyp = 255 - *dyp;
96  dyp++;
97  }
98 
99  // left and right borders
100  for (unsigned int i = roi->start.y; i < (roi->start.y + roi->height); ++i) {
101  ldyp += roi->line_step;
102  dyp = ldyp;
103  *dyp = 255 - *dyp;
104  dyp += roi->width;
105  *dyp = 255 - *dyp;
106  }
107  ldyp += roi->line_step;
108  dyp = ldyp;
109 
110  // bottom border
111  for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
112  *dyp = 255 - *dyp;
113  dyp++;
114  }
115  }
116 }
117 
118 void
120 {
121  if (dst_roi) {
122  draw_roi(dst_roi);
123  }
124  if (rois_) {
125  for (std::list<ROI>::const_iterator r = rois_->begin(); r != rois_->end(); ++r) {
126  draw_roi(&(*r));
127  }
128  }
129 }
130 
131 /** Set ROIs.
132  * Set a list of ROIs. The list must persist as long as the filter is applied with
133  * this list. Set to NULL to have it ignored again.
134  * @param rois list of ROIs to draw additionally to the dst_roi.
135  */
136 void
137 FilterROIDraw::set_rois(const std::list<ROI> *rois)
138 {
139  rois_ = rois;
140 }
141 
142 /** Sets the preferred style
143  * @param style The preferred style
144  */
145 void
147 {
148  border_style_ = style;
149 }
150 
151 } // end namespace firevision
firevision::ColorObjectMap::get_color
static YUV_t get_color(color_t color)
YUV_t getter.
Definition: color_object_map.cpp:107
firevision::ROI::width
unsigned int width
ROI width.
Definition: roi.h:123
firevision::ROI::image_width
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:127
firevision::ROI::image_height
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:129
fawkes::upoint_t
Point with cartesian coordinates as unsigned integers.
Definition: types.h:34
firevision::Drawer::set_color
void set_color(unsigned char y, unsigned char u, unsigned char v)
Set drawing color.
Definition: drawer.cpp:77
firevision::ROI
Definition: roi.h:60
firevision::YUV_t_struct
YUV pixel.
Definition: yuv.h:64
firevision::FilterROIDraw::border_style_t
border_style_t
Defines the possible border styles to display a ROI.
Definition: roidraw.h:46
firevision::Drawer::color_point
void color_point(unsigned int x, unsigned int y)
Color the given point.
Definition: drawer.cpp:322
firevision::FilterROIDraw::FilterROIDraw
FilterROIDraw(const std::list< ROI > *rois=0, border_style_t style=INVERTED)
Constructor.
Definition: roidraw.cpp:48
firevision::FilterROIDraw::~FilterROIDraw
virtual ~FilterROIDraw()
Destructor.
Definition: roidraw.cpp:55
firevision::FilterROIDraw::set_style
void set_style(border_style_t style)
Sets the preferred style.
Definition: roidraw.cpp:152
firevision::ROI::height
unsigned int height
ROI height.
Definition: roi.h:125
firevision::FilterROIDraw::set_rois
void set_rois(const std::list< ROI > *rois)
Set ROIs.
Definition: roidraw.cpp:143
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:133
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition: filter.h:80
firevision::FilterROIDraw::DASHED_HINT
@ DASHED_HINT
Displays border dashed black and color of hint.
Definition: roidraw.h:48
firevision::FilterROIDraw::apply
virtual void apply()
Definition: roidraw.cpp:125
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition: roi.h:121
firevision::ROI::line_step
unsigned int line_step
line step
Definition: roi.h:131
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition: types.h:36
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:75
firevision::Drawer::set_buffer
void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height)
Set the buffer to draw to.
Definition: drawer.cpp:64
firevision::ROI::color
color_t color
ROI primary color.
Definition: roi.h:138