[futurebasic] Re: [FB] Faster access to pictures with GWorld

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2008 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Fri, 25 Apr 2008 02:20:01 -0400
Your program is quite nice, I hope you continue with it.

You can do something like this...(typed in email, tested as to demo  
mode (just plots rects for test), errors are possible though)

One way to do this... *And  I'm way rusty these days * :)

// Lil Pict Plotter Engine, Robert Covington, April 2008
// Loads pict resources into a gworld for sending elsewhere later
// Assumes resources in app resources file...uses GetPicture
// Then copies to an array of handles, if needed for future.
// Array has handles and src and dstrects, but adjust to suit
// or ignore...
// Can just load and go direct, see PictureSetter function.

_startID   = 128
_endID     = 158
_MaxFrames = 32

_demo = _True // plots if true... // Need resources

Begin Record Sequence
dim srcRect as Rect
dim dstRect as Rect
dim h as handle// Pict handle, resources marked as purgeable
dim id as long// yeah, I know it's an int ;)
End Record

dim frame(_MaxFrames) as Sequence

dim PICTWorld as long// offscreen buffer
dim gDestGW as long// your window or port
dim gDestDV as long
dim @tmpGW,tmpDV as long

end globals

Local Fn GetPictures
dim i as int
For i = _startID to _endID
frame.h(i) = FN GetPicture(i)
long if frame.h(i)
hLock(frame.h(i))
end if
next
end fn

Local Fn MakeLockedGWorld(theRect as pointer to rect, depth)
dim qdErr
DIM @ myGWorld as long
myGWorld = 0
qdErr = FN NEWGWORLD(myGWorld, depth, #theRect, 0,0,0)
LONG IF (qdErr != _noErr)
if myGWorld then call DisposeGWorld(myGWorld)
myGWorld = 0
Xelse
long if (FN LOCKPIXELS(FN GETGWORLDPIXMAP(myGWorld)) == _false)
if myGWorld then call DisposeGWorld(myGWorld)
myGWorld = 0
end if
END IF
END FN = myGWorld

Local Fn PictureSetter
// port setting
dim r as rect
dim j,k,cnt as int
dim h as handle // optional direct load as you go

SetRect(r,0,0,128,32)// one row = 0,0,256,16

PICTWorld = Fn MakeLockedGWorld(r, 32)

long if PICTWorld
cnt = 0
SetRect(r,0,0,16,16)
for j = 0 to 1
for k = 0 to 15
frame.srcRect(cnt) = r
long if _demo
frameRect(r)
xelse
// Can skip master loader
// Use in the loop below...
// h = FN GetPicture(i)
// DrawPicture(h,r)
long if frame.h(_startID+cnt) <> 0
DrawPicture(frame.h(_startID+cnt),r)
// Unlock if not needed again...
HUnlock(frame.h(_startID+cnt))// if  marked Purgeable, resource  
manager releases PICT memory
end if
end if
OffsetRect(r,16,0)//move over a notch
next k
SetRect(r,0,0,16,16)
OffsetRect(r,0,16)// down 1 row
next j
end if
end fn

local fn CopyQuick( srcGW as Long, destGW as Long, srcR as Ptr, destR  
as Ptr, cMode )
'~'1
ForeColor( _blackColor )
BackColor( _whiteColor )
CopyBits( #srcGW+2, #destGW+2, #srcR, #destR, cMode, 0)
end fn

Local  Fn CopyPICTElement(id as int, dr as ^Rect)
GetGWorld(tmpGW,tmpDV)
SetGWorld(gDestGW,gDestDV) // Your window
Fn CopyQuick( PICTWorld , gDestGW , frame.srcRect(id), dr, _srcCopy )
SetGWorld(tmpGW,tmpDV)
end fn

dim @r as rect
window 1
GetGWorld(gDestGW,gDestDV)
//Fn GetPictures // load images from PICT Resources
Fn PictureSetter // Demo or draw picts from handles
// view images (if loaded, and non-demo)
long if _demo = _False
SetRect(r,0,0,128,32)
long if PICTWorld
fn CopyQuick( PICTWorld , gDestGW, r, r,_srcCopy )
end if
end if


// draw some random element..
//Fn CopyPICTElement(id as int, dr as ^Rect) // dr is Dest Rect

do
handleEvents
until gFBQuit