1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/PTdecode/CImg-1.3.0/plugins/cimgIPL.h Mon Aug 03 14:09:20 2009 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* 1.5 +# 1.6 +# File : cimgIPL.h 1.7 +# ( C++ header file - CImg plug-in ) 1.8 +# 1.9 +# Description : CImg plug-in providing the CImg->IPL and IPL->CImg 1.10 +# conversions for generic image types 1.11 +# ( IPL = Intel Performance Library ) 1.12 +# This file is a part of the CImg Library project. 1.13 +# ( http://cimg.sourceforge.net ) 1.14 +# 1.15 +# Copyright : newleft (haibo.zheng@gmail.com) 1.16 +# newleftist@hotmail.com 1.17 +# 1.18 +# License : CeCILL v2.0 1.19 +# ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.20 +# 1.21 +# This software is governed by the CeCILL license under French law and 1.22 +# abiding by the rules of distribution of free software. You can use, 1.23 +# modify and/ or redistribute the software under the terms of the CeCILL 1.24 +# license as circulated by CEA, CNRS and INRIA at the following URL 1.25 +# "http://www.cecill.info". 1.26 +# 1.27 +# As a counterpart to the access to the source code and rights to copy, 1.28 +# modify and redistribute granted by the license, users are provided only 1.29 +# with a limited warranty and the software's author, the holder of the 1.30 +# economic rights, and the successive licensors have only limited 1.31 +# liability. 1.32 +# 1.33 +# In this respect, the user's attention is drawn to the risks associated 1.34 +# with loading, using, modifying and/or developing or reproducing the 1.35 +# software by the user in light of its specific status of free software, 1.36 +# that may mean that it is complicated to manipulate, and that also 1.37 +# therefore means that it is reserved for developers and experienced 1.38 +# professionals having in-depth computer knowledge. Users are therefore 1.39 +# encouraged to load and test the software's suitability as regards their 1.40 +# requirements in conditions enabling the security of their systems and/or 1.41 +# data to be ensured and, more generally, to use and operate it in the 1.42 +# same conditions as regards security. 1.43 +# 1.44 +# The fact that you are presently reading this means that you have had 1.45 +# knowledge of the CeCILL license and that you accept its terms. 1.46 +# 1.47 +*/ 1.48 + 1.49 +#ifndef cimg_plugin_cimgIPL 1.50 +#define cimg_plugin_cimgIPL 1.51 + 1.52 +// Conversion IPL -> CImg (constructor) 1.53 +CImg(const IplImage* src):width(0),height(0),depth(0),dim(0),data(0),is_shared(false) { 1.54 + assign(src); 1.55 +} 1.56 + 1.57 +// Conversion IPL -> CImg (in-place constructor) 1.58 +CImg<T>& assign(const IplImage* src) { 1.59 + if (!src) return assign(); 1.60 + switch (src->depth) { 1.61 + case IPL_DEPTH_1U: { // 1-bit int. 1.62 + IplImage *src1 = cvCreateImage(cvGetSize(src),IPL_DEPTH_8U,1); 1.63 + cvConvert(src,src1); 1.64 + CImg<ucharT>((unsigned char*)src1->imageData,src1->nChannels,src1->width,src1->height,1,true). 1.65 + get_permute_axes("yzvx").transfer_to(*this); 1.66 + cvReleaseImage(&src1); 1.67 + } break; 1.68 + case IPL_DEPTH_8U: // 8-bit unsigned int. 1.69 + CImg<ucharT>((unsigned char*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.70 + get_permute_axes("yzvx").transfer_to(*this); 1.71 + break; 1.72 + case IPL_DEPTH_8S: // 8-bit signed int. 1.73 + CImg<charT>((char*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.74 + get_permute_axes("yzvx").transfer_to(*this); 1.75 + break; 1.76 + case IPL_DEPTH_16U: // 16-bit unsigned int. 1.77 + CImg<ushortT>((unsigned short*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.78 + get_permute_axes("yzvx").transfer_to(*this); 1.79 + break; 1.80 + case IPL_DEPTH_16S: // 16-bit signed int. 1.81 + CImg<shortT>((short*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.82 + get_permute_axes("yzvx").transfer_to(*this); 1.83 + break; 1.84 + case IPL_DEPTH_32S: // 32-bit signed int. 1.85 + CImg<intT>((int*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.86 + get_permute_axes("yzvx").transfer_to(*this); 1.87 + break; 1.88 + case IPL_DEPTH_32F: // 32-bit float. 1.89 + CImg<floatT>((float*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.90 + get_permute_axes("yzvx").transfer_to(*this); 1.91 + break; 1.92 + case IPL_DEPTH_64F: // 64-bit double. 1.93 + CImg<doubleT>((double*)src->imageData,src->nChannels,src->width,src->height,1,true). 1.94 + get_permute_axes("yzvx").transfer_to(*this); 1.95 + break; 1.96 + default: 1.97 + throw CImgInstanceException("CImg<%s>::assign(const IplImage* img) : IplImage depth is invalid.", 1.98 + pixel_type()); 1.99 + break; 1.100 + } 1.101 + if (!std::strcmp(src->channelSeq,"BGR")) mirror('v'); 1.102 + else if (!std::strcmp(src->channelSeq,"BGRA")) get_shared_channels(0,2).mirror('v'); 1.103 + return *this; 1.104 +} 1.105 + 1.106 +// Conversion CImg -> IPL 1.107 +IplImage* get_IPL(const unsigned int z=0) const { 1.108 + if (is_empty()) 1.109 + throw CImgInstanceException("CImg<%s>::get_IPL() : instance image (%u,%u,%u,%u,%p) is empty.", 1.110 + pixel_type(),width,height,depth,dim,data); 1.111 + if (z>=depth) 1.112 + throw CImgInstanceException("CImg<%s>::get_IPL() : specified slice %u is out of image bounds (%u,%u,%u,%u,%p).", 1.113 + pixel_type(),z,width,height,depth,dim,data); 1.114 + const CImg<T> 1.115 + _slice = depth>1?get_slice(z):CImg<T>(), 1.116 + &slice = depth>1?_slice:*this; 1.117 + CImg<T> buf(slice); 1.118 + if (dim==3 || dim==4) buf.get_shared_channels(0,2).mirror('v'); 1.119 + buf.permute_axes("vxyz"); 1.120 + IplImage* const dst = cvCreateImage(cvSize(width,height),sizeof(T)*8,dim); 1.121 + std::memcpy(dst->imageData,buf.ptr(),buf.size()*sizeof(T)); 1.122 + return dst; 1.123 +} 1.124 + 1.125 +#endif