本文发表在 rolia.net 枫下论坛其中send surface那一段没看明白,那位高手指点一下?谢谢!
void PrintSurface (int hDevice, SDL_Surface *surface, char justify)
{
Uint8 byte;
int bit;
SDL_Color pixel;
int i, pc;
int r, c;
**==================================================
** Start bit image printing.
**==================================================
*/
write (hDevice, "\x1B\x2A\x62", 3);
byte = surface->h % 256;
write (hDevice, &byte, sizeof (byte));
byte = surface->h / 256;
write (hDevice, &byte, sizeof (byte));
for (r = 0; r < surface->h; r++)
{
byte = 0x00;
bit = 7;
pc = 0;
/*
**==================================================
** Justify line.
**==================================================
*/
if (surface->w < DotsPerLine[Model])
{
switch (toupper (justify))
{
case 'C':
pc = (DotsPerLine[Model] - surface->w) / 2;
break;
case 'R':
pc = DotsPerLine[Model] - surface->w;
break;
default:
pc = 0;
break;
}
byte = 0x00;
for (i = 0; i < (pc / 8); i++)
{
write (hDevice, &byte, sizeof (byte));
}
bit = 7 - (pc % 8);
}
/*
**==================================================
** Send surface.
**==================================================
*/
for (c = 0; (pc < DotsPerLine[Model]) && (c < surface->w); c++, pc++)
{
pixel = GetPixel (surface, c, r);
if ((pixel.r < 128) && (pixel.g < 128) && (pixel.b < 128))
{
byte |= (0x01 << bit);
}
bit--;
if (bit < 0)
{
write (hDevice, &byte, sizeof (byte));
bit = 7;
byte = 0x00;
}
}
/*
**==================================================
** Finish out line.
**==================================================
*/
if (bit != 7)
{
write (hDevice, &byte, sizeof (byte));
pc += bit + 1;
}
byte = 0x00;
for (bit = (DotsPerLine[Model] - pc) / 8; bit > 0; bit--)
{
write (hDevice, &byte, sizeof (byte));
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
void PrintSurface (int hDevice, SDL_Surface *surface, char justify)
{
Uint8 byte;
int bit;
SDL_Color pixel;
int i, pc;
int r, c;
**==================================================
** Start bit image printing.
**==================================================
*/
write (hDevice, "\x1B\x2A\x62", 3);
byte = surface->h % 256;
write (hDevice, &byte, sizeof (byte));
byte = surface->h / 256;
write (hDevice, &byte, sizeof (byte));
for (r = 0; r < surface->h; r++)
{
byte = 0x00;
bit = 7;
pc = 0;
/*
**==================================================
** Justify line.
**==================================================
*/
if (surface->w < DotsPerLine[Model])
{
switch (toupper (justify))
{
case 'C':
pc = (DotsPerLine[Model] - surface->w) / 2;
break;
case 'R':
pc = DotsPerLine[Model] - surface->w;
break;
default:
pc = 0;
break;
}
byte = 0x00;
for (i = 0; i < (pc / 8); i++)
{
write (hDevice, &byte, sizeof (byte));
}
bit = 7 - (pc % 8);
}
/*
**==================================================
** Send surface.
**==================================================
*/
for (c = 0; (pc < DotsPerLine[Model]) && (c < surface->w); c++, pc++)
{
pixel = GetPixel (surface, c, r);
if ((pixel.r < 128) && (pixel.g < 128) && (pixel.b < 128))
{
byte |= (0x01 << bit);
}
bit--;
if (bit < 0)
{
write (hDevice, &byte, sizeof (byte));
bit = 7;
byte = 0x00;
}
}
/*
**==================================================
** Finish out line.
**==================================================
*/
if (bit != 7)
{
write (hDevice, &byte, sizeof (byte));
pc += bit + 1;
}
byte = 0x00;
for (bit = (DotsPerLine[Model] - pc) / 8; bit > 0; bit--)
{
write (hDevice, &byte, sizeof (byte));
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net