Morphing on a Square Mesh: Working Matrix Version (Horray!) lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2024-10-25 16:07 I tried to convert some VBNet code that performs morphing using a square mesh. Got the loading of the images and the mesh working. Got the saving of the mesh points working. Bmps saved after btnMorph click Not working: Moving the control points The morphed bmps don't show the morphing correctly. Ah, headaches over this one ! ---------------------------------------------------------------------- DomingoGP · 2024-10-26 09:51 Fix for moving control points (barely tested) note the var parameters r and c Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FindControlPoint(index, X, Y: Integer;var  r, c: Integer);var  dx, dy: Single;begin  r:=0;  while r < NUM_POINTS do  begin    c:=0;  while c < NUM_POINTS  do    begin      dx := Abs(m_Point[index, r, c].X - X);      dy := Abs(m_Point[index, r, c].Y - Y);      if (dx < POINT_WID - 1) and (dy < POINT_WID - 1) then        Exit;      inc(c)    end;    inc(r);  end;   r := -1;  c := -1;end; ---------------------------------------------------------------------- TRon · 2024-10-26 09:58 As mentioned by DomingoGP, all byref's in the original basic code should be a var parameter in pascal. Thus also for method STToPoints and function PointsToST. ---------------------------------------------------------------------- Boleeman · 2024-10-26 13:10 Brilliant DomingoGP and TRon. Thanks for the fixes to moving the points. Now trying to work out why the rendered bmp are not rendering the morphed pictures properly. Looking at the bmps, there seems to be a triangular part which shouldn't be there. The VBNet code used clone to copy the pixels, whereas I am using draw to white background   m_Bm[2] := TBGRABitmap.Create(m_Bm[0].Width, m_Bm[0].Height, clWhite);   m_Bm[2].Draw(m_Bm[0].Canvas, 0, 0, True); Also I used the TBgrabmp MergeBGRA to merge the morphed pixels: m_Bm[2].SetPixel(x, y, MergeBGRA(AColor, Round((1 - fraction) * 255), BColor, Round(fraction * 255))); Perhaps something here is a bit off ? Not sure if circular might have any idea on the morphed render anomaly ? ---------------------------------------------------------------------- Boleeman · 2024-10-26 18:37 I was also working on another version that uses Matrices, written in Delphi by some French Programmer. Contains a really good (High End) Matrix Unit. Finally got it working so here it is. It loads jpg on start up. Would be nice to convert to Bgrabmp. On startup it loads 2  jpg pictures and their corresponding mesh points (Need to have these in the startup folder) The difficulty with the conversion came in getting the ReShape procedure to overlay the grid of TShape dots over the loaded jpg. After many attempts I realized that the TPanels were giving an "index(1) out of bounds error" even thought that did not happen with the Delphi version. The initial conversion was also making the dots disappear each time one was clicked in the Lazarus version. Also perhaps I wonder if someone could possibly add a save to Anigif or Apng (Not entirely sure how to do it) Lastly needed to mention that "When you click GO to do a Morph it takes a while and then the magic happens" Anyhow. Enjoy.