Page 1 of 2
Making Code to a procedure
Posted: Wed Aug 16, 2006 3:06 pm
by Konne
it's impossible to make this code to a procedure and I have no idea why. To test it just remove the comments and change the image path to an image u want. Would be great if someone else could tell me if the same problem occurs at his computer.
Code: Select all
Macro Make2(MyVal)
Int((MyVal*v)/100)
EndMacro
Macro RedValue(MyVal)
Make2(Red(MyVal))
EndMacro
Macro GreenValue(MyVal)
Make2(Green(MyVal))
EndMacro
Macro BlueValue(MyVal)
Make2(Blue(MyVal))
EndMacro
Macro Make(MyVal)
RGB(RedValue(MyVal),GreenValue(MyVal),BlueValue(MyVal))
EndMacro
LoadImage(1,"nicefrau4.bmp")
;Procedure MirrorImage();Image1,Image2);Size of the Mirror Effect in %
Define Bmp.BITMAP
Size=100
Image1=1
Image2=2
iw=ImageWidth(Image1) ;Image Width
ih=ImageHeight(Image1) ;Image Height
ihd=Int(ih*Size/100) ;Image Height Difference
inh=ih+ihd ;image New Height
CreateImage(Image2, iw, inh,32)
StartDrawing(ImageOutput(Image2))
DrawImage(ImageID(Image1),0,0)
StopDrawing()
GetObject_(ImageID(Image2), SizeOf(BITMAP), Bmp)
Dim *ib.l(ihd*2,iw-1)
*ib()=Bmp\bmBits
For y = 0 To ihd-1
v.f=(y+1)/ihd*50
For x = 0 To iw-1
*ib(y,x)=Make(*ib(ihd*2-y-1,x))
Next
Next
;EndProcedure
;MirrorImage()
SaveImage(2,"Out.bmp")
RunProgram("mspaint.exe","Out.bmp","")
Posted: Wed Aug 16, 2006 3:11 pm
by Straker
Sorry, but you'll have to post "nicefrau4.bmp" before we can help.
Posted: Wed Aug 16, 2006 3:13 pm
by dontmailme
and nicefrau1,2 and 3 as well

Posted: Wed Aug 16, 2006 3:44 pm
by Kiffi
Straker wrote:Sorry, but you'll have to post "nicefrau4.bmp" before we can help.
take
this nicefrau instead
Greetings ... Kiffi
Posted: Wed Aug 16, 2006 4:26 pm
by Konne
Frau is German your not suppost to understand that

Anyway your not the only one:
http://www.purebasic.fr/english/viewtop ... sc&start=0
There is no 1,2,3 or 5. It's just because I reziced the image a couple of times.
So no if u have the picture, can someone tell me if that's a real bug?
Posted: Wed Aug 16, 2006 5:00 pm
by Straker
nett!
Posted: Wed Aug 16, 2006 6:25 pm
by netmaestro
Hi Konne - Your problem is the dimmed array inside the procedure. If you want to use its contents outside the procedure, change its definition to:
and it should work.
Posted: Wed Aug 16, 2006 7:13 pm
by Kale
Try this (might need cleaning up a bit):
Code: Select all
; FlipImage(ImageNumber.l, Lateral.b)
; ImageNumber.l = Image's PB Number
; Lateral.b = flip direction. #True = horizontal, #False = vertical
Procedure FlipImage(ImageNumber.l, Lateral.b = #False)
SourceDC.l = CreateCompatibleDC_(#Null)
DestDC.l = CreateCompatibleDC_(#Null)
bm.BITMAP
hImage.l = ImageID(ImageNumber)
GetObject_(hImage, SizeOf(bm), @bm)
BmDC.l = CreateDC_("DISPLAY", #Null, #Null, dm.DEVMODE)
hbmResult.l = CreateCompatibleBitmap_(BmDC, bm\bmWidth, bm\bmHeight)
hbmOldSource.l = SelectObject_(SourceDC, hImage)
hbmOldDest.l = SelectObject_(DestDC, hbmResult)
If Lateral
StretchBlt_(DestDC, 0, 0, bm\bmWidth, bm\bmHeight, sourceDC, bm\bmWidth-1, 0, -bm\bmWidth, bm\bmHeight, #SRCCOPY)
Else
StretchBlt_(DestDC, 0, 0, bm\bmWidth, bm\bmHeight, sourceDC, 0, bm\bmHeight-1, bm\bmWidth, -bm\bmHeight, #SRCCOPY)
EndIf
SelectObject_(SourceDC, hbmOldSource)
SelectObject_(DestDC, hbmOldDest)
StartDrawing(ImageOutput(ImageNumber))
DrawImage(hbmResult, 0, 0)
StopDrawing()
DeleteDC_(SourceDC)
DeleteDC_(DestDC)
DeleteDC_(BmDC)
EndProcedure
LoadImage(1, "test.bmp")
FlipImage(1, #True)
SaveImage(1, "test_converted.bmp")
FreeImage(1)
RunProgram("test_converted.bmp")
You get the idea.

Posted: Wed Aug 16, 2006 8:13 pm
by Konne
@netmaestro
But I thought in PB 4.0 you could create Arrays, LinkedLists inside a procedure :roll:
@kale
Acutally No :roll:
And the problem is I can't create it outside the procedure because the I would havbe to resize it all the time and I can't redim the Dimension.
Posted: Wed Aug 16, 2006 9:04 pm
by Flype
Konne wrote:@netmaestro
But I thought in PB 4.0 you could create Arrays, LinkedLists inside a procedure :roll:
You can but, take care !
It's the same limit than the one described here :
http://www.purebasic.fr/english/viewtop ... highlight=
It's not a bug, but a known limitation :
Inside a procedure, arrays are limited by the stack.
Solutions are :
1/ use globals (no limit in this case).
2/ allocate yourself a (structured) memory bloc.
Posted: Wed Aug 16, 2006 9:11 pm
by Trond
Flype wrote:Konne wrote:@netmaestro
But I thought in PB 4.0 you could create Arrays, LinkedLists inside a procedure :roll:
You can but, take care !
It's the same limit than the one described here :
http://www.purebasic.fr/english/viewtop ... highlight=
It's not a bug, but a known limitation :
Inside a procedure, arrays are limited by the stack.
Solutions are :
1/ use globals (no limit in this case).
2/ allocate yourself a (structured) memory bloc.
I think you should he read a bit more on what he does. He's creating a
pointer to an array. That would be about 4 bytes and should not fill up the stack.
Posted: Wed Aug 16, 2006 9:14 pm
by Trond
netmaestro wrote:Hi Konne - Your problem is the dimmed array inside the procedure. If you want to use its contents outside the procedure, change its definition to:
and it should work.
Well, he
doesn't want to use it outside the procedure, so that can't be the problem.
Posted: Wed Aug 16, 2006 9:20 pm
by Flype
@trond,
ha yes, sorry, not a good idea to read the bug report while watching TV

Posted: Wed Aug 16, 2006 9:22 pm
by netmaestro
Well - adding the Global keyword to the Dim line makes it work, so it might just actually be the problem. :roll:
Posted: Wed Aug 16, 2006 9:24 pm
by Trond
Flype wrote:@trond,
ha yes, sorry, not a good idea to read the bug report while watching TV

lol