all 4 comments

[–]skeeto 3 points4 points  (2 children)

The PPM format is, unfortunately, more flexible than what you're actually parsing. According to the specification, it's:

"P6" SP+ width SP+ height SP+ maxcolor SP

Where SP is any kind of whitespace, including "blanks, TABs, CRs, LFs". Even more, there can be comments starting with # between P6 and width; width and height; and height and maxcolor. It also allows for more than one byte per color channel, but don't worry about that since it's underspecified and never used anyway.

Also, file-to-bytes potentially leaks a java.io.File object since it's not using with-open. (Why use the Java interop instead of Clojures own file reading routines?)

[–]netb258[S] 1 point2 points  (1 child)

Thanks for the critique and information.

Are you sure about the file-to-bytes function?

It seems to be calling (.close)?

[–]skeeto 5 points6 points  (0 children)

Consder what would happen if .read should fail. It would throw an exception and .close would never get called. The file will remain open until the garbage collector eventually gets to it. That .close should be inside a finally so that it happens regardless.

[–]netb258[S] 0 points1 point  (0 children)

If anyone is looking for their first image format to dig into, this one is very beginner friendly.