Merge lp:~aber/widelands/deleteSomeFilesNow into lp:widelands

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
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+58042@code.launchpad.net
To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

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 :)

Preview Diff

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

Subscribers

People subscribed via source and target branches

to status/vote changes: