summaryrefslogtreecommitdiff
path: root/im/include/im_format.h
blob: 6ee0473b93a85119027f4217e0d9e7c6d8686bf7 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** \file
 * \brief File Format Access
 *
 * See Copyright Notice in im_lib.h
 */

#include "im_file.h"
#include "im_attrib.h"

#ifndef __IM_FORMAT_H
#define __IM_FORMAT_H


class imFormat;

/** \brief Image File Format Virtual Class (SDK Use Only) 
 * 
 * \par
 * Virtual Base class for file formats. All file formats inherit from this class.
 * \ingroup filesdk */
class imFileFormatBase: public _imFile
{
public:
  const imFormat* iformat;

  imFileFormatBase(const imFormat* _iformat): iformat(_iformat) {}
  virtual ~imFileFormatBase() {}

  imAttribTable* AttribTable() {return (imAttribTable*)this->attrib_table;}

  /* Pure Virtual Methods. Every driver must implement all the following methods. */

  virtual int Open(const char* file_name) = 0; // Must initialize compression and image_count
  virtual int New(const char* file_name) = 0;
  virtual void Close() = 0;
  virtual void* Handle(int index) = 0;
  virtual int ReadImageInfo(int index) = 0;    // Should update compression
  virtual int ReadImageData(void* data) = 0;
  virtual int WriteImageInfo() = 0;            // Should update compression
  virtual int WriteImageData(void* data) = 0;  // Must update image_count
};

/** \brief Image File Format Descriptor (SDK Use Only) 
 * 
 * \par
 * All file formats must define these informations. They are stored by \ref imFormatRegister.
 * \ingroup filesdk */
class imFormat
{
public:
  const char* format; 
  const char* desc;
  const char* ext;
  const char** comp;
  int comp_count, 
      can_sequence;

  virtual imFileFormatBase* Create() const = 0;
  virtual int CanWrite(const char* compression, int color_mode, int data_type) const = 0;

  imFormat(const char* _format, const char* _desc, const char* _ext, 
           const char** _comp, int _comp_count, int _can_sequence)
    :format(_format), desc(_desc), ext(_ext), comp(_comp), 
     comp_count(_comp_count), can_sequence(_can_sequence)
    {} 
  virtual ~imFormat() {}
};

extern "C"
{

/* Internal Use only */

/* Opens a file with the respective format driver 
 * Uses the file extension to speed up the search for the format driver.
 * Used by "im_file.cpp" only. */
imFileFormatBase* imFileFormatBaseOpen(const char* file_name, int *error);

/* Opens a file with the given format
 * Used by "im_file.cpp" only. */
imFileFormatBase* imFileFormatBaseOpenAs(const char* file_name, const char* format, int *error);

/* Creates a file using the given format driver.
 * Used by "im_file.cpp" only. */
imFileFormatBase* imFileFormatBaseNew(const char* file_name, const char* format, int *error);


/* File Format SDK */

/** Register a format driver.
 * \ingroup filesdk */
void imFormatRegister(imFormat* iformat);


}

#endif