Hacker News new | ask | show | jobs
by objclxt 4904 days ago
Somebody covered this further up, but in more detail:

It is not the rotation itself that is the problem, but saving the resultant file. If you're working directly with the pixel buffer you only do a lossless JPG rotation if the image height and width are multiples of 8 (or 16, in some situations). This is because once you've performed the rotation you'll need to save the resulting output as a JPG, and unless your dimensions factor into the block size you'll need to recompute. This SO answer covers it in more detail[1].

However, if you're not working with the pixel buffer this doesn't apply. You can use jpegtran (part of libjpeg), for example, which manipulates the JPG file directly and never decodes it. Many basic image viewers and editors (like the Windows Picture Viewer, and probably the iOS Photos app but I'm not sure) don't use this approach though.

[1]: http://photo.stackexchange.com/questions/12361/are-windows-p...

1 comments

Very informative, thanks a lot. I hadn't considered that JPEG rotation is more complicated than regular bitmap rotation.
Doesn't the camera have the original bitmap data though? Seems like it could just rotate it before converting to JPEG.