-
Notifications
You must be signed in to change notification settings - Fork 910
Can't open created ppm file (PPM must be ASCII or UTF-8) #636
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
From the book:
I use ImageMagick personally, but there are other results. |
I'm on Windows by the way... I've searched for information about the ppm header and I don't see any differences compared to mine so I'm not sure what's happening. |
Attached a PPM file that you should be able to view. You'll need to rename the extension from .txt to .ppm (GitHub restricts uploads to a small set of acceptable file extensions). Is your file written out with a Unicode BOM perhaps? Here are the first bytes of the attached PPM file:
(Note that you should be able to use either LF or CRLF line endings.) |
I reran your code, on windows, and got a ppm that I was able to view in FastStone |
You could also rename your PPM output file to have a |
Yup. Your file is UTF-16 with BOM. It should be UTF-8 or ASCII with no BOM. |
Image looks good when converted to UTF-8 no BOM. |
Ok great! So I assume this has something to do with the Visual Studio project settings? I'm going to search on how to set the output format. |
Ugh. Now I'm not confident that I know how my code's working. :) I thought it would be a project setting, but then I just read that the text output is indeed UTF-8, but the Windows console transforms this to UTF-16. I remember getting this same result in another project, and ended up (for a while) setting my codepage to Unicode to fix this. You can change the codepage in a Windows command shell with the There's also mention of the Windows API Still I don't know why this is all working for me, as I'm doing none of these things. It's possible that CMake is fixing this for me, by supplying the Visual Studio |
I don't see any obvious Unicode or UTF-8 mentions in the CMake-generated |
Ok, I tried it but it wasn't working. This gave me an idea however. I was running the executable from a PowerShell window inside Visual Studio. I tried running it from a regular CMD window and that fixed the issue. |
Sigh. |
Without too much work, you could alter the program to take an output image filename on the command line and create the file directly. Or just take your workaround and carry on. |
However, it's useful to note that the program/build wasn't the issue, it was the environment inducing the encoding change. |
I can open a CMD window inside VS so it's not really an issue at the moment. And yes, I assumed it was going to be something like that. This might be good to add as a note in the book. |
Glad to help. We have kicked around the idea of general system-specific notes. This would indeed be a good candidate entry. I'm leaving this open, assigned to a future milestone. |
Same problem, thanks for helping me track this down. This is what fixed it for me with Powershell on Windows. Based on some stack overflow posts this is a problem lots of people have with Powershell for various text outputs:
I tried |
Maybe this should get spun out into a discussion? I'm not sure what the issue to solve here is? |
Since this is such a basic requirement for our project, it warrants a quick mention somehow. In the past, we talked about developer notes for various platforms, but for now we can just mention generally that if you can't see the image, you should check the actual emitted bytes somehow, since all of the rest depends on being able to view the resulting images. |
Revisiting this, I like Trevor's suggestion. I'll seed a discussion, and then point to it from a very short comment in the book. |
See discussion #1114. |
* Add hints for dealing with bad PPMs on Windows Resolves #636 * Incorporating review comments
* Add hints for dealing with bad PPMs on Windows Resolves #636 * Incorporating review comments
* Add hints for dealing with bad PPMs on Windows Resolves #636 * Incorporating review comments
I've just started reading/implementing Ray Tracing in One Weekend and already stumbled upon this problem. This is my c++ code:
And this is the output in the .ppm file:
P3
256 256
255
0 255 63
1 255 63
2 255 63
3 255 63
4 255 63
5 255 63
6 255 63
7 255 63
8 255 63
9 255 63
10 255 63
...
Tried opening this with Gimp, XNView and IrfanView but they all can't seem to read the file.
The text was updated successfully, but these errors were encountered: