Merge lp:~aber/widelands/deleteSomeFilesNow into lp:widelands
- deleteSomeFilesNow
- Merge into trunk
Proposed by
David Allwicher
Status: | Merged |
---|---|
Merge reported by: | David Allwicher |
Merged at revision: | not available |
Proposed branch: | lp:~aber/widelands/deleteSomeFilesNow |
Merge into: | lp:widelands |
Diff against target: |
526 lines (+8/-498) 3 files modified
src/economy/request.cc (+8/-5) src/graphic/SDL_mng.cc (+0/-433) src/graphic/SDL_mng.h (+0/-60) |
To merge this branch: | bzr merge lp:~aber/widelands/deleteSomeFilesNow |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Widelands Developers | Pending | ||
Review via email: mp+58042@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/economy/request.cc' | |||
2 | --- src/economy/request.cc 2011-03-06 11:12:42 +0000 | |||
3 | +++ src/economy/request.cc 2011-04-17 17:41:40 +0000 | |||
4 | @@ -301,11 +301,14 @@ | |||
5 | 301 | int32_t Request::get_base_required_time | 301 | int32_t Request::get_base_required_time |
6 | 302 | (Editor_Game_Base & egbase, uint32_t const nr) const | 302 | (Editor_Game_Base & egbase, uint32_t const nr) const |
7 | 303 | { | 303 | { |
13 | 304 | if (m_count <= nr) | 304 | if (m_count <= nr) { |
14 | 305 | log | 305 | if (not(m_count == 1 and nr == 1)) { |
15 | 306 | ("Request::get_base_required_time: WARNING nr = %u but count is %u, " | 306 | log |
16 | 307 | "which is not allowed according to the comment for this function\n", | 307 | ("Request::get_base_required_time: WARNING nr = %u but count is %u, " |
17 | 308 | nr, m_count); | 308 | "which is not allowed according to the comment for this function\n", |
18 | 309 | nr, m_count); | ||
19 | 310 | } | ||
20 | 311 | } | ||
21 | 309 | int32_t const curtime = egbase.get_gametime(); | 312 | int32_t const curtime = egbase.get_gametime(); |
22 | 310 | 313 | ||
23 | 311 | if (!nr || !m_required_interval) | 314 | if (!nr || !m_required_interval) |
24 | 312 | 315 | ||
25 | === removed file 'src/graphic/SDL_mng.cc' | |||
26 | --- src/graphic/SDL_mng.cc 2009-11-20 11:52:19 +0000 | |||
27 | +++ src/graphic/SDL_mng.cc 1970-01-01 00:00:00 +0000 | |||
28 | @@ -1,433 +0,0 @@ | |||
29 | 1 | /* | ||
30 | 2 | SDL_mng: A library to load MNG files | ||
31 | 3 | Copyright (C) 2003, Thomas Kircher | ||
32 | 4 | |||
33 | 5 | PNG code based on SDL_png.c, Copyright (C) 1998 Philippe Lavoie | ||
34 | 6 | |||
35 | 7 | This library is free software; you can redistribute it and/or | ||
36 | 8 | modify it under the terms of the GNU Library General Public | ||
37 | 9 | License as published by the Free Software Foundation; either | ||
38 | 10 | version 2 of the License, or (at your option) any later version. | ||
39 | 11 | |||
40 | 12 | This library is distributed in the hope that it will be useful, | ||
41 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
42 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
43 | 15 | Library General Public License for more details. | ||
44 | 16 | |||
45 | 17 | You should have received a copy of the GNU Library General Public | ||
46 | 18 | License along with this library; if not, write to the Free | ||
47 | 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
48 | 20 | */ | ||
49 | 21 | |||
50 | 22 | |||
51 | 23 | #include "SDL_mng.h" | ||
52 | 24 | |||
53 | 25 | #include <SDL.h> | ||
54 | 26 | #include <SDL_endian.h> | ||
55 | 27 | |||
56 | 28 | #include <png.h> | ||
57 | 29 | |||
58 | 30 | /* Chunk structure */ | ||
59 | 31 | struct chunk_t { | ||
60 | 32 | unsigned int chunk_ID; | ||
61 | 33 | unsigned int chunk_size; | ||
62 | 34 | char * chunk_data; | ||
63 | 35 | unsigned int chunk_CRC; | ||
64 | 36 | }; | ||
65 | 37 | |||
66 | 38 | struct MNG_Frame { | ||
67 | 39 | SDL_Surface * frame; | ||
68 | 40 | MNG_Frame * next; | ||
69 | 41 | }; | ||
70 | 42 | |||
71 | 43 | /* Some select chunk IDs, from libmng.h */ | ||
72 | 44 | #define MNG_UINT_MHDR 0x4d484452L | ||
73 | 45 | #define MNG_UINT_BACK 0x4241434bL | ||
74 | 46 | #define MNG_UINT_PLTE 0x504c5445L | ||
75 | 47 | #define MNG_UINT_tRNS 0x74524e53L | ||
76 | 48 | #define MNG_UINT_IHDR 0x49484452L | ||
77 | 49 | #define MNG_UINT_IDAT 0x49444154L | ||
78 | 50 | #define MNG_UINT_IEND 0x49454e44L | ||
79 | 51 | #define MNG_UINT_MEND 0x4d454e44L | ||
80 | 52 | #define MNG_UINT_FRAM 0x4652414dL | ||
81 | 53 | #define MNG_UINT_LOOP 0x4c4f4f50L | ||
82 | 54 | #define MNG_UINT_ENDL 0x454e444cL | ||
83 | 55 | #define MNG_UINT_TERM 0x5445524dL | ||
84 | 56 | |||
85 | 57 | /* Internal MNG functions */ | ||
86 | 58 | unsigned char MNG_read_byte (SDL_RWops *); | ||
87 | 59 | unsigned int MNG_read_uint32 (SDL_RWops *); | ||
88 | 60 | chunk_t MNG_read_chunk (SDL_RWops *); | ||
89 | 61 | MNG_Image * MNG_iterate_chunks(SDL_RWops *); | ||
90 | 62 | |||
91 | 63 | /* Read one MNG frame and return it as an SDL_Surface */ | ||
92 | 64 | SDL_Surface * MNG_read_frame(SDL_RWops * src); | ||
93 | 65 | |||
94 | 66 | /* Return whether or not the file claims to be an MNG */ | ||
95 | 67 | int IMG_isMNG(SDL_RWops * const src) | ||
96 | 68 | { | ||
97 | 69 | unsigned char buf[8]; | ||
98 | 70 | |||
99 | 71 | if (SDL_RWread(src, buf, 1, 8) != 8) | ||
100 | 72 | return 0; | ||
101 | 73 | |||
102 | 74 | return !memcmp(buf, "\212MNG\r\n\032\n", 8); | ||
103 | 75 | } | ||
104 | 76 | |||
105 | 77 | MNG_Image * IMG_loadMNG(char * const file) | ||
106 | 78 | { | ||
107 | 79 | SDL_RWops * const src = SDL_RWFromFile(file, "rb"); | ||
108 | 80 | |||
109 | 81 | if (not src) | ||
110 | 82 | return 0; | ||
111 | 83 | |||
112 | 84 | /* See whether or not this data source can handle seeking */ | ||
113 | 85 | if (SDL_RWseek(src, 0, SEEK_CUR) < 0) { | ||
114 | 86 | SDL_SetError("Can not seek in this data source"); | ||
115 | 87 | SDL_RWclose(src); | ||
116 | 88 | return 0; | ||
117 | 89 | } | ||
118 | 90 | |||
119 | 91 | /* Verify MNG signature */ | ||
120 | 92 | if (!IMG_isMNG(src)) { | ||
121 | 93 | SDL_SetError("File is not an MNG file"); | ||
122 | 94 | SDL_RWclose(src); | ||
123 | 95 | return 0; | ||
124 | 96 | } | ||
125 | 97 | |||
126 | 98 | return (MNG_iterate_chunks(src)); | ||
127 | 99 | } | ||
128 | 100 | |||
129 | 101 | /* Read a byte from the src stream */ | ||
130 | 102 | unsigned char MNG_read_byte(SDL_RWops * const src) | ||
131 | 103 | { | ||
132 | 104 | unsigned char ch; | ||
133 | 105 | |||
134 | 106 | SDL_RWread(src, &ch, 1, 1); | ||
135 | 107 | |||
136 | 108 | return ch; | ||
137 | 109 | } | ||
138 | 110 | |||
139 | 111 | /* Read a 4-byte uint32 from the src stream */ | ||
140 | 112 | unsigned int MNG_read_uint32(SDL_RWops * const src) | ||
141 | 113 | { | ||
142 | 114 | unsigned char buffer[4]; | ||
143 | 115 | unsigned int value; | ||
144 | 116 | |||
145 | 117 | buffer[0] = MNG_read_byte(src); buffer[1] = MNG_read_byte(src); | ||
146 | 118 | buffer[2] = MNG_read_byte(src); buffer[3] = MNG_read_byte(src); | ||
147 | 119 | |||
148 | 120 | value = buffer[0] << 24; value |= buffer[1] << 16; | ||
149 | 121 | value |= buffer[2] << 8; value |= buffer[3]; | ||
150 | 122 | |||
151 | 123 | return value; | ||
152 | 124 | } | ||
153 | 125 | |||
154 | 126 | /* Read an MNG chunk */ | ||
155 | 127 | chunk_t MNG_read_chunk(SDL_RWops * const src) | ||
156 | 128 | { | ||
157 | 129 | chunk_t this_chunk; | ||
158 | 130 | |||
159 | 131 | this_chunk.chunk_size = MNG_read_uint32(src); | ||
160 | 132 | this_chunk.chunk_ID = MNG_read_uint32(src); | ||
161 | 133 | |||
162 | 134 | this_chunk.chunk_data = | ||
163 | 135 | static_cast<char *>(calloc(sizeof(char), this_chunk.chunk_size)); | ||
164 | 136 | |||
165 | 137 | SDL_RWread(src, this_chunk.chunk_data, 1, this_chunk.chunk_size); | ||
166 | 138 | |||
167 | 139 | this_chunk.chunk_CRC = MNG_read_uint32(src); | ||
168 | 140 | |||
169 | 141 | return this_chunk; | ||
170 | 142 | } | ||
171 | 143 | |||
172 | 144 | /* Read MHDR chunk data */ | ||
173 | 145 | MHDR_chunk read_MHDR(SDL_RWops * const src) | ||
174 | 146 | { | ||
175 | 147 | MHDR_chunk mng_header; | ||
176 | 148 | |||
177 | 149 | mng_header.Frame_width = MNG_read_uint32(src); | ||
178 | 150 | mng_header.Frame_height = MNG_read_uint32(src); | ||
179 | 151 | mng_header.Ticks_per_second = MNG_read_uint32(src); | ||
180 | 152 | mng_header.Nominal_layer_count = MNG_read_uint32(src); | ||
181 | 153 | mng_header.Nominal_frame_count = MNG_read_uint32(src); | ||
182 | 154 | mng_header.Nominal_play_time = MNG_read_uint32(src); | ||
183 | 155 | mng_header.Simplicity_profile = MNG_read_uint32(src); | ||
184 | 156 | |||
185 | 157 | /* skip CRC bits */ | ||
186 | 158 | MNG_read_uint32(src); | ||
187 | 159 | |||
188 | 160 | return mng_header; | ||
189 | 161 | } | ||
190 | 162 | |||
191 | 163 | /* Iterate through the MNG chunks */ | ||
192 | 164 | MNG_Image * MNG_iterate_chunks(SDL_RWops * const src) | ||
193 | 165 | { | ||
194 | 166 | chunk_t current_chunk; | ||
195 | 167 | |||
196 | 168 | uint32_t byte_count = 0; | ||
197 | 169 | uint32_t frame_count = 0; | ||
198 | 170 | |||
199 | 171 | MNG_Frame * start_frame = 0; | ||
200 | 172 | MNG_Frame * current_frame = 0; | ||
201 | 173 | |||
202 | 174 | MNG_Image * const image = | ||
203 | 175 | static_cast<MNG_Image *>(malloc(sizeof(MNG_Image))); | ||
204 | 176 | |||
205 | 177 | do { | ||
206 | 178 | current_chunk = MNG_read_chunk(src); | ||
207 | 179 | byte_count += current_chunk.chunk_size + 12; | ||
208 | 180 | |||
209 | 181 | switch (current_chunk.chunk_ID) { | ||
210 | 182 | /* Read MHDR chunk, and store in image struct */ | ||
211 | 183 | case MNG_UINT_MHDR: | ||
212 | 184 | SDL_RWseek(src, -(current_chunk.chunk_size + 4), SEEK_CUR); | ||
213 | 185 | image->mhdr = read_MHDR(src); | ||
214 | 186 | break; | ||
215 | 187 | |||
216 | 188 | /* Reset our byte count */ | ||
217 | 189 | case MNG_UINT_IHDR: | ||
218 | 190 | byte_count = current_chunk.chunk_size + 12; | ||
219 | 191 | break; | ||
220 | 192 | |||
221 | 193 | /* We've reached the end of a PNG - seek to IHDR and read */ | ||
222 | 194 | case MNG_UINT_IEND: | ||
223 | 195 | SDL_RWseek(src, -byte_count, SEEK_CUR); | ||
224 | 196 | |||
225 | 197 | /* We don't know how many frames there will be, really. */ | ||
226 | 198 | if (not start_frame) { | ||
227 | 199 | current_frame = | ||
228 | 200 | static_cast<MNG_Frame *>(malloc(sizeof(MNG_Frame))); | ||
229 | 201 | start_frame = current_frame; | ||
230 | 202 | } else { | ||
231 | 203 | current_frame->next = | ||
232 | 204 | static_cast<MNG_Frame *>(malloc(sizeof(MNG_Frame))); | ||
233 | 205 | current_frame = current_frame->next; | ||
234 | 206 | } | ||
235 | 207 | |||
236 | 208 | current_frame->frame = MNG_read_frame(src); | ||
237 | 209 | ++frame_count; | ||
238 | 210 | |||
239 | 211 | break; | ||
240 | 212 | |||
241 | 213 | default: | ||
242 | 214 | break; | ||
243 | 215 | } | ||
244 | 216 | } while (current_chunk.chunk_ID != MNG_UINT_MEND); | ||
245 | 217 | |||
246 | 218 | /* Now that we're done, move the frames into our image struct */ | ||
247 | 219 | image->frame_count = frame_count; | ||
248 | 220 | image->frame = | ||
249 | 221 | static_cast<SDL_Surface * *>(calloc(sizeof(SDL_Surface *), frame_count)); | ||
250 | 222 | |||
251 | 223 | current_frame = start_frame; | ||
252 | 224 | |||
253 | 225 | for (uint32_t i = 0; i < frame_count; ++i) { | ||
254 | 226 | image->frame[i] = current_frame->frame; | ||
255 | 227 | current_frame = current_frame->next; | ||
256 | 228 | } | ||
257 | 229 | return image; | ||
258 | 230 | } | ||
259 | 231 | |||
260 | 232 | /* png_read_data callback; return <size> bytes from wherever */ | ||
261 | 233 | static void png_read_data(png_structp ctx, png_bytep area, png_size_t size) | ||
262 | 234 | { | ||
263 | 235 | SDL_RWread(static_cast<SDL_RWops *>(png_get_io_ptr(ctx)), area, size, 1); | ||
264 | 236 | } | ||
265 | 237 | |||
266 | 238 | /* Read a PNG frame from the MNG file */ | ||
267 | 239 | SDL_Surface * MNG_read_frame(SDL_RWops * const src) | ||
268 | 240 | { | ||
269 | 241 | png_uint_32 width, height; | ||
270 | 242 | int bit_depth, color_type, interlace_type; | ||
271 | 243 | Uint32 Rmask; | ||
272 | 244 | Uint32 Gmask; | ||
273 | 245 | Uint32 Bmask; | ||
274 | 246 | Uint32 Amask; | ||
275 | 247 | SDL_Palette * palette; | ||
276 | 248 | volatile int ckey = -1; | ||
277 | 249 | png_color_16 * transv; | ||
278 | 250 | |||
279 | 251 | /* Initialize the data we will clean up when we're done */ | ||
280 | 252 | png_structp png_ptr = 0; | ||
281 | 253 | png_infop info_ptr = 0; | ||
282 | 254 | png_bytep * volatile row_pointers = 0; | ||
283 | 255 | SDL_Surface * volatile surface = 0; | ||
284 | 256 | |||
285 | 257 | /* Check to make sure we have something to do */ | ||
286 | 258 | if (! src) | ||
287 | 259 | goto done; | ||
288 | 260 | |||
289 | 261 | /* Create the PNG loading context structure */ | ||
290 | 262 | png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0); | ||
291 | 263 | if (not png_ptr) { | ||
292 | 264 | SDL_SetError("Could not allocate memory for PNG file"); | ||
293 | 265 | goto done; | ||
294 | 266 | } | ||
295 | 267 | |||
296 | 268 | // Allocate/initialize the memory for image information. REQUIRED. | ||
297 | 269 | info_ptr = png_create_info_struct(png_ptr); | ||
298 | 270 | if (not info_ptr) { | ||
299 | 271 | SDL_SetError("Could not create image information for PNG file"); | ||
300 | 272 | goto done; | ||
301 | 273 | } | ||
302 | 274 | |||
303 | 275 | /* Set error handling if you are using setjmp/longjmp method (this is | ||
304 | 276 | * the normal method of doing things with libpng). REQUIRED unless you | ||
305 | 277 | * set up your own error handlers in png_create_read_struct() earlier. | ||
306 | 278 | */ | ||
307 | 279 | if (setjmp(png_ptr->jmpbuf)) { | ||
308 | 280 | SDL_SetError("Error reading the PNG file."); | ||
309 | 281 | goto done; | ||
310 | 282 | } | ||
311 | 283 | |||
312 | 284 | /* Set up the input control */ | ||
313 | 285 | png_set_read_fn(png_ptr, src, png_read_data); | ||
314 | 286 | |||
315 | 287 | /* tell PNG not to read the signature */ | ||
316 | 288 | png_set_sig_bytes(png_ptr, 8); | ||
317 | 289 | |||
318 | 290 | /* Read PNG header info */ | ||
319 | 291 | png_read_info(png_ptr, info_ptr); | ||
320 | 292 | png_get_IHDR | ||
321 | 293 | (png_ptr, info_ptr, | ||
322 | 294 | &width, &height, | ||
323 | 295 | &bit_depth, | ||
324 | 296 | &color_type, &interlace_type, | ||
325 | 297 | 0, 0); | ||
326 | 298 | |||
327 | 299 | /* tell libpng to strip 16 bit/color files down to 8 bits/color */ | ||
328 | 300 | png_set_strip_16(png_ptr); | ||
329 | 301 | |||
330 | 302 | /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single | ||
331 | 303 | * byte into separate bytes (useful for paletted and grayscale images). | ||
332 | 304 | */ | ||
333 | 305 | png_set_packing(png_ptr); | ||
334 | 306 | |||
335 | 307 | /* scale greyscale values to the range 0..255 */ | ||
336 | 308 | if (color_type == PNG_COLOR_TYPE_GRAY) | ||
337 | 309 | png_set_expand(png_ptr); | ||
338 | 310 | |||
339 | 311 | /* For images with a single "transparent colour", set colour key; | ||
340 | 312 | if more than one index has transparency, or if partially transparent | ||
341 | 313 | entries exist, use full alpha channel */ | ||
342 | 314 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { | ||
343 | 315 | int num_trans; | ||
344 | 316 | Uint8 * trans; | ||
345 | 317 | png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &transv); | ||
346 | 318 | if (color_type == PNG_COLOR_TYPE_PALETTE) { | ||
347 | 319 | /* Check if all tRNS entries are opaque except one */ | ||
348 | 320 | uint32_t i = 0; | ||
349 | 321 | int32_t t = -1; | ||
350 | 322 | for (; i < static_cast<uint32_t>(num_trans); ++i) | ||
351 | 323 | if (trans[i] == 0) { | ||
352 | 324 | if (t >= 0) | ||
353 | 325 | break; | ||
354 | 326 | t = i; | ||
355 | 327 | } else if (trans[i] != 255) | ||
356 | 328 | break; | ||
357 | 329 | if (i == static_cast<uint32_t>(num_trans)) { | ||
358 | 330 | /* exactly one transparent index */ | ||
359 | 331 | ckey = t; | ||
360 | 332 | } else { | ||
361 | 333 | /* more than one transparent index, or translucency */ | ||
362 | 334 | png_set_expand(png_ptr); | ||
363 | 335 | } | ||
364 | 336 | } else | ||
365 | 337 | ckey = 0; // actual value will be set later | ||
366 | 338 | } | ||
367 | 339 | |||
368 | 340 | if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | ||
369 | 341 | png_set_gray_to_rgb(png_ptr); | ||
370 | 342 | |||
371 | 343 | png_read_update_info(png_ptr, info_ptr); | ||
372 | 344 | |||
373 | 345 | png_get_IHDR | ||
374 | 346 | (png_ptr, info_ptr, | ||
375 | 347 | &width, &height, | ||
376 | 348 | &bit_depth, | ||
377 | 349 | &color_type, &interlace_type, | ||
378 | 350 | 0, 0); | ||
379 | 351 | |||
380 | 352 | /* Allocate the SDL surface to hold the image */ | ||
381 | 353 | Rmask = Gmask = Bmask = Amask = 0; | ||
382 | 354 | if (color_type != PNG_COLOR_TYPE_PALETTE) { | ||
383 | 355 | if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { | ||
384 | 356 | Rmask = 0x000000FF; | ||
385 | 357 | Gmask = 0x0000FF00; | ||
386 | 358 | Bmask = 0x00FF0000; | ||
387 | 359 | Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0; | ||
388 | 360 | } else { | ||
389 | 361 | int const s = (info_ptr->channels == 4) ? 0 : 8; | ||
390 | 362 | Rmask = 0xFF000000 >> s; | ||
391 | 363 | Gmask = 0x00FF0000 >> s; | ||
392 | 364 | Bmask = 0x0000FF00 >> s; | ||
393 | 365 | Amask = 0x000000FF >> s; | ||
394 | 366 | } | ||
395 | 367 | } | ||
396 | 368 | surface = | ||
397 | 369 | SDL_AllocSurface | ||
398 | 370 | (SDL_SWSURFACE, | ||
399 | 371 | width, height, | ||
400 | 372 | bit_depth * info_ptr->channels, | ||
401 | 373 | Rmask, Gmask, Bmask, Amask); | ||
402 | 374 | if (not surface) { | ||
403 | 375 | SDL_SetError("Out of memory"); | ||
404 | 376 | goto done; | ||
405 | 377 | } | ||
406 | 378 | |||
407 | 379 | if (ckey != -1) { | ||
408 | 380 | if (color_type != PNG_COLOR_TYPE_PALETTE) | ||
409 | 381 | /* FIXME: Should these be truncated or shifted down? */ | ||
410 | 382 | ckey = | ||
411 | 383 | SDL_MapRGB | ||
412 | 384 | (surface->format, | ||
413 | 385 | static_cast<Uint8>(transv->red), | ||
414 | 386 | static_cast<Uint8>(transv->green), | ||
415 | 387 | static_cast<Uint8>(transv->blue)); | ||
416 | 388 | SDL_SetColorKey(surface, SDL_SRCCOLORKEY, ckey); | ||
417 | 389 | } | ||
418 | 390 | |||
419 | 391 | /* Create the array of pointers to image data */ | ||
420 | 392 | row_pointers = static_cast<png_bytep *>(malloc(sizeof(png_bytep) * height)); | ||
421 | 393 | if (not row_pointers) { | ||
422 | 394 | SDL_SetError("Out of memory"); | ||
423 | 395 | SDL_FreeSurface(surface); | ||
424 | 396 | surface = 0; | ||
425 | 397 | goto done; | ||
426 | 398 | } | ||
427 | 399 | for (uint32_t row = 0; row < height; ++row) | ||
428 | 400 | row_pointers[row] = | ||
429 | 401 | static_cast<png_bytep>(static_cast<Uint8 *>(surface->pixels)) + | ||
430 | 402 | row * surface->pitch; | ||
431 | 403 | |||
432 | 404 | /* Read the entire image in one go */ | ||
433 | 405 | png_read_image(png_ptr, row_pointers); | ||
434 | 406 | |||
435 | 407 | /* read rest of file, get additional chunks in info_ptr - REQUIRED */ | ||
436 | 408 | png_read_end(png_ptr, info_ptr); | ||
437 | 409 | |||
438 | 410 | /* Load the palette, if any */ | ||
439 | 411 | if ((palette = surface->format->palette)) { | ||
440 | 412 | if (color_type == PNG_COLOR_TYPE_GRAY) { | ||
441 | 413 | palette->ncolors = 256; | ||
442 | 414 | for (uint16_t i = 0; i < 256; ++i) { | ||
443 | 415 | palette->colors[i].r = i; | ||
444 | 416 | palette->colors[i].g = i; | ||
445 | 417 | palette->colors[i].b = i; | ||
446 | 418 | } | ||
447 | 419 | } else if (info_ptr->num_palette > 0) { | ||
448 | 420 | palette->ncolors = info_ptr->num_palette; | ||
449 | 421 | for (uint32_t i = 0; i < info_ptr->num_palette; ++i) { | ||
450 | 422 | palette->colors[i].b = info_ptr->palette[i].blue; | ||
451 | 423 | palette->colors[i].g = info_ptr->palette[i].green; | ||
452 | 424 | palette->colors[i].r = info_ptr->palette[i].red; | ||
453 | 425 | } | ||
454 | 426 | } | ||
455 | 427 | } | ||
456 | 428 | |||
457 | 429 | done: /* Clean up and return */ | ||
458 | 430 | png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : 0, 0); | ||
459 | 431 | free(row_pointers); | ||
460 | 432 | return (surface); | ||
461 | 433 | } | ||
462 | 434 | 0 | ||
463 | === removed file 'src/graphic/SDL_mng.h' | |||
464 | --- src/graphic/SDL_mng.h 2009-11-01 07:13:59 +0000 | |||
465 | +++ src/graphic/SDL_mng.h 1970-01-01 00:00:00 +0000 | |||
466 | @@ -1,60 +0,0 @@ | |||
467 | 1 | /* | ||
468 | 2 | SDL_mng: A library to load MNG files | ||
469 | 3 | Copyright (C) 2003, Thomas Kircher | ||
470 | 4 | |||
471 | 5 | This library is free software; you can redistribute it and/or | ||
472 | 6 | modify it under the terms of the GNU Library General Public | ||
473 | 7 | License as published by the Free Software Foundation; either | ||
474 | 8 | version 2 of the License, or (at your option) any later version. | ||
475 | 9 | |||
476 | 10 | This library is distributed in the hope that it will be useful, | ||
477 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
478 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
479 | 13 | Library General Public License for more details. | ||
480 | 14 | |||
481 | 15 | You should have received a copy of the GNU Library General Public | ||
482 | 16 | License along with this library; if not, write to the Free | ||
483 | 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
484 | 18 | */ | ||
485 | 19 | |||
486 | 20 | #ifndef __SDL_mng_h__ | ||
487 | 21 | #define __SDL_mng_h__ | ||
488 | 22 | |||
489 | 23 | #include <SDL.h> | ||
490 | 24 | |||
491 | 25 | #ifdef __cplusplus | ||
492 | 26 | extern "C" { | ||
493 | 27 | #endif | ||
494 | 28 | |||
495 | 29 | typedef struct | ||
496 | 30 | { | ||
497 | 31 | unsigned int Frame_width; | ||
498 | 32 | unsigned int Frame_height; | ||
499 | 33 | unsigned int Ticks_per_second; | ||
500 | 34 | unsigned int Nominal_layer_count; | ||
501 | 35 | unsigned int Nominal_frame_count; | ||
502 | 36 | unsigned int Nominal_play_time; | ||
503 | 37 | unsigned int Simplicity_profile; | ||
504 | 38 | } | ||
505 | 39 | MHDR_chunk; | ||
506 | 40 | |||
507 | 41 | /* MNG_Image type */ | ||
508 | 42 | typedef struct | ||
509 | 43 | { | ||
510 | 44 | MHDR_chunk mhdr; | ||
511 | 45 | unsigned int frame_count; | ||
512 | 46 | SDL_Surface * * frame; | ||
513 | 47 | } | ||
514 | 48 | MNG_Image; | ||
515 | 49 | |||
516 | 50 | /* Check for MNG signature */ | ||
517 | 51 | int IMG_isMNG(SDL_RWops *); | ||
518 | 52 | |||
519 | 53 | /* Read and return an MNG image */ | ||
520 | 54 | MNG_Image * IMG_loadMNG(char const * file); | ||
521 | 55 | |||
522 | 56 | #ifdef __cplusplus | ||
523 | 57 | } | ||
524 | 58 | #endif | ||
525 | 59 | |||
526 | 60 | #endif /* __SDL_mng_h__ */ |
I am sorry. I had planed to review this but failed utterly in remembering to do so... But I am confident that the changes are alright :)