Recent

Author Topic: [SOLVED] Projective transformation and the poor image quality  (Read 2052 times)

furious programming

  • Sr. Member
  • ****
  • Posts: 468
  • I click a little.
    • TreeStructInfo — format for text and binary configuration files
Re: [SOLVED] Projective transformation and the poor image quality
« Reply #15 on: August 30, 2020, 12:42:01 am »
Coordinates were the same as in the windowed application (which work correctly to this day), and even the source image was the same (exactly the same file). But instead of got the same output, I got what you see in the attachment. Same shape (correct coordinates), same background (white), same antialiased edges but instead of the transformed texture, only a black polygon (no colored content).

If I have some time, I will try to prepare a test program and reproduce this bug. Though I'm not saying it's a bug — maybe I made a mistake somewhere porting the code. The test program should answer.
« Last Edit: August 30, 2020, 12:43:42 am by furious programming »
Lazarus 2.0.10 with FPC 3.2.0 (SVN Revision 63526), Windows XP (all 32-bit)

paweld

  • Full Member
  • ***
  • Posts: 248
Re: [SOLVED] Projective transformation and the poor image quality
« Reply #16 on: August 30, 2020, 07:31:14 am »
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$R *.res}
  4.  
  5. uses
  6.   BGRABitmap, BGRABitmapTypes;
  7.  
  8. var
  9.   ImageSource, ImageDest: TBGRABitmap;
  10.  
  11. begin
  12.   //load
  13.   ImageSource := TBGRAbitmap.Create('data\source.png');
  14.   //apply
  15.   ImageDest := TBGRABitmap.Create(ImageSource.Width, ImageSource.Height, BGRAWhite);
  16.   ImageDest.FillQuadPerspectiveMappingAntialias(
  17.     PointF(0, 176),
  18.     PointF(1088, -24),
  19.     PointF(1024, 768),
  20.     PointF(192, 652),
  21.     ImageSource,
  22.     PointF(0, 0),
  23.     PointF(ImageSource.Width, 0),
  24.     PointF(ImageSource.Width, ImageSource.Height),
  25.     PointF(0, ImageSource.Height)
  26.   );
  27.   //save
  28.   ImageDest.SaveToFile('data\dest.png');
  29.   ImageDest.Free;
  30.   ImageSource.Free;
  31. end.                  
Best regards
paweld

furious programming

  • Sr. Member
  • ****
  • Posts: 468
  • I click a little.
    • TreeStructInfo — format for text and binary configuration files
Re: [SOLVED] Projective transformation and the poor image quality
« Reply #17 on: August 31, 2020, 04:36:48 am »
Thank you @paweld — looks like I did something wrong earlier, that's why the “kicked” image was entirely black. But still I don't know why it happened — why the transformation produced a black shape. Never mind.

Finally, I made a small console application that searches for an image in its directory, does a transformation and crop on it, and finally saves the snip to a new file (without showing a console window). The final code is below, and the project files in the attachment (with source image to test its operation).

Code: Pascal  [Select][+][-]
  1. program thumbnail;
  2.  
  3. {$MODE OBJFPC}{$LONGSTRINGS ON}
  4.  
  5. uses
  6.   SysUtils, Types, BGRABitmap, BGRABitmapTypes;
  7. var
  8.   InputFile: TSearchRec;
  9.   ImageSource, ImageKicked, ImageOutput: TBGRABitmap;
  10. begin
  11.   if FindFirst('*.png', faAnyFile, InputFile) = 0 then
  12.   try
  13.     try
  14.       ImageSource := TBGRABitmap.Create(InputFile.Name);
  15.       ImageKicked := TBGRABitmap.Create(ImageSource.Width, ImageSource.Height, BGRAWhite);
  16.       ImageKicked.FillQuadPerspectiveMappingAntialias(
  17.         PointF(0, 176),
  18.         PointF(1088, -24),
  19.         PointF(1024, 768),
  20.         PointF(192, 652),
  21.         ImageSource,
  22.         PointF(0, 0),
  23.         PointF(ImageSource.Width, 0),
  24.         PointF(ImageSource.Width, ImageSource.Height),
  25.         PointF(0, ImageSource.Height)
  26.       );
  27.       ImageOutput := TBGRABitmap.Create(680, 382, BGRAWhite);
  28.       ImageOutput.CanvasBGRA.CopyRect(0, 0, ImageKicked, Bounds(202, 240, 680, 382));
  29.       ImageOutput.SaveToFile('thumbnail.png');
  30.     finally
  31.       ImageSource.Free();
  32.       ImageKicked.Free();
  33.       ImageOutput.Free();
  34.     end;
  35.   finally
  36.     FindClose(InputFile);
  37.   end;
  38. end.

Before anyone asks — the name of the output file is hardcoded because in my environment there will never be a collision with another file. Just in the executable directory, there will always be one source image file whose name is in a specific format.

Thanks again for your help. 8)
« Last Edit: September 01, 2020, 12:14:17 am by furious programming »
Lazarus 2.0.10 with FPC 3.2.0 (SVN Revision 63526), Windows XP (all 32-bit)

 

TinyPortal © 2005-2018