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
[imgcodecs] Support unicode filenames on Windows. #19862
Conversation
Please check conversations from the similar PRs / issues first. There is also FAQ item about this topic.
This is not true. Almost all codecs are external and they are located in the "3rdparty" subdirectory (or they are used as external libraries, e.g. in vcpkg build scripts). |
Internal codecs? |
|
jenkins cn please retry a build |
1 similar comment
jenkins cn please retry a build |
modules/imgcodecs/src/utils.cpp
Outdated
if (f) | ||
return f; | ||
// try unicode path assuming utf8 was passed | ||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems, static should removed to prevent data races.
@egorpugin, thank you for the contribution! there are several issues with the patch:
One of the possible methods to fix the problem with unicode paths on Windows would be to implement cv::imread()/cv::imwrite in 2 steps:
There is a problem with such in-memory encoding/decoding approach is that for some codecs cv::imdecode()/cv::imencode are implemented via cv::imread()/cv::imwrite with temporary files, so there is a risk of infinite recursion. But the majority of codecs support in-memory encoding/decoding. In any case, there should be protection against infinite recursion. Are you willing to try to implement this 2-step approach with a proper protection? |
Hi, Thank you for the explanation. |
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.
Hi,
This PR enables unicode file name support for imgcodecs on Windows. With it opencv can read and write to files with unicode file names given utf8 file name is provided.
It also adds long path support (see PR condition
if (s.size() >= 255)
).Custom
cv::fopen()
is added to utils.hpp, so all codecs will see it.On windows it performs utf8 to wstring conversion and
_wfopen_s()
call.On other systems libc fopen is called.
There is fast path if we open ascii filename. If it fails, conversion code path is used.