[Patch] fcl-image, interpolation, wrong initialization of alpha channel
Original Reporter info from Mantis: 7bit
-
Reporter name: Bernd Kreuss
Original Reporter info from Mantis: 7bit
- Reporter name: Bernd Kreuss
Description:
There is a small bug in packages/fcl-image/src/fpinterpolation.inc that essentially makes it impossible to use TFPImageCanvas.StretchDraw() with images that have alpha transparency.
Attached is a patch.
When it calculates the interpolated value of the new pixel it will first initialize this pixel with colBlack. This is wrong.
The intention is to initialize all 4 channels of the pixel with zero but colBlack only has the RGB values set to zero, alpha is set to $ffff. The correct value would have been colTransparent which has them all four set to zero. The attached patch will fix it.
Without the patch any attempt to use StretchDraw() on an image with alpha transparency would end up with most of the resulting alpha values in the resulting image set to $ffff.
I am also attaching a small demo program (interpoltest.lpr), there is also a small PNG file with alpha channel in this archive for convenience, running the program should scale the image 'original.png' to 64*64 and save it to 'scaled.png' where you can then examine it with gimp to observe how the alpha channel gets messeed up during this operation.
The patch was made against the current 2.6 fixes branch, I have not yet tested 2.7 trunk but most likely it is there also.
(also maybe after it is fixed it would be nice to add a small example how to scale images to the fcl-image examples, it took me a while to figure out that it actually even has the capability to do this)
Steps to reproduce:
To reproduce it unzip and compile the attached demo in the attached interpoltest.tar.bz2 archive. Run the program, it will create an image 'scaled.png', observe how the alpha channel in this image was corrupted during scaling.
Mantis conversion info:
- Mantis ID: 22245
- OS: all
- OS Build: all
- Platform: all
- Version: 2.6.1
- Fixed in revision: 21639 (#ee47ad22)
- Monitored by: » zaher (Zaher Dirkey)