fb:porticula NoPaste
RotPut5.bi
Uploader: | Muttonhead |
Datum/Zeit: | 25.05.2016 07:43:24 |
'definitely inspired by D.J.Peters'>>Multiput version 1<<
'original code at: http://www.freebasic.net/forum/viewtopic.php?f=8&t=19303
type RotPoint
x as single
y as single
end type
sub RotPut(Src_Img as any ptr,posx as integer,posy as integer, pivotx as integer=0, pivoty as integer=0, radian as single)
'posx,posy Position,es gilt Koordinatensystem Screen
'pivotx,pivoty Drehpunkt als Offset von Pixel(0,0) links oben, es gilt Koordinatensystem Screen
dim as RotPoint Points(10) 'Punkte und Vektoren
dim as any ptr Dest_Img 'Ziel
dim as Image ptr Src_Header,Dest_Header 'Zeiger um an die Daten im ImageHeader zu kommen
dim as integer Src_ImgWidth,Src_ImgHeight,Dest_ImgWidth,Dest_ImgHeight
'dim as integer Src_ImgPitch,Src_ImgBPP,Dest_ImgPitch,Dest_ImgBPP
dim as integer ptr Src_pixaddr,Dest_pixaddr 'Pixeladressen
dim as integer Top,Bottom 'Indizes für höchste und tiefste Punkt der Quelle
dim as integer Dest_Topx,Dest_Bottomx 'x Koordinaten des höchsten/tiefsten Punktes in Quelle/Ziel
dim as single Src_Stepx,Src_Stepy,Dest_Stepx 'Scan Offsets Quelle und Ziel
dim as integer Src_PixelPosx,Src_PixelPosy,Dest_PrePixelPosx,Dest_PixelPosx,Dest_PixelPosy
dim as single x,y,xx,yy 'allgemeine Hilfsvariablen
dim as integer i,ii,k,kk
dim as integer xmin,xmax,ymin,ymax,pixelrun,exitrun
Src_Header=Src_Img
Src_ImgWidth=Src_Header->width
Src_ImgHeight=Src_Header->height
'Src_ImgPitch=Src_Header->pitch
'Src_ImgBPP=Src_Header->bpp
'Eckpunkte Original positionieren
'Pixel(0,0) im Koordinatenursprung
Points(0).x=0
Points(0).y=0
Points(1).x=0
Points(1).y=-Src_ImgHeight+1
Points(2).x=Src_ImgWidth-1
Points(2).y=-Src_ImgHeight+1
Points(3).x=Src_ImgWidth-1
Points(3).y=0
'Eckpunkte drehen
'Index des höchsten/tiefsten Eckpunktes ermitteln
'Hilfsvariablen zur Positionierung und Größenermittlung Ziel berechnen
xmin=0
xmax=0
ymin=0
ymax=0
Top=4
Bottom=4
for i as integer=0 to 3
x= Points(i).x * cos(radian) - Points(i).y * sin(radian)
y= Points(i).x * sin(radian) + Points(i).y * cos(radian)
ii=i+4
Points(ii).x= x
Points(ii).y= y
if Points(ii).y > Points(Top).y then
Top=ii
elseif Points(ii).y = Points(Top).y then
if Points(ii).x < Points(Top).x then Top=ii
end if
if Points(ii).y < Points(Bottom).y then
Bottom=ii
elseif Points(ii).y = Points(Bottom).y then
if Points(ii).x > Points(Bottom).x then Bottom=ii
end if
if x<xmin then xmin=x
if x>xmax then xmax=x
if y<ymin then ymin=y
if y>ymax then ymax=y
next i
'PUT-Position linke obere Ecke des Ziels
Points(8).x=xmin
Points(8).y=ymax
'Offset für Points(8) berechnen, falls Drehpunkt nicht Pixel(0,0) sein soll
Points(9).x= pivotx - (pivotx * cos(radian) - (-pivoty) * sin(radian))
Points(9).y= -pivoty - (pivotx * sin(radian) + (-pivoty) * cos(radian))
'Größe Ziel
Dest_ImgWidth=xmax-xmin+1
Dest_ImgHeight=ymax-ymin+1
'Startkoordinate oberster Punkt im Ziel
'Scan Offsets X Koordinate Quelle und Ziel
Dest_Topx=Points(Top).x - xmin
Dest_Bottomx=Points(Bottom).x - xmin
Dest_Stepx=(Dest_Bottomx - Dest_Topx) / (Dest_ImgHeight - 1)
'Indizes auf die ungedrehten Koordinaten des höchsten/tiefsten Punktes der Quelle stellen
Top -=4
Bottom-=4
Src_Stepx=(Points(Bottom).x - Points(Top).x) / (Dest_ImgHeight - 1)
Src_Stepy=(Points(Bottom).y - Points(Top).y) / (Dest_ImgHeight - 1)
'ZeilenScanvektor Richtung links >> rechts, Länge 1(Pixel)
Points(10).x=1
Points(10).y=0
'Vektor drehen
x= Points(10).x * cos(-radian) - Points(10).y * sin(-radian)'
y= Points(10).x * sin(-radian) + Points(10).y * cos(-radian)
Points(10).x= x
Points(10).y= y
Dest_Img=imagecreate(Dest_ImgWidth,Dest_ImgHeight,&HFF00FF)
if Dest_Img then
Dest_Header=Dest_Img
'Scan
for k=0 to Dest_ImgHeight-1
Dest_PixelPosy=k
Dest_PrePixelPosx=Dest_Topx + k*Dest_Stepx
'Scan nach rechts
exitrun=0
pixelrun=0
do
Src_PixelPosx=Points(Top).x + k*Src_Stepx + pixelrun*Points(10).x
Src_PixelPosy=Points(Top).y + k*Src_Stepy + pixelrun*Points(10).y
Dest_PixelPosx=Dest_PrePixelPosx + pixelrun
if (Src_PixelPosx>=0) and (Src_PixelPosx<Src_ImgWidth) and (Src_PixelPosy<=0) and (Src_PixelPosy>-Src_ImgHeight) then
Src_pixaddr=(Src_Img + 32 + (-Src_PixelPosy * Src_Header->pitch) + (Src_PixelPosx * Src_Header->bpp))
Dest_pixaddr=(Dest_Img + 32 + (Dest_PixelPosy * Dest_Header->pitch) + (Dest_PixelPosx * Dest_Header->bpp))
*Dest_pixaddr=*Src_pixaddr
else
exitrun=1
end if
pixelrun +=1
loop until exitrun
'[komm]LycKICAgICAgICAnU2NhbiBuYWNoIGxpbmtzCiAgICAgICAgZXhpdHJ1bj0wCiAgICAgICAgcGl4ZWxydW49MAogICAgICAgIGRvCiAgICAgICAgICBTcmNfUGl4ZWxQb3N4PVBvaW50cyhUb3ApLnggKyBrKlNyY19TdGVweCArIHBpeGVscnVuKlBvaW50cygxMCkueAogICAgICAgICAgU3JjX1BpeGVsUG9zeT1Qb2ludHMoVG9wKS55ICsgaypTcmNfU3RlcHkgKyBwaXhlbHJ1bipQb2ludHMoMTApLnkKICAgICAgICAgIERlc3RfUGl4ZWxQb3N4PURlc3RfUHJlUGl4ZWxQb3N4ICsgcGl4ZWxydW4KCiAgICAgICAgICBpZiAoU3JjX1BpeGVsUG9zeCZndDs9MCkgYW5kIChTcmNfUGl4ZWxQb3N4Jmx0O1NyY19JbWdXaWR0aCkgYW5kIChTcmNfUGl4ZWxQb3N5Jmx0Oz0wKSBhbmQgKFNyY19QaXhlbFBvc3kmZ3Q7LVNyY19JbWdIZWlnaHQpIHRoZW4KICAgICAgICAgICAgU3JjX3BpeGFkZHI9KFNyY19JbWcgKyAzMiArICgtU3JjX1BpeGVsUG9zeSAqIFNyY19IZWFkZXItJmd0O3BpdGNoKSArIChTcmNfUGl4ZWxQb3N4ICogU3JjX0hlYWRlci0mZ3Q7YnBwKSkKICAgICAgICAgICAgRGVzdF9waXhhZGRyPShEZXN0X0ltZyArIDMyICsgKERlc3RfUGl4ZWxQb3N5ICogRGVzdF9IZWFkZXItJmd0O3BpdGNoKSArIChEZXN0X1BpeGVsUG9zeCAqIERlc3RfSGVhZGVyLSZndDticHApKQogICAgICAgICAgICAqRGVzdF9waXhhZGRyPSpTcmNfcGl4YWRkcgogICAgICAgICAgZWxzZQogICAgICAgICAgICBleGl0cnVuPTEKICAgICAgICAgIGVuZCBpZgogICAgICAgICAgcGl4ZWxydW4gLT0xCiAgICAgICAgbG9vcCB1bnRpbCBleGl0cnVuCiAgICAgICAgJy8ß[/komm]
next k
put (posx + Points(8).x + Points(9).x,posy - Points(8).y - Points(9).y),Dest_Img,trans
imagedestroy Dest_Img
end if
end sub