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

Subscribers

People subscribed via source and target branches

to status/vote changes: