Path: utzoo!attcan!uunet!mcvax!enea!tut!santra!jmunkki
From: jmunkki@santra.HUT.FI (Juri Munkki)
Newsgroups: comp.sys.mac.programmer
Subject: Re: bitmap --> region
Message-ID: <14231@santra.UUCP>
Date: 4 Jul 88 07:13:42 GMT
References: <2958@cvl.umd.edu>
Sender: jmunkki@santra.UUCP
Reply-To: jmunkki@santra.UUCP (Juri Munkki)
Organization: Helsinki University of Technology, Finland
Lines: 55

In article <2958@cvl.umd.edu> avjewe@cvl.umd.edu (Andrew Donaldson Jewell) writes:
>Here's something which I hope is an easy question :
>	How can I turn a bitmap into a region?

The sources for a program that turns a bitmap into a region are available
from Apple licensing. The function will also be in a future System.

Disclaimer:
I haven't seen the apple code or any other program code related to this
problem. Any errors just show how dumb I am and that I haven't really
tried to do this.

Let's suppose that you have a bitmap bm of size sx*sy. You then need a
buffering bitmap bb of size sx*1.

The rest is in pseudocode:

  Paint bb to white

  for every line y from 0 to sy-1 do
    exclusive or line y from bm to line 0 of bb

    if bb is not totally white then			*
      write y into regiondata
      flag is white

      for every pixel x from 0 to sx-1 do
	if flag is not pixel x,0 from bb then
	  flag is pixel x,0 from bb
	  write x into regiondata

      if flag is not white then
	write sx into regiondata
      copy line y from bm to line 0 of bb
      write 32767 into regiondata

  copy the data from the last line of the region into regiondata
  store sy as the line number of that data
  write 32767 into regiondata

The line with the asterisk can be easily optimized out so that
the check is not needed. You can simply do the stuff that follows
and then look if some pixels were found. You can also optimize
large bitmaps by looking at bytes, words or longwords at a time
and then only then test the actual pixels.

For more information on why this might work, look at by region
format posting (a long time ago) or try to find it from MacTutor,
where it appeared on the mousehole column.

I would of course appreciate if someone checked this out and flamed.

Juri Munkki
jmunkki@santra.hut.fi
jmunkki@fingate.bitnet