Skip to content

Commit ac86b51

Browse files
committed
Warnings
Fixed warnings so the code is compliant with “Treat Warnings as Errors”
1 parent ffefe03 commit ac86b51

2 files changed

Lines changed: 106 additions & 54 deletions

File tree

src/Processing.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#if __has_include("stb_truetype.h")
22
# define PROCESSING_HAS_STB_TRUETYPE 1
33
# define STB_TRUETYPE_IMPLEMENTATION
4+
# if defined(_MSC_VER)
5+
# pragma warning(push)
6+
# pragma warning(disable: 4365)
7+
# endif
48
# include "stb_truetype.h"
9+
# if defined(_MSC_VER)
10+
# pragma warning(pop)
11+
# endif
512
#else
613
# define PROCESSING_HAS_STB_TRUETYPE 0
714
#endif
815

916
#include "Processing.h"
17+
#ifdef _MSC_VER
18+
#pragma warning(push)
19+
#pragma warning(disable: 4365 4245 4100 4189)
20+
#endif
1021
#ifdef __EMSCRIPTEN__
1122
#include <emscripten.h>
1223
#include <emscripten/html5.h>
@@ -16,6 +27,7 @@
1627
#undef GL_QUAD_STRIP
1728
#define GL_QUAD_STRIP GL_TRIANGLE_STRIP
1829
#endif
30+
1931
#include <csignal>
2032
#include <cstdlib>
2133
#include <cmath>
@@ -30,9 +42,11 @@
3042
#include <objc/message.h>
3143
#include <dlfcn.h>
3244
#endif
45+
3346
#ifndef _WIN32
3447
#include <thread>
3548
#endif
49+
3650
#include <vector>
3751
#include <array>
3852
#include <string>
@@ -52,13 +66,26 @@
5266
// Uncomment + drop stb_image_write.h to enable saveFrame()/save():
5367
// #define STB_IMAGE_WRITE_IMPLEMENTATION
5468
#define STB_IMAGE_WRITE_IMPLEMENTATION
69+
#if defined(__clang__)
5570
#pragma clang diagnostic push
5671
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
72+
#elif defined(__GNUC__)
5773
#pragma GCC diagnostic push
5874
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
75+
#endif
76+
#ifdef _MSC_VER
77+
#pragma warning(push)
78+
#pragma warning(disable: 4365)
79+
#endif
5980
#include "stb_image_write.h"
81+
#ifdef _MSC_VER
82+
#pragma warning(pop)
83+
#endif
84+
#if defined(__clang__)
6085
#pragma clang diagnostic pop
86+
#elif defined(__GNUC__)
6187
#pragma GCC diagnostic pop
88+
#endif
6289

6390
// ── Manual glu replacements (no GLU header needed) ───────────────────────────
6491
static void _gluPerspective(double fovY_deg, double aspect, double zNear, double zFar) {
@@ -337,8 +364,8 @@ color PApplet::makeColor(float gray,float alpha){
337364
float br=gray/colorMaxB;
338365
br=::std::fmax(0.f,::std::fmin(1.f,br));
339366
int v=(int)(br*255);
340-
unsigned int a=::std::fmax(0.f,::std::fmin(1.f,alpha/colorMaxA))*255;
341-
return colorVal(v,v,v,(int)a);
367+
unsigned int a=static_cast<unsigned int>(::std::fmax(0.f,::std::fmin(1.f,alpha/colorMaxA))*255.0f);
368+
return colorVal(v,v,v,static_cast<int>(a));
342369
}
343370
return makeColor(gray,gray,gray,alpha);
344371
}
@@ -2296,7 +2323,7 @@ void PApplet::drawBitmapStr(float x, float y, const ::std::string& s, int scale)
22962323
}
22972324

22982325
float PApplet::bitmapStrWidth(const ::std::string& s, int scale) {
2299-
return s.size() * (BF_GW+1) * scale;
2326+
return static_cast<float>(s.size()) * static_cast<float>(BF_GW+1) * static_cast<float>(scale);
23002327
}
23012328

23022329
// -- TTF rendering -------------------------------------------------------------
@@ -2401,7 +2428,7 @@ void PApplet::renderText(const ::std::string& msg, float x, float y) {
24012428
// Bitmap fallback
24022429
int sc = ::std::max(1,(int)(g_textSize/8.0f));
24032430
// Shift so baseline sits at y (bitmap font: ascent = BF_GH-2 rows)
2404-
float ascent = (BF_GH - 2) * sc;
2431+
float ascent = static_cast<float>(BF_GH - 2) * static_cast<float>(sc);
24052432
drawBitmapStr(dx, dy - ascent, ls[li], sc);
24062433
}
24072434
}
@@ -2540,7 +2567,7 @@ float PApplet::textAscent() {
25402567
}
25412568
#endif
25422569
int sc = ::std::max(1,(int)(g_textSize/8.0f));
2543-
return (BF_GH - 2) * sc;
2570+
return static_cast<float>(BF_GH - 2) * static_cast<float>(sc);
25442571
}
25452572

25462573
float PApplet::textDescent() {
@@ -2860,13 +2887,13 @@ void PApplet::filter(int mode, float param) {
28602887
int r=buf[i*4],g=buf[i*4+1],b=buf[i*4+2];
28612888
int grey=(r+g+b)/3;
28622889
if (mode==GRAY) { buf[i*4]=buf[i*4+1]=buf[i*4+2]=(unsigned char)grey; }
2863-
else if (mode==INVERT) { buf[i*4]=255-r; buf[i*4+1]=255-g; buf[i*4+2]=255-b; }
2890+
else if (mode==INVERT) { buf[i*4]=static_cast<unsigned char>(255-r); buf[i*4+1]=static_cast<unsigned char>(255-g); buf[i*4+2]=static_cast<unsigned char>(255-b); }
28642891
else if (mode==THRESHOLD) { unsigned char t=(grey>param*255)?255:0; buf[i*4]=buf[i*4+1]=buf[i*4+2]=t; }
2865-
else if (mode==OPAQUE) { buf[i*4+3]=255; }
2892+
else if (mode==OPAQUE) { buf[i*4+3]=static_cast<unsigned char>(255); }
28662893
else if (mode==POSTERIZE) {
28672894
int levels = ::std::max(2,(int)param);
28682895
auto post = [levels](int v){ return (int)((int)(v*(levels-1)/255.0f+0.5f)*255/(levels-1)); };
2869-
buf[i*4]=post(r); buf[i*4+1]=post(g); buf[i*4+2]=post(b);
2896+
buf[static_cast<size_t>(i)*4u]=static_cast<unsigned char>(post(r)); buf[static_cast<size_t>(i)*4u+1u]=static_cast<unsigned char>(post(g)); buf[static_cast<size_t>(i)*4u+2u]=static_cast<unsigned char>(post(b));
28702897
}
28712898
}
28722899
} else if (mode == BLUR) {
@@ -2881,7 +2908,7 @@ void PApplet::filter(int mode, float param) {
28812908
sr+=tmp[j]; sg+=tmp[j+1]; sb+=tmp[j+2]; sa+=tmp[j+3]; cnt++;
28822909
}
28832910
int i=(y*w+x2)*4;
2884-
buf[i]=sr/cnt; buf[i+1]=sg/cnt; buf[i+2]=sb/cnt; buf[i+3]=sa/cnt;
2911+
buf[i]=static_cast<unsigned char>(sr/cnt); buf[i+1]=static_cast<unsigned char>(sg/cnt); buf[i+2]=static_cast<unsigned char>(sb/cnt); buf[i+3]=static_cast<unsigned char>(sa/cnt);
28852912
}
28862913
} else if (mode == ERODE || mode == DILATE) {
28872914
::std::vector<unsigned char> tmp(buf);
@@ -3076,7 +3103,7 @@ void PApplet::saveFrame(const ::std::string& filename) {
30763103
for (int x = 0; x < w * 3; x++)
30773104
::std::swap(px[y*w*3+x], px[(h-1-y)*w*3+x]);
30783105
::std::string ext = fn.size() > 4 ? fn.substr(fn.size()-4) : "";
3079-
for (auto& c : ext) c = tolower(c);
3106+
for (auto& c : ext) c = static_cast<char>(tolower(static_cast<unsigned char>(c)));
30803107
int ok = 0;
30813108
if (ext == ".png") ok = stbi_write_png(fn.c_str(), w, h, 3, px.data(), w*3);
30823109
else if (ext == ".jpg" || ext == "jpeg") ok = stbi_write_jpg(fn.c_str(), w, h, 3, px.data(), 95);
@@ -5346,3 +5373,7 @@ ::std::string PApplet::binary(int v) {
53465373

53475374
} // namespace Processing
53485375

5376+
#ifdef _MSC_VER
5377+
#pragma warning(pop)
5378+
#endif
5379+

0 commit comments

Comments
 (0)