roidraw.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <filters/roidraw.h>
00025 #include <fvutils/color/color_object_map.h>
00026 #include <fvutils/draw/drawer.h>
00027
00028 #include <cstddef>
00029
00030 namespace firevision {
00031 #if 0
00032 }
00033 #endif
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 FilterROIDraw::FilterROIDraw(const std::list<ROI> *rois, border_style_t style)
00046 : Filter("FilterROIDraw"),
00047 __rois(rois),
00048 __border_style(style)
00049 {
00050 __drawer = new Drawer;
00051 }
00052
00053
00054 FilterROIDraw::~FilterROIDraw() {
00055 delete __drawer;
00056 }
00057
00058 void
00059 FilterROIDraw::draw_roi(const ROI *roi)
00060 {
00061 if (__border_style == DASHED_HINT) {
00062 YUV_t hint_color = ColorObjectMap::get_color(ColorObjectMap::get_instance().get(roi->hint));
00063 __drawer->set_buffer(dst, roi->image_width, roi->image_height);
00064 bool draw_black = false;
00065 fawkes::point_t end;
00066 end.x = std::min(roi->image_width - 1, roi->start.x + roi->width);
00067 end.y = std::min(roi->image_height - 1, roi->start.y + roi->height);
00068
00069
00070 for (unsigned int x = roi->start.x; x <= end.x ; ++x) {
00071 if (!(x % 2)) {
00072 __drawer->set_color(draw_black ? YUV_t::black() : hint_color);
00073 draw_black = !draw_black;
00074 }
00075
00076 __drawer->color_point(x, roi->start.y);
00077 __drawer->color_point(x, end.y);
00078 }
00079
00080
00081 for (unsigned int y = roi->start.y; y <= end.y; ++y) {
00082 if (!(y % 2)) {
00083 __drawer->set_color(draw_black ? YUV_t::black() : hint_color);
00084 draw_black = !draw_black;
00085 }
00086
00087 __drawer->color_point(roi->start.x, y);
00088 __drawer->color_point(end.x, y);
00089 }
00090 }
00091 else {
00092
00093 unsigned char *dyp = dst + (roi->start.y * roi->line_step) + (roi->start.x * roi->pixel_step);
00094
00095
00096 unsigned char *ldyp = dyp;
00097
00098
00099 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
00100 *dyp = 255 - *dyp;
00101 dyp++;
00102 }
00103
00104
00105 for (unsigned int i = roi->start.y; i < (roi->start.y + roi->height); ++i) {
00106 ldyp += roi->line_step;
00107 dyp = ldyp;
00108 *dyp = 255 - *dyp;
00109 dyp += roi->width;
00110 *dyp = 255 - *dyp;
00111 }
00112 ldyp += roi->line_step;
00113 dyp = ldyp;
00114
00115
00116 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
00117 *dyp = 255 - *dyp;
00118 dyp++;
00119 }
00120 }
00121 }
00122
00123 void
00124 FilterROIDraw::apply()
00125 {
00126 if ( dst_roi ) {
00127 draw_roi(dst_roi);
00128 }
00129 if ( __rois ) {
00130 for (std::list<ROI>::const_iterator r = __rois->begin(); r != __rois->end(); ++r) {
00131 draw_roi(&(*r));
00132 }
00133 }
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 void
00143 FilterROIDraw::set_rois(const std::list<ROI> *rois)
00144 {
00145 __rois = rois;
00146 }
00147
00148
00149
00150
00151
00152 void
00153 FilterROIDraw::set_style(border_style_t style)
00154 {
00155 __border_style = style;
00156 }
00157
00158 }