I'm trying to create a bitplane mask to use with BitMaskBitMapRastPort (or, in actual fact, the BltBitMapTags equivalent) for arbitrary BitMaps.
I've created the mask with AllocRaster(width, height) and poked the mask in by referencing it as an array.
This works for some bitmaps, but not for others - and I think the problem is because the bitplanes are 16-bit(?) aligned, and when I'm poking the values in I'm not taking any extra space into account.
Basically my routine is:
PLANEPTR mask = AllocRaster(width, height);
int w = width / 8;
for(y=0; y<height; y++) {
for(x=0; x<width; x++) {
/* set maskbit to 0 or 1 */
mask[(y*w) + (x/8)] = (mask[(y*w) + (x/8)] << 1) | maskbit;
}
}
Basically I think when the width is not a multiple of 8, width/8 gets rounded down and that causes a problem, but also when the width itself isn't a multiple of 16, that also causes a problem because I'm not skipping the extra bits at the end of the plane.
Any ideas how to work around this?
(as an aside - picture.datatype documentation is misleading, as it suggests that PDTA_MaskPlane will return a 1-bit mask, with no mention that it doesn't if the mask type is mskHasAlpha)