© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 36 of 52
FNDNEW
is a constant defined in the PBASIC code template as
$F8
and finds pixels or edges between
pixels
Begin
and
End
, inclusive.
Begin
and
End
can
range from
1
to
255
, and
Begin
should be less
than or equal to
End
. (Remember that binary pixel locations are one-based, not zero-based. The first
pixel is pixel #1.)
FNDNXT
finds pixels or edges between the current internal Left and Right limits, whatever they might
be. These limits are set by the following actions, whichever occurred most recently:
•
Any acquire command, which resets Left to
1
and Right to
255
.
•
Any
CNTNEW
command. Left ends up at
Begin
; Right, at
End
.
•
A
FNDNEW
command. Left is initialized to
Begin
; Right, to
End
.
•
Any
FNDNEW
or
FNDNXT
command, wherein Left is moved to the found pixel or edge
(searching forward), or Right is moved to the found pixel or edge (searching backward). If the
desired feature is not found, Left will equal Right + 1, causing further counts and finds to return
zero.
The modifiers that can be used with (i.e. ORed to)
FNDNEW
and
FNDNXT
are:
Name
Value
Description
FWD
$00
Search from left-to-right.
BKWD
$04
Search from right-to-left.
DRKPIX
$00
Locate dark pixels.
BRTPIX
$02
Locate bright pixels.
DRKEDG
$03
Locate dark (high-to-low) edges.
BRTEDG
$01
Locate bright (low-to-high) edges.
These are the same modifiers used with
CNTNEW
and
CNTNXT
, but with two additions:
FWD
and
BKWD
. With these modifiers, you can select which end to start the search from. Searching forward starts
from the Left limit and scans towards the right until either the desired feature is found or the Right limit
is reached. Searching backwards starts at the Right limit and scans to the left until either the desired
feature is found or the Left limit is reached.
Each invocation of
FNDNEW
or
FNDNXT
appends one byte to the results buffer. If the sought-after
pixel or edge was found, this byte will be its position (
1
to
255
) in the binary image. If it wasn’t found,
the result will be
0
.
Another side effect of the find commands is that the Left or Right limit, whichever one you started from,
is replaced by the result of the find. So, for example, if the first dark pixel, scanning from the left, were
found at position 45, then the new value of Left would become 45. That way, the next time you use
FNDNXT
to scan from the left, the search picks up where the last one ended, at position 45. This makes
it possible to chain multiple finds to locate, say, the third occurrence of a certain feature, rather than just
the first one. If the result of the search is
0
, the internal Left and Right limits will have crossed, forcing all
subsequent searches to result in
0
as well, until these limits are reset to new values.
When the
DRKPIX
or
BRTPIX
modifier is selected,
FNDNEW
and
FNDNXT
will look for the first dark
or light pixel in the selected direction, depending on the modifier used. For example, suppose we want to
find the first dark pixel between locations 32 and 64, scanning from left to right. Here’s the code that
does it:
OWOUT owio, 0, [FNDNEW|FWD|DRKPIX, 32, 64]
GOSUB Ready