all: fix warnings on MSVC
authorprojectitis <32183808+projectitis@users.noreply.github.com>
Sat, 9 Oct 2021 02:33:45 +0000 (15:33 +1300)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 15 Oct 2021 00:42:27 +0000 (09:42 +0900)
* Explicit casts to suppress warnings
* Fixed compiler warnings

src/lib/gl_engine/tvgGlRenderer.cpp
src/lib/sw_engine/tvgSwMath.cpp
src/lib/tvgShape.cpp
src/loaders/external_png/tvgPngLoader.cpp
src/loaders/raw/tvgRawLoader.cpp
src/loaders/svg/tvgSvgLoader.cpp
src/loaders/svg/tvgSvgLoaderCommon.h
src/loaders/svg/tvgSvgPath.cpp
src/loaders/svg/tvgSvgUtil.cpp
test/testShape.cpp
test/testSwEngine.cpp

index be2b752..95a8f06 100644 (file)
@@ -137,7 +137,7 @@ bool GlRenderer::renderShape(RenderData data)
     uint8_t r, g, b, a;
     size_t flags = static_cast<size_t>(sdata->updateFlag);
 
-    GL_CHECK(glViewport(0, 0, sdata->viewWd, sdata->viewHt));
+    GL_CHECK(glViewport(0, 0, (GLsizei)sdata->viewWd, (GLsizei)sdata->viewHt));
 
     uint32_t primitiveCount = sdata->geometry->getPrimitiveCount();
     for (uint32_t i = 0; i < primitiveCount; ++i)
index 55c563f..b6247aa 100644 (file)
@@ -82,7 +82,7 @@ static int32_t _normalize(SwPoint& pt)
     auto v = pt;
 
     //High order bit(MSB)
-    auto shift = 31 - _clz(abs(v.x) | abs(v.y));
+    int32_t shift = 31 - _clz(abs(v.x) | abs(v.y));
 
     if (shift <= SAFE_MSB) {
         shift = SAFE_MSB - shift;
index 8665afa..c360f1d 100644 (file)
@@ -157,7 +157,7 @@ Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
 
 Result Shape::appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept
 {
-    const float M_PI_HALF = M_PI * 0.5f;
+    const float M_PI_HALF = (float)(M_PI * 0.5f);
 
     //just circle
     if (sweep >= 360 || sweep <= -360) return appendCircle(cx, cy, radius, radius);
index 15ccfaa..faafc62 100644 (file)
@@ -45,8 +45,8 @@ bool PngLoader::open(const string& path)
 
     if (!png_image_begin_read_from_file(image, path.c_str())) return false;
 
-    w = image->width;
-    h = image->height;
+    w = (float)image->width;
+    h = (float)image->height;
 
     return true;
 }
@@ -57,8 +57,8 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
 
     if (!png_image_begin_read_from_memory(image, data, size)) return false;
 
-    w = image->width;
-    h = image->height;
+    w = (float)image->width;
+    h = (float)image->height;
 
     return true;
 }
index 41c7430..a38dc5e 100644 (file)
@@ -45,8 +45,8 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
 {
     if (!data || w == 0 || h == 0) return false;
 
-    this->w = w;
-    this->h = h;
+    this->w = (float)w;
+    this->h = (float)h;
     this->copy = copy;
 
     if (copy) {
index 1d661df..7ff86f8 100644 (file)
@@ -97,9 +97,9 @@ static float _toFloat(const SvgParser* svgParse, const char* str, SvgParserLengt
         else if (type == SvgParserLengthType::Horizontal) parsedValue = (parsedValue / 100.0) * svgParse->global.w;
         else //if other then it's radius
         {
-            float max = svgParse->global.w;
+            float max = (float)svgParse->global.w;
             if (max < svgParse->global.h)
-                max = svgParse->global.h;
+                max = (float)svgParse->global.h;
             parsedValue = (parsedValue / 100.0) * max;
         }
     }
@@ -122,8 +122,8 @@ static float _gradientToFloat(const SvgParser* svgParse, const char* str, SvgPar
     *
     * https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html
     */
-    if (type == SvgParserLengthType::Vertical) max = svgParse->global.h;
-    else if (type == SvgParserLengthType::Horizontal) max = svgParse->global.w;
+    if (type == SvgParserLengthType::Vertical) max = (float)svgParse->global.h;
+    else if (type == SvgParserLengthType::Horizontal) max = (float)svgParse->global.w;
     else if (type == SvgParserLengthType::Other) max = sqrtf(pow(svgParse->global.h, 2) + pow(svgParse->global.w, 2)) / sqrtf(2.0);
 
     if (strstr(str, "%")) parsedValue = parsedValue / 100.0;
@@ -747,13 +747,13 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
             if (_parseNumber(&value, &doc->vy)) {
                 if (_parseNumber(&value, &doc->vw)) {
                     _parseNumber(&value, &doc->vh);
-                    loader->svgParse->global.h = doc->vh;
+                    loader->svgParse->global.h = (uint32_t)doc->vh;
                 }
-                loader->svgParse->global.w = doc->vw;
+                loader->svgParse->global.w = (uint32_t)doc->vw;
             }
-            loader->svgParse->global.y = doc->vy;
+            loader->svgParse->global.y = (int)doc->vy;
         }
-        loader->svgParse->global.x = doc->vx;
+        loader->svgParse->global.x = (int)doc->vx;
     } else if (!strcmp(key, "preserveAspectRatio")) {
         if (!strcmp(value, "none")) doc->preserveAspect = false;
     } else if (!strcmp(key, "style")) {
@@ -1121,11 +1121,11 @@ static SvgNode* _createSvgNode(SvgLoaderData* loader, SvgNode* parent, const cha
 
     if (loader->svgParse->global.w == 0) {
         if (doc->w < FLT_EPSILON) loader->svgParse->global.w = 1;
-        else loader->svgParse->global.w = doc->w;
+        else loader->svgParse->global.w = (uint32_t)doc->w;
     }
     if (loader->svgParse->global.h == 0) {
         if (doc->h < FLT_EPSILON) loader->svgParse->global.h = 1;
-        else loader->svgParse->global.h =doc->h;
+        else loader->svgParse->global.h = (uint32_t)doc->h;
     }
 
     return loader->svgParse->node;
index 645f1b3..cbb699f 100644 (file)
@@ -335,6 +335,7 @@ struct SvgNode
         SvgImageNode image;
     } node;
     bool display;
+    ~SvgNode();
 };
 
 struct SvgParser
index d41af58..9af4308 100644 (file)
@@ -176,10 +176,10 @@ void _pathAppendArcTo(Array<PathCommand>* cmds, Array<Point>* pts, Point* cur, P
 
     if (sweep) {
         //Ensure delta theta < 0 or else add 360 degrees
-        if (deltaTheta < 0.0f) deltaTheta += 2.0f * M_PI;
+        if (deltaTheta < 0.0f) deltaTheta += (float)(2.0f * M_PI);
     } else {
         //Ensure delta theta > 0 or else substract 360 degrees
-        if (deltaTheta > 0.0f) deltaTheta -= 2.0f * M_PI;
+        if (deltaTheta > 0.0f) deltaTheta -= (float)(2.0f * M_PI);
     }
 
     //Add several cubic bezier to approximate the arc
@@ -477,8 +477,8 @@ static char* _nextCommand(char* path, char* cmd, float* arr, int* count)
                         if (_parseFlag(&path, &sweep)) {
                             if (_parseNumber(&path, &arr[5])) {
                                 if (_parseNumber(&path, &arr[6])) {
-                                    arr[3] = large;
-                                    arr[4] = sweep;
+                                    arr[3] = (float)large;
+                                    arr[4] = (float)sweep;
                                     return path;
                                 }
                             }
index b0f1d84..def03c8 100644 (file)
@@ -214,17 +214,17 @@ float svgUtilStrtof(const char *nPtr, char **endPtr)
         }
         else if (*iter == 0) goto on_success;
 
-        if ((_floatExact(val, 2.2250738585072011)) && ((minus_e * (int)expo_part) == -308))
+        if ((_floatExact(val, 2.2250738585072011f)) && ((minus_e * (int)expo_part) == -308))
         {
-            val *= 1.0e-308;
+            val *= 1.0e-308f;
             a = iter;
             errno = ERANGE;
             goto on_success;
         }
 
-        if ((_floatExact(val, 2.2250738585072012)) && ((minus_e * (int)expo_part) <= -308))
+        if ((_floatExact(val, 2.2250738585072012f)) && ((minus_e * (int)expo_part) <= -308))
         {
-            val *= 1.0e-308;
+            val *= 1.0e-308f;
             a = iter;
             goto on_success;
         }
index 66e0bb6..529ee73 100644 (file)
@@ -34,17 +34,17 @@ TEST_CASE("Appending Commands", "[tvgShape]")
     REQUIRE(shape->close() == Result::Success);
 
     REQUIRE(shape->moveTo(100, 100) == Result::Success);
-    REQUIRE(shape->moveTo(99999999, -99999999) == Result::Success);
+    REQUIRE(shape->moveTo(99999999.0f, -99999999.0f) == Result::Success);
     REQUIRE(shape->moveTo(0, 0) == Result::Success);
 
     REQUIRE(shape->lineTo(120, 140) == Result::Success);
-    REQUIRE(shape->lineTo(99999999, -99999999) == Result::Success);
+    REQUIRE(shape->lineTo(99999999.0f, -99999999.0f) == Result::Success);
     REQUIRE(shape->lineTo(0, 0) == Result::Success);
 
     REQUIRE(shape->cubicTo(0, 0, 0, 0, 0, 0) == Result::Success);
-    REQUIRE(shape->cubicTo(0, 0, 99999999, -99999999, 0, 0) == Result::Success);
-    REQUIRE(shape->cubicTo(0, 0, 99999999, -99999999, 99999999, -99999999) == Result::Success);
-    REQUIRE(shape->cubicTo(99999999, -99999999, 99999999, -99999999, 99999999, -99999999) == Result::Success);
+    REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 0, 0) == Result::Success);
+    REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
+    REQUIRE(shape->cubicTo(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
 
     REQUIRE(shape->close() == Result::Success);
 
@@ -61,22 +61,22 @@ TEST_CASE("Appending Shapes", "[tvgShape]")
     REQUIRE(shape->lineTo(120, 140) == Result::Success);
 
     REQUIRE(shape->appendRect(0, 0, 0, 0, 0, 0) == Result::Success);
-    REQUIRE(shape->appendRect(0, 0,99999999, -99999999, 0, 0) == Result::Success);
-    REQUIRE(shape->appendRect(0, 0, 0, 0, -99999999, 99999999) == Result::Success);
-    REQUIRE(shape->appendRect(99999999, -99999999, 99999999, -99999999, 99999999, -99999999) == Result::Success);
+    REQUIRE(shape->appendRect(0, 0,99999999.0f, -99999999.0f, 0, 0) == Result::Success);
+    REQUIRE(shape->appendRect(0, 0, 0, 0, -99999999.0f, 99999999.0f) == Result::Success);
+    REQUIRE(shape->appendRect(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success);
 
     REQUIRE(shape->appendCircle(0, 0, 0, 0) == Result::Success);
-    REQUIRE(shape->appendCircle(-99999999, 99999999, 0, 0) == Result::Success);
-    REQUIRE(shape->appendCircle(-99999999, 99999999, -99999999, 99999999) == Result::Success);
+    REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, 0, 0) == Result::Success);
+    REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f) == Result::Success);
 
     REQUIRE(shape->appendArc(0, 0, 0, 0, 0, false) == Result::Success);
     REQUIRE(shape->appendArc(0, 0, 0, 0, 0, true) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, 0, 0, 0, false) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, 0, 0, 0, true) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, -99999999, 99999999, 0, false) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, -99999999, 99999999, 0, true) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, -99999999, 99999999, -400, false) == Result::Success);
-    REQUIRE(shape->appendArc(-99999999, 99999999, -99999999, 99999999, 400, true) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, false) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, true) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, false) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, true) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -400, false) == Result::Success);
+    REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 400, true) == Result::Success);
 }
 
 TEST_CASE("Appending Pathes", "[tvgShape]")
index 5dddc77..4d6e8aa 100644 (file)
@@ -275,7 +275,7 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
     basicPicture = Picture::gen();
     REQUIRE(basicPicture);
     REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
-    REQUIRE(basicPicture->scale(0.2) == Result::Success);
+    REQUIRE(basicPicture->scale(0.2f) == Result::Success);
     rectMask = tvg::Shape::gen();
     REQUIRE(rectMask);
     REQUIRE(rectMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);