Page 1 of 1

opening images with unicode filepaths?

Posted: 2006-12-30T14:14:16-07:00
by Seriema

I need to open images with unicode filepaths, such as japanese characters (example: 私.tga).

I'm using MagickCore and noticed that ImageInfo::filename is a char array. I need it to use wchar_t... or at least open the FILE* ImageInfo::file some other way.

I read the image like so:

Code: Select all

wchar_t* path = L"私.tga";
ExceptionInfo *exception = AcquireExceptionInfo();
ImageInfo *image_info=CloneImageInfo((ImageInfo *) NULL);
wcstombs(image_info->filename, path, sizeof(image_info->filename)/sizeof(char)); // Here I copy the wchar_t* path to the char* filename in ImageInfo.
Image *images=ReadImage(image_info,exception);
How should I read an image that has unicode characters in the filepath?

Posted: 2007-01-03T12:24:19-07:00
by Seriema
Seriously, can't ImageMagick read images with unicode file paths?

Posted: 2007-01-03T12:41:45-07:00
by magick
Post a URL to one of your Unicode images so we can download and investigate. We need to reproduce the problem before we can offer a solution.

Posted: 2007-01-03T16:05:28-07:00
by Seriema
Here's one

Thank you.

Posted: 2007-01-03T16:44:27-07:00
by magick
We unpacked your image and displayed and converted it without any problems. We tried both *.tga and 私.tga. We're using ImageMagick 6.3.1-5 under Fedora Core 6.

Posted: 2007-01-03T16:50:48-07:00
by Seriema
That's really odd, since MagickCore uses a char* for filepaths. How did you do it in code?..

Posted: 2007-01-03T19:12:14-07:00
by anthony
UTF-8 unicode is designed to be storable in normal strings. Just with specal meta-charcater codes to handle the non-ascii parts. that is one character may not ne one byte.

char* is fine for unicode, you just have to know it may be unicode and use the appropriate librarys to handle the unicode strings, rather than the old one byte = one char techniques.

study it a little and you will understand.

Posted: 2007-01-04T08:49:55-07:00
by Seriema
On my target platform (Windows XP) the following holds true:
printf("%p\n", fopen("c:\\temp\\私.tga", "rb")); // null
printf("%p\n", _wfopen(L"c:\\temp\\私.tga", L"rb"));// works!
Im guessing Fedora Core is a bit smarter about its path handling.

So how do I pass a wchar_t* as a file path, or how do I override the file loading rutine?

Posted: 2007-01-04T10:48:47-07:00
by magick
We have a patch to read Unicode filenames for Windows. Look for the patch in ImageMagick 6.3.1-6 Beta within a few days.

Posted: 2007-01-04T17:27:36-07:00
by Seriema
That sounds awesome! Can't wait. Thank you, I'll let you know how it goes.

Posted: 2007-01-04T17:50:27-07:00
by anthony
Seriema wrote: Im guessing Fedora Core is a bit smarter about its path handling.

More likely the Window OS is just makign things more complex. The OS designers tend to fix things by adding replacement routines, rather than fixing the original OS routines as it is done in the UNIX.

The need to specify 'binary' for files is a case in point, dating back to the DOS days.

PS: you may have guessed, I am not a big fan of Window-doze!

Re: opening images with unicode filepaths?

Posted: 2007-03-22T15:29:12-07:00
by Seriema
Sorry for not writing in sooner. I did try out that patch and even version 6.3.2, but I don't see how it's fixed anything since the function still takes a regular char*. As I noted in my earlier example you have to pass a string as a wide char pointer otherwise Windows won't recognize any special characters. Did I miss something? Was a new ReadImage introduced that I didn't see?

Re: opening images with unicode filepaths?

Posted: 2007-03-23T07:46:24-07:00
by magick
Our understanding is that you can UTF-8 encode your file path and pass it as a char *.