#include "driver.h"
void
cupsPackHorizontal(const unsigned char *ipixels,
unsigned char *obytes,
int width,
const unsigned char clearto,
const int step)
{
register unsigned char b;
while (width > 7)
{
b = clearto;
if (*ipixels)
b ^= 0x80;
ipixels += step;
if (*ipixels)
b ^= 0x40;
ipixels += step;
if (*ipixels)
b ^= 0x20;
ipixels += step;
if (*ipixels)
b ^= 0x10;
ipixels += step;
if (*ipixels)
b ^= 0x08;
ipixels += step;
if (*ipixels)
b ^= 0x04;
ipixels += step;
if (*ipixels)
b ^= 0x02;
ipixels += step;
if (*ipixels)
b ^= 0x01;
ipixels += step;
*obytes++ = b;
width -= 8;
}
b = clearto;
switch (width)
{
case 7 :
if (ipixels[6 * step])
b ^= 0x02;
case 6 :
if (ipixels[5 * step])
b ^= 0x04;
case 5 :
if (ipixels[4 * step])
b ^= 0x08;
case 4 :
if (ipixels[3 * step])
b ^= 0x10;
case 3 :
if (ipixels[2 * step])
b ^= 0x20;
case 2 :
if (ipixels[1 * step])
b ^= 0x40;
case 1 :
if (ipixels[0])
b ^= 0x80;
*obytes = b;
break;
}
}
void
cupsPackHorizontal2(const unsigned char *ipixels,
unsigned char *obytes,
int width,
const int step)
{
register unsigned char b;
while (width > 3)
{
b = *ipixels;
ipixels += step;
b = (b << 2) | *ipixels;
ipixels += step;
b = (b << 2) | *ipixels;
ipixels += step;
b = (b << 2) | *ipixels;
ipixels += step;
*obytes++ = b;
width -= 4;
}
b = 0;
switch (width)
{
case 3 :
b = ipixels[2 * step];
case 2 :
b = (b << 2) | ipixels[step];
case 1 :
b = (b << 2) | ipixels[0];
*obytes = b << (8 - 2 * width);
break;
}
}
void
cupsPackHorizontalBit(const unsigned char *ipixels,
unsigned char *obytes,
int width,
const unsigned char clearto,
const unsigned char bit)
{
register unsigned char b;
while (width > 7)
{
b = clearto;
if (*ipixels++ & bit)
b ^= 0x80;
if (*ipixels++ & bit)
b ^= 0x40;
if (*ipixels++ & bit)
b ^= 0x20;
if (*ipixels++ & bit)
b ^= 0x10;
if (*ipixels++ & bit)
b ^= 0x08;
if (*ipixels++ & bit)
b ^= 0x04;
if (*ipixels++ & bit)
b ^= 0x02;
if (*ipixels++ & bit)
b ^= 0x01;
*obytes++ = b;
width -= 8;
}
b = clearto;
switch (width)
{
case 7 :
if (ipixels[6] & bit)
b ^= 0x02;
case 6 :
if (ipixels[5] & bit)
b ^= 0x04;
case 5 :
if (ipixels[4] & bit)
b ^= 0x08;
case 4 :
if (ipixels[3] & bit)
b ^= 0x10;
case 3 :
if (ipixels[2] & bit)
b ^= 0x20;
case 2 :
if (ipixels[1] & bit)
b ^= 0x40;
case 1 :
if (ipixels[0] & bit)
b ^= 0x80;
*obytes = b;
break;
}
}
void
cupsPackVertical(const unsigned char *ipixels,
unsigned char *obytes,
int width,
const unsigned char bit,
const int step)
{
while (width > 7)
{
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
if (*ipixels++)
*obytes ^= bit;
obytes += step;
width -= 8;
}
while (width > 0)
{
if (*ipixels++)
*obytes ^= bit;
obytes += step;
width --;
}
}