image rescale with filter function lazarus / 39-Graphics ---------------------------------------------------------------------- Phoenix · 2025-07-28 09:52 Hello, I'm trying to translate a piece of code to scale an image with a filter. But when translating from C, there's a problem with the colors. Does anyone know what the problem is? I've attached a test application and the original source file. The problem is clearly visible in the screenshots (original small for attached limit), but you can see the building's portico in the image, so I assume the solution isn't far off, even if I can't find it. Note: I also tried translating the part about loading from a "raw" file, but it was too C-based and just didn't work. So I opted to use the raw data via TBitmap. But that's of secondary importance. ---------------------------------------------------------------------- marcov · 2025-07-28 10:22 Your example  loads a bmp, but you attach a jpg ? Can't find it in the archives either. I would add checks on several places and check the pixelformat is as you expect. ---------------------------------------------------------------------- Phoenix · 2025-07-28 10:36 Quote from: marcov on July 28, 2025, 12:22:07 pmYour example  loads a bmp, but you attach a jpg ? Can't find it in the archives either. I would add checks on several places and check the pixelformat is as you expect. Thanks for your interest. As indicated, there's a limit on attachments on the forum, and the BMP format isn't the most suitable. The original image is a 24-bit BMP, 3.51 MB, 1280x960, and I don't know how to post it here. A check would be helpful, but currently the program should work with any 24-bit image. Note: In the code, the target is "downscale," so there's a simple "div 2" on the dimensions. So just keep this in mind when choosing a 24-bit BMP image for testing. ---------------------------------------------------------------------- TBMan · 2025-07-28 12:34 It looks as though the palette isn't being loaded. ---------------------------------------------------------------------- Ally · 2025-07-28 14:28 Hello Phoenix, Here is a small sample program. The actual work is done by the BitmapScale procedure from the rhsBitmapScale.pas file. Best regards, Roland ---------------------------------------------------------------------- Phoenix · 2025-07-28 14:57 Quote from: TBMan on July 28, 2025, 02:34:21 pmIt looks as though the palette isn't being loaded. I'm not very experienced but the palette is optional in bitmap format plus I use TBitmap internally for loading and saving so am I subject to this problem anyway? Quote from: Ally on July 28, 2025, 04:28:26 pmHere is a small sample program. The actual work is done by the BitmapScale procedure from the rhsBitmapScale.pas file. Thank you very much for this version. I usually use bgrabitmap, so it'll be interesting to compare  . In any case, even if I can solve the problem using other solutions (with higher abstraction), I'd like to find out why the one in the post (less portable but more low-level) doesn't work. ---------------------------------------------------------------------- Phoenix · 2025-07-28 15:07 I assume the problem stems from how version C uses the pixel color as a double. I tried a few ideas, but they all failed.