Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!oliveb!sun!pepper!cmcmanis From: cmcmanis%pepper@Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga.tech Subject: Re: bitmaps with intuition... Message-ID: <56215@sun.uucp> Date: 11 Jun 88 11:37:09 GMT References: <4370@gryphon.CTS.COM> <3170@charon.unm.edu> Sender: news@sun.uucp Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Organization: Sun Microsystems, Mountain View Lines: 65 In article <3170@charon.unm.edu> hansb@ariel.unm.edu.UUCP (Hans Bechtel) writes: >Questions: > >how do I convert planeptrs to window's bitmap to common x,y >coordinates? Bitmaps are *always* an even multiple of 16 bits wide even when the image they contain or are displaying is not. So the Address of a pixel in the plane pointer is y * the width in bytes of the bitmap. The width can be calculated with the formula : ByteWidth = (BitMap->Width + 15)/8; So the byte containing the pixel of interest is x + y * ByteWidth. The actual bit that is the pixel at X,Y is calculated using : PixelBit = x % 8; >how do I get the correct offsets to the window's bitmaps? Using the two formulas above you can get the bit using this formula MyBit = *(BitMap->PlanePtr[n] + ByteWidth*y + x) >> (7 - PixelBit); This will return a value of one or zero depending on if the pixel has a bit set in this bitplane. >This may all seem easy, but I have read and read the manuals until >the guru finally wins... >Please post the code to do the following: > >read a x,y pixel on all bitplanes of a window (not the readpixel way) I haven't tried this so take it with a grain of salt but here goes ... To read a pixel, assuming the following defines and your bitmap is pointed to by a BitMap structure named BitMap : #define PIXEL(n,x,y) *(BitMap->PlanePtr[n]+ByteWidth*y+x) #define ThisBit(n,x,y) PIXEL(n,x,y) >> (7-(x % 8)); Assuming ByteWidth had already been calculated. Use the statement ... for (Pixel=0, i=0; iDepth; i++) Pixel += ThisBit(i,x,y) * (1<write a x,y pixel " " Assuming the same defines above, an additional define like the one below and the value you are writing is already in the variable Pixel ... #define MoveBit(from,to,byte) (((byte >> (7-from)) & 1) << to) for (i=0; iDepth; i++) { PIXEL(i,x,y) &= ~(MoveBit(7,(x%8),1)); /* Mask off old value */ PIXEL(i,x,y) |= MoveBit(i,(x%8),Pixel); /* Or in new value */ } >get the offsets Offset = ByteWidth*y + x; >etc.... Have fun ... --Chuck McManis uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com These opinions are my own and no one elses, but you knew that didn't you.