Most active commenters
  • DidYaWipe(5)
  • account42(4)
  • kllrnohj(3)

←back to thread

A new PNG spec

(www.programmax.net)
616 points bluedel | 30 comments | | HN request time: 0.001s | source | bottom
Show context
qwertox ◴[] No.44373847[source]
> Officially supports Exif data

Probably the best news here. While you already can write custom data into a header, having Exif is good.

BTW: Does Exif have a magnetometer (rotation) and acceleration (gravity) field? I often wonder about why Google isn't saving this information in the images which the camera app saves. It could help so much with post-processing, like with leveling the horizon or creating panoramas.

replies(7): >>44373955 #>>44373957 #>>44373987 #>>44375555 #>>44376496 #>>44382700 #>>44384608 #
Aardwolf ◴[] No.44373955[source]
Exif can also cause confusion for how to render the image: should its rotation be applied or not?

Old decoders and new decoders now could render an image with exif rotation differently since it's an optional chunk that can be ignored, and even for new decoders, the spec lists no decoder recommendations for how to use the exif rotation

It does say "It is recommended that unless a decoder has independent knowledge of the validity of the Exif data, the data should be considered to be of historical value only.", so hopefully the rotation will not be used by renderers, but it's only a vague recommendation, there's no strict "don't rotate the image" which would be the only backwards compatible way

With jpeg's exif, there have also been bugs with the rotation being applied twice, e.g. desktop environment and underlying library both doing it independently

replies(1): >>44374585 #
1. DidYaWipe ◴[] No.44374585[source]
The stupid thing is that any device with an orientation sensor is still writing images the wrong way and then setting a flag, expecting every viewing application to rotate the image.

The camera knows which way it's oriented, so it should just write the pixels out in the correct order. Write the upper-left pixel first. Then the next one. And so on. WTF.

replies(4): >>44374826 #>>44375663 #>>44376252 #>>44378679 #
2. mavhc ◴[] No.44374826[source]
Because your non-smartphone camera doesn't have enough ram/speed to do that I assume (when in burst mode)

If a smartphone camera is doing it, then bad camera app!

replies(4): >>44374904 #>>44375115 #>>44375776 #>>44385606 #
3. Joel_Mckay ◴[] No.44374904[source]
Most modern camera modules have built in hardware codecs like mjpeg, region of interest selection, and frame mirror/flip options.

This is particularly important on smartphones and battery operated devices. However, most smartphone devices simply save the photo the same way regardless of orientation, and simply add a display-rotated flag to the metadata.

It can be super annoying sometimes, as one can't really disable the feature on many devices. =3

4. Aardwolf ◴[] No.44375115[source]
Rotation for speed/efficiency/compression reasons (indeed with PNG's horizontal line filters it can have a compression reason too) should have been a flag part of the compressed image data format and for use by the encoder/decoder only (which does have caveats for renderers to handle partial decoding though... but the point is to have the behavior rigorously specified and encoded in the image format itself and handled by exactly one known place namely the decoder), not part of metadata

It's basically a shame that the exif metadata contains things that affect the rendering

5. ralferoo ◴[] No.44375663[source]
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.
replies(4): >>44377497 #>>44378464 #>>44380408 #>>44382688 #
6. joking ◴[] No.44375776[source]
the main reason is probably that the chip is already outputting the image in a lossy format, and if you reorder the pixels you must reencode the image which means degrading the image, so it's much better to just change the exif orientation.
replies(2): >>44380600 #>>44382773 #
7. klabb3 ◴[] No.44376252[source]
TIL, and hard agree (on face value). I’ve been struck by this with arbitrary rotation of images depending on application, very annoying.

What are the arguments for this? It would seem easier for everyone to rotate and then store exif for the original rotation if necessary.

replies(1): >>44376856 #
8. kllrnohj ◴[] No.44376856[source]
> What are the arguments for this? It would seem easier for everyone to rotate and then store exif for the original rotation if necessary.

Performance. Rotation during rendering is often free, whereas the camera would need an intermediate buffer + copy if it's unable to change the way it samples from the sensor itself.

replies(2): >>44376911 #>>44382757 #
9. airstrike ◴[] No.44376911{3}[source]
How is rotation during rendering free?
replies(2): >>44377445 #>>44378101 #
10. chainingsolid ◴[] No.44377445{4}[source]
Pretty much every pixel rendered these days was generated by a shader so gpu side you probably already have way more translation options than just a 90° rotation (likely already being used for a rotation of 0°). You'd likely have to write more code cpu side to handle the case of tell the gpu to rotate this please and handle the UI layout diffrence. Honestly not a lot of code.
11. pwdisswordfishz ◴[] No.44377497[source]
That doesn't seem to apply to images that aren't multiples of 8 in size, does it?
replies(2): >>44377708 #>>44378176 #
12. hidroto ◴[] No.44377708{3}[source]
are there any cameras that take pictures that are not a multiple of 8 in width and height?
replies(1): >>44380788 #
13. kllrnohj ◴[] No.44378101{4}[source]
For anything GPU-rendered, applying a rotation matrix to a texture sample and/or frame-buffer write is trivially cheap (see also why Vulkan prerotation exists on Android). Even ignoring GPU-rendering, you always are doing a copy as part of rendering and often have some sort of matrix operation anyway at which point concatenating a rotation matrix often doesn't change much of anything.
replies(1): >>44385579 #
14. justincormack ◴[] No.44378176{3}[source]
the stored image is always a multiple of 8, with padding that is ignored (and heavily compressed).
replies(1): >>44379045 #
15. dylan604 ◴[] No.44378464[source]
Slight nitpicking, but you can rotate in 90° increments without loss.
16. Someone ◴[] No.44378679[source]
> The camera knows which way it's oriented, so it should just write the pixels out in the correct order. Write the upper-left pixel first. Then the next one. And so on. WTF.

The hardware likely is optimized for the common case, so I would think that can be a lot slower. It wouldn’t surprise me, for example, if there are image sensors out there that can only be read out in top to bottom, left to right order.

Also, with RAW images and sensors that aren’t rectangular grids, I think that would complicate RAW images parsing. Code for that could have to support up to four different formats, depending on how the sensor is designed,

replies(2): >>44382729 #>>44385564 #
17. pwdisswordfishz ◴[] No.44379045{4}[source]
But can this lossless rotation process account for padding not being in the usual place (lower right corner presumably)?
replies(1): >>44380252 #
18. mort96 ◴[] No.44380252{5}[source]
I'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.
19. meindnoch ◴[] No.44380408[source]
Only if the image width/height is a multiple of 8. See: the manpage of jpegtran, especially the -p flag.
20. lsaferite ◴[] No.44380600{3}[source]
> the chip is already outputting the image in a lossy format

Could you explain this one?

21. bdavbdav ◴[] No.44380788{4}[source]
People may crop
22. DidYaWipe ◴[] No.44382688[source]
Indeed. 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.
replies(1): >>44385552 #
23. DidYaWipe ◴[] No.44382729[source]
At this point I expect any camera ASICs to be able to incorporate this logic for plenty-fast processing. Or to do it when writing out the image file, after acquiring it to a buffer.

Your raw-image idea is interesting. I'm curious as to how photosites' arrangement would play into this.

24. DidYaWipe ◴[] No.44382757{3}[source]
Given that rotation sensors have been standard equipment on most cameras (AKA phones) for many years now, I would expect pixel-reordering to be built into supporting ASICs and to impose negligible performance penalties.
25. DidYaWipe ◴[] No.44382773{3}[source]
Image sensors don't "output images in a lossy format" as far as I know.
26. account42 ◴[] No.44385552{3}[source]
Or lossy re-encoding.
27. account42 ◴[] No.44385564[source]
Sensors are not read out as JPEG but into intermediate memory. The encoding step can then deal with the needed rotation.

RAW images aren't JPEGs so not relevant to the discussion.

28. account42 ◴[] No.44385579{5}[source]
The cost is paid in different memory access patterns which may or may not be mitigated by the GPU scheduler. It's an insignificant cost either way though, both for the encoder and the renderer. Also depending on the pixel order in sensor, file or frame buffer "rotated" might actually be the native way and the default is where things get flipped around from source to destination.
replies(1): >>44387043 #
29. account42 ◴[] No.44385606[source]
Burst mode in cameras means the sensor is readout is buffered in RAM while the encoding and writing to persistent storage catches up. Rotating the buffer would be part of the latter and not affect burst speed - and is an insignificant cost anyway.
30. kllrnohj ◴[] No.44387043{6}[source]
Access pattern is mitigated by texture swizzling which will happen regardless of how it's ultimately rendered. So even if drawn with an identity matrix you're still "paying" for it regardless just due to the underlying texture layout. GPUs can sample from linear textures, but often it comes with a significant performance penalty unless you stay on a specific, and undefined, path.