last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2003 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 00042 /** 00043 * \file cvrMergeYUVToImage.h 00044 * Merge YUV channels into a color image 00045 * \author Volker Schmirgel 00046 * \author Pablo Alvarado 00047 * \date 17.10.2003 00048 * 00049 * $Id: cvrMergeYUVToImage.h,v 1.3 2007/04/05 22:56:59 alvarado Exp $ 00050 */ 00051 00052 00053 #ifndef _CVR_MERGE_Y_U_V_TO_IMAGE_H_ 00054 #define _CVR_MERGE_Y_U_V_TO_IMAGE_H_ 00055 00056 #include "cvrMergeImage.h" 00057 #include "cvrMergeYPbPrToImage.h" 00058 00059 namespace cvr { 00060 00061 /** 00062 * Compute RGB values from given YUV values by merging float or ubyte values 00063 * to an rgbaPixel, merging channels(floats) or matrix<ubyte>s(ubytes) to an Image 00064 * 00065 * In the literature, technical and scientific, there is often confusion 00066 * among the color spaces YUV, YPbPr and YPbPr. Poynton in 00067 * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html explains that 00068 * YUV is usually never correctly meant, because the color space normally 00069 * used for component digital video is the YCbCr (ITU-RS601 or CCIR-601). 00070 * Other devices use the YPbPr, but the "real" YUV is rarely employed. 00071 * 00072 * The CVR-Lib provides all three spaces: 00073 * 00074 * - YCbCr: cvr::mergeYCbCrToImage used by IEEE 1394 FireWire cameras 00075 * - YPbPr: cvr::mergeYPbPrToImage used by some WebCams 00076 * - YUV: cvr::mergeYUVToImage did they really meant to use this? 00077 * 00078 * Here, the inverse transformation of cvr::splitImageToYUV is followed 00079 * 00080 * \f[ 00081 * \begin{bmatrix} 00082 * R \\ 00083 * G \\ 00084 * B 00085 * \end{bmatrix} 00086 * = 00087 * M^{-1} 00088 * \begin{bmatrix} 00089 * Y \\ 00090 * U \\ 00091 * V 00092 * \end{bmatrix} 00093 * \f] 00094 * where M is the matrix given in cvr::splitImageToYUV. 00095 * 00096 * If you use \c ubyte values, then this functor is equivalent to 00097 * cvr::mergeYPbPrToImage, as the U and V values have to be linearly mapped 00098 * to make use of the limited range from 0 to 255. 00099 * 00100 * @ingroup gColor 00101 */ 00102 class mergeYUVToImage : public mergeImage { 00103 public: 00104 00105 /** 00106 * constructor 00107 */ 00108 mergeYUVToImage(void); 00109 00110 00111 /** 00112 * destructor 00113 */ 00114 ~mergeYUVToImage(); 00115 00116 /** 00117 * return the name of this type 00118 */ 00119 const std::string& name() const; 00120 00121 /** 00122 * copy data of "other" functor. 00123 * @param other the functor to be copied 00124 * @return a reference to this functor object 00125 */ 00126 mergeYUVToImage& copy(const mergeYUVToImage& other); 00127 00128 /** 00129 * alias for copy member 00130 * @param other the functor to be copied 00131 * @return a reference to this functor object 00132 */ 00133 mergeYUVToImage& operator=(const mergeYUVToImage& other); 00134 00135 /** 00136 * returns a pointer to a clone of the functor. 00137 */ 00138 virtual mergeYUVToImage* clone() const; 00139 00140 /** 00141 * Returns a pointer to a new instance of this functor. 00142 */ 00143 virtual mergeYUVToImage* newInstance() const; 00144 00145 /** 00146 * merge channels Y, U, V to an image 00147 * @param Y the Y channel, i.e. black&white 00148 * @param U the U channel, chromatic 00149 * @param V the V channel, chromatic 00150 * @param img the image to be splitted 00151 */ 00152 virtual bool apply(const matrix<float>& Y, 00153 const matrix<float>& U, 00154 const matrix<float>& V, 00155 image& img) const; 00156 00157 /** 00158 * merge 8-bit-channels Y, U, V to an image 00159 * @param Y the Y channel, i.e. black&white 00160 * @param U the U channel, chromatic 00161 * @param V the V channel, chromatic 00162 * @param img the image to be splitted 00163 */ 00164 virtual bool apply(const matrix<ubyte>& Y, 00165 const matrix<ubyte>& U, 00166 const matrix<ubyte>& V, 00167 image& img) const; 00168 00169 /** 00170 * merge the values Y, U and V 00171 * to a pixel 00172 * @param Y the Y value, i.e. black&white 00173 * @param U the U value, chromatic 00174 * @param V the V value, chromatic 00175 * @param pixel the merged pixel 00176 */ 00177 inline virtual bool apply(const float& Y, 00178 const float& U, 00179 const float& V, 00180 rgbaPixel& pixel) const; 00181 00182 /** 00183 * merge the 8-bit-values Y, U and V 00184 * to a pixel 00185 * @param Y the Y value, i.e. black&white 00186 * @param U the U value, chromatic 00187 * @param V the V value, chromatic 00188 * @param pixel the merged pixel 00189 */ 00190 inline virtual bool apply(const ubyte& Y, 00191 const ubyte& U, 00192 const ubyte& V, 00193 rgbaPixel& pixel) const; 00194 00195 protected: 00196 00197 /** 00198 * Clip function 00199 * 00200 * Equivalent to min(255,max(0,val)) but maybe faster 00201 */ 00202 inline ubyte clip(const int val) const; 00203 }; 00204 00205 } 00206 00207 #include "cvrMergeYUVToImage_inline.h" 00208 00209 #endif