Used standard C++ fixed-width integer types instead of SDL-provided ones

More consistent this way. It's very unlikely the SDL defines would clash with the standard
C++ ones, even in SDL-related code.
This commit is contained in:
Charles Dang 2017-12-06 01:31:59 +11:00
parent 52421672e1
commit d09ad24037
38 changed files with 304 additions and 304 deletions

View file

@ -48,7 +48,7 @@ public:
/**
* The string color parameter is in the same format expected by the
* image::locator modifiers parameter. Examples: red is "red" or "FF0000" or "255,0,0".
* Feel free to add another method that accepts an Uint32 as a parameter instead.
* Feel free to add another method that accepts an uint32_t as a parameter instead.
*/
virtual void set_color(const std::string& color);

View file

@ -272,7 +272,7 @@ void controller_base::play_slice(bool is_delay_enabled)
const double joysticky = values.second;
int mousex, mousey;
Uint8 mouse_flags = SDL_GetMouseState(&mousex, &mousey);
uint8_t mouse_flags = SDL_GetMouseState(&mousex, &mousey);
// TODO enable after an axis choosing mechanism is implemented
#if 0

View file

@ -51,25 +51,25 @@ static SDL_Cursor* create_cursor(surface surf)
cursor_width += 8 - (cursor_width%8);
}
#endif
std::vector<Uint8> data((cursor_width*nsurf->h)/8,0);
std::vector<Uint8> mask(data.size(),0);
std::vector<uint8_t> data((cursor_width*nsurf->h)/8,0);
std::vector<uint8_t> mask(data.size(),0);
// See http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation
// on the format that data has to be in to pass to SDL_CreateCursor
const_surface_lock lock(nsurf);
const Uint32* const pixels = lock.pixels();
const uint32_t* const pixels = lock.pixels();
for(int y = 0; y != nsurf->h; ++y) {
for(int x = 0; x != nsurf->w; ++x) {
if (static_cast<size_t>(x) < cursor_width) {
Uint8 r,g,b,a;
uint8_t r,g,b,a;
SDL_GetRGBA(pixels[y*nsurf->w + x],nsurf->format,&r,&g,&b,&a);
const size_t index = y*cursor_width + x;
const size_t shift = 7 - (index % 8);
const Uint8 trans = (a < 128 ? 0 : 1) << shift;
const Uint8 black = (trans == 0 || (r+g + b) / 3 > 128 ? 0 : 1) << shift;
const uint8_t trans = (a < 128 ? 0 : 1) << shift;
const uint8_t black = (trans == 0 || (r+g + b) / 3 > 128 ? 0 : 1) << shift;
data[index/8] |= black;
mask[index/8] |= trans;

View file

@ -339,7 +339,7 @@ void mouse_action_paste::set_mouse_overlay(editor_display& disp)
SDL_Rect r {6, 6, 0, 0};
sdl_blit(image60, nullptr, image, &r);
Uint8 alpha = 196;
uint8_t alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
@ -457,7 +457,7 @@ void mouse_action_starting_position::set_mouse_overlay(editor_display& disp)
SDL_Rect r {6, 6, 0, 0};
sdl_blit(image60, nullptr, image, &r);
Uint8 alpha = 196;
uint8_t alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());

View file

@ -237,7 +237,7 @@ void mouse_action_item::set_item_mouse_overlay(editor_display& disp, const overl
// << team::get_side_color_id(disp.viewing_side()) << ')';
surface image(image::get_image(filename.str()));
Uint8 alpha = 196;
uint8_t alpha = 196;
//TODO don't hardcode
int size = 72;
//int size = image->w;

View file

@ -118,7 +118,7 @@ void mouse_action_map_label::set_mouse_overlay(editor_display& disp)
SDL_Rect r {6, 6, 0, 0};
sdl_blit(image60, nullptr, image, &r);
Uint8 alpha = 196;
uint8_t alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());

View file

@ -65,7 +65,7 @@ void mouse_action_select::set_mouse_overlay(editor_display& disp)
} else {
image = image::get_image("editor/tool-overlay-select-brush.png");
}
Uint8 alpha = 196;
uint8_t alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());

View file

@ -238,7 +238,7 @@ void mouse_action_unit::set_unit_mouse_overlay(editor_display& disp, const unit_
<< team::get_side_color_id(disp.viewing_side()) << ')';
surface image(image::get_image(filename.str()));
Uint8 alpha = 196;
uint8_t alpha = 196;
//TODO don't hardcode
int size = 72;
//int size = image->w;

View file

@ -47,7 +47,7 @@ void mouse_action_village::set_mouse_overlay(editor_display& disp)
SDL_Rect r {6, 6, 0, 0};
sdl_blit(image60, nullptr, image, &r);
Uint8 alpha = 196;
uint8_t alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());

View file

@ -378,7 +378,7 @@ bool has_focus(const sdl_handler* hand, const SDL_Event* event)
return false;
}
const Uint32 resize_timeout = 100;
const uint32_t resize_timeout = 100;
SDL_Event last_resize_event;
bool last_resize_event_used = true;
@ -469,7 +469,7 @@ void pump()
}
// remove all inputs, draw events and only keep the last of the resize events
// This will turn horrible after ~38 days when the Uint32 wraps.
// This will turn horrible after ~38 days when the uint32_t wraps.
if(resize_found || SDL_GetTicks() <= last_resize_event.window.timestamp + resize_timeout) {
events.erase(std::remove_if(events.begin(), events.end(), remove_on_resize), events.end());
} else if(SDL_GetTicks() > last_resize_event.window.timestamp + resize_timeout && !last_resize_event_used) {

View file

@ -25,13 +25,13 @@ static lg::log_domain log_filesystem("filesystem");
namespace filesystem {
// Arbitrary numbers larger than 5
static const Uint32 read_type = 7;
static const Uint32 write_type = 8;
static const uint32_t read_type = 7;
static const uint32_t write_type = 8;
static Sint64 ifs_size (struct SDL_RWops * context);
static Sint64 ofs_size (struct SDL_RWops * context);
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static Sint64 SDLCALL ofs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static int64_t ifs_size (struct SDL_RWops * context);
static int64_t ofs_size (struct SDL_RWops * context);
static int64_t SDLCALL ifs_seek(struct SDL_RWops *context, int64_t offset, int whence);
static int64_t SDLCALL ofs_seek(struct SDL_RWops *context, int64_t offset, int whence);
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ofs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num);
@ -85,7 +85,7 @@ rwops_ptr make_write_RWops(const std::string &path) {
return rw;
}
static Sint64 ifs_size (struct SDL_RWops * context) {
static int64_t ifs_size (struct SDL_RWops * context) {
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
std::streampos orig = ifs->tellg();
@ -97,7 +97,7 @@ static Sint64 ifs_size (struct SDL_RWops * context) {
return len;
}
static Sint64 ofs_size (struct SDL_RWops * context) {
static int64_t ofs_size (struct SDL_RWops * context) {
std::ostream *ofs = static_cast<std::ostream*>(context->hidden.unknown.data1);
std::streampos orig = ofs->tellp();
@ -110,22 +110,22 @@ static Sint64 ofs_size (struct SDL_RWops * context) {
return len;
}
typedef std::pair<Sint64, std::ios_base::seekdir> offset_dir;
typedef std::pair<int64_t, std::ios_base::seekdir> offset_dir;
static offset_dir translate_seekdir(Sint64 offset, int whence) {
static offset_dir translate_seekdir(int64_t offset, int whence) {
switch(whence){
case RW_SEEK_SET:
return std::make_pair(std::max<Sint64>(0, offset), std::ios_base::beg);
return std::make_pair(std::max<int64_t>(0, offset), std::ios_base::beg);
case RW_SEEK_CUR:
return std::make_pair(offset, std::ios_base::cur);
case RW_SEEK_END:
return std::make_pair(std::min<Sint64>(0, offset), std::ios_base::end);
return std::make_pair(std::min<int64_t>(0, offset), std::ios_base::end);
default:
assert(false);
throw "assertion ignored";
}
}
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
static int64_t SDLCALL ifs_seek(struct SDL_RWops *context, int64_t offset, int whence) {
std::ios_base::seekdir seekdir;
std::tie(offset, seekdir) = translate_seekdir(offset, whence);
@ -142,7 +142,7 @@ static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whe
std::streamsize pos = ifs->tellg();
return static_cast<int>(pos);
}
static Sint64 SDLCALL ofs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
static int64_t SDLCALL ofs_seek(struct SDL_RWops *context, int64_t offset, int whence) {
std::ios_base::seekdir seekdir;
std::tie(offset, seekdir) = translate_seekdir(offset, whence);

View file

@ -122,7 +122,7 @@ surface floating_label::create_surface()
return surf_ = foreground;
}
Uint32 color = SDL_MapRGBA(foreground->format, bgcolor_.r, bgcolor_.g, bgcolor_.b, bgalpha_);
uint32_t color = SDL_MapRGBA(foreground->format, bgcolor_.r, bgcolor_.g, bgcolor_.b, bgalpha_);
sdl::fill_surface_rect(background, nullptr, color);
// we make the text less transparent, because the blitting on the

View file

@ -88,7 +88,7 @@ std::string::const_iterator parse_markup(std::string::const_iterator i1,
// Very primitive parsing for rgb value
// should look like <213,14,151>
++i1;
Uint8 red=0, green=0, blue=0, temp=0;
uint8_t red=0, green=0, blue=0, temp=0;
while (i1 != i2 && *i1 >= '0' && *i1<='9') {
temp*=10;
temp += lexical_cast<int, char>(*i1);

View file

@ -598,7 +598,7 @@ struct inverse_table
}
}
unsigned operator[](Uint8 i) const { return values[i]; }
unsigned operator[](uint8_t i) const { return values[i]; }
};
static const inverse_table inverse_table_;
@ -607,7 +607,7 @@ static const inverse_table inverse_table_;
* Helper function for un-premultiplying alpha
* Div should be the high-precision inverse for the alpha value.
*/
static void unpremultiply(Uint8 & value, const unsigned div) {
static void unpremultiply(uint8_t & value, const unsigned div) {
unsigned temp = (value * div) / 256u;
// Note: It's always the case that alpha * div < 256 if div is the inverse
// for alpha, so if cairo is computing premultiplied alpha by rounding down,
@ -623,19 +623,19 @@ static void unpremultiply(Uint8 & value, const unsigned div) {
* Converts from cairo-format ARGB32 premultiplied alpha to plain alpha.
* @param c a uint32 representing the color
*/
static void from_cairo_format(Uint32 & c)
static void from_cairo_format(uint32_t & c)
{
Uint8 a = (c >> 24) & 0xff;
Uint8 r = (c >> 16) & 0xff;
Uint8 g = (c >> 8) & 0xff;
Uint8 b = c & 0xff;
uint8_t a = (c >> 24) & 0xff;
uint8_t r = (c >> 16) & 0xff;
uint8_t g = (c >> 8) & 0xff;
uint8_t b = c & 0xff;
const unsigned div = inverse_table_[a];
unpremultiply(r, div);
unpremultiply(g, div);
unpremultiply(b, div);
c = (static_cast<Uint32>(a) << 24) | (static_cast<Uint32>(r) << 16) | (static_cast<Uint32>(g) << 8) | static_cast<Uint32>(b);
c = (static_cast<uint32_t>(a) << 24) | (static_cast<uint32_t>(r) << 16) | (static_cast<uint32_t>(g) << 8) | static_cast<uint32_t>(b);
}
void pango_text::render(PangoLayout& layout, const PangoRectangle& rect, const size_t surface_buffer_offset, const unsigned stride)
@ -706,12 +706,12 @@ void pango_text::rerender(const bool force)
render(*layout_, rect_, 0u, stride);
static_assert(sizeof(Uint32) == 4, "Something is wrong with our typedefs");
static_assert(sizeof(uint32_t) == 4, "Something is wrong with our typedefs");
// The cairo surface is in CAIRO_FORMAT_ARGB32 which uses
// pre-multiplied alpha. SDL doesn't use that so the pixels need to be
// decoded again.
Uint32 * pixels = reinterpret_cast<Uint32 *>(&surface_buffer_[0]);
uint32_t * pixels = reinterpret_cast<uint32_t *>(&surface_buffer_[0]);
for(int y = 0; y < height; ++y) {
for(int x = 0; x < width; ++x) {

View file

@ -56,7 +56,7 @@ namespace event
*
* @returns The new timer interval, 0 to stop.
*/
static Uint32 popup_callback(Uint32 /*interval*/, void* /*param*/)
static uint32_t popup_callback(uint32_t /*interval*/, void* /*param*/)
{
DBG_GUI_E << "Pushing popup removal event in queue.\n";
@ -506,7 +506,7 @@ void mouse_button<T>::signal_handler_sdl_button_up(const event::ui_event event,
template<typename T>
void mouse_button<T>::mouse_button_click(widget* widget)
{
Uint32 stamp = SDL_GetTicks();
uint32_t stamp = SDL_GetTicks();
if(last_click_stamp_ + settings::double_click_time >= stamp
&& last_clicked_widget_ == widget) {
@ -589,7 +589,7 @@ distributor::~distributor()
void distributor::initialize_state()
{
const Uint8 button_state = SDL_GetMouseState(nullptr, nullptr);
const uint8_t button_state = SDL_GetMouseState(nullptr, nullptr);
mouse_button_left::initialize_state((button_state & SDL_BUTTON(1)) != 0);
mouse_button_middle::initialize_state((button_state & SDL_BUTTON(2)) != 0);

View file

@ -189,7 +189,7 @@ public:
protected:
/** The time of the last click used for double clicking. */
Uint32 last_click_stamp_;
uint32_t last_click_stamp_;
/** The widget the last click was on, used for double clicking. */
widget* last_clicked_widget_;

View file

@ -75,7 +75,7 @@ static unsigned event_poll_interval = 0;
*
* @returns The new timer interval, 0 to stop.
*/
static Uint32 timer_sdl_draw_event(Uint32, void*)
static uint32_t timer_sdl_draw_event(uint32_t, void*)
{
// DBG_GUI_E << "Pushing draw event in queue.\n";
@ -96,7 +96,7 @@ static Uint32 timer_sdl_draw_event(Uint32, void*)
*
* @returns The new timer interval, 0 to stop.
*/
static Uint32 timer_sdl_poll_events(Uint32, void*)
static uint32_t timer_sdl_poll_events(uint32_t, void*)
{
try
{
@ -195,7 +195,7 @@ private:
* @param button The SDL id of the button that caused the
* event.
*/
void mouse_button_up(const point& position, const Uint8 button);
void mouse_button_up(const point& position, const uint8_t button);
/**
* Fires a mouse button down event.
@ -204,7 +204,7 @@ private:
* @param button The SDL id of the button that caused the
* event.
*/
void mouse_button_down(const point& position, const Uint8 button);
void mouse_button_down(const point& position, const uint8_t button);
/**
* Fires a mouse wheel event.
@ -460,7 +460,7 @@ void sdl_event_handler::handle_event(const SDL_Event& event)
default:
#ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
WRN_GUI_E << "Unhandled event " << static_cast<Uint32>(event.type)
WRN_GUI_E << "Unhandled event " << static_cast<uint32_t>(event.type)
<< ".\n";
#endif
break;
@ -598,7 +598,7 @@ void sdl_event_handler::mouse(const ui_event event, const point& position)
}
}
void sdl_event_handler::mouse_button_up(const point& position, const Uint8 button)
void sdl_event_handler::mouse_button_up(const point& position, const uint8_t button)
{
switch(button) {
case SDL_BUTTON_LEFT:
@ -613,13 +613,13 @@ void sdl_event_handler::mouse_button_up(const point& position, const Uint8 butto
default:
#ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
WRN_GUI_E << "Unhandled 'mouse button up' event for button "
<< static_cast<Uint32>(button) << ".\n";
<< static_cast<uint32_t>(button) << ".\n";
#endif
break;
}
}
void sdl_event_handler::mouse_button_down(const point& position, const Uint8 button)
void sdl_event_handler::mouse_button_down(const point& position, const uint8_t button)
{
switch(button) {
case SDL_BUTTON_LEFT:
@ -634,7 +634,7 @@ void sdl_event_handler::mouse_button_down(const point& position, const Uint8 but
default:
#ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
WRN_GUI_E << "Unhandled 'mouse button down' event for button "
<< static_cast<Uint32>(button) << ".\n";
<< static_cast<uint32_t>(button) << ".\n";
#endif
break;
}

View file

@ -31,7 +31,7 @@ struct timer
}
SDL_TimerID sdl_id;
Uint32 interval;
uint32_t interval;
std::function<void(size_t id)> callback;
};
@ -84,7 +84,7 @@ public:
extern "C" {
static Uint32 timer_callback(Uint32, void* id)
static uint32_t timer_callback(uint32_t, void* id)
{
DBG_GUI_E << "Pushing timer event in queue.\n";
@ -108,7 +108,7 @@ static Uint32 timer_callback(Uint32, void* id)
} // extern "C"
size_t add_timer(const Uint32 interval,
size_t add_timer(const uint32_t interval,
const std::function<void(size_t id)>& callback,
const bool repeat)
{

View file

@ -49,7 +49,7 @@ namespace gui2
* @returns The id of the timer.
* @retval [0] Failed to create a timer.
*/
size_t add_timer(const Uint32 interval,
size_t add_timer(const uint32_t interval,
const std::function<void(size_t id)>& callback,
const bool repeat = false);

View file

@ -148,7 +148,7 @@ static void push_draw_event()
*
* @return The new timer interval (always 0).
*/
static Uint32 delay_event_callback(const Uint32, void* event)
static uint32_t delay_event_callback(const uint32_t, void* event)
{
SDL_PushEvent(static_cast<SDL_Event*>(event));
delete static_cast<SDL_Event*>(event);
@ -164,7 +164,7 @@ static Uint32 delay_event_callback(const Uint32, void* event)
* @param event The event to delay.
* @param delay The number of ms to delay the event.
*/
static void delay_event(const SDL_Event& event, const Uint32 delay)
static void delay_event(const SDL_Event& event, const uint32_t delay)
{
SDL_AddTimer(delay, delay_event_callback, new SDL_Event(event));
}

View file

@ -224,7 +224,7 @@ surface wipe_alpha_modification::operator()(const surface& src) const
class pixel_callable : public wfl::formula_callable
{
public:
pixel_callable(SDL_Point p, color_t clr, Uint32 w, Uint32 h)
pixel_callable(SDL_Point p, color_t clr, uint32_t w, uint32_t h)
: p(p), clr(clr), w(w), h(h)
{}
@ -267,7 +267,7 @@ public:
private:
SDL_Point p;
color_t clr;
Uint32 w, h;
uint32_t w, h;
};
surface adjust_alpha_modification::operator()(const surface & src) const
@ -287,9 +287,9 @@ surface adjust_alpha_modification::operator()(const surface & src) const
{
surface_lock lock(nsurf);
Uint32* cur = lock.pixels();
Uint32* const end = cur + nsurf->w * src->h;
Uint32* const beg = cur;
uint32_t* cur = lock.pixels();
uint32_t* const end = cur + nsurf->w * src->h;
uint32_t* const beg = cur;
while(cur != end) {
color_t pixel;
@ -334,9 +334,9 @@ surface adjust_channels_modification::operator()(const surface & src) const
{
surface_lock lock(nsurf);
Uint32* cur = lock.pixels();
Uint32* const end = cur + nsurf->w * src->h;
Uint32* const beg = cur;
uint32_t* cur = lock.pixels();
uint32_t* const end = cur + nsurf->w * src->h;
uint32_t* const beg = cur;
while(cur != end) {
color_t pixel;
@ -541,18 +541,18 @@ surface o_modification::operator()(const surface& src) const
return nullptr;
}
Uint16 amount = ftofxp(opacity_);
uint16_t amount = ftofxp(opacity_);
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w * src->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w * src->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -982,16 +982,16 @@ REGISTER_MOD_PARSER(CROP, args)
SDL_Rect slice_rect { 0, 0, 0, 0 };
slice_rect.x = lexical_cast_default<Sint16, const std::string&>(slice_params[0]);
slice_rect.x = lexical_cast_default<int16_t, const std::string&>(slice_params[0]);
if(s > 1) {
slice_rect.y = lexical_cast_default<Sint16, const std::string&>(slice_params[1]);
slice_rect.y = lexical_cast_default<int16_t, const std::string&>(slice_params[1]);
}
if(s > 2) {
slice_rect.w = lexical_cast_default<Uint16, const std::string&>(slice_params[2]);
slice_rect.w = lexical_cast_default<uint16_t, const std::string&>(slice_params[2]);
}
if(s > 3) {
slice_rect.h = lexical_cast_default<Uint16, const std::string&>(slice_params[3]);
slice_rect.h = lexical_cast_default<uint16_t, const std::string&>(slice_params[3]);
}
return new crop_modification(slice_rect);

View file

@ -230,7 +230,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
}
}
SDL_Rect fillrect {maprect.x, maprect.y, scale * 3/4, scale};
const Uint32 mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
const uint32_t mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
sdl::fill_surface_rect(minimap, &fillrect, mapped_col);
}
}
@ -270,7 +270,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
, scale
};
const Uint32 mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
const uint32_t mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
sdl::fill_surface_rect(minimap, &fillrect, mapped_col);
}

View file

@ -440,7 +440,7 @@ bool savegame::save_game(const std::string& filename)
{
try {
Uint32 start, end;
uint32_t start, end;
start = SDL_GetTicks();
if (filename_.empty())

View file

@ -112,7 +112,7 @@ void fill_rectangle(const SDL_Rect& rect, const color_t& color);
* @param dst_rect The rectangle to fill.
* @param color Color of the rectangle.
*/
inline void fill_surface_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color)
inline void fill_surface_rect(surface& dst, SDL_Rect* dst_rect, const uint32_t color)
{
SDL_FillRect(dst, dst_rect, color);
}

View file

@ -128,7 +128,7 @@ template<typename T>
class surface_locker
{
private:
using pixel_t = utils::const_clone_t<Uint32, T>;
using pixel_t = utils::const_clone_t<uint32_t, T>;
public:
surface_locker(T& surf) : surface_(surf), locked_(false)

View file

@ -133,11 +133,11 @@ surface stretch_surface_horizontal(
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* dst_pixels = dst_lock.pixels();
for(unsigned y = 0; y < static_cast<unsigned>(src->h); ++y) {
const Uint32 pixel = src_pixels [y * src->w];
const uint32_t pixel = src_pixels [y * src->w];
for(unsigned x = 0; x < w; ++x) {
*dst_pixels++ = pixel;
@ -178,8 +178,8 @@ surface stretch_surface_vertical(
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* dst_pixels = dst_lock.pixels();
for(unsigned y = 0; y < static_cast<unsigned>(h); ++y) {
for(unsigned x = 0; x < static_cast<unsigned>(src->w); ++x) {
@ -304,8 +304,8 @@ surface scale_surface(const surface &surf, int w, int h)
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* const dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* const dst_pixels = dst_lock.pixels();
fixed_t xratio = fxpdiv(surf->w,w);
fixed_t yratio = fxpdiv(surf->h,h);
@ -317,15 +317,15 @@ surface scale_surface(const surface &surf, int w, int h)
const int xsrcint = fxptoi(xsrc);
const int ysrcint = fxptoi(ysrc);
const Uint32* const src_word = src_pixels + ysrcint*src->w + xsrcint;
Uint32* const dst_word = dst_pixels + ydst*dst->w + xdst;
const uint32_t* const src_word = src_pixels + ysrcint*src->w + xsrcint;
uint32_t* const dst_word = dst_pixels + ydst*dst->w + xdst;
const int dx = (xsrcint + 1 < src->w) ? 1 : 0;
const int dy = (ysrcint + 1 < src->h) ? src->w : 0;
Uint8 r,g,b,a;
Uint32 rr,gg,bb,aa, temp;
uint8_t r,g,b,a;
uint32_t rr,gg,bb,aa, temp;
Uint32 pix[4], bilin[4];
uint32_t pix[4], bilin[4];
// This next part is the fixed point
// equivalent of "take everything to
@ -431,8 +431,8 @@ surface scale_surface_legacy(const surface &surf, int w, int h)
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* const dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* const dst_pixels = dst_lock.pixels();
fixed_t xratio = fxpdiv(surf->w,w);
fixed_t yratio = fxpdiv(surf->h,h);
@ -444,15 +444,15 @@ surface scale_surface_legacy(const surface &surf, int w, int h)
const int xsrcint = fxptoi(xsrc);
const int ysrcint = fxptoi(ysrc);
const Uint32* const src_word = src_pixels + ysrcint*src->w + xsrcint;
Uint32* const dst_word = dst_pixels + ydst*dst->w + xdst;
const uint32_t* const src_word = src_pixels + ysrcint*src->w + xsrcint;
uint32_t* const dst_word = dst_pixels + ydst*dst->w + xdst;
const int dx = (xsrcint + 1 < src->w) ? 1 : 0;
const int dy = (ysrcint + 1 < src->h) ? src->w : 0;
Uint8 r,g,b,a;
Uint32 rr,gg,bb,aa;
Uint16 avg_r, avg_g, avg_b;
Uint32 pix[4], bilin[4];
uint8_t r,g,b,a;
uint32_t rr,gg,bb,aa;
uint16_t avg_r, avg_g, avg_b;
uint32_t pix[4], bilin[4];
// This next part is the fixed point
// equivalent of "take everything to
@ -521,9 +521,9 @@ surface scale_surface_legacy(const surface &surf, int w, int h)
g = pix[loc] >> 8;
b = pix[loc] >> 0;
if (a == 0) {
r = static_cast<Uint8>(avg_r);
g = static_cast<Uint8>(avg_g);
b = static_cast<Uint8>(avg_b);
r = static_cast<uint8_t>(avg_r);
g = static_cast<uint8_t>(avg_g);
b = static_cast<uint8_t>(avg_b);
}
rr += r * bilin[loc];
gg += g * bilin[loc];
@ -576,8 +576,8 @@ surface scale_surface_sharp(const surface& surf, int w, int h)
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* const dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* const dst_pixels = dst_lock.pixels();
float xratio = static_cast<float>(surf->w) / w;
float yratio = static_cast<float>(surf->h) / h;
@ -600,7 +600,7 @@ surface scale_surface_sharp(const surface& surf, int w, int h)
const int ysrcint = std::max<int>(0,std::min<int>(src->h-1,static_cast<int>(ysrc)));
const float ysize = std::min<float>(std::floor(yloc+1)-yloc,ysrc+yratio-yloc);
Uint8 r,g,b,a;
uint8_t r,g,b,a;
SDL_GetRGBA(src_pixels[ysrcint*src->w + xsrcint],src->format,&r,&g,&b,&a);
float value = xsize * ysize;
@ -654,8 +654,8 @@ surface tile_surface(const surface& surf, int w, int h, bool centered)
const_surface_lock srclock(src);
surface_lock destlock(dest);
const Uint32* srcpixels = srclock.pixels();
Uint32* destpixels = destlock.pixels();
const uint32_t* srcpixels = srclock.pixels();
uint32_t* destpixels = destlock.pixels();
const int& sw = src->w;
const int& sh = src->h;
@ -699,14 +699,14 @@ surface adjust_surface_color(const surface &surf, int red, int green, int blue)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg) >> 0;
@ -738,27 +738,27 @@ surface greyscale_image(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
//const Uint8 avg = (red+green+blue)/3;
//const uint8_t avg = (red+green+blue)/3;
// Use the correct formula for RGB to grayscale conversion.
// Ok, this is no big deal :)
// The correct formula being:
// gray=0.299red+0.587green+0.114blue
const Uint8 avg = static_cast<Uint8>((
77 * static_cast<Uint16>(r) +
150 * static_cast<Uint16>(g) +
29 * static_cast<Uint16>(b) ) / 256);
const uint8_t avg = static_cast<uint8_t>((
77 * static_cast<uint16_t>(r) +
150 * static_cast<uint16_t>(g) +
29 * static_cast<uint16_t>(b) ) / 256);
*beg = (alpha << 24) | (avg << 16) | (avg << 8) | avg;
}
@ -783,14 +783,14 @@ surface monochrome_image(const surface &surf, const int threshold)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b, result;
uint8_t r, g, b, result;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -798,7 +798,7 @@ surface monochrome_image(const surface &surf, const int threshold)
// first convert the pixel to grayscale
// if the resulting value is above the threshold make it black
// else make it white
result = static_cast<Uint8>(0.299 * r + 0.587 * g + 0.114 * b) > threshold ? 255 : 0;
result = static_cast<uint8_t>(0.299 * r + 0.587 * g + 0.114 * b) > threshold ? 255 : 0;
*beg = (alpha << 24) | (result << 16) | (result << 8) | result;
}
@ -823,14 +823,14 @@ surface sepia_image(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -838,9 +838,9 @@ surface sepia_image(const surface &surf)
// this is the formula for applying a sepia effect
// that can be found on various web sites
// for example here: https://software.intel.com/sites/default/files/article/346220/sepiafilter-intelcilkplus.pdf
Uint8 outRed = std::min(255, static_cast<int>((r * 0.393) + (g * 0.769) + (b * 0.189)));
Uint8 outGreen = std::min(255, static_cast<int>((r * 0.349) + (g * 0.686) + (b * 0.168)));
Uint8 outBlue = std::min(255, static_cast<int>((r * 0.272) + (g * 0.534) + (b * 0.131)));
uint8_t outRed = std::min(255, static_cast<int>((r * 0.393) + (g * 0.769) + (b * 0.189)));
uint8_t outGreen = std::min(255, static_cast<int>((r * 0.349) + (g * 0.686) + (b * 0.168)));
uint8_t outBlue = std::min(255, static_cast<int>((r * 0.272) + (g * 0.534) + (b * 0.131)));
*beg = (alpha << 24) | (outRed << 16) | (outGreen << 8) | (outBlue);
}
@ -865,14 +865,14 @@ surface negative_image(const surface &surf, const int thresholdR, const int thre
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b, newR, newG, newB;
uint8_t r, g, b, newR, newG, newB;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -880,7 +880,7 @@ surface negative_image(const surface &surf, const int thresholdR, const int thre
// invert he channel only if its value is greater than the supplied threshold
// this can be used for solarization effects
// for a full negative effect, use a value of -1
// 255 is a no-op value (doesn't do anything, since a Uint8 cannot contain a greater value than that)
// 255 is a no-op value (doesn't do anything, since a uint8_t cannot contain a greater value than that)
newR = r > thresholdR ? 255 - r : r;
newG = g > thresholdG ? 255 - g : g;
newB = b > thresholdB ? 255 - b : b;
@ -908,11 +908,11 @@ surface alpha_to_greyscale(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
*beg = (0xff << 24) | (alpha << 16) | (alpha << 8) | alpha;
@ -936,8 +936,8 @@ surface wipe_alpha(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
@ -966,11 +966,11 @@ surface shadow_image(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
// increase alpha and color in black (RGB=0)
@ -1000,14 +1000,14 @@ surface swap_channels_image(const surface& surf, channel r, channel g, channel b
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 red, green, blue, newRed, newGreen, newBlue, newAlpha;
uint8_t red, green, blue, newRed, newGreen, newBlue, newAlpha;
red = (*beg) >> 16;
green = (*beg) >> 8;
blue = (*beg);
@ -1106,16 +1106,16 @@ surface recolor_image(surface surf, const color_range_map& map_rgb)
}
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
// Don't recolor invisible pixels.
if(alpha) {
// Palette use only RGB channels, so remove alpha
Uint32 oldrgb = (*beg) | 0xFF000000;
uint32_t oldrgb = (*beg) | 0xFF000000;
auto i = map_rgb.find(color_t::from_argb_bytes(oldrgb));
if(i != map_rgb.end()) {
@ -1144,15 +1144,15 @@ surface brighten_image(const surface &surf, fixed_t amount)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
if (amount < 0) amount = 0;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -1177,7 +1177,7 @@ void adjust_surface_alpha(surface& surf, fixed_t amount)
return;
}
SDL_SetSurfaceAlphaMod(surf, Uint8(amount));
SDL_SetSurfaceAlphaMod(surf, uint8_t(amount));
}
surface adjust_surface_alpha_add(const surface &surf, int amount)
@ -1195,19 +1195,19 @@ surface adjust_surface_alpha_add(const surface &surf, int amount)
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
alpha = Uint8(std::max<int>(0,std::min<int>(255,int(alpha) + amount)));
alpha = uint8_t(std::max<int>(0,std::min<int>(255,int(alpha) + amount)));
*beg = (alpha << 24) + (r << 16) + (g << 8) + b;
}
@ -1253,21 +1253,21 @@ surface mask_surface(const surface &surf, const surface &mask, bool* empty_resul
surface_lock lock(nsurf);
const_surface_lock mlock(nmask);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
const Uint32* mbeg = mlock.pixels();
const Uint32* mend = mbeg + nmask->w*nmask->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
const uint32_t* mbeg = mlock.pixels();
const uint32_t* mend = mbeg + nmask->w*nmask->h;
while(beg != end && mbeg != mend) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
Uint8 malpha = (*mbeg) >> 24;
uint8_t malpha = (*mbeg) >> 24;
if (alpha > malpha) {
alpha = malpha;
}
@ -1313,15 +1313,15 @@ bool in_mask_surface(const surface &surf, const surface &mask)
surface_lock lock(nsurf);
const_surface_lock mlock(nmask);
const Uint32* mbeg = mlock.pixels();
const Uint32* mend = mbeg + nmask->w*nmask->h;
Uint32* beg = lock.pixels();
const uint32_t* mbeg = mlock.pixels();
const uint32_t* mend = mbeg + nmask->w*nmask->h;
uint32_t* beg = lock.pixels();
// no need for 'end', because both surfaces have same size
while(mbeg != mend) {
Uint8 malpha = (*mbeg) >> 24;
uint8_t malpha = (*mbeg) >> 24;
if(malpha == 0) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if (alpha)
return false;
}
@ -1344,16 +1344,16 @@ surface submerge_alpha(const surface &surf, int depth, float alpha_base, float a
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* limit = beg + (nsurf->h-depth) * nsurf->w ;
Uint32* end = beg + nsurf->w * nsurf->h;
uint32_t* beg = lock.pixels();
uint32_t* limit = beg + (nsurf->h-depth) * nsurf->w ;
uint32_t* end = beg + nsurf->w * nsurf->h;
beg = limit; // directlt jump to the bottom part
while(beg != end){
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -1369,16 +1369,16 @@ surface submerge_alpha(const surface &surf, int depth, float alpha_base, float a
/*
for(int y = submerge_height; y < nsurf->h; ++y) {
Uint32* cur = beg + y * nsurf->w;
Uint32* row_end = beg + (y+1) * nsurf->w;
uint32_t* cur = beg + y * nsurf->w;
uint32_t* row_end = beg + (y+1) * nsurf->w;
float d = y * 1.0 / depth;
double a = 0.2;//std::max<double>(0, (1-d)*0.3);
fixed_t amount = ftofxp(a);
while(cur != row_end) {
Uint8 alpha = (*cur) >> 24;
uint8_t alpha = (*cur) >> 24;
if(alpha) {
Uint8 r, g, b;
uint8_t r, g, b;
r = (*cur) >> 16;
g = (*cur) >> 8;
b = (*cur);
@ -1423,21 +1423,21 @@ surface light_surface(const surface &surf, const surface &lightmap)
surface_lock lock(nsurf);
const_surface_lock llock(lightmap);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w * nsurf->h;
const Uint32* lbeg = llock.pixels();
const Uint32* lend = lbeg + lightmap->w * lightmap->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w * nsurf->h;
const uint32_t* lbeg = llock.pixels();
const uint32_t* lend = lbeg + lightmap->w * lightmap->h;
while(beg != end && lbeg != lend) {
Uint8 alpha = (*beg) >> 24;
uint8_t alpha = (*beg) >> 24;
if(alpha) {
Uint8 lr, lg, lb;
uint8_t lr, lg, lb;
lr = (*lbeg) >> 16;
lg = (*lbeg) >> 8;
lb = (*lbeg);
Uint8 r, g, b;
uint8_t r, g, b;
r = (*beg) >> 16;
g = (*beg) >> 8;
b = (*beg);
@ -1445,7 +1445,7 @@ surface light_surface(const surface &surf, const surface &lightmap)
int dr = (static_cast<int>(lr) - 128) * 2;
int dg = (static_cast<int>(lg) - 128) * 2;
int db = (static_cast<int>(lb) - 128) * 2;
//note that r + dr will promote r to int (needed to avoid Uint8 math)
//note that r + dr will promote r to int (needed to avoid uint8_t math)
r = std::max<int>(0,std::min<int>(255, r + dr));
g = std::max<int>(0,std::min<int>(255, g + dg));
b = std::max<int>(0,std::min<int>(255, b + db));
@ -1491,19 +1491,19 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth)
depth = max_blur;
}
Uint32 queue[max_blur];
const Uint32* end_queue = queue + max_blur;
uint32_t queue[max_blur];
const uint32_t* end_queue = queue + max_blur;
const Uint32 ff = 0xff;
const uint32_t ff = 0xff;
const unsigned pixel_offset = rect.y * surf->w + rect.x;
surface_lock lock(surf);
for(int y = 0; y < rect.h; ++y) {
const Uint32* front = &queue[0];
Uint32* back = &queue[0];
Uint32 red = 0, green = 0, blue = 0, avg = 0;
Uint32* p = lock.pixels() + pixel_offset + y * surf->w;
const uint32_t* front = &queue[0];
uint32_t* back = &queue[0];
uint32_t red = 0, green = 0, blue = 0, avg = 0;
uint32_t* p = lock.pixels() + pixel_offset + y * surf->w;
for(int x = 0; x <= depth && x < rect.w; ++x, ++p) {
red += ((*p) >> 16)&0xFF;
green += ((*p) >> 8)&0xFF;
@ -1534,7 +1534,7 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth)
}
if(x + depth+1 < rect.w) {
Uint32* q = p + depth+1;
uint32_t* q = p + depth+1;
red += ((*q) >> 16)&0xFF;
green += ((*q) >> 8)&0xFF;
blue += (*q)&0xFF;
@ -1548,10 +1548,10 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth)
}
for(int x = 0; x < rect.w; ++x) {
const Uint32* front = &queue[0];
Uint32* back = &queue[0];
Uint32 red = 0, green = 0, blue = 0, avg = 0;
Uint32* p = lock.pixels() + pixel_offset + x;
const uint32_t* front = &queue[0];
uint32_t* back = &queue[0];
uint32_t red = 0, green = 0, blue = 0, avg = 0;
uint32_t* p = lock.pixels() + pixel_offset + x;
for(int y = 0; y <= depth && y < rect.h; ++y, p += surf->w) {
red += ((*p) >> 16)&0xFF;
green += ((*p) >> 8)&0xFF;
@ -1582,7 +1582,7 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth)
}
if(y + depth+1 < rect.h) {
Uint32* q = p + (depth+1)*surf->w;
uint32_t* q = p + (depth+1)*surf->w;
red += ((*q) >> 16)&0xFF;
green += ((*q) >> 8)&0xFF;
blue += (*q)&0xFF;
@ -1615,21 +1615,21 @@ surface blur_alpha_surface(const surface &surf, int depth)
}
struct Pixel{
Uint8 alpha;
Uint8 red;
Uint8 green;
Uint8 blue;
Pixel(Uint32* p)
uint8_t alpha;
uint8_t red;
uint8_t green;
uint8_t blue;
Pixel(uint32_t* p)
: alpha(((*p) >> 24)&0xFF)
, red(((*p) >> 16)&0xFF)
, green(((*p) >> 8)&0xFF)
, blue((*p)&0xFF) {}
};
struct Average{
Uint32 alpha;
Uint32 red;
Uint32 green;
Uint32 blue;
uint32_t alpha;
uint32_t red;
uint32_t green;
uint32_t blue;
Average() : alpha(), red(), green(), blue()
{}
Average& operator+=(const Pixel& pix){
@ -1646,8 +1646,8 @@ surface blur_alpha_surface(const surface &surf, int depth)
alpha -= pix.alpha;
return *this;
}
Uint32 operator()(unsigned num){
const Uint32 ff = 0xff;
uint32_t operator()(unsigned num){
const uint32_t ff = 0xff;
if(!alpha){
return 0;
}
@ -1668,7 +1668,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
Average avg;
// Preload the first depth+1 pixels
Uint32* p = lock.pixels() + y*res->w;
uint32_t* p = lock.pixels() + y*res->w;
for(x = 0; x <= depth && x < res->w; ++x, ++p) {
assert(!queue.full());
queue.push_back(Pixel{p});
@ -1679,7 +1679,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
p = lock.pixels() + y*res->w;
for(x = 0; x < res->w; ++x, ++p) {
// Write the current average
const Uint32 num = queue.size();
const uint32_t num = queue.size();
*p = avg(num);
// Unload earlier pixels that are now too far away
@ -1691,7 +1691,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
// Add new pixels
if(x + depth+1 < res->w) {
Uint32* q = p + depth+1;
uint32_t* q = p + depth+1;
assert(!queue.full());
queue.push_back(Pixel{q});
avg += queue.back();
@ -1707,7 +1707,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
Average avg;
// Preload the first depth+1 pixels
Uint32* p = lock.pixels() + x;
uint32_t* p = lock.pixels() + x;
for(y = 0; y <= depth && y < res->h; ++y, p += res->w) {
assert(!queue.full());
queue.push_back(Pixel{p});
@ -1718,7 +1718,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
p = lock.pixels() + x;
for(y = 0; y < res->h; ++y, p += res->w) {
// Write the current average
const Uint32 num = queue.size();
const uint32_t num = queue.size();
*p = avg(num);
// Unload earlier pixels that are now too far away
@ -1730,7 +1730,7 @@ surface blur_alpha_surface(const surface &surf, int depth)
// Add new pixels
if(y + depth+1 < res->h) {
Uint32* q = p + (depth+1)*res->w;
uint32_t* q = p + (depth+1)*res->w;
assert(!queue.full());
queue.push_back(Pixel{q});
avg += queue.back();
@ -1787,12 +1787,12 @@ surface cut_surface(const surface &surf, SDL_Rect const &r)
const_surface_lock slock(surf);
surface_lock rlock(res);
const Uint8* src = reinterpret_cast<const Uint8 *>(slock.pixels());
Uint8* dest = reinterpret_cast<Uint8 *>(rlock.pixels());
const uint8_t* src = reinterpret_cast<const uint8_t *>(slock.pixels());
uint8_t* dest = reinterpret_cast<uint8_t *>(rlock.pixels());
for(int y = 0; y < src_rect.h && (src_rect.y + y) < surf->h; ++y) {
const Uint8* line_src = src + (src_rect.y + y) * spitch + src_rect.x * sbpp;
Uint8* line_dest = dest + (dst_rect.y + y) * rpitch + dst_rect.x * rbpp;
const uint8_t* line_src = src + (src_rect.y + y) * spitch + src_rect.x * sbpp;
uint8_t* line_dest = dest + (dst_rect.y + y) * rpitch + dst_rect.x * rbpp;
size_t size = src_rect.w + src_rect.x <= surf->w ? src_rect.w : surf->w - src_rect.x;
assert(rpitch >= src_rect.w * rbpp);
@ -1819,20 +1819,20 @@ surface blend_surface(
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
uint32_t* beg = lock.pixels();
uint32_t* end = beg + nsurf->w*surf->h;
Uint16 ratio = amount * 256;
const Uint16 red = ratio * color.r;
const Uint16 green = ratio * color.g;
const Uint16 blue = ratio * color.b;
uint16_t ratio = amount * 256;
const uint16_t red = ratio * color.r;
const uint16_t green = ratio * color.g;
const uint16_t blue = ratio * color.b;
ratio = 256 - ratio;
while(beg != end) {
Uint8 a = static_cast<Uint8>(*beg >> 24);
Uint8 r = (ratio * static_cast<Uint8>(*beg >> 16) + red) >> 8;
Uint8 g = (ratio * static_cast<Uint8>(*beg >> 8) + green) >> 8;
Uint8 b = (ratio * static_cast<Uint8>(*beg) + blue) >> 8;
uint8_t a = static_cast<uint8_t>(*beg >> 24);
uint8_t r = (ratio * static_cast<uint8_t>(*beg >> 16) + red) >> 8;
uint8_t g = (ratio * static_cast<uint8_t>(*beg >> 8) + green) >> 8;
uint8_t b = (ratio * static_cast<uint8_t>(*beg) + blue) >> 8;
*beg = (a << 24) | (r << 16) | (g << 8) | b;
@ -1905,17 +1905,17 @@ surface rotate_any_surface(const surface& surf, float angle, int zoom, int offse
return dst;
}
void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, Uint32 pixel)
void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, uint32_t pixel)
{
const int bpp = surf->format->BytesPerPixel;
/* dst is the address to the pixel we want to set */
Uint8* const dst = reinterpret_cast<Uint8*>(surf_lock.pixels()) + y * surf->pitch + x * bpp;
uint8_t* const dst = reinterpret_cast<uint8_t*>(surf_lock.pixels()) + y * surf->pitch + x * bpp;
switch (bpp) {
case 1:
*dst = pixel;
break;
case 2:
*reinterpret_cast<Uint16*>(dst) = pixel;
*reinterpret_cast<uint16_t*>(dst) = pixel;
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
@ -1929,23 +1929,23 @@ void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, Uint3
}
break;
case 4:
*reinterpret_cast<Uint32*>(dst) = pixel;
*reinterpret_cast<uint32_t*>(dst) = pixel;
break;
default:
break;
}
}
Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y)
uint32_t get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y)
{
const int bpp = surf->format->BytesPerPixel;
/* p is the address to the pixel we want to retrieve */
const Uint8* const src = reinterpret_cast<const Uint8*>(surf_lock.pixels()) + y * surf->pitch + x * bpp;
const uint8_t* const src = reinterpret_cast<const uint8_t*>(surf_lock.pixels()) + y * surf->pitch + x * bpp;
switch (bpp) {
case 1:
return *src;
case 2:
return *reinterpret_cast<const Uint16*>(src);
return *reinterpret_cast<const uint16_t*>(src);
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return src[0] << 16 | src[1] << 8 | src[2];
@ -1953,7 +1953,7 @@ Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x
return src[0] | src[1] << 8 | src[2] << 16;
break;
case 4:
return *reinterpret_cast<const Uint32*>(src);
return *reinterpret_cast<const uint32_t*>(src);
}
return 0;
}
@ -1974,7 +1974,7 @@ surface rotate_180_surface(const surface &surf)
{// Code block to limit the scope of the surface lock.
surface_lock lock(nsurf);
Uint32* const pixels = lock.pixels();
uint32_t* const pixels = lock.pixels();
// Swap pixels in the upper half of the image with
// those in the lower half.
@ -2019,8 +2019,8 @@ surface rotate_90_surface(const surface &surf, bool clockwise)
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* const dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* const dst_pixels = dst_lock.pixels();
// Copy the pixels.
for ( int y = 0; y != src->h; ++y ) {
@ -2053,7 +2053,7 @@ surface flip_surface(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* const pixels = lock.pixels();
uint32_t* const pixels = lock.pixels();
for(int y = 0; y != nsurf->h; ++y) {
for(int x = 0; x != nsurf->w/2; ++x) {
@ -2082,7 +2082,7 @@ surface flop_surface(const surface &surf)
{
surface_lock lock(nsurf);
Uint32* const pixels = lock.pixels();
uint32_t* const pixels = lock.pixels();
for(int x = 0; x != nsurf->w; ++x) {
for(int y = 0; y != nsurf->h/2; ++y) {
@ -2188,8 +2188,8 @@ void blit_surface(const surface& surf,
const_surface_lock src_lock(src);
surface_lock dst_lock(dst);
const Uint32* const src_pixels = src_lock.pixels();
Uint32* dst_pixels = dst_lock.pixels();
const uint32_t* const src_pixels = src_lock.pixels();
uint32_t* dst_pixels = dst_lock.pixels();
for(unsigned y = 0; y < height; ++y) {
for(unsigned x = 0; x < width; ++x) {
@ -2204,8 +2204,8 @@ void blit_surface(const surface& surf,
const int src_offset = (y + src_rect.y) * src->w + (x + src_rect.x);
assert(src_offset < src->w * src->h);
const Uint32 src_pixel = src_pixels[src_offset];
const Uint8 src_a = (src_pixel & 0xFF000000) >> 24;
const uint32_t src_pixel = src_pixels[src_offset];
const uint8_t src_a = (src_pixel & 0xFF000000) >> 24;
if(!src_a) {
// Fully transparent source, ignore
@ -2220,8 +2220,8 @@ void blit_surface(const surface& surf,
continue;
}
const Uint32 dst_pixel = dst_pixels[dst_offset];
Uint8 dst_a = (dst_pixel & 0xFF000000) >> 24;
const uint32_t dst_pixel = dst_pixels[dst_offset];
uint8_t dst_a = (dst_pixel & 0xFF000000) >> 24;
if(!dst_a) {
// Fully transparent destination, copy
@ -2229,13 +2229,13 @@ void blit_surface(const surface& surf,
continue;
}
const Uint8 src_r = (src_pixel & 0x00FF0000) >> 16;
const Uint8 src_g = (src_pixel & 0x0000FF00) >> 8;
const Uint8 src_b = src_pixel & 0x000000FF;
const uint8_t src_r = (src_pixel & 0x00FF0000) >> 16;
const uint8_t src_g = (src_pixel & 0x0000FF00) >> 8;
const uint8_t src_b = src_pixel & 0x000000FF;
Uint8 dst_r = (dst_pixel & 0x00FF0000) >> 16;
Uint8 dst_g = (dst_pixel & 0x0000FF00) >> 8;
Uint8 dst_b = dst_pixel & 0x000000FF;
uint8_t dst_r = (dst_pixel & 0x00FF0000) >> 16;
uint8_t dst_g = (dst_pixel & 0x0000FF00) >> 8;
uint8_t dst_b = dst_pixel & 0x000000FF;
if(dst_a == 255) {
@ -2308,8 +2308,8 @@ struct not_alpha
not_alpha() {}
// we assume neutral format
bool operator()(Uint32 pixel) const {
Uint8 alpha = pixel >> 24;
bool operator()(uint32_t pixel) const {
uint8_t alpha = pixel >> 24;
return alpha != 0x00;
}
};
@ -2328,12 +2328,12 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
const not_alpha calc;
surface_lock lock(nsurf);
const Uint32* const pixels = lock.pixels();
const uint32_t* const pixels = lock.pixels();
int n;
for(n = 0; n != nsurf->h; ++n) {
const Uint32* const start_row = pixels + n*nsurf->w;
const Uint32* const end_row = start_row + nsurf->w;
const uint32_t* const start_row = pixels + n*nsurf->w;
const uint32_t* const end_row = start_row + nsurf->w;
if(std::find_if(start_row,end_row,calc) != end_row)
break;
@ -2342,8 +2342,8 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
res.y = n;
for(n = 0; n != nsurf->h-res.y; ++n) {
const Uint32* const start_row = pixels + (nsurf->h-n-1)*surf->w;
const Uint32* const end_row = start_row + nsurf->w;
const uint32_t* const start_row = pixels + (nsurf->h-n-1)*surf->w;
const uint32_t* const end_row = start_row + nsurf->w;
if(std::find_if(start_row,end_row,calc) != end_row)
break;
@ -2357,7 +2357,7 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
for(n = 0; n != nsurf->w; ++n) {
int y;
for(y = 0; y != nsurf->h; ++y) {
const Uint32 pixel = pixels[y*nsurf->w + n];
const uint32_t pixel = pixels[y*nsurf->w + n];
if(calc(pixel))
break;
}
@ -2371,7 +2371,7 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
for(n = 0; n != nsurf->w-res.x; ++n) {
int y;
for(y = 0; y != nsurf->h; ++y) {
const Uint32 pixel = pixels[y*nsurf->w + surf->w - n - 1];
const uint32_t pixel = pixels[y*nsurf->w + surf->w - n - 1];
if(calc(pixel))
break;
}
@ -2389,7 +2389,7 @@ void draw_centered_on_background(surface surf, const SDL_Rect& rect, const color
{
clip_rect_setter clip_setter(target, &rect);
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.a);
uint32_t col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.a);
//TODO: only draw background outside the image
SDL_Rect r = rect;
sdl::fill_surface_rect(target, &r, col);

View file

@ -334,8 +334,8 @@ SDL_Rect get_non_transparent_portion(const surface &surf);
* @param x The position in the row of the pixel.
* @param y The row of the pixel.
*/
void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, Uint32 pixel);
Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y);
void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, uint32_t pixel);
uint32_t get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y);
// blit the image on the center of the rectangle
// and a add a colored background

View file

@ -27,8 +27,8 @@ window::window(const std::string& title,
const int y,
const int w,
const int h,
const Uint32 window_flags,
const Uint32 render_flags)
const uint32_t window_flags,
const uint32_t render_flags)
: window_(SDL_CreateWindow(title.c_str(), x, y, w, h, window_flags))
, pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
{
@ -118,7 +118,7 @@ void window::full_screen()
SDL_SetWindowFullscreen(window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
}
void window::fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
void window::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
SDL_SetRenderDrawColor(*this, r, g, b, a);
if(SDL_RenderClear(*this) != 0) {

View file

@ -67,8 +67,8 @@ public:
const int y,
const int w,
const int h,
const Uint32 window_flags,
const Uint32 render_flags);
const uint32_t window_flags,
const uint32_t render_flags);
~window();
@ -130,7 +130,7 @@ public:
* @param g Green value of the color.
* @param b Blue value of the color.
*/
void fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 0);
void fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0);
/** Renders the contents of the window. */
void render();
@ -186,7 +186,7 @@ private:
SDL_Window* window_;
/** The preferred pixel format for the renderer. */
Uint32 pixel_format_;
uint32_t pixel_format_;
};
} // namespace sdl

View file

@ -26,7 +26,7 @@
/**
* For Win32 API.
*
* On Windows, wchar_t is defined as Uint16.
* On Windows, wchar_t is defined as uint16_t.
* Wide strings are expected to be UTF-16.
*/
namespace utf16 {

View file

@ -41,7 +41,7 @@ namespace utf8 {
/**
* For Win32 API.
*
* On windows, wchar_t is defined as Uint16.
* On windows, wchar_t is defined as uint16_t.
* Wide strings are expected to be UTF-16.
*/
namespace utf16 {

View file

@ -457,7 +457,7 @@ bool init_sound()
void close_sound()
{
int frequency, channels;
Uint16 format;
uint16_t format;
if(mix_ok) {
stop_bell();

View file

@ -678,7 +678,7 @@ inline ter_layer get_layer_mask_(ter_layer terrain)
if((terrain & 0x000000FF) == 0x0000002A) return 0xFFFFFF00;
/*
Uint8 *ptr = (Uint8 *) &terrain;
uint8_t *ptr = (uint8_t *) &terrain;
if(ptr[3] == 0x2A) return 0x00000000;
if(ptr[2] == 0x2A) return 0xFF000000;

View file

@ -54,8 +54,8 @@
// const_surface_lock src_lock(src);
// const_surface_lock dst_lock(dst);
//
// const Uint32* src_pixels = src_lock.pixels();
// const Uint32* dst_pixels = dst_lock.pixels();
// const uint32_t* src_pixels = src_lock.pixels();
// const uint32_t* dst_pixels = dst_lock.pixels();
//
// const unsigned pixels = src->w * src->h;
//
@ -75,12 +75,12 @@
//}
//static void
//test_blend(const surface& dst, const Uint8 amount, const Uint32 color)
//test_blend(const surface& dst, const uint8_t amount, const uint32_t color)
//{
// std::stringstream sstr;
// sstr << std::hex << std::setfill('0')
// << "Blend image amount »"
// << std::setw(2) << static_cast<Uint32>(amount)
// << std::setw(2) << static_cast<uint32_t>(amount)
// << "« color »"
// << std::setw(8) << color
// << "« : ";

View file

@ -19,14 +19,14 @@
#include "utils/functional.hpp"
typedef std::function<
void(const surface&, const double, const Uint32)>
void(const surface&, const double, const uint32_t)>
tblend_functor;
inline void
blend_image(const surface& src, tblend_functor functor)
{
for(Uint32 color = 0x00FF0000; color != 0x00000000; color >>= 8) {
for(uint32_t color = 0x00FF0000; color != 0x00000000; color >>= 8) {
for(int i = 0xf; i < 0x100; i += 0x10) {
const surface dst = blend_surface(src, i / 255., color);
if(functor) {
@ -37,7 +37,7 @@ blend_image(const surface& src, tblend_functor functor)
}
inline std::string
blend_get_filename(std::string root, const Uint8 amount, const Uint32 color)
blend_get_filename(std::string root, const uint8_t amount, const uint32_t color)
{
// The name of the file is
// A the amount of blended [0..256) as hex.

View file

@ -396,7 +396,7 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
size_t unfilled = static_cast<size_t>(height * (1.0 - filled));
if(unfilled < height && alpha >= ftofxp(0.3)) {
const Uint8 r_alpha = std::min<unsigned>(unsigned(fxpmult(alpha,255)),255);
const uint8_t r_alpha = std::min<unsigned>(unsigned(fxpmult(alpha,255)),255);
surface filled_surf = create_compatible_surface(bar_surf, bar_loc.w, height - unfilled);
SDL_Rect filled_area = sdl::create_rect(0, 0, bar_loc.w, height-unfilled);
sdl::fill_surface_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
@ -405,7 +405,7 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
}
struct is_energy_color {
bool operator()(Uint32 color) const { return (color&0xFF000000) > 0x10000000 &&
bool operator()(uint32_t color) const { return (color&0xFF000000) > 0x10000000 &&
(color&0x00FF0000) < 0x00100000 &&
(color&0x0000FF00) < 0x00001000 &&
(color&0x000000FF) < 0x00000010; }
@ -423,12 +423,12 @@ const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf) const
surface image(make_neutral_surface(surf));
const_surface_lock image_lock(image);
const Uint32* const begin = image_lock.pixels();
const uint32_t* const begin = image_lock.pixels();
for(int y = 0; y != image->h; ++y) {
const Uint32* const i1 = begin + image->w*y;
const Uint32* const i2 = i1 + image->w;
const Uint32* const itor = std::find_if(i1,i2,is_energy_color());
const uint32_t* const i1 = begin + image->w*y;
const uint32_t* const i2 = i1 + image->w;
const uint32_t* const itor = std::find_if(i1,i2,is_energy_color());
const int count = std::count_if(itor,i2,is_energy_color());
if(itor != i2) {

View file

@ -238,7 +238,7 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
const std::string resourceToProcess(*cmdline_opts.preprocess_path);
const std::string targetDir(*cmdline_opts.preprocess_target);
Uint32 startTime = SDL_GetTicks();
uint32_t startTime = SDL_GetTicks();
// if the users add the SKIP_CORE define we won't preprocess data/core
bool skipCore = false;
bool skipTerrainGFX = false;

View file

@ -626,7 +626,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
}
int mousex, mousey;
const Uint8 mousebuttons = SDL_GetMouseState(&mousex,&mousey);
const uint8_t mousebuttons = SDL_GetMouseState(&mousex,&mousey);
if(!(mousebuttons & SDL_BUTTON(1))) {
grabmouse_ = false;
}