1 /**
2  * @file images.h
3  * @brief Extract *.spr file into 'image' and 'bitmap' structures
4  * @created 2006-12-13
5  * @date 2011-02-26
6  */
7 /*
8  * copyright (c) 1998-2015 TLK Games all rights reserved
9  * $Id: images.h,v 1.25 2012/06/03 17:06:15 gurumeditation Exp $
10  *
11  * Powermanga is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * Powermanga is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA  02110-1301, USA.
25  */
26 #ifndef __IMAGES__
27 #define __IMAGES__
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 /** Max. origins of shots (location of the cannons) per sprite */
35 #define MAX_OF_CANNONS 12
36 /** Max number of points of collision */
37 #define MAX_OF_COLLISION_POINTS 12
38 /** Max number of zones of collision  */
39 #define MAX_OF_COLLISION_ZONES 6
40 /** Max number of imgaes per sprite */
41 #define IMAGES_MAXOF 40
42 
43 #define EXPORT_DIR "sprites"
44 
45   typedef struct _compress
46   {
47     Uint32 offset;
48     Uint16 r1;
49     Uint16 r2;
50   }
51   _compress;
52 
53   /** Width and height of collision zone */
54   typedef enum
55   {
56     IMAGE_WIDTH,
57     IMAGE_HEIGHT
58   } IMAGE_ENUM;
59 
60   /** Bitmap structure used for fontes, TLK's logo, main menu text,
61    * scrolltext, and right options box */
62   typedef struct bitmap
63   {
64     /** Number of pixels */
65     Sint32 numof_pixels;
66     /** Pixels buffer */
67     char *img;
68     /** Size of offsets buffer */
69     Sint32 nbr_data_comp;
70     /** Offsets and repeat values buffer */
71     char *compress;
72   } bitmap;
73 
74   /** Image structure used for all sprites */
75   typedef struct image
76   {
77     /** X-center of gravity of the image */
78     Sint16 x_gc;
79     /** Y-center of gravity of the image */
80     Sint16 y_gc;
81     /** Image width */
82     Sint16 w;
83     /** Image height */
84     Sint16 h;
85     /** Number of collision coordinates  */
86     Sint16 numof_collisions_points;
87     /** List of the collision coordinates */
88     Sint16 collisions_points[MAX_OF_COLLISION_POINTS][2];
89     /** Number of collision areas */
90     Sint16 numof_collisions_zones;
91     /** List of the collision zones coordinates */
92     Sint16 collisions_coords[MAX_OF_COLLISION_ZONES][2];
93     /** List of the collision zones sizes (width/height) */
94     Sint16 collisions_sizes[MAX_OF_COLLISION_ZONES][2];
95     /** Number of cannons coordinates */
96     Sint16 numof_cannons;
97     /** Lists of the cannons coordinates */
98     Sint16 cannons_coords[MAX_OF_CANNONS][2];
99     /** Lists of the shots angles of the canons */
100     Sint16 cannons_angles[MAX_OF_CANNONS];
101     /** Nmber of pixels of the image */
102     Sint32 numof_pixels;
103     /** Pixel data */
104     char *img;
105     /** Size of offsets and repeats values table */
106     Sint32 nbr_data_comp;
107     /** Offsets and repeat values table */
108     char *compress;
109   }
110   image;
111 
112   typedef struct sprite
113   {
114     /** 0=friend sprite / 1=ennemy sprite */
115     Uint32 type;
116     /** Trajectory: 0=linear/1=compute/2=curve */
117     Sint16 trajectory;
118     /** Power of destruction (if collision) */
119     Sint16 pow_of_dest;
120     /** Energy level  (<= 0 destroyed sprite) */
121     Sint16 energy_level;
122     /** Initial energy level */
123     Sint16 max_energy_level;
124     /** Number of images of the sprite */
125     Sint16 numof_images;
126     /** Current image index */
127     Sint16 current_image;
128     /** Time delay before next image (animation speed) */
129     Sint16 anim_speed;
130     /** Time delay counter before ne image */
131     Sint16 anim_count;
132     /** Images data, points of collision, and
133      * location of the cannons of the sprite,*/
134     image *img[IMAGES_MAXOF];
135     /** X coordinate */
136     float xcoord;
137     /** Y coordinate */
138     float ycoord;
139     /** Speed of the sprite */
140     float speed;
141   } sprite;
142   bool image_load (const char *fname, image * img, Uint32 num_of_sprites,
143                    Uint32 num_of_images);
144   bool image_load_num (const char *fname, Sint32 num, image * img,
145                        Uint32 num_of_sprites, Uint32 num_of_anims);
146   bool image_load_single (const char *fname, image * img);
147   bool bitmap_load (const char *fname, bitmap * fonte, Uint32 num_of_obj,
148                     Uint32 num_of_images);
149   char *images_read (image * img, Uint32 num_of_sprites, Uint32 num_of_images,
150                      char *addr, Uint32 max_of_anims);
151   void images_free (image * first_image, Uint32 num_of_sprites,
152                     Uint32 num_of_anims, Uint32 max_of_anims);
153   void bitmap_free (bitmap * first_bitmap, Uint32 num_of_bitmap,
154                     Uint32 num_of_anims, Uint32 max_of_anims);
155 #ifdef PNG_EXPORT_ENABLE
156   bool image_to_png (image * img, const char *filename);
157   bool bitmap_to_png (bitmap * bmp, const char *filename, Uint32 width,
158                       Uint32 height, Uint32 size_of_line);
159 #endif
160 #ifdef __cplusplus
161 }
162 #endif
163 #endif
164