Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text with shadow rendering #3932

Open
progweb opened this issue Jul 31, 2023 · 3 comments
Open

Text with shadow rendering #3932

progweb opened this issue Jul 31, 2023 · 3 comments
Labels
image processing Related to ImageBufAlgo or other image processing topic.

Comments

@progweb
Copy link
Contributor

progweb commented Jul 31, 2023

As render text with shadow with channel alpha, I don't get the same result that without channel alpha.

Without channel alpha, shadow option permit to draw a dilated text in black, whereas with channel alpha, OIIO makes a gap...

Working with dev-2.2 branch, I can see the same issue on master branch.

[Note]: OpenImageIO is used in the gpx2video project.

@progweb
Copy link
Contributor Author

progweb commented Jul 31, 2023

From bec7340a06844588d5364f444033624bfe8d8559 Mon Sep 17 00:00:00 2001
From: Nicolas VIVIEN <nicolas@vivien.fr>
Date: Mon, 31 Jul 2023 13:44:22 +0200
Subject: [PATCH] Fix shadow text rendering on alpha buffer

---
 src/libOpenImageIO/imagebufalgo_draw.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/libOpenImageIO/imagebufalgo_draw.cpp b/src/libOpenImageIO/imagebufalgo_draw.cpp
index 376f66451..18dc7c527 100644
--- a/src/libOpenImageIO/imagebufalgo_draw.cpp
+++ b/src/libOpenImageIO/imagebufalgo_draw.cpp
@@ -930,7 +930,10 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
         // If the buffer doesn't have an alpha, but the text color passed
         // has 4 values, assume the last value is supposed to be alpha.
         textalpha = textcolor[3];
+		alpha_channel = 3;
     }
+    } else
+		alpha_channel = -1;
 
     // Convert the UTF to 32 bit unicode
     std::vector<uint32_t> utext;
@@ -1009,8 +1012,14 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
         float val   = t[0];
         float alpha = a[0] * textalpha;
         R.getpixel(r.x(), r.y(), pixelcolor);
-        for (int c = 0; c < nchannels; ++c)
-            pixelcolor[c] = val * textcolor[c] + (1.0f - alpha) * pixelcolor[c];
+		if (alpha == 0.0)
+			continue;
+        for (int c = 0; c < nchannels; ++c) {
+			if (c == alpha_channel)
+				pixelcolor[c] = alpha + (1.0f - alpha) * pixelcolor[c];
+			else 
+				pixelcolor[c] = (val * alpha * textcolor[c]) + (1.0f - alpha) * pixelcolor[c];
+		}
         R.setpixel(r.x(), r.y(), pixelcolor);
     }
 
-- 
2.39.0

@progweb
Copy link
Contributor Author

progweb commented Jul 31, 2023

In using this patch, shadow option works as expected on image with alpha buffer.

@lgritz
Copy link
Collaborator

lgritz commented Jul 31, 2023

Hi, can you please submit this as a actual PR so it will run in CI, reviewed with comments, and then easily merged?

@lgritz lgritz added the image processing Related to ImageBufAlgo or other image processing topic. label Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
image processing Related to ImageBufAlgo or other image processing topic.
Projects
None yet
Development

No branches or pull requests

2 participants