1 /*
2 Copyright 2020, Dirk Krause. All rights reserved.
3 SPDX-License-Identifier:	BSD-3-Clause
4 */
5 
6 /**	@file	dk4bifty.h	Type definitions for bitmap image files.
7 */
8 
9 #ifndef	DK4BIFTY_H_INCLUDED
10 /**	Protection against multiple inclusions. */
11 #define	DK4BIFTY_H_INCLUDED	1
12 
13 #ifndef	DK4CONF_H_INCLUDED
14 #if DK4_BUILDING_DKTOOLS4
15 #include "dk4conf.h"
16 #else
17 #include <dktools-4/dk4conf.h>
18 #endif
19 #endif
20 
21 #ifndef	DK4TYPES_H_INCLUDED
22 #if DK4_BUILDING_DKTOOLS4
23 #include <libdk4base/dk4types.h>
24 #else
25 #include <dktools-4/dk4types.h>
26 #endif
27 #endif
28 
29 #ifndef	DK4ERROR_H_INCLUDED
30 #if DK4_BUILDING_DKTOOLS4
31 #include <libdk4base/dk4error.h>
32 #else
33 #include <dktools-4/dk4error.h>
34 #endif
35 #endif
36 
37 #ifndef	DK4STO_H_INCLUDED
38 #if DK4_BUILDING_DKTOOLS4
39 #include <libdk4c/dk4sto.h>
40 #else
41 #include <dktools-4/dk4sto.h>
42 #endif
43 #endif
44 
45 #ifndef	DK4PX_H_INCLUDED
46 #if DK4_BUILDING_DKTOOLS4
47 #include <libdk4bif/dk4px.h>
48 #else
49 #include <dktools-4/dk4px.h>
50 #endif
51 #endif
52 
53 #ifndef	DK4PXRES_H_INCLUDED
54 #if DK4_BUILDING_DKTOOLS4
55 #include <libdk4bif/dk4pxres.h>
56 #else
57 #include <dktools-4/dk4pxres.h>
58 #endif
59 #endif
60 
61 #ifndef	DK4CS_H_INCLUDED
62 #if DK4_BUILDING_DKTOOLS4
63 #include <libdk4bif/dk4cs.h>
64 #else
65 #include <dktools-4/dk4cs.h>
66 #endif
67 #endif
68 
69 
70 /**	Image dimension and coordinate specifcation.
71 */
72 typedef	long	dk4_bif_dim_t;
73 
74 
75 /**	Image file type.
76 */
77 enum {
78 	DK4_BIF_TYPE_PNG	= 0,				/**< PNG image. */
79 	DK4_BIF_TYPE_JPEG ,						/**< JPEG image. */
80 	DK4_BIF_TYPE_TIFF ,						/**< TIFF image. */
81 	DK4_BIF_TYPE_NETPBM ,					/**< NetPBM image. */
82 
83 	DK4_BIF_TYPE_MIN = DK4_BIF_TYPE_PNG ,	/**< Minimum value. */
84 	DK4_BIF_TYPE_MAX = DK4_BIF_TYPE_NETPBM	/**< Maximum value. */
85 };
86 
87 
88 
89 /**	One frame from image.
90 
91 	The l_cs component is the color space the image reading library
92 	returned, possibly after applying transformations to the image data.
93 
94 	The f_cs component is the original color space used in the image file.
95 
96 	The bg array contains a background color suggested in the image
97 	file if there is partial transparency.
98 	If l_cs is DK4_CS_GRAY_ALPHA there is only one gray component in the array.
99 	If l_cs is DK4_CS_RGB_ALPHA there are red, green and blue components.
100 */
101 typedef struct {
102 	dk4_px_t			 bg[4];		/**< Background data, output bit depth. */
103 	dk4_px_t			 bglbd[4];	/**< Background data, original bit depth. */
104 	dk4_px_resample_t	 resampler;	/**< Bit depth resampler. */
105 	void				*tsdata;	/**< Type-specific data per frame. */
106 	double				 res_x;		/**< X resolution in dpi (dots per inch). */
107 	double				 res_y;		/**< Y resolution in dpi (dots per inch). */
108 	size_t				 fno;		/**< Frame number. */
109 	size_t				 n_comp;	/**< Number of color components. */
110 	dk4_bif_dim_t		 dim_x;		/**< Image width (number of pixels),
111 										 positive number required.
112 									*/
113 	dk4_bif_dim_t		 dim_y;		/**< Image height (number of pixels),
114 										 positive number required.
115 									*/
116 	int					 l_cs;		/**< Color space returned by library. */
117 	int					 f_cs;		/**< Color space in file. */
118 	int					 szmod;		/**< Flag: Size modified for restriction. */
119 	int					 hbg;		/**< Flag: Background chunk in file. */
120 	int					 fmres;		/**< Flag: Must resample, unusual maxval. */
121 	dk4_px_t			 fmrmv;		/**< Unusual maxval value of frame. */
122 	dk4_px_bit_depth_t	 l_bdepth;	/**< Original bit depth from image file. */
123 	dk4_px_bit_depth_t	 r_bdepth;	/**< Required output bit depth. */
124 } dk4_bif_frame_t;
125 
126 
127 /**	Bitmap image file.
128 */
129 typedef struct {
130 	dk4_cs_conv_ctx_t	 cs_ctx;	/**< Color space conversion context. */
131 	void				*tsdata;	/**< Type-specific data per file. */
132 	dk4_sto_t			*s_frames;	/**< Container to store frames. */
133 	dk4_sto_it_t		*i_frames;	/**< Iterator for frames container. */
134 	dkChar				*filename;	/**< Name of image file. */
135 	dk4_bif_frame_t		*cf;		/**< Current frame to process. */
136 	size_t				 n_frames;	/**< Number of frames in image. */
137 	int					 imgtype;	/**< Image type. */
138 	int					 hdronly;	/**< Flag: Read header information only. */
139 } dk4_bif_t;
140 
141 
142 
143 /**	Allowed difference in aspect ratio when setting custom resolution.
144 */
145 #define	DK4_BIF_EPSILON_ASPECT	(1.0e-5)
146 
147 
148 #endif
149 /* ifndef DK4BIFTY_H_INCLUDED */
150 
151 /* vim: set ai sw=4 ts=4 : */
152 
153