use c++ style casts

This commit is contained in:
Dane Springmeyer 2016-03-10 12:45:47 -08:00
parent 51cabe0d34
commit 192f5c26c1
7 changed files with 34 additions and 34 deletions

View file

@ -365,20 +365,20 @@ private:
if (r->count>0) if (r->count>0)
{ {
printf("%d: (+%d/%d/%.5f) (%d %d %d %d)\n", printf("%d: (+%d/%d/%.5f) (%d %d %d %d)\n",
id, (int)r->count, (int)r->pixel_count, r->reduce_cost, id, static_cast<int>(r->count), static_cast<int>(r->pixel_count), r->reduce_cost,
(int)round(gamma(r->reds / r->count, gamma_)), static_cast<int>(round(gamma(r->reds / r->count, gamma_))),
(int)round(gamma(r->greens / r->count, gamma_)), static_cast<int>(round(gamma(r->greens / r->count, gamma_))),
(int)round(gamma(r->blues / r->count, gamma_)), static_cast<int>(round(gamma(r->blues / r->count, gamma_))),
(int)(r->alphas / r->count)); static_cast<int>((r->alphas / r->count)));
} }
else else
{ {
printf("%d: (%d/%d/%.5f) (%d %d %d %d)\n", id, printf("%d: (%d/%d/%.5f) (%d %d %d %d)\n", id,
(int)r->count, (int)r->pixel_count, r->reduce_cost, static_cast<int>(r->count), static_cast<int>(r->pixel_count), r->reduce_cost,
(int)round(gamma(r->reds / r->pixel_count, gamma_)), static_cast<int>(round(gamma(r->reds / r->pixel_count, gamma_))),
(int)round(gamma(r->greens / r->pixel_count, gamma_)), static_cast<int>(round(gamma(r->greens / r->pixel_count, gamma_))),
(int)round(gamma(r->blues / r->pixel_count, gamma_)), static_cast<int>(round(gamma(r->blues / r->pixel_count, gamma_))),
(int)(r->alphas / r->pixel_count)); static_cast<int>((r->alphas / r->pixel_count)));
} }
for (unsigned idx=0; idx < 16; ++idx) for (unsigned idx=0; idx < 16; ++idx)
{ {
@ -399,9 +399,9 @@ private:
std::uint8_t a = std::uint8_t(itr->alphas/float(count)); std::uint8_t a = std::uint8_t(itr->alphas/float(count));
if (a > InsertPolicy::MAX_ALPHA) a = 255; if (a > InsertPolicy::MAX_ALPHA) a = 255;
if (a < InsertPolicy::MIN_ALPHA) a = 0; if (a < InsertPolicy::MIN_ALPHA) a = 0;
palette.push_back(rgba((std::uint8_t)round(gamma(itr->reds / count, gamma_)), palette.push_back(rgba(static_cast<std::uint8_t>(round(gamma(itr->reds / count, gamma_))),
(std::uint8_t)round(gamma(itr->greens / count, gamma_)), static_cast<std::uint8_t>(round(gamma(itr->greens / count, gamma_))),
(std::uint8_t)round(gamma(itr->blues / count, gamma_)), a)); static_cast<std::uint8_t>(round(gamma(itr->blues / count, gamma_))), a));
} }
for (unsigned idx=0; idx < 16; ++idx) for (unsigned idx=0; idx < 16; ++idx)
{ {

View file

@ -99,10 +99,10 @@ void save_as_png(T1 & file,
png_infop info_ptr = png_create_info_struct(png_ptr); png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_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; 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) if (jmp_context)
{ {
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
@ -120,7 +120,7 @@ void save_as_png(T1 & file,
const std::unique_ptr<png_bytep[]> row_pointers(new png_bytep[image.height()]); const std::unique_ptr<png_bytep[]> row_pointers(new png_bytep[image.height()]);
for (unsigned int i = 0; i < image.height(); i++) 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_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); png_write_png(png_ptr, info_ptr, (opts.trans_mode == 0) ? PNG_TRANSFORM_STRIP_FILLER_AFTER : PNG_TRANSFORM_IDENTITY, nullptr);
@ -161,7 +161,7 @@ void reduce_8(T const& in,
break; break;
} }
} }
if (idx>=0 && idx<(int)alpha.size()) if (idx>=0 && idx < static_cast<int>(alpha.size()))
{ {
alpha[idx]+=U2ALPHA(val); alpha[idx]+=U2ALPHA(val);
alphaCount[idx]++; alphaCount[idx]++;
@ -212,7 +212,7 @@ void reduce_4(T const& in,
break; break;
} }
} }
if (idx>=0 && idx<(int)alpha.size()) if (idx>=0 && idx < static_cast<int>(alpha.size()))
{ {
alpha[idx]+=U2ALPHA(val); alpha[idx]+=U2ALPHA(val);
alphaCount[idx]++; alphaCount[idx]++;
@ -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); png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_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; 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) if (jmp_context)
{ {
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
@ -310,14 +310,14 @@ void save_as_png(T & file, std::vector<mapnik::rgb> const& palette,
} }
if (alphaSize>0) 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); png_write_info(png_ptr, info_ptr);
for (unsigned i=0;i<height;i++) 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); png_write_end(png_ptr, info_ptr);
@ -352,7 +352,7 @@ void save_as_png8_oct(T1 & file,
{ {
for (unsigned x = 0; x < width; ++x) 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]++; alphaHist[val]++;
meanAlpha += val; meanAlpha += val;
if (val>0 && val<255) if (val>0 && val<255)

View file

@ -75,7 +75,7 @@ unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *
if (count <= 0) return 0; if (count <= 0) return 0;
FILE * file = static_cast<FILE *>(stream->descriptor.pointer); FILE * file = static_cast<FILE *>(stream->descriptor.pointer);
std::fseek (file , offset , SEEK_SET); 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) bool freetype_engine::register_font(std::string const& file_name)

View file

@ -37,8 +37,8 @@ rgb::rgb(rgba const& c)
// ordering by mean(a,r,g,b), a, r, g, b // ordering by mean(a,r,g,b), a, r, g, b
bool rgba::mean_sort_cmp::operator() (const rgba& x, const rgba& y) const 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 t1 = x.a + x.r + x.g + x.b;
int t2 = (int)y.a + y.r + y.g + y.b; int t2 = y.a + y.r + y.g + y.b;
if (t1 != t2) return t1 < t2; if (t1 != t2) return t1 < t2;
// https://github.com/mapnik/mapnik/issues/1087 // https://github.com/mapnik/mapnik/issues/1087
@ -97,9 +97,9 @@ std::string rgba_palette::to_string() const
str << std::hex << std::setfill('0'); str << std::hex << std::setfill('0');
for (unsigned i = 0; i < length; i++) { for (unsigned i = 0; i < length; i++) {
str << " #"; str << " #";
str << std::setw(2) << (unsigned)rgb_pal_[i].r; str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].r);
str << std::setw(2) << (unsigned)rgb_pal_[i].g; str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].g);
str << std::setw(2) << (unsigned)rgb_pal_[i].b; str << std::setw(2) << static_cast<unsigned>(rgb_pal_[i].b);
if (i < alphaLength) str << std::setw(2) << alpha_pal_[i]; if (i < alphaLength) str << std::setw(2) << alpha_pal_[i];
} }
str << "]"; str << "]";

View file

@ -154,7 +154,7 @@ double parse_svg_value(T & error_messages, const char* str, bool & percent)
("pc", DPI/6.0) ("pc", DPI/6.0)
("mm", DPI/25.4) ("mm", DPI/25.4)
("cm", DPI/2.54) ("cm", DPI/2.54)
("in", (double)DPI) ("in", static_cast<double>(DPI))
; ;
const char* cur = str; // phrase_parse modifies the first iterator const char* cur = str; // phrase_parse modifies the first iterator
const char* end = str + std::strlen(str); const char* end = str + std::strlen(str);

View file

@ -41,7 +41,7 @@ font_face::font_face(FT_Face face)
bool font_face::set_character_sizes(double size) 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() bool font_face::set_unscaled_character_sizes()
@ -113,7 +113,7 @@ void font_face_set::set_unscaled_character_sizes()
void stroker::init(double radius) 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_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND, FT_STROKER_LINEJOIN_ROUND,
0); 0);

View file

@ -103,13 +103,13 @@ public:
switch (format_) switch (format_)
{ {
case wkbSpatiaLite: case wkbSpatiaLite:
byteOrder_ = (wkbByteOrder) wkb_[1]; byteOrder_ = static_cast<wkbByteOrder>(wkb_[1]);
pos_ = 39; pos_ = 39;
break; break;
case wkbGeneric: case wkbGeneric:
default: default:
byteOrder_ = (wkbByteOrder) wkb_[0]; byteOrder_ = static_cast<wkbByteOrder>(wkb_[0]);
pos_ = 1; pos_ = 1;
break; break;
} }