[futurebasic] Re: [FB] Pixel peeking-poking v LINETO Part 2

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2004 : Group Archive : Group : All Groups

From: tedd <tedd@...>
Date: Sun, 3 Oct 2004 14:10:23 -0400
>Your customLineTo fn is set up to draw a single 
>pixel, not a line. It knows nothing of where the 
>quickdraw pen is, and only plots the single 
>point you've sent it.
>
>As to why that pixel doesn't show up, I haven't 
>found that yet. But you're correct that you 
>can't easily combine direct pixel poking with 
>quickdraw. You can't use regions unless you 
>build them with quickdraw and test them with 
>ptinrgn before plotting. Iif you want to refer 
>to the pen location, you must update it yourself 
>with moveto, and read it with getPen(point). 
>It's probably simpler to maintain your own pen 
>location.
>
>My recommendation would  be to replace your FN 
>customLineTo with a FN customLine(x1, y1, x2, 
>y2), to calculate and plot all the x's and y's 
>in between. Yes, that's a lot more work, but you 
>didn't expect this to be simple, did you? For 
>simple we have slothy QD. :-)
>
>hth
>  e-e
>  =J= a  y


Jay:

So you want something simple, huh?  :-)

Try explaining the gaps shown in this "real" 
CustomLINETO function demo below. You should find 
that simple, for I don't. Try adjusting the STEP 
value and see what happens.

I think I'll give up on this and work on something else.

tedd

---


toolbox fn LockPortBits(  CGrafPtr port) = OSErr
toolbox fn GetPortPixMap( CGrafPtr port) = PixMapHandle
toolbox Microseconds(UnsignedWide * microTickCount)

dim as UnsignedWide t1, t2'for timing
dim as long      gRowBytes
dim as ptr       gBaseAddr
dim as long      gDepth
dim gLineToFlag
dim gLastX

end globals

'~'<
local fn BuildWindow
dim as rect     r

setrect(r, 0, 0, 600, 600)
appearance Window 1, "LINETO v RC's PLOTLINE 
Demo", @r, _kDocumentWindowClass, 
_kWindowStandardFloatingAttributes
text _Monaco, 9

end fn

'~'<

local fn PlotDot(x as long, y as long)
dim as ptr pixelAddress

pixelAddress = gBaseAddr +y * gRowBytes
select gDepth
case 32
pixelAddress     += (x << 2)
pixelAddress.nil& = 1'4-byte value for 32-bit deep
case 16
pixelAddress     += (x << 1)
pixelAddress.nil% = 1'2-byte value for 16-bit deep
case 8
pixelAddress     += x
pixelAddress.nil` = 1'1-byte value for 8-bit deep
end select

end fn

'~'<
'do many dots

local fn CustomLineTo(x as long, y as long)
dim x1, y1 as long
dim i

long if gLineToFlag
for i = gLastX to x
x1 = i
y1 = i
fn PlotDot(x1, y1)
next
gLastX = x1
xelse
fn PlotDot(x,y)
gLastX = x
gLineToFlag = _true
end if

end fn


'~'<

local fn showCustomLINETO
dim x, y as long
dim i

moveto (0,0)
for i = 1 to 500 step 50
y = i
x = i
FN CustomLineTo(x,y)
next

end fn

'~'<

local fn showStandardLINETO
dim x, y as long
dim i

moveto (0,0)
for i = 1 to 500 step 50
y = i
x = i
lineto(x,y)
next

end fn

'~'<

local fn show
dim as long      pixelValue, dummy
dim as rect      bounds
dim pmHandle     as ^^PixMap
dim as CGrafPtr  @ port
dim as OSErr     err
dim a$

// draw directly into the window's port
port          = fn GetWindowPort(window(_wndPointer))
err           = fn LockPortBits(port)

// values for CustomLineTo
pmHandle      = fn GetPortPixMap(port)
gRowBytes      = pmHandle..rowBytes and 0x3fff
gDepth            = pmHandle..pixelSize
gBaseAddr      = fn 
GetPixbaseAddr(pmHandle)'address of pixel at top 
left of window

Microseconds(t1)'for TIME Display
FN showCustomLINETO
Microseconds(t2)'elapsed time in microsecs
print %(50,10) str$((t2.lo -t1.lo)) +" µs  using RC's PLOTLINE method"

Microseconds(t1)'for TIME Display
fn showStandardLINETO
Microseconds(t2)
print %(50,20) str$((t2.lo -t1.lo)) +" µs  using LINETO method";

end fn

'~'<
gLineToFlag = _false
fn BuildWindow
fn show

include "Subs Quick Event Loop.Incl"

--

--
--------------------------------------------------------------------------------
http://sperling.com/