From 71bb4163eda81a69332a27b2d3826db118ecc175 Mon Sep 17 00:00:00 2001 From: Fabian Blatz Date: Wed, 12 Feb 2025 17:43:34 +0900 Subject: [PATCH] common: fixed double-precision promotion compilation warnings Co-Authored-By: Hermet Park --- examples/EffectDropShadow.cpp | 6 +-- examples/GradientTransform.cpp | 8 +-- examples/ImageRotation.cpp | 2 +- examples/SceneEffects.cpp | 4 +- examples/Transform.cpp | 6 +-- examples/Update.cpp | 4 +- inc/thorvg.h | 2 +- src/loaders/lottie/tvgLottieBuilder.cpp | 4 +- src/loaders/lottie/tvgLottieParser.cpp | 2 +- src/loaders/svg/tvgSvgSceneBuilder.cpp | 2 +- src/loaders/webp/utils/random.cpp | 4 +- src/renderer/gl_engine/tvgGlTessellator.cpp | 56 ++++++++++----------- 12 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/EffectDropShadow.cpp b/examples/EffectDropShadow.cpp index bad94cfb..895ad516 100644 --- a/examples/EffectDropShadow.cpp +++ b/examples/EffectDropShadow.cpp @@ -101,13 +101,13 @@ struct UserExample : tvgexam::Example //Clear the previously applied effects scene1->push(tvg::SceneEffect::ClearAll); //Apply DropShadow post effect (r, g, b, a, angle, distance, sigma of blurness, quality) - scene1->push(tvg::SceneEffect::DropShadow, 0, 0, 0, 125, 120.0f, 20.0f * progress, 3.0f, 100); + scene1->push(tvg::SceneEffect::DropShadow, 0, 0, 0, 125, 120, (double)(20.0f * progress), 3, 100); scene2->push(tvg::SceneEffect::ClearAll); - scene2->push(tvg::SceneEffect::DropShadow, 65, 143, 222, (int)(255.0f * progress), 135.0f, 10.0f, 3.0f, 100); + scene2->push(tvg::SceneEffect::DropShadow, 65, 143, 222, (int)(255.0f * progress), 135, 10, 3, 100); scene3->push(tvg::SceneEffect::ClearAll); - scene3->push(tvg::SceneEffect::DropShadow, 0, 0, 0, 125, 360.0f * progress, 20.0f, 3.0f, 100); + scene3->push(tvg::SceneEffect::DropShadow, 0, 0, 0, 125, (double)(360.0f * progress), 20, 3, 100); canvas->update(); diff --git a/examples/GradientTransform.cpp b/examples/GradientTransform.cpp index eeb78396..8cb530ff 100644 --- a/examples/GradientTransform.cpp +++ b/examples/GradientTransform.cpp @@ -63,8 +63,8 @@ struct UserExample : tvgexam::Example shape->translate(385, 400); //Update Shape1 - shape->scale(1 - 0.75 * progress); - shape->rotate(360 * progress); + shape->scale(1.0f - 0.75f * progress); + shape->rotate(360.0f * progress); canvas->push(shape); @@ -113,8 +113,8 @@ struct UserExample : tvgexam::Example shape3->translate(400, 400); //Update Shape3 - shape3->rotate(-360 * progress); - shape3->scale(0.5 + progress); + shape3->rotate(-360.0f * progress); + shape3->scale(0.5f + progress); canvas->push(shape3); diff --git a/examples/ImageRotation.cpp b/examples/ImageRotation.cpp index 7c5c97d6..23822218 100644 --- a/examples/ImageRotation.cpp +++ b/examples/ImageRotation.cpp @@ -34,7 +34,7 @@ struct UserExample : tvgexam::Example float deg2rad(float degree) { - return degree * (M_PI / 180.0f); + return degree * (float(M_PI) / 180.0f); } bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override diff --git a/examples/SceneEffects.cpp b/examples/SceneEffects.cpp index 33b5a4e1..586b50c4 100644 --- a/examples/SceneEffects.cpp +++ b/examples/SceneEffects.cpp @@ -104,7 +104,7 @@ struct UserExample : tvgexam::Example //Apply GaussianBlur post effect (sigma, direction, border option, quality) for (int i = 0; i < 3; ++i) { blur[i]->push(tvg::SceneEffect::ClearAll); - blur[i]->push(tvg::SceneEffect::GaussianBlur, 10.0f * progress, i, 0, 100); + blur[i]->push(tvg::SceneEffect::GaussianBlur, (double)(10.0f * progress), i, 0, 100); } //Apply Fill post effect (rgba) @@ -113,7 +113,7 @@ struct UserExample : tvgexam::Example //Apply Tint post effect (black:rgb, white:rgb, intensity) tint->push(tvg::SceneEffect::ClearAll); - tint->push(tvg::SceneEffect::Tint, 0, 0, 0, 0, (int)(progress * 255), 0, progress * 100.0f); + tint->push(tvg::SceneEffect::Tint, 0, 0, 0, 0, (int)(progress * 255), 0, (double)(progress * 100.0f)); //Apply Trintone post effect (shadow:rgb, midtone:rgb, highlight:rgb) trintone->push(tvg::SceneEffect::ClearAll); diff --git a/examples/Transform.cpp b/examples/Transform.cpp index 7000e313..2d812f60 100644 --- a/examples/Transform.cpp +++ b/examples/Transform.cpp @@ -49,7 +49,7 @@ struct UserExample : tvgexam::Example shape->appendCircle(115, 200, 170, 100); shape->fill(255, 255, 255); shape->translate(385, 400); - shape->scale(1 - 0.75 * progress); + shape->scale(1.0f - 0.75f * progress); shape->rotate(360 * progress); canvas->push(shape); @@ -71,8 +71,8 @@ struct UserExample : tvgexam::Example shape3->appendRect(100, 100, 150, 50, 20, 20); shape3->fill(255, 0, 255); shape3->translate(400, 400); - shape3->rotate(-360 * progress); - shape3->scale(0.5 + progress); + shape3->rotate(-360.0f * progress); + shape3->scale(0.5f + progress); canvas->push(shape3); return true; diff --git a/examples/Update.cpp b/examples/Update.cpp index a6dad7a4..1dce73a9 100644 --- a/examples/Update.cpp +++ b/examples/Update.cpp @@ -54,8 +54,8 @@ struct UserExample : tvgexam::Example shape->appendRect(-100, -100, 200, 200, (100 * progress), (100 * progress)); shape->fill(rand() % 255, rand() % 255, rand() % 255); shape->translate(800 * progress, 800 * progress); - shape->scale(1 - 0.75 * progress); - shape->rotate(360 * progress); + shape->scale(1.0f - 0.75f * progress); + shape->rotate(360.0f * progress); canvas->push(shape); diff --git a/inc/thorvg.h b/inc/thorvg.h index 5ae245a6..f239051b 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -230,7 +230,7 @@ enum class SceneEffect : uint8_t { ClearAll = 0, ///< Reset all previously applied scene effects, restoring the scene to its original state. GaussianBlur, ///< Apply a blur effect with a Gaussian filter. Param(3) = {sigma(float)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]} - DropShadow, ///< Apply a drop shadow effect with a Gaussian Blur filter. Param(8) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255], angle(float)[0 - 360], distance(float), blur_sigma(float)[> 0], quality(int)[0 - 100]} + DropShadow, ///< Apply a drop shadow effect with a Gaussian Blur filter. Param(8) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255], angle(double)[0 - 360], distance(double), blur_sigma(double)[> 0], quality(int)[0 - 100]} Fill, ///< Override the scene content color with a given fill information (Experimental API). Param(5) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255]} Tint, ///< Tinting the current scene color with a given black, white color paramters (Experimental API). Param(7) = {black_R(int)[0 - 255], black_G(int)[0 - 255], black_B(int)[0 - 255], white_R(int)[0 - 255], white_G(int)[0 - 255], white_B(int)[0 - 255], intensity(float)[0 - 100]} Tritone ///< Apply a tritone color effect to the scene using three color parameters for shadows, midtones, and highlights (Experimental API). Param(9) = {Shadow_R(int)[0 - 255], Shadow_G(int)[0 - 255], Shadow_B(int)[0 - 255], Midtone_R(int)[0 - 255], Midtone_G(int)[0 - 255], Midtone_B(int)[0 - 255], Highlight_R(int)[0 - 255], Highlight_G(int)[0 - 255], Highlight_B(int)[0 - 255]} diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index eeaac22e..407c384a 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -1303,12 +1303,12 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) auto effect = static_cast(*p); auto color = effect->color(frameNo); //seems the opacity range in dropshadow is 0 ~ 256 - layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), (double)effect->distance(frameNo), (double)effect->blurness(frameNo) * BLUR_TO_SIGMA, QUALITY); + layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), (double)effect->distance(frameNo), (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), QUALITY); break; } case LottieEffect::GaussianBlur: { auto effect = static_cast(*p); - layer->scene->push(SceneEffect::GaussianBlur, (double)effect->blurness(frameNo) * BLUR_TO_SIGMA, effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY); + layer->scene->push(SceneEffect::GaussianBlur, (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY); break; } default: break; diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 4c6af859..b8625f74 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -372,7 +372,7 @@ LottieInterpolator* LottieParser::getInterpolator(const char* key, Point& in, Po char buf[20]; if (!key) { - snprintf(buf, sizeof(buf), "%.2f_%.2f_%.2f_%.2f", in.x, in.y, out.x, out.y); + snprintf(buf, sizeof(buf), "%.2f_%.2f_%.2f_%.2f", (double)in.x, (double)in.y, (double)out.x, (double)out.y); key = buf; } diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 4c7418b9..c1c3d34b 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -384,7 +384,7 @@ static Paint* _applyFilter(SvgLoaderData& loaderData, Paint* paint, const SvgNod stdDevX *= bbox.w; stdDevY *= bbox.h; } - scene->push(SceneEffect::GaussianBlur, 1.25f * (direction == 2 ? stdDevY * sy : stdDevX * sx), direction, gauss.edgeModeWrap, 55); + scene->push(SceneEffect::GaussianBlur, (double)(1.25f * (direction == 2 ? stdDevY * sy : stdDevX * sx)), direction, gauss.edgeModeWrap, 55); } } diff --git a/src/loaders/webp/utils/random.cpp b/src/loaders/webp/utils/random.cpp index 24e96ad6..fac43c57 100644 --- a/src/loaders/webp/utils/random.cpp +++ b/src/loaders/webp/utils/random.cpp @@ -34,8 +34,8 @@ void VP8InitRandom(VP8Random* const rg, float dithering) { memcpy(rg->tab_, kRandomTable, sizeof(rg->tab_)); rg->index1_ = 0; rg->index2_ = 31; - rg->amp_ = (dithering < 0.0) ? 0 - : (dithering > 1.0) ? (1 << VP8_RANDOM_DITHER_FIX) + rg->amp_ = (dithering < 0.0f) ? 0 + : (dithering > 1.0f) ? (1 << VP8_RANDOM_DITHER_FIX) : (uint32_t)((1 << VP8_RANDOM_DITHER_FIX) * dithering); } diff --git a/src/renderer/gl_engine/tvgGlTessellator.cpp b/src/renderer/gl_engine/tvgGlTessellator.cpp index 96fc3120..54b6a572 100644 --- a/src/renderer/gl_engine/tvgGlTessellator.cpp +++ b/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -182,16 +182,16 @@ struct Edge : public Object // https://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line // return > 0 means point in left // return < 0 means point in right - double sideDist(const Point& p); + float sideDist(const Point& p); bool isRightOf(const Point& p) { - return sideDist(p) < 0.0; + return sideDist(p) < 0.0f; } bool isLeftOf(const Point& p) { - return sideDist(p) > 0.0; + return sideDist(p) > 0.0f; } // https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection @@ -202,9 +202,9 @@ struct Edge : public Object void disconnect(); private: - double le_a; - double le_b; - double le_c; + float le_a; + float le_b; + float le_c; }; @@ -403,14 +403,14 @@ Edge::Edge(Vertex *top, Vertex *bottom, int32_t winding) : top(top), bottom(bottom), winding(winding), - le_a(static_cast(bottom->point.y) - top->point.y), - le_b(static_cast(top->point.x) - bottom->point.x), - le_c(static_cast(top->point.y) * bottom->point.x - static_cast(top->point.x) * bottom->point.y) + le_a(bottom->point.y - top->point.y), + le_b(top->point.x - bottom->point.x), + le_c(top->point.y * bottom->point.x - top->point.x * bottom->point.y) { } -double Edge::sideDist(const Point& p) +float Edge::sideDist(const Point& p) { return le_a * p.x + le_b * p.y + le_c; } @@ -431,22 +431,22 @@ bool Edge::intersect(Edge *other, Point* point) auto denom = le_a * other->le_b - le_b * other->le_a; if (tvg::zero(denom)) return false; - auto dx = static_cast(other->top->point.x) - top->point.x; - auto dy = static_cast(other->top->point.y) - top->point.y; + auto dx = other->top->point.x - top->point.x; + auto dy = other->top->point.y - top->point.y; auto s_number = dy * other->le_b + dx * other->le_a; auto t_number = dy * le_b + dx * le_a; - if (denom > 0.0 ? (s_number < 0.0 || s_number > denom || t_number < 0.0 || t_number > denom) : (s_number > 0.0 || s_number < denom || t_number > 0.0 || t_number < denom)) return false; + if (denom > 0.0f ? (s_number < 0.0f || s_number > denom || t_number < 0.0f || t_number > denom) : (s_number > 0.0f || s_number < denom || t_number > 0.0f || t_number < denom)) return false; - auto scale = 1.0 / denom; - point->x = nearbyintf(static_cast(top->point.x - s_number * le_b * scale)); - point->y = nearbyintf(static_cast(top->point.y + s_number * le_a * scale)); + auto scale = 1.0f / denom; + point->x = nearbyintf(top->point.x - s_number * le_b * scale); + point->y = nearbyintf(top->point.y + s_number * le_a * scale); if (std::isinf(point->x) || std::isinf(point->y)) return false; - if (std::abs(point->x - top->point.x) < 1e-6 && std::abs(point->y - top->point.y) < 1e-6) return false; - if (std::abs(point->x - bottom->point.x) < 1e-6 && std::abs(point->y - bottom->point.y) < 1e-6) return false; - if (std::abs(point->x - other->top->point.x) < 1e-6 && std::abs(point->y - other->top->point.y) < 1e-6) return false; - if (std::abs(point->x - other->bottom->point.x) < 1e-6 && std::abs(point->y - other->bottom->point.y) < 1e-6) return false; + if (fabsf(point->x - top->point.x) < 1e-6f && fabsf(point->y - top->point.y) < 1e-6f) return false; + if (fabsf(point->x - bottom->point.x) < 1e-6f && fabsf(point->y - bottom->point.y) < 1e-6f) return false; + if (fabsf(point->x - other->top->point.x) < 1e-6f && fabsf(point->y - other->top->point.y) < 1e-6f) return false; + if (fabsf(point->x - other->bottom->point.x) < 1e-6f && fabsf(point->y - other->bottom->point.y) < 1e-6f) return false; return true; } @@ -454,9 +454,9 @@ bool Edge::intersect(Edge *other, Point* point) void Edge::recompute() { - le_a = static_cast(bottom->point.y) - top->point.y; - le_b = static_cast(top->point.x) - bottom->point.x; - le_c = static_cast(top->point.y) * bottom->point.x - static_cast(top->point.x) * bottom->point.y; + le_a = bottom->point.y - top->point.y; + le_b = top->point.x - bottom->point.x; + le_c = top->point.y * bottom->point.x - top->point.x * bottom->point.y; } @@ -1488,12 +1488,12 @@ void Tessellator::emitPoly(MonotonePolygon *poly) return; } - double ax = static_cast(curr->point.x) - prev->point.x; - double ay = static_cast(curr->point.y) - prev->point.y; - double bx = static_cast(next->point.x) - curr->point.x; - double by = static_cast(next->point.y) - curr->point.y; + auto ax = curr->point.x - prev->point.x; + auto ay = curr->point.y - prev->point.y; + auto bx = next->point.x - curr->point.x; + auto by = next->point.y - curr->point.y; - if (ax * by - ay * bx >= 0.0) { + if (ax * by - ay * bx >= 0.0f) { emitTriangle(prev, curr, next); v->prev->next = v->next; v->next->prev = v->prev;