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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 FilterROIDraw::FilterROIDraw(const std::list<ROI> *rois, border_style_t style)
00041 : Filter("FilterROIDraw"),
00042 __rois(rois),
00043 __border_style(style)
00044 {
00045 __drawer = new Drawer;
00046 }
00047
00048
00049 FilterROIDraw::~FilterROIDraw() {
00050 delete __drawer;
00051 }
00052
00053 void
00054 FilterROIDraw::draw_roi(const ROI *roi)
00055 {
00056 if (__border_style == DASHED_HINT) {
00057 YUV_t hint_color = ColorObjectMap::get_color(ColorObjectMap::get_instance().get(roi->hint));
00058 __drawer->set_buffer(dst, roi->image_width, roi->image_height);
00059 bool draw_black = false;
00060 fawkes::point_t end;
00061 end.x = std::min(roi->image_width - 1, roi->start.x + roi->width);
00062 end.y = std::min(roi->image_height - 1, roi->start.y + roi->height);
00063
00064
00065 for (unsigned int x = roi->start.x; x <= end.x ; ++x) {
00066 if (!(x % 2)) {
00067 __drawer->set_color(draw_black ? YUV_t::black() : hint_color);
00068 draw_black = !draw_black;
00069 }
00070
00071 __drawer->color_point(x, roi->start.y);
00072 __drawer->color_point(x, end.y);
00073 }
00074
00075
00076 for (unsigned int y = roi->start.y; y <= end.y; ++y) {
00077 if (!(y % 2)) {
00078 __drawer->set_color(draw_black ? YUV_t::black() : hint_color);
00079 draw_black = !draw_black;
00080 }
00081
00082 __drawer->color_point(roi->start.x, y);
00083 __drawer->color_point(end.x, y);
00084 }
00085 }
00086 else {
00087
00088 unsigned char *dyp = dst + (roi->start.y * roi->line_step) + (roi->start.x * roi->pixel_step);
00089
00090
00091 unsigned char *ldyp = dyp;
00092
00093
00094 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
00095 *dyp = 255 - *dyp;
00096 dyp++;
00097 }
00098
00099
00100 for (unsigned int i = roi->start.y; i < (roi->start.y + roi->height); ++i) {
00101 ldyp += roi->line_step;
00102 dyp = ldyp;
00103 *dyp = 255 - *dyp;
00104 dyp += roi->width;
00105 *dyp = 255 - *dyp;
00106 }
00107 ldyp += roi->line_step;
00108 dyp = ldyp;
00109
00110
00111 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) {
00112 *dyp = 255 - *dyp;
00113 dyp++;
00114 }
00115 }
00116 }
00117
00118 void
00119 FilterROIDraw::apply()
00120 {
00121 if ( dst_roi ) {
00122 draw_roi(dst_roi);
00123 }
00124 if ( __rois ) {
00125 for (std::list<ROI>::const_iterator r = __rois->begin(); r != __rois->end(); ++r) {
00126 draw_roi(&(*r));
00127 }
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 void
00138 FilterROIDraw::set_rois(const std::list<ROI> *rois)
00139 {
00140 __rois = rois;
00141 }
00142
00143
00144
00145
00146
00147 void
00148 FilterROIDraw::set_style(border_style_t style)
00149 {
00150 __border_style = style;
00151 }