Skip to content

Commit e1d4fce

Browse files
committed
Merge pull request #362 from glynnc/master
Deal with some warnings
2 parents e2512e1 + c849a37 commit e1d4fce

14 files changed

+96
-82
lines changed

src/bitmap.cpp

+4-59
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include <algorithm>
2323
#include <iostream>
2424

25-
#include <boost/scope_exit.hpp>
26-
#include <png.h>
27-
2825
#include "system.h"
2926
#include "utils.h"
3027
#include "cache.h"
@@ -88,15 +85,6 @@ Color Bitmap::GetPixel(int x, int y) const {
8885
return Color(r, g, b, a);
8986
}
9087

91-
static void write_data(png_structp out_ptr, png_bytep data, png_size_t len) {
92-
reinterpret_cast<std::ostream*>(png_get_io_ptr(out_ptr))->write(
93-
reinterpret_cast<char const*>(data), len);
94-
}
95-
static void flush_stream(png_structp out_ptr) {
96-
reinterpret_cast<std::ostream*>(png_get_io_ptr(out_ptr))->flush();
97-
}
98-
99-
10088
bool Bitmap::WritePNG(std::ostream& os) const {
10189
size_t const width = GetWidth(), height = GetHeight();
10290
size_t const stride = width * 4;
@@ -109,50 +97,7 @@ bool Bitmap::WritePNG(std::ostream& os) const {
10997
pixman_image_composite32(PIXMAN_OP_SRC, bitmap, NULL, dst.get(),
11098
0, 0, 0, 0, 0, 0, width, height);
11199

112-
for(size_t i = 0; i < width * height; ++i) {
113-
uint32_t const p = data[i];
114-
uint8_t* out = reinterpret_cast<uint8_t*>(&data[i]);
115-
uint8_t
116-
a = (p >> 24) & 0xff, r = (p >> 16) & 0xff,
117-
g = (p >> 8) & 0xff, b = (p >> 0) & 0xff;
118-
if(a != 0) {
119-
r = (r * 255) / a;
120-
g = (g * 255) / a;
121-
b = (b * 255) / a;
122-
}
123-
*out++ = r; *out++ = g; *out++ = b; *out++ = a;
124-
}
125-
126-
std::vector<png_bytep> ptrs(height);
127-
for(size_t i = 0; i < ptrs.size(); ++i) {
128-
ptrs[i] = reinterpret_cast<png_bytep>(&data[width*i]);
129-
}
130-
131-
png_structp write = NULL;
132-
if(!(write = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) {
133-
Output::Warning("Bitmap::WritePNG: error in png_create_write");
134-
return false;
135-
}
136-
137-
png_infop info = NULL;
138-
BOOST_SCOPE_EXIT((&write)(&info)) {
139-
png_destroy_write_struct(&write, &info);
140-
} BOOST_SCOPE_EXIT_END do {} while(0);
141-
if(!(info = png_create_info_struct(write))) {
142-
Output::Warning("Bitmap::WritePNG: error in png_create_info_struct");
143-
return false;
144-
}
145-
146-
png_set_write_fn(write, &os, &write_data, &flush_stream);
147-
148-
png_set_IHDR(write, info, width, height, 8,
149-
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
150-
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
151-
png_write_info(write, info);
152-
png_write_image(write, &ptrs.front());
153-
png_write_end(write, NULL);
154-
155-
return true;
100+
return ImagePNG::WritePNG(os, width, height, &data.front());
156101
}
157102

158103
void Bitmap::AttachBitmapScreen(BitmapScreen* bitmap) {
@@ -234,7 +179,7 @@ Bitmap::TileOpacity Bitmap::GetTileOpacity(int row, int col) {
234179
return opacity? (*opacity)[row][col] : Partial;
235180
}
236181

237-
uint8_t Bitmap::bytes() const {
182+
int Bitmap::bytes() const {
238183
return format.bytes;
239184
}
240185

@@ -717,7 +662,7 @@ void const* Bitmap::pixels() const {
717662
return (void const*) pixman_image_get_data(bitmap);
718663
}
719664

720-
uint8_t Bitmap::bpp() const {
665+
int Bitmap::bpp() const {
721666
return (pixman_image_get_depth(bitmap) + 7) / 8;
722667
}
723668

@@ -729,7 +674,7 @@ int Bitmap::height() const {
729674
return pixman_image_get_height(bitmap);
730675
}
731676

732-
uint16_t Bitmap::pitch() const {
677+
int Bitmap::pitch() const {
733678
return pixman_image_get_stride(bitmap);
734679
}
735680

src/bitmap.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Bitmap {
177177
protected:
178178
Bitmap();
179179

180-
uint8_t bytes() const;
180+
int bytes() const;
181181
uint32_t rmask() const;
182182
uint32_t gmask() const;
183183
uint32_t bmask() const;
@@ -701,8 +701,8 @@ class Bitmap {
701701
void const* pixels() const;
702702
int width() const;
703703
int height() const;
704-
uint8_t bpp() const;
705-
uint16_t pitch() const;
704+
int bpp() const;
705+
int pitch() const;
706706

707707
protected:
708708
/** Bitmap data. */

src/game_character.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,14 @@ class Game_Character {
285285
*
286286
* @return flash intensity
287287
*/
288-
virtual int GetFlashLevel() const = 0;
288+
virtual double GetFlashLevel() const = 0;
289289

290290
/**
291291
* Sets intensity of flash effect.
292292
*
293293
* @param flash_level new flash intensity
294294
*/
295-
virtual void SetFlashLevel(int flash_level) = 0;
295+
virtual void SetFlashLevel(double flash_level) = 0;
296296

297297
/**
298298
* Returns how many flash effect time is left.

src/game_event.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ void Game_Event::SetFlashColor(const Color& flash_color) {
209209
data.flash_green = flash_color.green;
210210
}
211211

212-
int Game_Event::GetFlashLevel() const {
212+
double Game_Event::GetFlashLevel() const {
213213
return data.flash_current_level;
214214
}
215215

216-
void Game_Event::SetFlashLevel(int flash_level) {
216+
void Game_Event::SetFlashLevel(double flash_level) {
217217
data.flash_current_level = flash_level;
218218
}
219219

src/game_event.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class Game_Event : public Game_Character {
7979
void SetSpriteIndex(int index);
8080
Color GetFlashColor() const;
8181
void SetFlashColor(const Color& flash_color);
82-
int GetFlashLevel() const;
83-
void SetFlashLevel(int flash_level);
82+
double GetFlashLevel() const;
83+
void SetFlashLevel(double flash_level);
8484
int GetFlashTimeLeft() const;
8585
void SetFlashTimeLeft(int time_left);
8686
bool IsMessageBlocking() const;

src/game_map.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ void Game_Map::SetChipset(int id) {
916916
passages_down = chipset.passable_data_lower;
917917
passages_up = chipset.passable_data_upper;
918918
animation_type = chipset.animation_type;
919-
animation_fast = chipset.animation_speed;
919+
animation_fast = chipset.animation_speed != 0;
920920
if (passages_down.size() < 162)
921921
passages_down.resize(162, (unsigned char) 0x0F);
922922
if (passages_up.size() < 144)

src/game_message.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void Game_Message::SetFaceRightPosition(bool right) {
108108
}
109109

110110
bool Game_Message::IsTransparent() {
111-
return data.message_transparent;
111+
return data.message_transparent != 0;
112112
}
113113

114114
void Game_Message::SetTransparent(bool transparent) {
@@ -132,7 +132,7 @@ void Game_Message::SetPositionFixed(bool fixed) {
132132
}
133133

134134
bool Game_Message::GetContinueEvents() {
135-
return data.message_continue_events;
135+
return data.message_continue_events != 0;
136136
}
137137

138138
void Game_Message::SetContinueEvents(bool continue_events) {

src/game_player.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ void Game_Player::SetFlashColor(const Color& flash_color) {
179179
location.flash_green = flash_color.green;
180180
}
181181

182-
int Game_Player::GetFlashLevel() const {
182+
double Game_Player::GetFlashLevel() const {
183183
return location.flash_current_level;
184184
}
185185

186-
void Game_Player::SetFlashLevel(int flash_level) {
186+
void Game_Player::SetFlashLevel(double flash_level) {
187187
location.flash_current_level = flash_level;
188188
}
189189

src/game_player.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class Game_Player : public Game_Character {
6969
void SetSpriteIndex(int index);
7070
Color GetFlashColor() const;
7171
void SetFlashColor(const Color& flash_color);
72-
int GetFlashLevel() const;
73-
void SetFlashLevel(int flash_level);
72+
double GetFlashLevel() const;
73+
void SetFlashLevel(double flash_level);
7474
int GetFlashTimeLeft() const;
7575
void SetFlashTimeLeft(int time_left);
7676
/** @} */

src/game_vehicle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ void Game_Vehicle::SetFlashColor(const Color& flash_color) {
174174
data.flash_green = flash_color.green;
175175
}
176176

177-
int Game_Vehicle::GetFlashLevel() const {
177+
double Game_Vehicle::GetFlashLevel() const {
178178
return data.flash_current_level;
179179
}
180180

181-
void Game_Vehicle::SetFlashLevel(int flash_level) {
181+
void Game_Vehicle::SetFlashLevel(double flash_level) {
182182
data.flash_current_level = flash_level;
183183
}
184184

src/game_vehicle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class Game_Vehicle : public Game_Character {
7777
void SetSpriteIndex(int index);
7878
Color GetFlashColor() const;
7979
void SetFlashColor(const Color& flash_color);
80-
int GetFlashLevel() const;
81-
void SetFlashLevel(int flash_level);
80+
double GetFlashLevel() const;
81+
void SetFlashLevel(double flash_level);
8282
int GetFlashTimeLeft() const;
8383
void SetFlashTimeLeft(int time_left);
8484
/** @} */

src/image_png.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <png.h>
2323
#include <cstdlib>
2424
#include <cstring>
25+
#include <csetjmp>
26+
#include <vector>
27+
2528
#include "output.h"
2629
#include "image_png.h"
2730

@@ -139,4 +142,63 @@ void ImagePNG::ReadPNG(FILE* stream, const void* buffer, bool transparent,
139142
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
140143
}
141144

145+
static void write_data(png_structp out_ptr, png_bytep data, png_size_t len) {
146+
reinterpret_cast<std::ostream*>(png_get_io_ptr(out_ptr))->write(reinterpret_cast<char const*>(data), len);
147+
}
148+
static void flush_stream(png_structp out_ptr) {
149+
reinterpret_cast<std::ostream*>(png_get_io_ptr(out_ptr))->flush();
150+
}
151+
152+
bool ImagePNG::WritePNG(std::ostream& os, int width, int height, uint32_t* data) {
153+
for (size_t i = 0; i < width * height; ++i) {
154+
uint32_t const p = data[i];
155+
uint8_t* out = reinterpret_cast<uint8_t*>(&data[i]);
156+
uint8_t
157+
a = (p >> 24) & 0xff, r = (p >> 16) & 0xff,
158+
g = (p >> 8) & 0xff, b = (p >> 0) & 0xff;
159+
if(a != 0) {
160+
r = (r * 255) / a;
161+
g = (g * 255) / a;
162+
b = (b * 255) / a;
163+
}
164+
*out++ = r; *out++ = g; *out++ = b; *out++ = a;
165+
}
166+
167+
png_structp write = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
168+
if (!write) {
169+
Output::Warning("Bitmap::WritePNG: error in png_create_write");
170+
return false;
171+
}
172+
173+
png_infop info = png_create_info_struct(write);
174+
if (!info) {
175+
png_destroy_write_struct(&write, &info);
176+
Output::Warning("ImagePNG::WritePNG: error in png_create_info_struct");
177+
return false;
178+
}
179+
180+
png_bytep* ptrs = new png_bytep[height];
181+
for (size_t i = 0; i < height; ++i) {
182+
ptrs[i] = reinterpret_cast<png_bytep>(&data[width*i]);
183+
}
184+
185+
if (setjmp(png_jmpbuf(write))) {
186+
png_destroy_write_struct(&write, &info);
187+
delete [] ptrs;
188+
Output::Warning("ImagePNG::WritePNG: error writing PNG file");
189+
return false;
190+
}
191+
192+
png_set_write_fn(write, &os, &write_data, &flush_stream);
193+
194+
png_set_IHDR(write, info, width, height, 8,
195+
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
196+
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
197+
png_write_info(write, info);
198+
png_write_image(write, ptrs);
199+
png_write_end(write, NULL);
200+
201+
return true;
202+
}
203+
142204
#endif // SUPPORT_PNG

src/image_png.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#ifdef SUPPORT_PNG
2323

2424
#include <cstdio>
25+
#include <ostream>
2526
#include "system.h"
2627

2728
namespace ImagePNG {
2829
void ReadPNG(FILE* stream, const void* buffer, bool transparent, int& width, int& height, void*& pixels);
30+
bool WritePNG(std::ostream& os, int width, int height, uint32_t* data);
2931
}
3032

3133
#endif // SUPPORT_PNG

src/window_message.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
const int Window_Message::speed_table[21] = {0, 0, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
4444
7, 7, 8, 8, 9, 9, 10, 10, 11};
4545

46+
// C4428 is nonsense
47+
#ifdef _MSC_VER
48+
#pragma warning (disable : 4428)
49+
#endif
50+
4651
Window_Message::Window_Message(int ix, int iy, int iwidth, int iheight) :
4752
Window_Selectable(ix, iy, iwidth, iheight),
4853
contents_x(0), contents_y(0), line_count(0), text(""),
@@ -57,9 +62,9 @@ Window_Message::Window_Message(int ix, int iy, int iwidth, int iheight) :
5762
visible = false;
5863
SetZ(10000);
5964

60-
escape_char = (Player::escape_symbol == "\u00A5" ? L'¥' :
61-
(Player::escape_symbol == "\u20A9" ? L'' :
62-
'\\'));
65+
escape_char = (Player::escape_symbol == "\xC2\xA5" ? L'\u00A5' :
66+
(Player::escape_symbol == "\xE2\x82\xA9" ? L'\u20A9' :
67+
L'\\'));
6368
active = false;
6469
index = -1;
6570
text_color = Font::ColorDefault;

0 commit comments

Comments
 (0)