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