private void setToBlack(byte[] buffer, int lineOffset, int bitOffset,
			int numBits) {
		int bitNum = (8 * lineOffset) + bitOffset;
		int lastBit = bitNum + numBits;

		int byteNum = bitNum >> 3;

		// Handle bits in first byte
		int shift = bitNum & 0x7;
		if (shift > 0) {
			int maskVal = 1 << (7 - shift);
			byte val = buffer[byteNum];
			while ((maskVal > 0) && (bitNum < lastBit)) {
				val |= maskVal;
				maskVal >>= 1;
				++bitNum;
			}
			buffer[byteNum] = val;
		}

		// Fill in 8 bits at a time
		byteNum = bitNum >> 3;
		while (bitNum < (lastBit - 7)) {
			buffer[byteNum++] = (byte) 255;
			bitNum += 8;
		}

		// Fill in remaining bits
		while (bitNum < lastBit) {
			byteNum = bitNum >> 3;
			buffer[byteNum] |= (1 << (7 - (bitNum & 0x7)));
			++bitNum;
		}
	}