[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] transform.chop and image cropping



On 9/2/07, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
> There's also another artist technique where empty space is
> deliberately used as a way of being able to set an image hotspot (the
> origin of the image). Basically no file format gives you a way to set
> a hotspot, but if the image loader assumes the center of the image is
> the hotspot then the artist can render images to take advantage of
> that. For it to work the image loader needs to be aware of the meaning
> of the empty space.

wow that's useful, I hadn't thought of that.

>
> Granted, like Greg said, an external l tool could be used to both crop
> such images and provide hotspot metadata instead of having the code
> for that work in the game - but maintaining external tools is a
> hassle, I like to embed such things in the game engine.

I think you can compromise, if you use a format like PNG and can save
PNG in the engine, you could implement a sort of caching -- use a
custom chunk of your own specifications to give the cropping rectangle
and centre coordinates, also store a copy of the image dimensions in
that chunk. If your custom chunk does not exist in a PNG you're
loading, or stored width/height mismatches image width/height, then
recalculate hotspot and cropping rectangle and save the result.
This deals gracefully with both badly-behaved apps that discard chunks
they don't know about, and well-behaved apps that preserve the content
of unknown chunks, and makes the autocropper's speed far less
time-critical.