Skip to content

Commit

Permalink
use c++ style casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Mar 10, 2016
1 parent 51cabe0 commit 192f5c2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
26 changes: 13 additions & 13 deletions include/mapnik/hextree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,20 @@ class hextree : private util::noncopyable
if (r->count>0)
{
printf("%d: (+%d/%d/%.5f) (%d %d %d %d)\n",
id, (int)r->count, (int)r->pixel_count, r->reduce_cost,
(int)round(gamma(r->reds / r->count, gamma_)),
(int)round(gamma(r->greens / r->count, gamma_)),
(int)round(gamma(r->blues / r->count, gamma_)),
(int)(r->alphas / r->count));
id, static_cast<int>(r->count), static_cast<int>(r->pixel_count), r->reduce_cost,
static_cast<int>(round(gamma(r->reds / r->count, gamma_))),
static_cast<int>(round(gamma(r->greens / r->count, gamma_))),
static_cast<int>(round(gamma(r->blues / r->count, gamma_))),
static_cast<int>((r->alphas / r->count)));
}
else
{
printf("%d: (%d/%d/%.5f) (%d %d %d %d)\n", id,
(int)r->count, (int)r->pixel_count, r->reduce_cost,
(int)round(gamma(r->reds / r->pixel_count, gamma_)),
(int)round(gamma(r->greens / r->pixel_count, gamma_)),
(int)round(gamma(r->blues / r->pixel_count, gamma_)),
(int)(r->alphas / r->pixel_count));
static_cast<int>(r->count), static_cast<int>(r->pixel_count), r->reduce_cost,
static_cast<int>(round(gamma(r->reds / r->pixel_count, gamma_))),
static_cast<int>(round(gamma(r->greens / r->pixel_count, gamma_))),
static_cast<int>(round(gamma(r->blues / r->pixel_count, gamma_))),
static_cast<int>((r->alphas / r->pixel_count)));
}
for (unsigned idx=0; idx < 16; ++idx)
{
Expand All @@ -399,9 +399,9 @@ class hextree : private util::noncopyable
std::uint8_t a = std::uint8_t(itr->alphas/float(count));
if (a > InsertPolicy::MAX_ALPHA) a = 255;
if (a < InsertPolicy::MIN_ALPHA) a = 0;
palette.push_back(rgba((std::uint8_t)round(gamma(itr->reds / count, gamma_)),
(std::uint8_t)round(gamma(itr->greens / count, gamma_)),
(std::uint8_t)round(gamma(itr->blues / count, gamma_)), a));
palette.push_back(rgba(static_cast<std::uint8_t>(round(gamma(itr->reds / count, gamma_))),
static_cast<std::uint8_t>(round(gamma(itr->greens / count, gamma_))),
static_cast<std::uint8_t>(round(gamma(itr->blues / count, gamma_))), a));
}
for (unsigned idx=0; idx < 16; ++idx)
{
Expand Down
20 changes: 10 additions & 10 deletions include/mapnik/png_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ void save_as_png(T1 & file,
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr,(png_infopp)0);
png_destroy_write_struct(&png_ptr,static_cast<png_infopp>(0));
return;
}
jmp_buf* jmp_context = (jmp_buf*) png_get_error_ptr(png_ptr);
jmp_buf* jmp_context = static_cast<jmp_buf*>(png_get_error_ptr(png_ptr));
if (jmp_context)
{
png_destroy_write_struct(&png_ptr, &info_ptr);
Expand All @@ -120,7 +120,7 @@ void save_as_png(T1 & file,
const std::unique_ptr<png_bytep[]> row_pointers(new png_bytep[image.height()]);
for (unsigned int i = 0; i < image.height(); i++)
{
row_pointers[i] = (png_bytep)image.get_row(i);
row_pointers[i] = const_cast<png_bytep>(reinterpret_cast<const unsigned char *>(image.get_row(i)));
}
png_set_rows(png_ptr, info_ptr, row_pointers.get());
png_write_png(png_ptr, info_ptr, (opts.trans_mode == 0) ? PNG_TRANSFORM_STRIP_FILLER_AFTER : PNG_TRANSFORM_IDENTITY, nullptr);
Expand Down Expand Up @@ -161,7 +161,7 @@ void reduce_8(T const& in,
break;
}
}
if (idx>=0 && idx<(int)alpha.size())
if (idx>=0 && idx < static_cast<int>(alpha.size()))
{
alpha[idx]+=U2ALPHA(val);
alphaCount[idx]++;
Expand Down Expand Up @@ -212,7 +212,7 @@ void reduce_4(T const& in,
break;
}
}
if (idx>=0 && idx<(int)alpha.size())
if (idx>=0 && idx < static_cast<int>(alpha.size()))
{
alpha[idx]+=U2ALPHA(val);
alphaCount[idx]++;
Expand Down Expand Up @@ -273,10 +273,10 @@ void save_as_png(T & file, std::vector<mapnik::rgb> const& palette,
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr,(png_infopp)0);
png_destroy_write_struct(&png_ptr,static_cast<png_infopp>(0));
return;
}
jmp_buf* jmp_context = (jmp_buf*) png_get_error_ptr(png_ptr);
jmp_buf* jmp_context = static_cast<jmp_buf*>(png_get_error_ptr(png_ptr));
if (jmp_context)
{
png_destroy_write_struct(&png_ptr, &info_ptr);
Expand Down Expand Up @@ -310,14 +310,14 @@ void save_as_png(T & file, std::vector<mapnik::rgb> const& palette,
}
if (alphaSize>0)
{
png_set_tRNS(png_ptr, info_ptr, (png_bytep)&trans[0], alphaSize, 0);
png_set_tRNS(png_ptr, info_ptr, static_cast<png_bytep>(&trans[0]), alphaSize, 0);
}
}

png_write_info(png_ptr, info_ptr);
for (unsigned i=0;i<height;i++)
{
png_write_row(png_ptr,(png_bytep)image.get_row(i));
png_write_row(png_ptr,const_cast<png_bytep>(image.get_row(i)));
}

png_write_end(png_ptr, info_ptr);
Expand Down Expand Up @@ -352,7 +352,7 @@ void save_as_png8_oct(T1 & file,
{
for (unsigned x = 0; x < width; ++x)
{
unsigned val = U2ALPHA((unsigned)image.get_row(y)[x]);
unsigned val = U2ALPHA(static_cast<unsigned>(image.get_row(y)[x]));
alphaHist[val]++;
meanAlpha += val;
if (val>0 && val<255)
Expand Down
2 changes: 1 addition & 1 deletion src/font_engine_freetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *
if (count <= 0) return 0;
FILE * file = static_cast<FILE *>(stream->descriptor.pointer);
std::fseek (file , offset , SEEK_SET);
return std::fread ((char*)buffer, 1, count, file);
return std::fread(reinterpret_cast<unsigned char*>(buffer), 1, count, file);
}

bool freetype_engine::register_font(std::string const& file_name)
Expand Down
10 changes: 5 additions & 5 deletions src/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ rgb::rgb(rgba const& c)
// ordering by mean(a,r,g,b), a, r, g, b
bool rgba::mean_sort_cmp::operator() (const rgba& x, const rgba& y) const
{
int t1 = (int)x.a + x.r + x.g + x.b;
int t2 = (int)y.a + y.r + y.g + y.b;
int t1 = x.a + x.r + x.g + x.b;
int t2 = y.a + y.r + y.g + y.b;
if (t1 != t2) return t1 < t2;

// https://github.com/mapnik/mapnik/issues/1087
Expand Down Expand Up @@ -97,9 +97,9 @@ std::string rgba_palette::to_string() const
str << std::hex << std::setfill('0');
for (unsigned i = 0; i < length; i++) {
str << " #";
str << std::setw(2) << (unsigned)rgb_pal_[i].r;
str << std::setw(2) << (unsigned)rgb_pal_[i].g;
str << std::setw(2) << (unsigned)rgb_pal_[i].b;
str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].r);
str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].g);
str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].b);
if (i < alphaLength) str << std::setw(2) << alpha_pal_[i];
}
str << "]";
Expand Down
2 changes: 1 addition & 1 deletion src/svg/svg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ double parse_svg_value(T & error_messages, const char* str, bool & percent)
("pc", DPI/6.0)
("mm", DPI/25.4)
("cm", DPI/2.54)
("in", (double)DPI)
("in", static_cast<double>(DPI))
;
const char* cur = str; // phrase_parse modifies the first iterator
const char* end = str + std::strlen(str);
Expand Down
4 changes: 2 additions & 2 deletions src/text/face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ font_face::font_face(FT_Face face)

bool font_face::set_character_sizes(double size)
{
return (FT_Set_Char_Size(face_,0,(FT_F26Dot6)(size * (1<<6)),0,0) == 0);
return (FT_Set_Char_Size(face_,0,static_cast<FT_F26Dot6>(size * (1<<6)),0,0) == 0);
}

bool font_face::set_unscaled_character_sizes()
Expand Down Expand Up @@ -113,7 +113,7 @@ void font_face_set::set_unscaled_character_sizes()

void stroker::init(double radius)
{
FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)),
FT_Stroker_Set(s_, static_cast<FT_Fixed>(radius * (1<<6)),
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
Expand Down
4 changes: 2 additions & 2 deletions src/wkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ struct wkb_reader : util::noncopyable
switch (format_)
{
case wkbSpatiaLite:
byteOrder_ = (wkbByteOrder) wkb_[1];
byteOrder_ = static_cast<wkbByteOrder>(wkb_[1]);
pos_ = 39;
break;

case wkbGeneric:
default:
byteOrder_ = (wkbByteOrder) wkb_[0];
byteOrder_ = static_cast<wkbByteOrder>(wkb_[0]);
pos_ = 1;
break;
}
Expand Down

0 comments on commit 192f5c2

Please sign in to comment.