PTdecode/CImg-1.3.0/plugins/cimgIPL.h

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