Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!helios.ee.lbl.gov!ux1!osborn From: osborn@ux1 (James R Osborn) Newsgroups: comp.sys.mac.programmer Subject: Offscreen BitMaps Summary: Tech Note 41 Error Keywords: bitmap, offscreen Message-ID: <3023@helios.ee.lbl.gov> Date: 18 Jul 89 22:16:36 GMT Sender: usenet@helios.ee.lbl.gov Reply-To: osborn@ux1 (James R Osborn) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 61 Hi folks, I assume that what I have to say here is old hat to most mac programmers. However, I have used a piece of code given in TN 41 for quite awhile without any problems and only recently did I discover the problem. The code I am refering to is that which calculates the necessary rowbytes for your bitmap: {make it at least as big as we need} OffRowBytes:=((OffRight-OffLeft) div 8) +1; {make OffRowBytes even} If Odd(OffRowBytes) then OffRowBytes:= OffRowBytes -1; This works great if you have a number ourRowBits which is: odd multiple of 8 bits <= ourRowBits <= even multiple of 8 bits In this range, the row bits that are missed by the integer truncation (from the division) are counted because of the extra byte needed to make the row bytes even. If you are unforunate enough to have a number ourRowBits which is: even multiple of 8 bits < ourRowBits < odd multiple of 8 bits then, not enough bytes are allocated for the last few bits of your image. I noticed this because things that were being drawn at the right edge of my bitmap were "overflowing" to the beginning of the next row. You could just add an extra rowbyte instead of subtracting, but this would waste memory in certain cases. Here is how I dealt with it (in C). I make no claims as to the efficiency of my code: int numBytes, rowBits; rowBits = ourRect.right - ourRect.left; numBytes = rowBits / 8; if (odd(numBytes)) /* You must write your own odd() */ numBytes += 1; else if (rowBits % 8) /* % is mod for pascal people */ numBytes += 2; Now rowBytes should contain the proper (and even) number of bytes to contain ourRect. I hope this does some other people good. It just goes to show you it's always something. Either it's incorrect tech notes or your mac is smoking. It's always something. |------------------------------| | James R. Osborn | | Lawrence Berkeley Laboratory | | osborn@ux1.lbl.gov | |------------------------------|