1 #include "image.h"
2 #include "../display/simgraph.h"
3 #include "../simtypes.h"
4 #include "../simdebug.h"
5 #include "../macros.h"
6
7 #include <string.h>
8 #include <stdlib.h>
9
10
11 /*
12 * Definition of special colors
13 * @author Hj. Malthaner
14 */
15 const uint32 image_t::rgbtab[SPECIAL] = {
16 0x244B67, // Player color 1
17 0x395E7C,
18 0x4C7191,
19 0x6084A7,
20 0x7497BD,
21 0x88ABD3,
22 0x9CBEE9,
23 0xB0D2FF,
24
25 0x7B5803, // Player color 2
26 0x8E6F04,
27 0xA18605,
28 0xB49D07,
29 0xC6B408,
30 0xD9CB0A,
31 0xECE20B,
32 0xFFF90D,
33
34 0x57656F, // Dark windows, lit yellowish at night
35 0x7F9BF1, // Lighter windows, lit blueish at night
36 0xFFFF53, // Yellow light
37 0xFF211D, // Red light
38 0x01DD01, // Green light
39 0x6B6B6B, // Non-darkening grey 1 (menus)
40 0x9B9B9B, // Non-darkening grey 2 (menus)
41 0xB3B3B3, // non-darkening grey 3 (menus)
42 0xC9C9C9, // Non-darkening grey 4 (menus)
43 0xDFDFDF, // Non-darkening grey 5 (menus)
44 0xE3E3FF, // Nearly white light at day, yellowish light at night
45 0xC1B1D1, // Windows, lit yellow
46 0x4D4D4D, // Windows, lit yellow
47 0xFF017F, // purple light
48 0x0101FF, // blue light
49 };
50
51
copy_image(const image_t & other)52 image_t* image_t::copy_image(const image_t& other)
53 {
54 image_t* img = new image_t(other.len);
55 img->len = other.len;
56 img->x = other.x;
57 img->y = other.y;
58 img->w = other.w;
59 img->h = other.h;
60 img->imageid = IMG_EMPTY;
61 img->zoomable = other.zoomable;
62 memcpy(img->data, other.data, other.len * sizeof(PIXVAL));
63 return img;
64 }
65
66 // creates a single pixel dummy picture
create_single_pixel()67 image_t* image_t::create_single_pixel()
68 {
69 image_t* desc = new image_t(4);
70 desc->len = 4;
71 desc->x = 0;
72 desc->y = 0;
73 desc->w = 1;
74 desc->h = 1;
75 desc->zoomable = 0;
76 desc->data[0] = 0;
77 desc->data[1] = 0;
78 desc->data[2] = 0;
79 desc->data[3] = 0;
80 return desc;
81 }
82
83
84 /* rotate_image_data - produces a (rotated) image
85 * only rotates by 90 degrees or multiples thereof, and assumes a square image
86 * Otherwise it will only succeed for angle=0;
87 */
copy_rotate(const sint16 angle) const88 image_t *image_t::copy_rotate(const sint16 angle) const
89 {
90 #if COLOUR_DEPTH == 0
91 (void)angle;
92 return create_single_pixel();
93 #endif
94 assert(angle == 0 || (w == h && x == 0 && y == 0));
95
96 image_t* target_image = copy_image(*this);
97
98 // the format is
99 // transparent PIXELVAL number
100 // PIXEL number of pixels, data*PIXVAL
101 // repeated until zero transparent pixels
102 // in pak64 case it is 0 64 64*PIXVAL 0 for a single line, e.g. 70 bytes per line for pak64
103 // first data will have an offset of two PIXVAL
104 // now you should understand below arithmetics ...
105
106 sint16 const x_y = w;
107 PIXVAL const* const src = get_data();
108 PIXVAL* const target = target_image->get_data();
109
110 switch(angle) {
111 case 90:
112 for(int j=0; j<x_y; j++) {
113 for(int i=0; i<x_y; i++) {
114 target[j*(x_y+3)+i+2]=src[i*(x_y+3)+(x_y-j-1)+2];
115 }
116 }
117 break;
118
119 case 180:
120 for(int j=0; j<x_y; j++) {
121 for(int i=0; i<x_y; i++) {
122 target[j*(x_y+3)+i+2]=src[(x_y-j-1)*(x_y+3)+(x_y-i-1)+2];
123 }
124 }
125 break;
126 case 270:
127 for(int j=0; j<x_y; j++) {
128 for(int i=0; i<x_y; i++) {
129 target[j*(x_y+3)+i+2]=src[(x_y-i-1)*(x_y+3)+j+2];
130 }
131 }
132 break;
133 default: // no rotation, just converts to array
134 ;
135 }
136 return target_image;
137 }
138
139
copy_flipvertical() const140 image_t *image_t::copy_flipvertical() const
141 {
142 image_t* target_image = copy_image(*this);
143
144 // the format is
145 // transparent PIXELVAL number
146 // PIXEL number of pixels, data*PIXVAL
147 // repeated until zero transparent pixels
148 // in pak64 case it is 0 64 64*PIXVAL 0 for a single line, e.g. 70 bytes per line for pak64
149 // first data will have an offset of two PIXVAL
150 // now you should understand below arithmetics ...
151
152 sint16 const x_y = w;
153 PIXVAL const* const src = get_data();
154 PIXVAL* const target = target_image->get_data();
155
156 for( int j = 0; j < x_y; j++ ) {
157 for( int i = 0; i < x_y; i++ ) {
158 target[i * (x_y + 3) + j + 2] = src[(x_y - i - 1) * (x_y + 3) + j + 2];
159 }
160 }
161 return target_image;
162 }
163
164
copy_fliphorizontal() const165 image_t *image_t::copy_fliphorizontal() const
166 {
167 image_t* target_image = copy_image(*this);
168
169 // the format is
170 // transparent PIXELVAL number
171 // PIXEL number of pixels, data*PIXVAL
172 // repeated until zero transparent pixels
173 // in pak64 case it is 0 64 64*PIXVAL 0 for a single line, e.g. 70 bytes per line for pak64
174 // first data will have an offset of two PIXVAL
175 // now you should understand below arithmetics ...
176
177 sint16 const x_y = w;
178 PIXVAL const* const src = get_data();
179 PIXVAL* const target = target_image->get_data();
180
181 for( int i = 0; i < x_y; i++ ) {
182 for( int j = 0; j < x_y; j++ ) {
183 target[i * (x_y + 3) + j + 2] = src[i * (x_y + 3) + (x_y - j - 1) + 2];
184 }
185 }
186 return target_image;
187 }
188