Opened 11 years ago

Last modified 8 years ago

#823 accepted defect

Ugly previews of scaled indexed images

Reported by: saul Owned by:
Priority: minor Milestone:
Component: programming Keywords: small
Cc: Parent Tickets:

Description

Previews of images using an indexed color mapping can become very ugly if the original image needs to be scaled down. For example:

http://barn.kerosenecow.net/mgoblin_media/media_entries/435/indexed-degradation.png

This degradation is inherent to scaling indexed images and though the result may vary depending on the scaling algorithm used (NEAREST, BILINEAR, BICUBIC, or ANTIALIAS), scaling will always result in degradation.

Of the file types that Mediagoblin supports, PNG and TIFF files may or may not use indexed color mapping, while GIF files always use indexed colors.

One way to improve the quality of such scaled previews is to convert the image to the RGB color space before scaling.

Change History (2)

comment:1 by saul, 11 years ago

My proposal is if it's necessary to scale a PNG file that uses indexed color mapping, the preview image should be converted to the RGB color space before it gets scaled. Since PNG files may or may not use indexed colors, there are two approaches that could be taken:

1) Retrieve information about the file and skip color space conversion if it is already in the RGB color space.

2) Always performed a conversion to RGB color space.

Which choice is best depends upon the capabilities of the Python Imaging Library. The second approach is simpler as long as PIL allows RGB to RGB "conversion" and does not degrade the original RGB image, while the first approach is more intuitive, it is dependent upon PIL's ability to retrieve the color space info of the original file.

Once the preview file has been scaled, the only reason to convert back to indexed -- and thus degrade the preview even more -- would be to reduce the file size of the preview image. Thus I recommend against converting it back to indexed color mapping.

With GIF files, conversion to RGB color space should be avoided if the file is a multi-layer animation; as this introduces additional problems with converting the scaled preview back to an animation -- with issues such as frame disposal, generating new color maps, and a strong potential that the end result would be worse than a scaled indexed version. In addition, animated GIFs that would exceed Mediagoblin's preview dimension are a very rare occurrence.

Ideally, GIF files that are single-layer (non-animated) should be converted to RGB color space before scaling; however, whether this is feasible depends upon Mediagoblin (PIL) being able to assert that there is only one layer in the file.

With regard to TIFF files, as it is a proprietary format controlled by Adobe, I personally don't care what is done. Nonetheless, whether a TIFF gets converted to RGB before scaling would again be dependent upon Mediagoblin (PIL) being able to determine whether or not the file is using indexed color mapping.

Version 0, edited 11 years ago by saul (next)

comment:2 by Ben Sturmfels, 8 years ago

Keywords: small added
Status: newaccepted

Marking as small sized as will require a few changes to the image processing workflow conditional on the colour-depth and whether there is animation.

The above example image is no longer available, but the degradation can be seen by converting a large photo to GIF and then uploading.

Note: See TracTickets for help on using tickets.