Search code examples
imageformatstoragepngjpeg

Could converting a JPG to PNG or PPM be a good idea?


I'm creating an image editor in C and I'm studying how some image formats are made and how they behave. It's a rabbit hole. I recently opened another thread asking if it was possible to convert a JPG image to PPM without losing quality. The answer is yes. If I understood correctly the same thing should happen when switching from JPG to PNG. So no quality loss.

In most cases converting a JPG image to PNG or PPM does not make sense. It doesn't make sense because the image was already compressed and some data was lost when the JPG file was created... So I would end up with a compressed file like the original JPG but which takes up much more space.

My situation: I have a JPG image that I need to edit and then archive and that I will have to edit more times later. From what I understand, after editing the initial file it should make more sense to export it to PNG or PPM. This way it isn't lossy compressed and I can edit it in the future without losing data.

If I need a compressed and smaller image I export the PNG again to JPG, WEBP, AVIF...

If I need to modify the archived PNG or PPM file I modify it without fear of losing data.

P.S. I don't care about the image storage size. Let's assume a scenario in which I have infinite storage space.

Does what I wrote make sense? Is there something I'm missing?

Thank you.


Solution

  • You didn't say what exactly you mean by "edit", but there is not a lot you can do to a JPEG image without first decompressing it to pixels. (Some things you could do while leaving the DCT blocks mostly intact are rotate, flip, and crop.) You don't necessarily need to convert it to PNG or PPM, but you'll have to do something like that.

    Yes, keeping the image in uncompressed form while you might have further edits to it makes sense. Decompressing JPEG and recompressing to JPEG repeatedly will generally lead to more loss and noise. You would only want to convert back to JPEG when you're pretty sure you're done messing with the image.