File: bmForAll.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (73 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#   include	"bitmapConfig.h"

#   include	"bmintern.h"
#   include	<string.h>

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Call a function for all pixels that have value '1' in a bitmap	*/
/*  image. [Or '0'.. when invertMaskIn == 0xff.].			*/
/*									*/
/*  Used inside morphology code and to extract features from the	*/
/*  result.								*/
/*									*/
/*  The behavior with ( invertMaskIn != 0xff && invertMaskIn != 0x00 )	*/
/*  is completely predictable, buf not what this routine was meant for.	*/
/*									*/
/*  1)  Determine the mask to ignore the trailing bits in the input	*/
/*	image.								*/
/*									*/
/************************************************************************/

void bmForAll1Pixels(		const BitmapDescription *	bdIn,
				const unsigned char *		bufIn,
				unsigned char			invertMaskIn,
				void *				through,
				BM_PIX_FUN			pixFun )
    {
    int			rowIn;
    unsigned char	lastMaskIn;

    int			col;

    if  ( bdIn->bdBitsPerPixel != 1 )
	{ LLDEB(bdIn->bdBitsPerPixel,bdIn->bdBitsPerPixel!=1);	}

    /*  1  */
    lastMaskIn= 0xff;
    lastMaskIn >>= ( bdIn->bdPixelsWide % 8 );
    lastMaskIn <<= ( bdIn->bdPixelsWide % 8 );

    for ( rowIn= 0; rowIn < bdIn->bdPixelsHigh; rowIn++ )
	{
	const unsigned char *	rowBufIn= bufIn+ rowIn* bdIn->bdBytesPerRow;

	for ( col= 0; col < bdIn->bdPixelsWide; rowBufIn++, col += 8 )
	    {
	    unsigned char	val= ( rowBufIn[0] ^ invertMaskIn );

	    unsigned char	mask= 0x80;
	    int		pix;

	    if  ( col+ 8 >= bdIn->bdPixelsWide )
		{ val &= lastMaskIn;	}
	    if  ( ! val )
		{ continue;	}

	    for ( pix= 0; pix < 8; mask >>= 1, pix++ )
		{
		int		colIn= col+ pix;

		if  ( ! ( val & mask ) )
		    { continue;	}

		(*pixFun)( through, rowIn, colIn );
		}
	    }
	}

    return;
    }