Skip to content

[Windows] load image with filenames other than english #7435

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

Open
wants to merge 124 commits into
base: master
Choose a base branch
from

Conversation

dimitre
Copy link
Member

@dimitre dimitre commented Mar 26, 2023

The idea behind this PR is to use std::filesystem::path object to store the filename until right up the freeimage function is called. FreeImage has some special functions to handle wstring, so they are called for windows, conserving original encoding.

@dimitre dimitre marked this pull request as ready for review March 26, 2023 19:53
@dimitre
Copy link
Member Author

dimitre commented Mar 26, 2023

Hey @oxillo please check this PR when you have the time. I don't know much about windows but I've tried to fix path encodings there, it seems to be working.

@dimitre
Copy link
Member Author

dimitre commented Mar 26, 2023

PS: there is a test there meant to be removed before merge

@dimitre
Copy link
Member Author

dimitre commented Oct 22, 2024

@roymacdonald thanks I've fixed the dialog title issues in latest and updated the repo with more tests and more filenames.
But there is another strange issue:
When opening filenames containing cyrillic in wchar_t / wstring it quits with a kernel panic.
it would be great to have more opinions from windows experienced ones.
ping : @openframeworks/windows @artificiel @danoli3

@roymacdonald
Copy link
Contributor

Interesting. What ever it is that causes a kernel panic it must not be nice. No idea from my side. I mostly work on macos

@artificiel
Copy link
Contributor

@dimitre do you have a trace on that crash? maybe the cyrilic are actually truly non-convertible wide (a lot of unicode is convertible wide->narrow, everything on the basic plane will not cause an exception with .string()). also what makes things complicated is the encoding of the source files — if you are getting an error from data received by the OS/FS, but not if you type the same strings in a .h, it may indicate that the source files are themselves being converted, so typed-in unicode chars are actually "preconverted" by the text editor. i don't have an MSVC env to try things...

one way to isolate the source encoding is by passing actual bytes like

std::wstring s = L"Hello, \u4E16\u754C!"; // "Hello, 世界!"

so whatever happens to the intepretation of the glyphs in the file, the string will be built with the actual codepoints (and as far as i can tell, those are true wides, but i did not find a super clear reference about that). if you can capture the wchar that trigger your crash they would be helpful for future testing.

(it would be very great if the MSVC tests in OF github CI could be augmented and also fail. right now it seems MSVC is passing everything although it should not... maybe a "hosted"/VM thing?)

@dimitre
Copy link
Member Author

dimitre commented Oct 23, 2024

@artificiel I don't have the trace. I only have occasional access to a slow windows "box"
the crash is related to cyrillic in some file name (jpg) I'm trying to load.
the tests are here if somebody else wants to check, including some filenames https://github.com/dimitre/ofTests/tree/main/WinEncoding
I'll be adding chinese / japanese or korean filenames to see if it runs ok when I test on windows again.

@NickHardeman
Copy link
Contributor

Hi @dimitre, testing on Windows 10 with your branch,
I get the following error in the debug console
[ error ] ofImage: loadImage(): couldn't load image from "consolação.jpg"

image

@danoli3
Copy link
Member

danoli3 commented Oct 25, 2024 via email

@artificiel
Copy link
Contributor

@NickHardeman can you check Project Properties > Configuration Properties > General > Character Set -> should be a form of unicode; and can you verify the encoding used for the source file that contains

image.load("consolação.jpg");

is correctly encoded File > Advanced Save Options... -> UTF-8 without BOM.

@NickHardeman
Copy link
Contributor

@artificiel This is the configuration property I found for unicode and it was already set for the openframeworksLib and WinEcoding project.
image
Not sure how check the source encoding for the file... I tried opening the image with VS, but there wasn't an option for Advanced Save Options

@artificiel
Copy link
Contributor

@NickHardeman the file encoding i meant was not for the image itself but the .cpp that contains the quoted string!

https://learn.microsoft.com/en-us/visualstudio/ide/how-to-save-and-open-files-with-encoding?view=vs-2022

@NickHardeman
Copy link
Contributor

image
image
I tried the following, but the errors persist.

@NickHardeman
Copy link
Contributor

Passing in a wstring to the load function works.
image

@NickHardeman
Copy link
Contributor

Not sure how, but passing in a narrow string to a path constructor and then passing that to image.load() also works.

std::string str = "consolação.jpg";
std::filesystem::path p{ str };
image.load(p);

@NickHardeman
Copy link
Contributor

NickHardeman commented Oct 25, 2024

If I remove the const and reference & from the image load function, then it works with a narrow string.
bool ofImage_<PixelType>::load( of::filesystem::path fileName, const ofImageLoadSettings & settings){

bool ofImage_<PixelType>::load(const of::filesystem::path & fileName, const ofImageLoadSettings & settings){

std::string str = "consolação.jpg";
image.load(str);
// also works
image.load("consolação.jpg");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants