SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.34k stars 847 forks source link

Allow decoding Tiff of different frame size. #2788

Closed JimBobSquarePants closed 3 weeks ago

JimBobSquarePants commented 1 month ago

Prerequisites

Description

See the discussion in #1982 Decoding is fairly trivial. We just needed to pass the correct parameters to the various internal types and draw to frames matching the root frame dimensions.

I don't know whether it is actually possible to trim transparent pixels on encode as there's no guarantee that the pixel format we have decoded to supports transparency. I guess we could add some sort of ChromaKeyColor property to the encoder and trim any bounding pixels matching that value?

I'll likely need assistance writing a performant trimming algorithm (My SIMD is rusty)

I've actually figured out a very neat way to handle all this transparently:

First off, we track the encoded dimensions in the same manner as ICO and CUR formats that ensures the frames are encoded at a configurable size.

By adding handling methods to the metadata APIs that run after processing a transformed image we can then automatically update those properties to scale with the transform. This mean you can load a Tiff Mipmap, resize the image and save each frame encoding only the relevant data!! 😄

In addition, I've normalized the ImageFrame.Size() method to now match the Image.Size property.