IM: im_plus.h Source File

IM - An Imaging Tool

im_plus.h

Go to the documentation of this file.
00001 /** \file
00002  * \brief C++ Wrapper for File Access
00003  *
00004  * See Copyright Notice in im_lib.h
00005  * $Id: im_plus.h,v 1.2 2006/11/21 11:56:16 scuri Exp $
00006  */
00007 
00008 #ifndef __IM_PLUS_H
00009 #define __IM_PLUS_H
00010 
00011  
00012 /** \brief C++ Wrapper for the Image File Structure
00013  *
00014  * \par
00015  * Usage is just like the C API. Open and New are replaced by equivalent constructors. \n
00016  * Close is replaced by the destructor. Error checking is done by the Error() member. \n
00017  * Open and New errors are cheked using the Failed() member.
00018  *  \ingroup file */
00019 class imImageFile
00020 {
00021   imFile* ifile;
00022   int error;
00023 
00024   imImageFile() {};
00025 
00026 public:
00027 
00028   imImageFile(const char* file_name)
00029     { this->ifile = imFileOpen(file_name, &this->error); }
00030 
00031   imImageFile(const char* file_name, const char* format)
00032     { this->ifile = imFileNew(file_name, format, &this->error); }
00033 
00034   ~imImageFile()
00035     { if (this->ifile) imFileClose(this->ifile); }
00036 
00037   int Failed() 
00038     { return this->ifile == 0; }
00039 
00040   int Error()
00041     { return this->error; }
00042 
00043   void SetAttribute(const char* attrib, int data_type, int count, const void* data)
00044     { imFileSetAttribute(this->ifile, attrib, data_type, count, data); }
00045 
00046   const void* GetAttribute(const char* attrib, int *data_type, int *count)
00047     { return imFileGetAttribute(this->ifile, attrib, data_type, count); }
00048 
00049   void GetInfo(char* format, char* compression, int *image_count)
00050     { imFileGetInfo(this->ifile, format, compression, image_count); }
00051 
00052   void ReadImageInfo(int index, int *width, int *height, int *color_mode, int *data_type)
00053     { this->error = imFileReadImageInfo(this->ifile, index, width, height, color_mode, data_type); }
00054 
00055   void GetPalette(long* palette, int *palette_count)
00056     { imFileGetPalette(this->ifile, palette, palette_count); }
00057 
00058   void ReadImageData(void* data, int convert2bitmap, int color_mode_flags)
00059     { this->error = imFileReadImageData(this->ifile, data, convert2bitmap, color_mode_flags); }
00060 
00061   void SetInfo(const char* compression)
00062     { imFileSetInfo(this->ifile, compression); }
00063 
00064   void SetPalette(long* palette, int palette_count)
00065     { imFileSetPalette(this->ifile, palette, palette_count); }
00066 
00067   void WriteImageInfo(int width, int height, int color_mode, int data_type)
00068     { this->error = imFileWriteImageInfo(this->ifile, width, height, color_mode, data_type); }
00069 
00070   void WriteImageData(void* data)
00071     { this->error = imFileWriteImageData(this->ifile, data); }
00072 };
00073 
00074 #endif