my mini image transform tool for your own expand.
it get an image, u click a rectangle with 4 points,
hit enter (and wait...) and it save a power of 2 texture.
day one:
// Project: Grab
// Created: MR 22.09.2015 22:46
// set window properties
SetWindowTitle( "Grab" )
//SetWindowSize( 1024, 768, 0 )
SetPrintColor(0,0,255)
type TPunkt
x as float
y as float
endtype
global Punkt as TPunkt[4]
Main()
end
function Main()
local i as integer
local sprnr as integer[4]
for i=1 to 4
sprnr[i]=LoadSprite(str(i)+".png") //number images 1-4
SetSpriteSize(sprnr[i],5,5)
SetSpritePosition(sprnr[i],5+i*5,5)
SetSpriteDepth(sprnr[i],10)
next
local spr
spr = LoadSprite("temp.jpg") //any example image
SetSpriteDepth(spr,20)
SetSpriteSize(spr,-1.0,100.0)
local p=1
do
//... Image Dialog
if GetPointerReleased()
p=p+1
if p>4 then p=1
endif
if GetPointerState()=1
x#=GetPointerX()
y#=GetPointerY()
Punkt[p].x=x#
Punkt[p].y=y#
endif
//aktivate point 1-4 with key 1-4
if GetRawKeyPressed(49) then p=1
if GetRawKeyPressed(50) then p=2
if GetRawKeyPressed(51) then p=3
if GetRawKeyPressed(52) then p=4
//Enter
if GetRawKeyPressed(13)
for i=1 to 4
SetSpriteVisible(sprnr[i],0)
next
Get(spr)
Ready()
for i=1 to 4
SetSpriteVisible(sprnr[i],1)
next
sync()
endif
Lines(Punkt,sprnr)
Sync()
loop
endfunction
function Lines(Punkt as TPunkt[],sprnr as integer[])
local col as integer
col= MakeColor(255,255,0)
Drawline(Punkt[1].x,Punkt[1].y,Punkt[2].x,Punkt[2].y,col,col)
Drawline(Punkt[2].x,Punkt[2].y,Punkt[3].x,Punkt[3].y,col,col)
Drawline(Punkt[3].x,Punkt[3].y,Punkt[4].x,Punkt[4].y,col,col)
Drawline(Punkt[4].x,Punkt[4].y,Punkt[1].x,Punkt[1].y,col,col)
for i=1 to 4
SetSpritePosition(sprnr[i],Punkt[i].x,Punkt[i].y)
next
endfunction
function Linear(p1 as TPunkt, p2 as TPunkt, mu as float)
local pn as TPunkt
pn.x = LinearInterpolate(p1.x,p2.x,mu)
pn.y = LinearInterpolate(p1.y,p2.y,mu)
endfunction pn
function LinearInterpolate( y1 as float, y2 as float, mu as float)
local f as float
f=(y1*(1.0-mu)+y2*mu)
endfunction f
function Get(spr as integer)
local pa as TPunkt
local pb as TPunkt
local pc as TPunkt
local a as float
local b as float
local x as float
local y as float
//----------------------
local width as float
local height as float
width=512 //<<< Output Texture Size
height=512
format=0
mipmap=0
depthImage=0
colorImage=CreateRenderImage ( width, height, format, mipmap )
memblock=CreateMemblockFromImage(colorImage)
deleteimage(colorImage)
//----------------------
//C:\Users\Gang\AppData\Local\AGKApps\GrabTexture\media
local col as integer
col= MakeColor(255,0,0)
local size as float
size=1.0 // / 100.0
for x=0 to width-1.0
a=x / (width-1.0)
pa=Linear(Punkt[1],Punkt[2],a)
pb=Linear(Punkt[4],Punkt[3],a)
render() //nach dem Sync ist der Backbuffer leer!
for y=0 to height-1.0
b=y / (height-1.0)
pc=Linear(pa,pb,b)
//------------------------
imageID=GetImage(pc.x,pc.y,size,size) //get from backbuffer
memtemp=CreateMemblockFromImage(imageID) //make image data
col=GetMemblockInt(memtemp,12) //first Pixel
//col = col + 0xFF000000
offset=12.0+(x*4+(y*width*4))
SetMemblockInt(memblock,offset,col) //write pixel to texture data
DeleteMemblock(memtemp)
DeleteImage(imageID)
//------------------------
next
next
//----------------------
colorImage=CreateImageFromMemblock(memblock)
DeleteMemblock(memblock)
SaveImage( colorImage, "grab.png" )
DeleteImage(colorImage)
endfunction
function Ready()
do
print("Ready. Click anywhere.")
if GetPointerPressed() then exit
sync()
loop
endfunction
AGK (Steam) V2 Beta .. : Windows 10 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)