Fawkes API  Fawkes Development Version
invert.cpp
1 
2 /***************************************************************************
3  * invert.cpp - implementation of invert filter
4  *
5  * Created: Mon Jun 05 12:47:18 2006
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/invert.h>
25 
26 #include <core/exceptions/software.h>
27 #include <fvutils/color/yuv.h>
28 #include <cstddef>
29 
30 namespace firevision {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class FilterInvert <fvfilters/invert.h>
36  * Inversion filter.
37  * This will invert the given image.
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor. */
43  : Filter("FilterInvert")
44 {
45 }
46 
47 
48 void
50 {
51  if ( src[0] == NULL ) throw fawkes::NullPointerException("FilterInvert: src buffer is NULL");
52  if ( src_roi[0] == NULL ) throw fawkes::NullPointerException("FilterInvert: src ROI is NULL");
53 
54  if ( (dst == NULL) || (dst == src[0]) ) {
55  // In-place
56 
57  register unsigned int h = 0;
58  register unsigned int w = 0;
59 
60  // y-plane
61  register unsigned char *yp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
62 
63  // line starts
64  unsigned char *lyp = yp; // y-plane
65 
66  for (h = 0; h < src_roi[0]->height; ++h) {
67  for (w = 0; w < src_roi[0]->width; ++w) {
68  *yp = 255 - *yp;
69  ++yp;
70  }
71  lyp += src_roi[0]->line_step;
72  yp = lyp;
73  }
74 
75  } else {
76 
77  register unsigned int h = 0;
78  register unsigned int w = 0;
79 
80  // y-plane
81  register unsigned char *yp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
82  // u-plane
83  register unsigned char *up = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
84  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
85  // v-plane
86  register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
87  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
88 
89  // destination y-plane
90  register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
91  // destination u-plane
92  register unsigned char *dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
93  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
94  // destination v-plane
95  register unsigned char *dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
96  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
97 
98  // line starts
99  unsigned char *lyp = yp; // y-plane
100  unsigned char *lup = up; // u-plane
101  unsigned char *lvp = vp; // v-plane
102  unsigned char *ldyp = dyp; // destination y-plane
103  unsigned char *ldup = dup; // destination u-plane
104  unsigned char *ldvp = dvp; // destination v-plane
105 
106  for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
107  for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) {
108  *dyp++ = 255 - *yp++;
109  *dyp++ = 255 - *yp++;
110  *dup++ = *up++;
111  *dvp++ = *vp++;
112  }
113 
114  lyp += src_roi[0]->line_step;
115  lup += src_roi[0]->line_step / 2;
116  lvp += src_roi[0]->line_step / 2;
117  ldyp += dst_roi->line_step;
118  ldup += dst_roi->line_step / 2;
119  ldvp += dst_roi->line_step / 2;
120  yp = lyp;
121  up = lup;
122  vp = lvp;
123  dyp = ldyp;
124  dup = ldup;
125  dvp = ldvp;
126  }
127  }
128 
129 }
130 
131 } // end namespace firevision
fawkes::upoint_t start
ROI start.
Definition: roi.h:119
unsigned int y
y coordinate
Definition: types.h:36
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:121
A NULL pointer was supplied where not allowed.
Definition: software.h:34
FilterInvert()
Constructor.
Definition: invert.cpp:42
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:125
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:127
Filter interface.
Definition: filter.h:35
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
unsigned int height
ROI height.
Definition: roi.h:123
virtual void apply()
Apply the filter.
Definition: invert.cpp:49
unsigned int line_step
line step
Definition: roi.h:129
unsigned char * dst
Destination buffer.
Definition: filter.h:67
unsigned int pixel_step
pixel step
Definition: roi.h:131
ROI * dst_roi
Destination ROI.
Definition: filter.h:72