summaryrefslogtreecommitdiff
path: root/im/include/im_plus.h
blob: 0aabd1f50d192e8c84deadfbaa1b60ba7f4a1a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** \file
 * \brief C++ Wrapper for File Access
 *
 * See Copyright Notice in im_lib.h
 */

#ifndef __IM_PLUS_H
#define __IM_PLUS_H

 
/** \brief C++ Wrapper for the Image File Structure
 *
 * \par
 * Usage is just like the C API. Open and New are replaced by equivalent constructors. \n
 * Close is replaced by the destructor. Error checking is done by the Error() member. \n
 * Open and New errors are cheked using the Failed() member.
 *  \ingroup file */
class imImageFile
{
  imFile* ifile;
  int error;

  imImageFile() {};

public:

  imImageFile(const char* file_name)
    { this->ifile = imFileOpen(file_name, &this->error); }

  imImageFile(const char* file_name, const char* format)
    { this->ifile = imFileNew(file_name, format, &this->error); }

  ~imImageFile()
    { if (this->ifile) imFileClose(this->ifile); }

  int Failed() 
    { return this->ifile == 0; }

  int Error()
    { return this->error; }

  void SetAttribute(const char* attrib, int data_type, int count, const void* data)
    { imFileSetAttribute(this->ifile, attrib, data_type, count, data); }

  const void* GetAttribute(const char* attrib, int *data_type, int *count)
    { return imFileGetAttribute(this->ifile, attrib, data_type, count); }

  void GetInfo(char* format, char* compression, int *image_count)
    { imFileGetInfo(this->ifile, format, compression, image_count); }

  void ReadImageInfo(int index, int *width, int *height, int *color_mode, int *data_type)
    { this->error = imFileReadImageInfo(this->ifile, index, width, height, color_mode, data_type); }

  void GetPalette(long* palette, int *palette_count)
    { imFileGetPalette(this->ifile, palette, palette_count); }

  void ReadImageData(void* data, int convert2bitmap, int color_mode_flags)
    { this->error = imFileReadImageData(this->ifile, data, convert2bitmap, color_mode_flags); }

  void SetInfo(const char* compression)
    { imFileSetInfo(this->ifile, compression); }

  void SetPalette(long* palette, int palette_count)
    { imFileSetPalette(this->ifile, palette, palette_count); }

  void WriteImageInfo(int width, int height, int color_mode, int data_type)
    { this->error = imFileWriteImageInfo(this->ifile, width, height, color_mode, data_type); }

  void WriteImageData(void* data)
    { this->error = imFileWriteImageData(this->ifile, data); }
};

#endif