summaryrefslogtreecommitdiff
path: root/im/include/im_file.h
blob: 58022ebd06175c7a5248191499ae42464ac013cb (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/** \file
 * \brief File Access
 *
 * See Copyright Notice in im_lib.h
 */

#ifndef __IM_FILE_H
#define __IM_FILE_H

#include "im.h"

#if	defined(__cplusplus)
extern "C" {
#endif


/** \defgroup filesdk File Format SDK
 * \par
 * All the file formats are based on theses structures. Use them to create new file formats. \n
 * The LineBuffer functions will help transfer image from format buffer to application buffer and vice-versa.
 * \par
 * See \ref im_file.h
 * \ingroup file */


/** \brief Image File Format Base Class (SDK Use Only)
 *
 * \par
 * Base container to hold format independent state variables.
 * \ingroup filesdk */
struct _imFile
{
  int is_new;
  void* attrib_table;    /**< in fact is a imAttribTable, but we hide this here */

  void* line_buffer;     /**< used for line convertion, contains all components if packed, or only one if not */
  int line_buffer_size;
  int line_buffer_extra; /**< extra bytes to be allocated */
  int line_buffer_alloc; /**< total allocated so far */
  int counter;

  int convert_bpp;       /**< number of bpp to unpack/pack to/from 1 byte. 
                              When reading converts n packed bits to 1 byte (unpack). If n>1 will also expand to 0-255. 
                              When writing converts 1 byte to 1 bit (pack). 
                              If negative will only expand to 0-255 (no unpack or pack). */
  int switch_type;       /**< flag to switch the original data type: char-byte, short-ushort, uint-int, double-float */

  long palette[256];
  int palette_count;

  int user_color_mode,
      user_data_type,
      file_color_mode,   /* these two must be filled by te driver always. */
      file_data_type;

  /* these must be filled by the driver when reading,
     and given by the user when writing. */

  char compression[10];
  int image_count,
      image_index,
      width,           
      height;
};


/* Internal Use only */

/* Initializes the imFile structure.
 * Used by the special format RAW. */
void imFileClear(imFile* ifile);

/* Initializes the line buffer.
 * Used by "im_file.cpp" only. */
void imFileLineBufferInit(imFile* ifile);

/* Check if the conversion is valid.
 * Used by "im_file.cpp" only. */
int imFileCheckConversion(imFile* ifile);


/* File Format SDK */

/** Number of lines to be accessed.
 * \ingroup filesdk */
int imFileLineBufferCount(imFile* ifile);

/** Increments the row and plane counters.
 * \ingroup filesdk */
void imFileLineBufferInc(imFile* ifile, int *row, int *plane);

/** Converts from FILE color mode to USER color mode.
 * \ingroup filesdk */
void imFileLineBufferRead(imFile* ifile, void* data, int line, int plane);

/** Converts from USER color mode to FILE color mode.
 * \ingroup filesdk */
void imFileLineBufferWrite(imFile* ifile, const void* data, int line, int plane);

/** Utility to calculate the line size in byte with a specified alignment. \n
 * "align" can be 1, 2 or 4.
 * \ingroup filesdk */
int imFileLineSizeAligned(int width, int bpp, int align);

/** Set the attributes FileFormat, FileCompression and FileImageCount. \n
 * Used in imFileOpen and imFileOpenAs, and after the attribute list cleared with RemoveAll.
 * \ingroup filesdk */
void imFileSetBaseAttributes(imFile* ifile);


#if defined(__cplusplus)
}
#endif

#endif