I've been working on a "magnifier" effect. The magnified image it produces is based off of the upper left corner of the original image. I want it to be based off of the center section of the image instead but I can't figure out how to calculate the offsets
#include once "fbgfx.bi"
type tr
as integer wd,ht,npix
org as fb.image ptr
dest as fb.image ptr
tfm as uinteger ptr 'the transform matrix
f as integer
declare constructor (byval w as integer, byval h as integer, matrix as string, byval factor as single = 1)
declare destructor ()
declare sub transform(byval x as integer, byval y as integer)
end type
constructor tr (byval w as integer, byval h as integer, effect as string, byval factor as single = 1)
wd = w
ht =h
f = factor
npix = w*h ' number of pixels
org = imagecreate (w,h)
dest = imagecreate (w,h)
for i as integer = 0 to w-1
tfm = new uinteger[npix] ' transform array
next
var pitch = org->pitch / org->bpp
select case effect
case "flipxy"
for i as integer =0 to w*h-1
tfm[i] = (w*h-1) -i
next
case "mag"
for i as integer = 0 to h-1
for j as integer = 0 to w-1
tfm[i*w+j] = cast(integer,(i / factor)) * pitch + cast(integer,(j / factor))
next
next
end select
end constructor
destructor tr()
imagedestroy org
imagedestroy dest
delete[] tfm
end destructor
sub tr.transform(byval x as integer, byval y as integer)
get (x,y) - step(wd-1,ht-1), org
var pitch = org->pitch / org->bpp
var o = cast(uinteger ptr, org+1)
var d = cast(uinteger ptr, dest+1)
dim as integer count = 0
for i as integer = 0 to ht-1
for j as integer = 0 to wd-1
d[i * pitch + j] = o[tfm[i*wd+j]]
next
next
put (x,y), dest', pset
end sub
dim as integer scw = 800, sch = 600
screenres scw,sch,32
dim as integer w = 100, h = 100
dim as tr effect = tr(w,h, "mag", 1.5)
dim as integer x = 200, y = 200
while not multikey(1)
if multikey(FB.SC_LEFT) and x > 0 then x -=1
if multikey(FB.SC_RIGHT) and x < scw-w-1 then x +=1
if multikey(FB.SC_UP) and y > 0 then y -=1
if multikey(FB.SC_DOWN) and y < sch-h-1 then y +=1
screenlock
cls
line (200+(w/4),200+(w/4))-STEP (w/2, h/2), rgb(0,0,255), BF
effect.transform(x,y)
line (x, y)-STEP (w, h), rgb(255,0,0), B
pset (x+(w/2),y+(h/2)), rgb(255,0,0)
screenunlock
wend
sleep