/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1998 Microsoft Corporation
Module Name:
Abstract:
Functions:
Notes:
--*/
#include "precomp.hxx"
#include <string.h>
#include "compress.h"
#include "local.h"
#include "serial.h"
// A6SDK.h
typedef struct tagA6P{
BYTE comm[5];
BYTE data[12000];
} A6PRINTDATA, *LPA6PRINTDATA;
static BYTE pixel[12000];
static BYTE data[12000];
static A6PRINTDATA pData;
// halftone.h
BYTE
GrayScale(
BYTE r,
BYTE g,
BYTE b
);
void
PrepareImage(
LPBYTE pixel,
LPBYTE dot,
DWORD dwLine,
DWORD dwWidth
);
// util.h
DWORD
Compress(
LPBYTE oData,
LPBYTE nData,
DWORD dwDataLen
);
BOOL bSkip;
//#define VERBOSE
#ifdef VERBOSE
#define TRACE(cond, args) \
do { if (cond) { MessageBox(GetFocus(), args, TEXT("A6PRN"), MB_OK); /*DebugBreak();*/ } } while (0)
#else
#define TRACE(cond, args)
#endif
#define HUE_B 0.64
#define HUE_G 0.9
#define GAMMA_C 1.3
#define GAMMA_K 1.4
#define GAMMA_V 2.1
#define DOT_K 1.3
#define DOT_C 1.1
#define DOT_M 1.2
#define DOT_Y 1.1
#define MAX_8 0x0ff
#define MAX_14 0x02000
#define MAX_13 0x01000
const static int BitMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
Printer printer;
Port::Port(void)
{
nBuffer = 0;
hPrinter = INVALID_HANDLE_VALUE;
}
Port::~Port(void)
{
TRACE(TRUE, (TEXT("A6PRN: Port::~Port\r\n")));
Close();
}
BOOL Port::Flush(void)
{
//nBuffer = 0;
//return TRUE;
BOOL f = TRUE;
if (nBuffer)
{
// Output data to debug window. This is temporary.
//
/*
int Total = nBuffer;
BYTE *pInput = Buffer;
while (Total)
{
int cnt;
if (Total < 32) cnt = Total;
else cnt = 32;
unsigned short Output[140];
unsigned short *pOutput = Output;
for (int i = 0; i < cnt; i++)
{
wsprintf(pOutput, (TEXT("%02x")), *pInput);
pOutput += 2;
pInput++;
}
RETAILMSG(TRUE, (TEXT("[%s]\r\n"), Output));
Total -= cnt;
}
*/
// Send data to printer.
//
if (hPrinter == (HANDLE)PRINT_SERIAL_PORT)
f = PortWrite(hPrinter, Buffer, nBuffer);
else
f = PrinterSend(hPrinter, Buffer, nBuffer);
nBuffer = 0;
}
TRACE(!f, (TEXT("\tPrinterSend() Failed\r\n")));
return f;
}
HANDLE Port::Open(PWSTR sPort)
{
PWSTR pPort=NULL;
Close();
if ((pPort = (PWSTR)malloc(max((lstrlen(sPort) + 1), 6) * sizeof(TCHAR)))) {
lstrcpy(pPort, sPort);
}
if (!pPort) {
SetLastError(ERROR_OUTOFMEMORY);
return INVALID_HANDLE_VALUE;
}
if (CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, TEXT("COM"), 3, pPort, 3) == CSTR_EQUAL)
hPrinter = PortInitialize(sPort);
else
hPrinter = PrinterOpen(sPort);
free(pPort);
return hPrinter;
}
void Port::Close(void)
{
TRACE(TRUE, (TEXT("A6PRN: Port::Close\r\n")));
if (INVALID_HANDLE_VALUE != hPrinter)
{
Flush();
if (hPrinter == (HANDLE)PRINT_SERIAL_PORT)
PortClose(hPrinter);
else
PrinterClose(hPrinter);
hPrinter = INVALID_HANDLE_VALUE;
}
}
BOOL Port::Write(BYTE *buffer, int length)
{
BOOL f = TRUE;
if (!buffer) return FALSE;
while (length && f)
{
// Is the buffer full and do we need to flush to the printer.
//
if (nBuffer == PORT_BUF_SIZE)
f = Flush();
// Move as many bytes as we can.
//
int nBytesToCopy = PORT_BUF_SIZE - nBuffer;
if (length < nBytesToCopy) nBytesToCopy = length;
memcpy(Buffer+nBuffer, buffer, nBytesToCopy);
buffer += nBytesToCopy;
length -= nBytesToCopy;
nBuffer += nBytesToCopy;
}
return f;
}
BOOL Port::WriteString(char *buffer)
{
if (!buffer) return FALSE;
unsigned int length = strlen(buffer);
return Write((BYTE *)buffer, length);
}
#define PCL_UNENCODED 0
#define PCL_TIFF 2
#define PCL_DELTAROW 3
BOOL Printer::AllocateBuffers(GDIINFO * pGI, DEVMODE * pDM)
{
TRACE(TRUE, (TEXT("A6PRN: AllocateBuffers\r\n")));
int i;
double d;
// Forget old buffers, if any.
//
DeallocateBuffers();
fColor = (DMCOLOR_COLOR == pDM->dmColor);
fColor = FALSE;
PaperSize = pDM->dmPaperSize;
ResolutionPixels = pGI->ulLogPixelsX;
if (DMORIENT_LANDSCAPE == pDM->dmOrientation)
{
HeightPixels = pGI->ulHorzRes;
WidthPixels = pGI->ulVertRes;
pColorRow = new BYTE[WidthPixels * 3];
}
else
{
HeightPixels = pGI->ulVertRes;
WidthPixels = pGI->ulHorzRes;
}
WidthOfRasterAreaInBytes = WidthPixels;//(WidthPixels+7)/8;
pScanRow = new BYTE[WidthOfRasterAreaInBytes];
pBlackRow = new BYTE[WidthOfRasterAreaInBytes];
pPCLData = new BYTE[WidthOfRasterAreaInBytes];
pError = new short[WidthPixels + 2];
pK = new short[WidthPixels];
pEK = new short[WidthPixels];
pSK = new BYTE[WidthOfRasterAreaInBytes];
pGK = new short[MAX_8 + 1];
d = pow(MAX_8, GAMMA_K) / MAX_14;
pGK[0] = pGK[1] = 0;
for (i = 2; i < MAX_8; i++)
pGK[i] = int(pow(i, GAMMA_K) / d + 0.5);
pGK[MAX_8] = MAX_14;
if (fColor) {
pC = new short[WidthPixels];
pM = new short[WidthPixels];
pY = new short[WidthPixels];
pEC = new short[WidthPixels];
pEM = new short[WidthPixels];
pEY = new short[WidthPixels];
pSC = new BYTE[WidthOfRasterAreaInBytes];
pSM = new BYTE[WidthOfRasterAreaInBytes];
pSY = new BYTE[WidthOfRasterAreaInBytes];
pGC = new short[MAX_8 + 1];
d = pow(MAX_8, GAMMA_C) / MAX_14;
pGC[0] = 0;
for (i = 1; i < MAX_8; i++)
pGC[i] = int(pow(i, GAMMA_C) / d + 0.5);
pGC[MAX_8] = MAX_14;
pGV = new BYTE[MAX_8 + 1];
d = pow(MAX_8, GAMMA_V) / MAX_8;
pGV[0] = 0;
for (i = 1; i < MAX_8; i++)
pGV[i] = int(pow(i, GAMMA_V) / d + 0.5);
pGV[MAX_8] = MAX_8;
}
iDotK = int(DOT_K * MAX_14);
iDotC = int(DOT_C * MAX_14);
iDotM = int(DOT_M * MAX_14);
iDotY = int(DOT_Y * MAX_14);
iHueB = int(HUE_B * MAX_8);
iHueG = int(HUE_G * MAX_8);
return pScanRow && pBlackRow && pPCLData && pError &&
(pColorRow || DMORIENT_LANDSCAPE != pDM->dmOrientation) &&
pK && pEK && pSK && pGK &&
(!fColor ||
(pC && pM && pY &&
pEC && pEM && pEY &&
pSC && pSM && pSY &&
pGV && pGC));
}
void Printer::DeallocateBuffers(void)
{
TRACE(TRUE, (TEXT("A6PRN: DeallocateBuffers\r\n")));
if (pColorRow)
{
delete pColorRow;
pColorRow = 0;
}
if (pScanRow)
{
delete pScanRow;
pScanRow = 0;
}
if (pBlackRow)
{
delete pBlackRow;
pBlackRow = 0;
}
if (pPCLData)
{
delete pPCLData;
pPCLData = 0;
}
if (pError)
{
delete pError;
pError = 0;
}
if (pC) {
delete pC;
pC = 0;
}
if (pY) {
delete pY;
pY = 0;
}
if (pM) {
delete pM;
pM = 0;
}
if (pK) {
delete pK;
pK = 0;
}
if (pSC) {
- 1
- 2
- 3
前往页