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
30namespace 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 */
42FilterROIDraw::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
54void
55FilterROIDraw::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;
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
118void
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 */
136void
137FilterROIDraw::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 */
145void
147{
148 border_style_ = style;
149}
150
151} // end namespace firevision
static YUV_t get_color(color_t color)
YUV_t getter.
Draw to an image.
Definition: drawer.h:32
void color_point(unsigned int x, unsigned int y)
Color the given point.
Definition: drawer.cpp:316
void set_color(unsigned char y, unsigned char u, unsigned char v)
Set drawing color.
Definition: drawer.cpp:71
void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height)
Set the buffer to draw to.
Definition: drawer.cpp:58
void set_rois(const std::list< ROI > *rois)
Set ROIs.
Definition: roidraw.cpp:137
virtual void apply()
Apply the filter.
Definition: roidraw.cpp:119
virtual ~FilterROIDraw()
Destructor.
Definition: roidraw.cpp:49
void set_style(border_style_t style)
Sets the preferred style.
Definition: roidraw.cpp:146
FilterROIDraw(const std::list< ROI > *rois=0, border_style_t style=INVERTED)
Constructor.
Definition: roidraw.cpp:42
border_style_t
Defines the possible border styles to display a ROI.
Definition: roidraw.h:40
@ DASHED_HINT
Displays border dashed black and color of hint.
Definition: roidraw.h:42
Filter interface.
Definition: filter.h:33
unsigned char * dst
Destination buffer.
Definition: filter.h:63
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
Region of interest.
Definition: roi.h:55
unsigned int height
ROI height.
Definition: roi.h:119
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
unsigned int line_step
line step
Definition: roi.h:125
unsigned int width
ROI width.
Definition: roi.h:117
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:121
color_t color
ROI primary color.
Definition: roi.h:132
unsigned int pixel_step
pixel step
Definition: roi.h:127
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:123
Point with cartesian coordinates as unsigned integers.
Definition: types.h:35
unsigned int x
x coordinate
Definition: types.h:36
unsigned int y
y coordinate
Definition: types.h:37
YUV pixel.
Definition: yuv.h:58
static YUV_t_struct black()
Definition: yuv.h:81