00001 // /// // C++ Cross Platform 00002 // ///// //// 00003 // /// XXX XXX /// /////////// ///////// /// /// 00004 // /// XXX XXX /// /// /// /// /// /// 00005 // /// XXX /// ///////// /// // ////// 00006 // /// XXX XXX /// /// /// /// /// /// 00007 // //// XXX XXX //// //////////// ////////// /// /// 00008 // //// //// 00009 // //// M O B O T I X //////////////////////////////////////////////// 00010 // //// Security Vision Systems ////////////////////////////////////////////// 00011 // 00012 // $Author: khe_admin $ 00013 // $LastChangedBy: khe_admin $ 00014 // $LastChangedDate: 2007-06-29 12:31:37 +0200 (Fri, 29 Jun 2007) $ 00015 // $HeadURL: http://svn.mobotix.net/svn/mxsdk/src/mxm/trunk/include/mxm/core/mxm_colorspaces.h $ 00016 // 00018 // 00019 // MOBOTIX MxPEG SDK 00020 // 00021 // This file belongs to the C++ library released as part of the MxPEG SDK. 00022 // 00023 // This software is licenced under the BSD licence, 00024 // http://www.opensource.org/licenses/bsd-license.php 00025 // 00026 // Copyright (c) 2005 - 2007, MOBOTIX AG 00027 // All rights reserved. 00028 // 00029 // Redistribution and use in source and binary forms, with or without 00030 // modification, are permitted provided that the following conditions are 00031 // met: 00032 // 00033 // - Redistributions of source code must retain the above copyright 00034 // notice, this list of conditions and the following disclaimer. 00035 // 00036 // - Redistributions in binary form must reproduce the above copyright 00037 // notice, this list of conditions and the following disclaimer in the 00038 // documentation and/or other materials provided with the distribution. 00039 // 00040 // - Neither the name of MOBOTIX AG nor the names of its contributors may 00041 // be used to endorse or promote products derived from this software 00042 // without specific prior written permission. 00043 // 00044 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00045 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00046 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00047 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00048 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00049 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00050 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00051 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00052 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00053 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00054 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00055 // 00057 00058 00059 00060 #ifndef __MXM_COLORSPACES_H__ 00061 #define __MXM_COLORSPACES_H__ 00062 00063 00064 00065 #include <mxm/core/mxm_core_platform_macros.h> 00066 00067 00068 00069 namespace mxm { 00070 00072 inline void convert_RGB_to_YUV( 00073 mxm::u8 r, mxm::u8 g, mxm::u8 b, 00074 mxm::u8 *y, mxm::u8 *u, mxm::u8 *v) { 00075 00076 int int_r, int_g, int_b; 00077 int int_y, int_u, int_v; 00078 00079 int_r = (int)r; 00080 int_g = (int)g; 00081 int_b = (int)b; 00082 00083 // coefficients computed from "Video Demystified" by K. JACK... 00084 int_y = (( 263*int_r + 516*int_g + 100*int_b) >> 10) + 16; 00085 int_u = ((-152*int_r - 298*int_g + 450*int_b) >> 10) + 128; 00086 int_v = (( 450*int_r - 377*int_g - 73*int_b) >> 10) + 128; 00087 00088 mxm::clamp_int(&int_y, 0, 255); 00089 mxm::clamp_int(&int_u, 0, 255); 00090 mxm::clamp_int(&int_v, 0, 255); 00091 00092 *y = (mxm::u8)int_y; 00093 *u = (mxm::u8)int_u; 00094 *v = (mxm::u8)int_v; 00095 } 00096 00099 inline void convert_RGB_to_YCbCr( 00100 mxm::u8 r, mxm::u8 g, mxm::u8 b, 00101 mxm::u8 *y, mxm::u8 *Cb, mxm::u8 *Cr) { 00102 00103 int int_r, int_g, int_b; 00104 int int_y, int_Cb, int_Cr; 00105 00106 int_r = (int)r; 00107 int_g = (int)g; 00108 int_b = (int)b; 00109 00110 // coefficients computed from ITU-R BT.601... 00111 int_y = (( 306*int_r + 601*int_g + 117*int_b) >> 10); 00112 int_Cb = ((-173*int_r - 339*int_g + 512*int_b) >> 10) + 128; 00113 int_Cr = (( 512*int_r - 429*int_g - 83*int_b) >> 10) + 128; 00114 00115 mxm::clamp_int(&int_y, 0, 255); 00116 mxm::clamp_int(&int_Cb, 0, 255); 00117 mxm::clamp_int(&int_Cr, 0, 255); 00118 00119 *y = (mxm::u8)int_y; 00120 *Cb = (mxm::u8)int_Cb; 00121 *Cr = (mxm::u8)int_Cr; 00122 } 00123 }; 00124 00125 00126 00127 #endif // __MXM_COLORSPACES_H__