Making Code to a procedure

Just starting out? Need help? Post your questions and find answers here.
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Making Code to a procedure

Post 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","") 
Apart from that Mrs Lincoln, how was the show?
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Sorry, but you'll have to post "nicefrau4.bmp" before we can help.
Image Image
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

and nicefrau1,2 and 3 as well :lol:
Paid up PB User !
User avatar
Kiffi
Addict
Addict
Posts: 1508
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Straker wrote:Sorry, but you'll have to post "nicefrau4.bmp" before we can help.
take this nicefrau instead ;-)

Greetings ... Kiffi
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post 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?
Apart from that Mrs Lincoln, how was the show?
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

nett!
Image Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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:

Code: Select all

Global Dim *ib.l(ihd*2,iw-1) 
and it should work.
BERESHEIT
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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. ;)
--Kale

Image
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post 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.
Apart from that Mrs Lincoln, how was the show?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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:

Code: Select all

Global Dim *ib.l(ihd*2,iw-1) 
and it should work.
Well, he doesn't want to use it outside the procedure, so that can't be the problem.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

@trond,

ha yes, sorry, not a good idea to read the bug report while watching TV :lol:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Well - adding the Global keyword to the Dim line makes it work, so it might just actually be the problem. :roll:
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Flype wrote:@trond,

ha yes, sorry, not a good idea to read the bug report while watching TV :lol:
lol
Post Reply