Transitions via greyscale - very slow on Mac
BlitzMax Forums/BlitzMax Programming/Transitions via greyscale - very slow on Mac
| ||
I'm working on implementing transitions using the method (well I think it is) developed by Beaker and Koriolis. Works well on PC but is painfully slow on my eMac so I would welcome some comment on my code. The greyscale in the following is here or you can make your own: http://mulawa.net/special/wip/spiral.bmp First I analyse the monochrome image: Strict ' analyses the monochrome image (eg) spiral.bmp ' records the x,y co-ords of each point with a particular greyscale value (eg spiral.dat) ' also records how many of each (eg spiraln.dat) ' these 2 files will be used by the transition program ' Local fn$="spiral" Local px:TPixmap=LoadPixmap(fn$+".bmp") Local f1:TStream=LittleEndianStream(WriteFile(fn$+"n.dat")) Local f2:TStream=LittleEndianStream(WriteFile(fn$+".dat")) For Local grey=0 To 255 Local n=0 For Local x=0 To 1023 For Local y=0 To 767 Local p=ReadPixel(px,x,y) p=p & 255 If p=grey n=n+1 WriteShort f2,x WriteShort f2,y End If Next Next WriteInt f1,n Print n ' would expect these values to be roughly the same for a smooth transition Next CloseFile f1 CloseFile f2 End Then I use the two files (they could be combined into one of course): to do the transition. You will need to provide your own two 1024x768 images. Strict Graphics 1024,768,32 Local px1:TPixmap,px2:TPixmap,name$ #data DefData "spiral","" Repeat ReadData name$ If name$="" Then RestoreData data;ReadData name$ px1=LoadPixmap("1.png") px2=LoadPixmap("2.png") transition(name$,px1,px2) Until KeyHit(KEY_ESCAPE) Or AppTerminate() End ' spiraln.dat (eg) contains 256 integers - ' they are the greyscale counters ' eg the third integer is 6 means ' there are 6 points in the greyscale map with a grey scale of 2 ' spiral.dat contains the x,y co-ords in short integers ' for the grayscale values ' eg the 1st pair is 100,350 means the greyscale value at 100,350 ' in the grayscale map is 0 ' Function transition(name$,px1:TPixmap,px2:TPixmap) Local f1:TStream,f2:TStream,grey,n,i,x,y,px,ms,dms ms=MilliSecs() DrawPixmap px1,0,0 Flip(1) f1=LittleEndianStream(ReadFile(name$+"n.dat")) f2=LittleEndianStream(ReadFile(name$+".dat")) For grey=0 To 255 n=ReadInt(f1) For i=1 To n x=ReadShort(f2) y=ReadShort(f2) px=ReadPixel(px2,x,y) WritePixel(px1,x,y,px) Next DrawPixmap px1,0,0 Flip 1 Repeat dms=MilliSecs()-ms Until dms>15 Or dms<0 ms=MilliSecs() Next CloseFile f1 CloseFile f2 End Function Peter |
| ||
DrawPixmap px1,0,0 There's your problem. It's an order of magnitude faster to have the pixmap as part of a TImage, and re-upload the texture after each modification, and then draw the TImage. |
| ||
Thanks Brucey - but I think I'll need more detailed instructions. I tried: ' DrawPixmap px1,0,0 img=LoadImage(px1) DrawImage img,0,0 and it slowed almost to a standstill on the PC so I'm obviously not following what you mean. I'm still very much a BlitzMax newbie! Peter |
| ||
Probably the ReadShort (and in general I/O operations) in a loop cause the slowness. Try to load first your data in an array, and then use these datas to write the pixmap and convert in into an image. And what f2 stream should do? It's not used in your code. |