5 ms·
One interesting thing about JPEG is that you can rotate an image with no quality loss. You don't need to convert each 8x8 square to pixels, rotate and convert b
by ralferoo 1y ago
One interesting thing about JPEG is that you can rotate an image with no quality loss. You don't need to convert each 8x8 square to pixels, rotate and convert back, instead you can transform them in the encoded form. So, rotating each 8x8 square is easy, and then rotating the image is just re-ordering the rotated squares.
- pwdisswordfishz 1y agoThat doesn't seem to apply to images that aren't multiples of 8 in size, does it?
- justincormack 1y agothe stored image is always a multiple of 8, with padding that is ignored (and heavily compressed).
- pwdisswordfishz 1y agoBut can this lossless rotation process account for padding not being in the usual place (lower right corner presumably)?
- mort96 1y agoI'm not sure if this is how JPEG implements it, but in H.264, you just have metadata which specifies a crop (since H.264 also encodes in blocks). From some quick Googling, it seems like JPEG also has EXIF data for cropping, so if that's the mechanism that's used to crop off the bottom and right portions today, there's no reason it couldn't also be used to crop off the top and left portions when losslessly rotating an image's blocks.
- hidroto 1y agoare there any cameras that take pictures that are not a multiple of 8 in width and height?
- bdavbdav 1y agoPeople may crop
- dylan604 1y agoSlight nitpicking, but you can rotate in 90° increments without loss.
- meindnoch 1y agoOnly if the image width/height is a multiple of 8. See: the manpage of jpegtran, especially the -p flag.
- DidYaWipe 1y agoIndeed. Whenever I'm using an image browser/manager application that supports rotating images, I wonder if it's doing JPEG rotation properly (as you describe) or just flipping the dumb flag.