$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 #ifndef VLRIMAGING_REORGANIZE_H_ 00037 #define VLRIMAGING_REORGANIZE_H_ 00038 00039 #include <cstdio> 00040 #include <cstdlib> 00041 #include <iostream> 00042 00043 namespace vlr { 00044 00045 typedef enum {COLORORG_GRAY, COLORORG_RGB, COLORORG_RGBA, COLORORG_BGR, COLORORG_BGRA} ColorOrganization_t; 00046 00047 template <class T, ColorOrganization_t colorOrg> 00048 class cpReorganize { 00049 public: 00050 void chunky2Planar(const T*, uint32_t, vlr::Image<T>&) 00051 { 00052 std::cout << "Unknown color format.\n"; 00053 } 00054 00055 void planar2Chunky(const vlr::Image<T>&, T*, uint32_t) 00056 { 00057 std::cout << "Unknown color format.\n"; 00058 } 00059 }; 00060 00061 template <class T> class cpReorganize<T, COLORORG_RGB> 00062 { 00063 public: 00064 void chunky2Planar(const T* chunky, uint32_t cPaddedWidth, Image<T>& img) 00065 { 00066 uint32_t cLineOffset=cPaddedWidth-img.width(); 00067 uint32_t pLineOffset=img.paddedWidth()-img.width(); 00068 00069 T* rdata = img.data(); 00070 T* gdata = rdata + img.paddedWidth()*img.height(); 00071 T* bdata = gdata + img.paddedWidth()*img.height(); 00072 00073 for(uint32_t y=0; y<img.height(); y++) 00074 { 00075 for(uint32_t x=0; x<img.width(); x++) 00076 { 00077 *rdata++ = *chunky++; 00078 *gdata++ = *chunky++; 00079 *bdata++ = *chunky++; 00080 } 00081 00082 rdata += pLineOffset; 00083 gdata += pLineOffset; 00084 bdata += pLineOffset; 00085 chunky += cLineOffset; 00086 } 00087 } 00088 00089 void planar2Chunky(const Image<T>& img, T* chunky, uint32_t cPaddedWidth) 00090 { 00091 uint32_t cLineOffset=cPaddedWidth-img.width(); 00092 uint32_t pLineOffset=img.paddedWidth()-img.width(); 00093 00094 const T* rdata = img.data(); 00095 const T* gdata = rdata + img.paddedWidth()*img.height(); 00096 const T* bdata = gdata + img.paddedWidth()*img.height(); 00097 00098 for(uint32_t y=0; y<img.height(); y++) 00099 { 00100 for(uint32_t x=0; x<img.width(); x++) 00101 { 00102 *chunky++ = *rdata++; 00103 *chunky++ = *gdata++; 00104 *chunky++ = *bdata++; 00105 } 00106 00107 rdata += pLineOffset; 00108 gdata += pLineOffset; 00109 bdata += pLineOffset; 00110 chunky += cLineOffset; 00111 } 00112 } 00113 }; 00114 00115 } // namespace vlr 00116 00117 #endif // VLRIMAGING_REORGANIZE_H_