Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleToPlanar.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExampleToPlanar.cpp
27  @relates ImageBase, ImageConvert
28  @brief Example for converting an interleaved to a planar image
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <Base/Image/ImageBase.hh>
34 #include <Base/ImageUtils/ImageDraw.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Base/Image/ImageIO.hh>
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 int main()
42 {
43  const unsigned int w = 640;
44  const unsigned int h = 400;
45  Image<unsigned char> im(w, h, 3);
47  Image<unsigned char> planLoaded;
48  unsigned char* pData = im.GetImageData();
49  //fill data
50  for(unsigned int i=0; i<(w*h); i++)
51  {
52  //store lowest 24bits of i in rgbchannels
53  unsigned char ti = (unsigned char)(i%256); //get lsbyte
54  pData[i*3+0] = ti;
55  pData[i*3+1] = (unsigned char)((i>>8)%256);
56  pData[i*3+2] = (unsigned char)((i>>16)%256);
57  }
58  ImageIO::Save("inter0.mip", im);
59  ImageConvert::ToPlanar(im,plan1);
60  if(!plan1.IsPlanar()||(plan1.IsInterleaved()))
61  {
62  cout<<"image planar flags inconsistend (plan1)"<<endl;
63  return -2;
64  }
66  pData = im.GetImageData(); //data pointer is now a different one...
67  for(unsigned int i=0; i<(w*h); i++)
68  {
69  //store lowest 24bits of i in rgbchannels
70  unsigned char ti = (unsigned char)(i%256); //get lsbyte
71  if((pData[i*3+0] != ti)||(pData[i*3+1] != ((i>>8)%256))
72  ||(pData[i*3+2] != ((i>>16)%256)))
73  {
74  cout<<"image data changed after conversion"<<endl;
75  return -1;
76  }
77  }
78  if(im.IsPlanar()||(!im.IsInterleaved()))
79  {
80  cout<<"image planar interleaved flags inconsistend"<<endl;
81  return -2;
82  }
83  if(!plan1.IsPlanar()||(plan1.IsInterleaved()))
84  {
85  cout<<"image planar interleaved flags inconsistend (plan1)"<<endl;
86  return -2;
87  }
88  ImageIO::Save("planar1.mip", plan1);
89  ImageIO::Load("planar1.mip",planLoaded);
90  if(!planLoaded.IsPlanar()||(planLoaded.IsInterleaved()))
91  {
92  cout<<"loaded image not planar anymore..."<<endl;
93  return -3;
94  }
95  ImageConvert::ToInterleaved(planLoaded,planLoaded);
96 
97  pData = im.GetImageData(); //data pointer is now a different one...
98  for(unsigned int i=0; i<(w*h); i++)
99  {
100  //store lowest 24bits of i in rgbchannels
101  unsigned char ti = (unsigned char)(i%256); //get lsbyte
102  if((pData[i*3+0] != ti)||(pData[i*3+1] != ((i>>8)%256))
103  ||(pData[i*3+2] != ((i>>16)%256)))
104  {
105  cout<<"image data changed after conversion"<<endl;
106  return -1;
107  }
108  }
109 
110  if(planLoaded.IsPlanar()||(!planLoaded.IsInterleaved()))
111  {
112  cout<<"image planar interleaved flags inconsistend"<<endl;
113  return -4;
114  }
115  ImageIO::Save("inter1.mip", planLoaded); //inplace converted ...
116 
117  return 0;
118 }
bool IsInterleaved() const
Definition: ImageBase.hh:491
bool IsPlanar() const
Definition: ImageBase.hh:484
static BIASImageBase_EXPORT int ToPlanar(const Image< StorageType > &source, Image< StorageType > &dest)
Converts the existing image to an planar version.
Definition: ToPlanar.cpp:33
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
static BIASImageBase_EXPORT int ToInterleaved(const Image< StorageType > &source, Image< StorageType > &dest)
Takes the source image, and build an interleaved version.