1 /** \file
2  * \brief File Access
3  *
4  * See Copyright Notice in im_lib.d
5  */
6 
7 module im.file;
8 
9 import im.im;
10 
11 extern (C) @safe nothrow:
12 
13 
14 /** \defgroup filesdk File Format SDK
15  * \par
16  * All the file formats are based on theses structures. Use them to create new file formats. \n
17  * The LineBuffer functions will help transfer image from format buffer to application buffer and vice-versa.
18  * \par
19  * See \ref im_file.h
20  * \ingroup file */
21 
22 
23 /** \brief Image File Structure (SDK Use Only)
24  *
25  * \par
26  * Base container to hold format independent state variables.
27  * \ingroup filesdk */
28 struct _imFile
29 {
30   int is_new;
31   void* attrib_table;    /**< in fact is a imAttribTable, but we hide this here */
32 
33   void* line_buffer;     /**< used for line conversion, contains all components if packed, or only one if not */
34   int line_buffer_size;
35   int line_buffer_extra; /**< extra bytes to be allocated */
36   int line_buffer_alloc; /**< total allocated so far */
37   int counter;
38 
39   int convert_bpp;       /**< number of bpp to unpack/pack to/from 1 byte.
40                               When reading converts n packed bits to 1 byte (unpack). If n>1 will also expand to 0-255.
41                               When writing converts 1 byte to 1 bit (pack).
42                               If negative will only expand to 0-255 (no unpack or pack). */
43   int switch_type;       /**< flag to switch the original data type: char-byte, short-ushort, uint-int, double-float */
44 
45   long[256] palette;
46   int palette_count;
47 
48   int user_color_mode,
49       user_data_type,
50       file_color_mode,   /* these two must be filled by te driver always. */
51       file_data_type;
52 
53   /* these must be filled by the driver when reading,
54      and given by the user when writing. */
55 
56   char[10] compression;
57   int image_count,
58       image_index,
59       width,
60       height;
61 }
62 
63 alias imFile = _imFile;
64 
65 
66 /* Internal Use only */
67 
68 /* Initializes the imFile structure.
69  * Used by the special format RAW. */
70 void imFileClear(imFile* ifile);
71 
72 /* Initializes the line buffer.
73  * Used by "im_file.cpp" only. */
74 void imFileLineBufferInit(imFile* ifile);
75 
76 /* Check if the conversion is valid.
77  * Used by "im_file.cpp" only. */
78 int imFileCheckConversion(imFile* ifile);
79 
80 
81 /* File Format SDK */
82 
83 /** Number of lines to be accessed.
84  * \ingroup filesdk */
85 int imFileLineBufferCount(imFile* ifile);
86 
87 /** Increments the line and plane counters.
88  * \ingroup filesdk */
89 void imFileLineBufferInc(imFile* ifile, int *line, int *plane);
90 
91 /** Converts from FILE color mode to USER color mode.
92  * \ingroup filesdk */
93 void imFileLineBufferRead(imFile* ifile, void* data, int line, int plane);
94 
95 /** Converts from USER color mode to FILE color mode.
96  * \ingroup filesdk */
97 void imFileLineBufferWrite(imFile* ifile, const(void) * data, int line, int plane);
98 
99 /** Utility to calculate the line size in byte with a specified alignment. \n
100  * "align" can be 1, 2 or 4.
101  * \ingroup filesdk */
102 int imFileLineSizeAligned(int width, int bpp, int align_);
103 
104 /** Set the attributes FileFormat, FileCompression and FileImageCount. \n
105  * Used in imFileOpen and imFileOpenAs, and after the attribute list cleared with RemoveAll.
106  * \ingroup filesdk */
107 void imFileSetBaseAttributes(imFile* ifile);
108