[squeak-dev] Who understand bilinear interpolation for reducing image size?

tim Rowledge tim at rowledge.org
Mon Dec 8 23:45:07 UTC 2014


On 08-12-2014, at 3:01 PM, Bert Freudenberg <bert at freudenbergs.de> wrote:

> On 08.12.2014, at 21:15, tim Rowledge <tim at rowledge.org> wrote:
>> 
>> The ScratchPlugin implements a prim to shrink a 32bpp image by use of bilinear interpolation. Unfortunately it completely ignores the alpha channel in 32bpp pixels and does some rather odd futzing to kinda-sorta fake handling of transparency.
>> 
>> I can see how to add in (what I think would be) proper ARGB interpolating, and I think that simply removing the futzing would be correct - but I’d much rather have some input from somebody with a bit of image processing theory so there is some hope of my final result being actually correct.
> 
> Why would you like to change it? To accept a wider range of inputs?

Well, the main need is to stop it breaking imported images. A frequent problem I’ve had reported is that importing gifs & pngs results in images that simply aren’t correct. Transparent backgrounds that are white, or black, for example. A fairly common problem is ‘transparent’ source pixels that are in the file as 0 alpha but RGB = white.

In the process if trying to sort them out it was noticed that this scaling prim strips away any alpha channel; I don’t particularly mean partial transparency, just all of it. Feed in a pixel that is A=255 and it comes out A=0. Bit of a pain if you ever need to display it with Form blend. 

> 
> This purposely does only output fully opaque and fully transparent pixels, which likely is a requirement further down the pipeline. Makes rendering faster, too: true alpha-blending is expensive.

The code gives the impression of having been written before the 32bpp ARGB pixel format was put into use. That could explain why it doesn’t set the alpha bits for the output. I could of course just do a bitblt with the fixAlpha rule but it’s faster to fix it inside the prim if possible.

The question becomes one of the final effect that is wanted - doing ‘the right thing’ by mixing the alpha values is simple and works ok for the examples I have right now but yes, they’re not using partial transparency and are finally displayed with Form paint instead of blend. And that is an issue too, since people are quite likely to try importing images with partial transparency from assorted paint programs and clipart, only to find it looks really strange. 

The old code was fudging transparency and effectively rounding it up to opaque if the weighted average was > ~half.  I could do similar easily enough I think.

But I’m not at all knowledgeable about image processing stuff, which is why I ask.


tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Useful Latin Phrases:- Vescere bracis meis. = Eat my shorts.




More information about the Squeak-dev mailing list