Bad result when TFPImageCanvas.StretchDraw enlarges an image

Original Reporter info from Mantis: Martin @martin_frb
  • Reporter name: Martin Friebe

Description:

Create a new Lazarus app, add 2 TImages to the form, and run below sample code in FormCreate.

See the (magnified) result image.

  1. the first 3 pixels, fading from black to red are in the wrong order, the darkest red should be on the side of the black, but it is next to the bright red.
    The same effect can be seen with the other lines.

  2. reduce the source image to
    ScFI := TFPCompactImgRGBA8Bit.Create(22, 30);
    and adapt the loops.
    The "c.Red := $7F7F;" is now on the rightmost pixel of the source.
    It is entirely missing in the result image.
    StretchDraw (to a bigger dest) looses the rightmost pixel.

---
I am aware that the colors are 16 bit.
The upper and lower bytes are the same though

Byte(ScCanvas.Colors[x,y].red >> 8) +
has the same artefacts

Steps to reproduce:

procedure TForm1.FormCreate(Sender: TObject);
var
  ScFI, ScFI2: TFPCompactImgRGBA8Bit;
  ScCanvas: TFPImageCanvas;
  i, x, y: Integer;
  c : TFPColor;
begin
  ScFI := TFPCompactImgRGBA8Bit.Create(30, 30);

  for x := 0 to 29 do for y := 0 to 29 do begin
    c.alpha := $FFFF;
    c.green := 0;
    c.blue := 0;
    c.Red := 0;
    ScFI.Colors[x,y] := c;
  end;

  for i := 1 to 20 do begin
    c.alpha := $FFFF;
    c.green := 0;
    c.blue := 0;
    c.Red := $FFFF;
    ScFI.Colors[10,i] := c;
    ScFI.Colors[20,i] := c;
    c.Red := $7F7F;
    ScFI.Colors[21,i] := c;
  end;

  for x := 0 to 29 do for y := 0 to 29 do
    Image1.Canvas.Pixels[x,y] :=
      Byte(ScFI.Colors[x,y].red) +
      Byte(ScFI.Colors[x,y].green) << 8 +
      Byte(ScFI.Colors[x,y].blue) << 16;

  ScFI2 := TFPCompactImgRGBA8Bit.Create(90, 90);
  ScCanvas := TFPImageCanvas.create(ScFI2);
  ScCanvas.StretchDraw(0,0, 90, 90, scFI);

  for x := 0 to 89 do for y := 0 to 89 do
    Image2.Canvas.Pixels[x,y] :=
      Byte(ScCanvas.Colors[x,y].red) +
      Byte(ScCanvas.Colors[x,y].green) << 8 +
      Byte(ScCanvas.Colors[x,y].blue) << 16;
end;

Mantis conversion info:

  • Mantis ID: 33978
  • OS: win 10
  • OS Build: 10
  • Platform: 64bit Intel
  • Version: 3.1.1
  • Monitored by: » AntonK (Anton Kavalenka)
Assignee Loading
Time tracking Loading