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

Rewrite Add Text node #181

Open
Correct-Syntax opened this issue Mar 17, 2023 · 10 comments
Open

Rewrite Add Text node #181

Correct-Syntax opened this issue Mar 17, 2023 · 10 comments
Assignees
Labels
feature New feature or request glsl This issue requires knowledge of GLSL shaders good first issue Good for new contributors medium priority Something we'd like to get to nodes Has to do with nodes python This issue includes writing Python code ready Non-blocked issue ready to be implemented

Comments

@Correct-Syntax
Copy link
Member

Correct-Syntax commented Mar 17, 2023

In an effort to remove our hard dependence on OpenImageIO which is difficult to install properly, this issue should rewrite the Add Text node (https://github.com/GimelStudio/GimelStudio/blob/master/src/nodes/corenodes/draw/add_text_node.py) using another library (numpy, opencv) or glsl.

@Correct-Syntax Correct-Syntax added feature New feature or request good first issue Good for new contributors python This issue includes writing Python code glsl This issue requires knowledge of GLSL shaders nodes Has to do with nodes medium priority Something we'd like to get to ready Non-blocked issue ready to be implemented labels Mar 17, 2023
@Yashupadhyay603
Copy link

Hello, @Correct-Syntax .
May I work on this rewriting?

@Correct-Syntax
Copy link
Member Author

Hi, @Yashupadhyay603. Sure I'll assign you. If you have any questions feel free to ask.

@Yashupadhyay603
Copy link

Yashupadhyay603 commented Mar 20, 2023

@Correct-Syntax ,Thank you very much.
Will start as soon as possible.

@Yashupadhyay603
Copy link

Yashupadhyay603 commented Mar 21, 2023

Hello @Correct-Syntax, I have seen the code to be changed .
I want to ask , how many fonts does OpenImageIO supports as opencv support only few types.
so using opencv would allow to use only few fonts.

@Correct-Syntax
Copy link
Member Author

Correct-Syntax commented Mar 21, 2023

Yeah, that would be a problem. OpenCV only has only a handful of fonts it can use, while OpenImageIO could use most any font (ref).

Text rendering via glsl/opengl is a complex topic, so I'm not even sure if you want to look into that.

I briefly looked into it (in case we want to go this route) and here's what I came up with:

There's also the Pillow library, but it has it's own set of problems.

  • We basically throw away a lot of data since Pillow only supports 8-bit (a waste since we are aiming for 16-bit editing)
  • It's another dependency

@iwoithe, any ideas?

@iwoithe
Copy link
Member

iwoithe commented Mar 21, 2023

There's also the Pillow library, but it has it's own set of problems.

We removed Pillow as a dependency a while back. I'd suggest to keep it this way if we can.

OpenCV only has only a handful of fonts it can use

Not sure how this translates to Python, but using custom fonts seems possible.

https://docs.opencv.org/4.1.1/d9/dfa/classcv_1_1freetype_1_1FreeType2.html

@iwoithe, any ideas?

I was also going to suggest GLSL until I looked into it. 🙄

The only other thing I can think of that you haven't suggested is using freetype-py. Not sure if it has all the features we currently have or if this will work at all with ModernGL/Numpy.

So, the order of my preference:

  1. OpenCV
  2. freetype-py (?)
  3. Keep using OpenImageIO

I will state that I would rather not use Pillow for the reasons @Correct-Syntax suggested (i.e. loss of 16-bit editing and another dependency). Also still not sure about freetype-py, so if OpenCV doesn't work out, I will let @Correct-Syntax decide whether to look into freetype-py or remain using OpenImageIO.

Hopefully there's something in this that helps. 🙂

@Correct-Syntax
Copy link
Member Author

Thanks for the additional thoughts, @iwoithe Looking at freetype-py, that actually seems like it could work.

I should say that I don't see using Pillow or sticking with OpenImageIO as options.

Ideally, we want to do as many of the image processing nodes on the gpu side of things using opengl/glsl as much as possible. This gives us the freedom to edit in high quality and, in theory, it will be faster. Plus, it's easier to translate opengl calls/glsl to anything we may do in the future (I think). So, my preference would be freetype-py + opengl/glsl if that works.

I think the real question is, @Yashupadhyay603 how comfortable are you with tackling this either using opencv or via freetype-py and opengl? Do you have experience with opengl/glsl?

Either of those would be acceptable for re-implementing this node, so whichever one works and you are comfortable using would be great.

For the opencv way, this: https://stackoverflow.com/a/57502572/12787591 may point in the right direction.
For the freetype-py + opengl way, that may involve some research on how to render the text to the opengl texture, etc.

I'm beginning to realize that the scope of this issue could be pretty big, so if you'd just rather not do it that is okay. But, if you're up for the challenge then I'll do my best to assist as time permits.

@Yashupadhyay603
Copy link

Thank you very much, @Correct-Syntax and @iwoithe for such good suggestions.

I will look over both of the ways and see which one would require least changes without loosing any functionality.

@Yashupadhyay603
Copy link

@Correct-Syntax , @iwoithe .
I have looked into both of these implementations and come to see a common process of importing font data from .ttf file.

So to import multiple font data we have to add their respective .ttf file in the project and then we can use custom fonts using OpenCV.

What are your suggestions regarding this ?

@Correct-Syntax
Copy link
Member Author

@Yashupadhyay603

We want to access the system fonts folder and get a list of the available ttf fonts on the user's computer. Then use that to populate the font selector dynamically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request glsl This issue requires knowledge of GLSL shaders good first issue Good for new contributors medium priority Something we'd like to get to nodes Has to do with nodes python This issue includes writing Python code ready Non-blocked issue ready to be implemented
Projects
Status: In Progress
Development

No branches or pull requests

3 participants