Recent

Author Topic: image rescale with filter function  (Read 1065 times)

Phoenix

  • Full Member
  • ***
  • Posts: 116
image rescale with filter function
« on: July 28, 2025, 11:52:51 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 12536
  • FPC developer.
Re: image rescale with filter function
« Reply #1 on: July 28, 2025, 12:22:07 pm »
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

  • Full Member
  • ***
  • Posts: 116
Re: image rescale with filter function
« Reply #2 on: July 28, 2025, 12:36:57 pm »
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.

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.
« Last Edit: July 28, 2025, 12:41:01 pm by Phoenix »

TBMan

  • Sr. Member
  • ****
  • Posts: 282
Re: image rescale with filter function
« Reply #3 on: July 28, 2025, 02:34:21 pm »
It looks as though the palette isn't being loaded.
I love programming.

Some things I've done using PTCgraph:

NFL Retro Football (almost finished):
https://www.youtube.com/watch?v=78mTtsd7ppk


Solitaire games:
https://www.youtube.com/watch?v=zmtxI7FdWuQ&list=PLa4BPpFl34iVhFwX1JZwVm3vE5ay_i3R2

Ally

  • Jr. Member
  • **
  • Posts: 80
Re: image rescale with filter function
« Reply #4 on: July 28, 2025, 04:28:26 pm »
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

  • Full Member
  • ***
  • Posts: 116
Re: image rescale with filter function
« Reply #5 on: July 28, 2025, 04:57:07 pm »
It 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?

Here 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

  • Full Member
  • ***
  • Posts: 116
Re: image rescale with filter function
« Reply #6 on: July 28, 2025, 05:07:06 pm »
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.

 

TinyPortal © 2005-2018