Old 09-11-2021, 12:40 AM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default How does gfx_xformblit work?

I would appreciate it very much if someone could explain to me how the "transformation table" of gfx_xformblit works.

The help documentation simply states:
Code:
gfx_xformblit(srcidx, x,y,w,h,  wdiv, hdiv, tab[, wantalpha=0])
Blits with a transformation table. 
tab is wdiv*hdiv*2 table of source point coordinates. 
If wantalpha=1, tab is wdiv*hdiv*3 table of src points including alpha for each point
juliansader is offline   Reply With Quote
Old 09-12-2021, 05:27 PM   #2
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

This thread has actual example of gfx_xformblit that transforms a square video into a circle:

https://forum.cockos.com/showthread.php?p=2443941
papagirafe is offline   Reply With Quote
Old 09-13-2021, 03:38 AM   #3
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I have indeed seen that thread and I have also checked other presets that use gfx_xformblit, but unfortunately I haven't been able to figure out exactly how the transformation table works.
juliansader is offline   Reply With Quote
Old 09-13-2021, 06:33 PM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

Quote:
gfx_xformblit(srcidx, x,y,w,h, wdiv, hdiv, tab[, wantalpha=0])
Blits with a transformation table.
tab is wdiv*hdiv*2 table of source point coordinates.
If wantalpha=1, tab is wdiv*hdiv*3 table of src points including alpha for each point
The table is a list of source texture coordinates. If wantalpha=0, then each coordinate is 2 values (X and Y coordinate of the source texture), or if wantalpha=1 then each coordinate is 3 values (the third value is alpha).

So, in a simple form, suppose wdiv=hdiv=3, and wantalpha=0. In this case the table would need to be 3*3*2 items in length, in this example a straight copy of the image would be:
Code:
tab[0] = 0; tab[1] = 0; // top left corner destination coordinate
tab[2] = srcw/2; tab[3] = 0; // top middle edge destination
tab[4] = srcw; tab[5] = 0; // top right corner
tab[6] = 0; tab[7] = srch/2; // middle left edge
tab[8] = srcw/2; tab[9] = srch/2; // middle of destination
tab[10] = srcw; tab[11] = srch/2; // middle right edge
tab[12] = 0; tab[13] = srch; // bottom left corner
tab[14] = srcw/2; tab[15]=srch; // bottom middle edge
tab[16] = srcw; tab[17]=srch; // bottom right corner
It would be a list of (s,t) coordinate pairs (or (s,t,a) coordinate triplets) for the source texture, which correspond to the destination rectangle subdivided by wdiv/hdiv.
Justin is offline   Reply With Quote
Old 09-14-2021, 03:09 PM   #5
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Ah, thanks, I think I understand now!
juliansader is offline   Reply With Quote
Old 09-14-2021, 05:16 PM   #6
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Many thanx too. I cannot claim yet to fully understand the power of this table transform yet but you gave us the key to start experimenting!
papagirafe is offline   Reply With Quote
Old 09-15-2021, 05:39 PM   #7
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Ok now I got it!

here is a simple pseudo-zoom with a simple 2x2x2 table:
Code:
//zoom xformblit()
//@param1:zoom "zoom" 1 0.01 4 1 0.001
src=0;
input_info(src,srcw,srch);
gfx_set(0,0,0,1);
gfx_fillrect(0,0,srcw,srch); 

function zoom_img(img,zoom) local(tab,dx,dy)
(
  dx=srcw-srcw*zoom; 
  dy=srch-srch*zoom;
  tab[0]=0-dx; tab[1]=0-dy;         tab[2]=srcw+dx; tab[3]=0-dy;
  tab[4]=0-dx; tab[5]=srch+dy;      tab[6]=srcw+dx; tab[7]=srch+dy;
  gfx_xformblit(src, 0,0,srcw,srch, 2,2,tab, 0);
);

zoom_img(src,zoom);
papagirafe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.