invert.cpp

00001
00002 /***************************************************************************
00003  *  invert.cpp - implementation of invert filter
00004  *
00005  *  Created: Mon Jun 05 12:47:18 2006
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #include <filters/invert.h>
00025
00026 #include <core/exceptions/software.h>
00027 #include <fvutils/color/yuv.h>
00028 #include <cstddef>
00029 
00030 /** @class FilterInvert <filters/invert.h>
00031  * Inversion filter.
00032  * This will invert the given image.
00033  * @author Tim Niemueller
00034  */
00035 
00036 /** Constructor. */
00037 FilterInvert::FilterInvert()
00038   : Filter("FilterInvert")
00039 {
00040 }
00041
00042
00043 void
00044 FilterInvert::apply()
00045 {
00046   if ( src[0] == NULL )     throw fawkes::NullPointerException("FilterInvert: src buffer is NULL");
00047   if ( src_roi[0] == NULL ) throw fawkes::NullPointerException("FilterInvert: src ROI is NULL");
00048
00049   if ( (dst == NULL) || (dst == src[0]) ) {
00050     // In-place
00051
00052     register unsigned int h = 0;
00053     register unsigned int w = 0;
00054
00055     // y-plane
00056     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);
00057
00058     // line starts
00059     unsigned char *lyp  = yp;   // y-plane
00060
00061     for (h = 0; h < src_roi[0]->height; ++h) {
00062       for (w = 0; w < src_roi[0]->width; ++w) {
00063         *yp = 255 - *yp;
00064         ++yp;
00065       }
00066       lyp  += src_roi[0]->line_step;
00067       yp    = lyp;
00068     }
00069
00070   } else {
00071
00072     register unsigned int h = 0;
00073     register unsigned int w = 0;
00074
00075     // y-plane
00076     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);
00077     // u-plane
00078     register unsigned char *up   = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00079       + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00080     // v-plane
00081     register unsigned char *vp   = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00082       + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00083
00084     // destination y-plane
00085     register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00086     // destination u-plane
00087     register unsigned char *dup   = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00088       + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
00089     // destination v-plane
00090     register unsigned char *dvp   = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00091       + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
00092
00093     // line starts
00094     unsigned char *lyp  = yp;   // y-plane
00095     unsigned char *lup  = up;   // u-plane
00096     unsigned char *lvp  = vp;   // v-plane
00097     unsigned char *ldyp = dyp;  // destination y-plane
00098     unsigned char *ldup = dup;  // destination u-plane
00099     unsigned char *ldvp = dvp;  // destination v-plane
00100
00101     for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
00102       for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) {
00103         *dyp++ = 255 - *yp++;
00104         *dyp++ = 255 - *yp++;
00105         *dup++ = *up++;
00106         *dvp++ = *vp++;
00107       }
00108
00109       lyp   += src_roi[0]->line_step;
00110       lup   += src_roi[0]->line_step / 2;
00111       lvp   += src_roi[0]->line_step / 2;
00112       ldyp  += dst_roi->line_step;
00113       ldup  += dst_roi->line_step / 2;
00114       ldvp  += dst_roi->line_step / 2;
00115       yp     = lyp;
00116       up     = lup;
00117       vp     = lvp;
00118       dyp    = ldyp;
00119       dup    = ldup;
00120       dvp    = ldvp;
00121     }
00122   }
00123
00124 }