xref: /haiku/src/add-ons/print/drivers/pcl6/PCL6.cpp (revision 9c8f4ac5d6ca3899b09fc889cb5fa5c7f21d82e2)
13bfe34e2SMichael Pfeiffer /*
23bfe34e2SMichael Pfeiffer  * PCL6.cpp
33bfe34e2SMichael Pfeiffer  * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
43bfe34e2SMichael Pfeiffer  * Copyright 2003 Michael Pfeiffer.
53bfe34e2SMichael Pfeiffer  */
63bfe34e2SMichael Pfeiffer 
7568716beSWim van der Meer 
8568716beSWim van der Meer #include "PCL6.h"
9568716beSWim van der Meer 
10568716beSWim van der Meer #include <memory.h>
11568716beSWim van der Meer 
123bfe34e2SMichael Pfeiffer #include <Alert.h>
133bfe34e2SMichael Pfeiffer #include <Bitmap.h>
143bfe34e2SMichael Pfeiffer #include <File.h>
152e86189fSMichael Pfeiffer 
163bfe34e2SMichael Pfeiffer #include "DbgMsg.h"
17dcab4343SMichael Pfeiffer #include "DeltaRowCompression.h"
182e86189fSMichael Pfeiffer #include "Halftone.h"
192e86189fSMichael Pfeiffer #include "JobData.h"
202e86189fSMichael Pfeiffer #include "PackBits.h"
212e86189fSMichael Pfeiffer #include "PCL6Cap.h"
225fc71589SMichael Pfeiffer #include "PCL6Config.h"
232e86189fSMichael Pfeiffer #include "PCL6Rasterizer.h"
24568716beSWim van der Meer #include "PrinterData.h"
252e86189fSMichael Pfeiffer #include "UIDriver.h"
262e86189fSMichael Pfeiffer #include "ValidRect.h"
273bfe34e2SMichael Pfeiffer 
28568716beSWim van der Meer 
29dcab4343SMichael Pfeiffer // DeltaRowStreamCompressor writes the delta row directly to the
30dcab4343SMichael Pfeiffer // in the contructor specified stream.
31dcab4343SMichael Pfeiffer class DeltaRowStreamCompressor : public AbstractDeltaRowCompressor
32dcab4343SMichael Pfeiffer {
33dcab4343SMichael Pfeiffer public:
DeltaRowStreamCompressor(int rowSize,uchar initialSeed,PCL6Writer * writer)34568716beSWim van der Meer 				DeltaRowStreamCompressor(int rowSize, uchar initialSeed,
35568716beSWim van der Meer 					PCL6Writer* writer)
36568716beSWim van der Meer 				:
37568716beSWim van der Meer 				AbstractDeltaRowCompressor(rowSize, initialSeed),
38568716beSWim van der Meer 				fWriter(writer)
39568716beSWim van der Meer 				{}
40dcab4343SMichael Pfeiffer 
41dcab4343SMichael Pfeiffer protected:
AppendByteToDeltaRow(uchar byte)42568716beSWim van der Meer 	void		AppendByteToDeltaRow(uchar byte)
43568716beSWim van der Meer 				{
44b1a3ccb8SMichael Pfeiffer 					fWriter->Append(byte);
45dcab4343SMichael Pfeiffer 				}
46dcab4343SMichael Pfeiffer 
47dcab4343SMichael Pfeiffer private:
48b1a3ccb8SMichael Pfeiffer 	PCL6Writer*	fWriter;
49dcab4343SMichael Pfeiffer };
50dcab4343SMichael Pfeiffer 
512e86189fSMichael Pfeiffer 
PCL6Driver(BMessage * message,PrinterData * printerData,const PrinterCap * printerCap)52fefd3ba5SMichael Pfeiffer PCL6Driver::PCL6Driver(BMessage* message, PrinterData* printerData,
53fefd3ba5SMichael Pfeiffer 	const PrinterCap* printerCap)
54568716beSWim van der Meer 	:
55fefd3ba5SMichael Pfeiffer 	GraphicsDriver(message, printerData, printerCap),
56fefd3ba5SMichael Pfeiffer 	fWriter(NULL),
57fefd3ba5SMichael Pfeiffer 	fMediaSide(PCL6Writer::kFrontMediaSide),
58fefd3ba5SMichael Pfeiffer 	fHalftone(NULL)
593bfe34e2SMichael Pfeiffer {
603bfe34e2SMichael Pfeiffer }
613bfe34e2SMichael Pfeiffer 
62568716beSWim van der Meer 
63568716beSWim van der Meer void
Write(const uint8 * data,uint32 size)64fefd3ba5SMichael Pfeiffer PCL6Driver::Write(const uint8* data, uint32 size)
653bfe34e2SMichael Pfeiffer {
66fefd3ba5SMichael Pfeiffer 	WriteSpoolData(data, size);
673bfe34e2SMichael Pfeiffer }
683bfe34e2SMichael Pfeiffer 
69568716beSWim van der Meer 
70568716beSWim van der Meer bool
StartDocument()71fefd3ba5SMichael Pfeiffer PCL6Driver::StartDocument()
723bfe34e2SMichael Pfeiffer {
733bfe34e2SMichael Pfeiffer 	try {
74fefd3ba5SMichael Pfeiffer 		_JobStart();
754410ee12SMichael Pfeiffer 		fHalftone = new Halftone(GetJobData()->GetSurfaceType(),
764410ee12SMichael Pfeiffer 			GetJobData()->GetGamma(), GetJobData()->GetInkDensity(),
774410ee12SMichael Pfeiffer 			GetJobData()->GetDitherType());
783bfe34e2SMichael Pfeiffer 		return true;
793bfe34e2SMichael Pfeiffer 	}
803bfe34e2SMichael Pfeiffer 	catch (TransportException& err) {
813bfe34e2SMichael Pfeiffer 		return false;
823bfe34e2SMichael Pfeiffer 	}
833bfe34e2SMichael Pfeiffer }
843bfe34e2SMichael Pfeiffer 
85568716beSWim van der Meer 
86568716beSWim van der Meer bool
EndDocument(bool)87fefd3ba5SMichael Pfeiffer PCL6Driver::EndDocument(bool)
883bfe34e2SMichael Pfeiffer {
893bfe34e2SMichael Pfeiffer 	try {
90568716beSWim van der Meer 		if (fHalftone)
91d2c03b1bSMichael Pfeiffer 			delete fHalftone;
92fefd3ba5SMichael Pfeiffer 		_JobEnd();
933bfe34e2SMichael Pfeiffer 		return true;
943bfe34e2SMichael Pfeiffer 	}
953bfe34e2SMichael Pfeiffer 	catch (TransportException& err) {
963bfe34e2SMichael Pfeiffer 		return false;
973bfe34e2SMichael Pfeiffer 	}
983bfe34e2SMichael Pfeiffer }
993bfe34e2SMichael Pfeiffer 
100568716beSWim van der Meer 
101568716beSWim van der Meer bool
NextBand(BBitmap * bitmap,BPoint * offset)102fefd3ba5SMichael Pfeiffer PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
1033bfe34e2SMichael Pfeiffer {
1043bfe34e2SMichael Pfeiffer 	DBGMSG(("> nextBand\n"));
1053bfe34e2SMichael Pfeiffer 
106*9c8f4ac5SPulkoMandy #if __GNUC__ <= 2
107*9c8f4ac5SPulkoMandy 	typedef auto_ptr<Rasterizer> RasterizerPointer;
108*9c8f4ac5SPulkoMandy 	typedef auto_ptr<DeltaRowCompressor> DeltaRowCompressorPointer;
109*9c8f4ac5SPulkoMandy #else
110*9c8f4ac5SPulkoMandy 	typedef shared_ptr<Rasterizer> RasterizerPointer;
111*9c8f4ac5SPulkoMandy 	typedef shared_ptr<DeltaRowCompressor> DeltaRowCompressorPointer;
112*9c8f4ac5SPulkoMandy #endif
113*9c8f4ac5SPulkoMandy 
1143bfe34e2SMichael Pfeiffer 	try {
1153bfe34e2SMichael Pfeiffer 		int y = (int)offset->y;
1163bfe34e2SMichael Pfeiffer 
1172e86189fSMichael Pfeiffer 		PCL6Rasterizer* rasterizer;
118fefd3ba5SMichael Pfeiffer 		if (_UseColorMode()) {
1192e86189fSMichael Pfeiffer 			#if COLOR_DEPTH == 8
1202e86189fSMichael Pfeiffer 				rasterizer = new ColorRGBRasterizer(fHalftone);
1212e86189fSMichael Pfeiffer 			#elif COLOR_DEPTH == 1
1222e86189fSMichael Pfeiffer 				rasterizer = new ColorRasterizer(fHalftone);
1232e86189fSMichael Pfeiffer 			#else
1242e86189fSMichael Pfeiffer 				#error COLOR_DEPTH must be either 1 or 8!
1252e86189fSMichael Pfeiffer 			#endif
126568716beSWim van der Meer 		} else
1272e86189fSMichael Pfeiffer 			rasterizer = new MonochromeRasterizer(fHalftone);
128568716beSWim van der Meer 
129*9c8f4ac5SPulkoMandy 		RasterizerPointer _rasterizer(rasterizer);
130568716beSWim van der Meer 		bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y,
131fefd3ba5SMichael Pfeiffer 			bitmap, GetPageHeight());
13291c89ca3SMichael Pfeiffer 
1332e86189fSMichael Pfeiffer 		if (valid) {
1342e86189fSMichael Pfeiffer 			rasterizer->InitializeBuffer();
13591c89ca3SMichael Pfeiffer 
1362e86189fSMichael Pfeiffer 			// Use compressor to calculate delta row size
1372e86189fSMichael Pfeiffer 			DeltaRowCompressor* deltaRowCompressor = NULL;
138fefd3ba5SMichael Pfeiffer 			if (_SupportsDeltaRowCompression()) {
139568716beSWim van der Meer 				deltaRowCompressor =
140568716beSWim van der Meer 					new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0);
1412e86189fSMichael Pfeiffer 				if (deltaRowCompressor->InitCheck() != B_OK) {
1422e86189fSMichael Pfeiffer 					delete deltaRowCompressor;
143dcab4343SMichael Pfeiffer 					return false;
144dcab4343SMichael Pfeiffer 				}
1452e86189fSMichael Pfeiffer 			}
146*9c8f4ac5SPulkoMandy 			DeltaRowCompressorPointer _deltaRowCompressor(deltaRowCompressor);
147dcab4343SMichael Pfeiffer 			int deltaRowSize = 0;
1483bfe34e2SMichael Pfeiffer 
1492e86189fSMichael Pfeiffer 			// remember position
1502e86189fSMichael Pfeiffer 			int xPage = rasterizer->GetX();
1512e86189fSMichael Pfeiffer 			int yPage = rasterizer->GetY();
1523bfe34e2SMichael Pfeiffer 
1532e86189fSMichael Pfeiffer 			while (rasterizer->HasNextLine()) {
154568716beSWim van der Meer 				const uchar* rowBuffer =
155568716beSWim van der Meer 					static_cast<const uchar*>(rasterizer->RasterizeNextLine());
1562e86189fSMichael Pfeiffer 
1572e86189fSMichael Pfeiffer 				if (deltaRowCompressor != NULL) {
158568716beSWim van der Meer 					int size =
159568716beSWim van der Meer 						deltaRowCompressor->CalculateSize(rowBuffer, true);
160568716beSWim van der Meer 					deltaRowSize += size + 2;
161568716beSWim van der Meer 						// two bytes for the row byte count
162dcab4343SMichael Pfeiffer 				}
1633bfe34e2SMichael Pfeiffer 			}
1643bfe34e2SMichael Pfeiffer 
1652e86189fSMichael Pfeiffer 			y = rasterizer->GetY();
1663bfe34e2SMichael Pfeiffer 
1672e86189fSMichael Pfeiffer 			uchar* outBuffer = rasterizer->GetOutBuffer();
1682e86189fSMichael Pfeiffer 			int outBufferSize = rasterizer->GetOutBufferSize();
1692e86189fSMichael Pfeiffer 			int outRowSize = rasterizer->GetOutRowSize();
1702e86189fSMichael Pfeiffer 			int width = rasterizer->GetWidth();
1712e86189fSMichael Pfeiffer 			int height = rasterizer->GetHeight();
172fefd3ba5SMichael Pfeiffer 			_WriteBitmap(outBuffer, outBufferSize, outRowSize, xPage, yPage,
173568716beSWim van der Meer 				width, height, deltaRowSize);
1743bfe34e2SMichael Pfeiffer 		}
1753bfe34e2SMichael Pfeiffer 
176fefd3ba5SMichael Pfeiffer 		if (y >= GetPageHeight()) {
1773bfe34e2SMichael Pfeiffer 			offset->x = -1.0;
1783bfe34e2SMichael Pfeiffer 			offset->y = -1.0;
1793bfe34e2SMichael Pfeiffer 		} else {
1802e86189fSMichael Pfeiffer 			offset->y += bitmap->Bounds().IntegerHeight()+1;
1813bfe34e2SMichael Pfeiffer 		}
1823bfe34e2SMichael Pfeiffer 
1833bfe34e2SMichael Pfeiffer 		return true;
1843bfe34e2SMichael Pfeiffer 	}
1853bfe34e2SMichael Pfeiffer 	catch (TransportException& err) {
1864410ee12SMichael Pfeiffer 		BAlert* alert = new BAlert("", err.What(), "OK");
187aed35104SHumdinger 		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
1883bfe34e2SMichael Pfeiffer 		alert->Go();
1893bfe34e2SMichael Pfeiffer 		return false;
1903bfe34e2SMichael Pfeiffer 	}
1913bfe34e2SMichael Pfeiffer }
1923bfe34e2SMichael Pfeiffer 
193568716beSWim van der Meer 
194568716beSWim van der Meer void
_WriteBitmap(const uchar * buffer,int outSize,int rowSize,int x,int y,int width,int height,int deltaRowSize)195fefd3ba5SMichael Pfeiffer PCL6Driver::_WriteBitmap(const uchar* buffer, int outSize, int rowSize, int x,
196568716beSWim van der Meer 	int y, int width, int height, int deltaRowSize)
197dcab4343SMichael Pfeiffer {
198dcab4343SMichael Pfeiffer 	// choose the best compression method
199b1a3ccb8SMichael Pfeiffer 	PCL6Writer::Compression compressionMethod = PCL6Writer::kNoCompression;
200dcab4343SMichael Pfeiffer 	int dataSize = outSize;
201dcab4343SMichael Pfeiffer 
202dcab4343SMichael Pfeiffer #if ENABLE_DELTA_ROW_COMPRESSION
203fefd3ba5SMichael Pfeiffer 	if (_SupportsDeltaRowCompression() && deltaRowSize < dataSize) {
204b1a3ccb8SMichael Pfeiffer 		compressionMethod = PCL6Writer::kDeltaRowCompression;
205dcab4343SMichael Pfeiffer 		dataSize = deltaRowSize;
206dcab4343SMichael Pfeiffer 	}
207dcab4343SMichael Pfeiffer #endif
208dcab4343SMichael Pfeiffer 
209dcab4343SMichael Pfeiffer #if ENABLE_RLE_COMPRESSION
210fefd3ba5SMichael Pfeiffer 	if (_SupportsRLECompression()) {
2115fc71589SMichael Pfeiffer 		int rleSize = pack_bits_size(buffer, outSize);
2125fc71589SMichael Pfeiffer 		if (rleSize < dataSize) {
213b1a3ccb8SMichael Pfeiffer 			compressionMethod = PCL6Writer::kRLECompression;
2145fc71589SMichael Pfeiffer 			dataSize = rleSize;
215dcab4343SMichael Pfeiffer 		}
216fcccd8b7SMichael Pfeiffer 	}
217dcab4343SMichael Pfeiffer #endif
218dcab4343SMichael Pfeiffer 
219dcab4343SMichael Pfeiffer 	// write bitmap
220fefd3ba5SMichael Pfeiffer 	_Move(x, y);
221dcab4343SMichael Pfeiffer 
222fefd3ba5SMichael Pfeiffer 	_StartRasterGraphics(x, y, width, height, compressionMethod);
223dcab4343SMichael Pfeiffer 
224fefd3ba5SMichael Pfeiffer 	_RasterGraphics(buffer, outSize, dataSize, rowSize, height,
225568716beSWim van der Meer 		compressionMethod);
226dcab4343SMichael Pfeiffer 
227fefd3ba5SMichael Pfeiffer 	_EndRasterGraphics();
228dcab4343SMichael Pfeiffer 
2295fc71589SMichael Pfeiffer #if DISPLAY_COMPRESSION_STATISTICS
230dcab4343SMichael Pfeiffer 	fprintf(stderr, "Out Size       %d %2.2f\n", (int)outSize, 100.0);
231dcab4343SMichael Pfeiffer #if ENABLE_RLE_COMPRESSION
232568716beSWim van der Meer 	fprintf(stderr, "RLE Size       %d %2.2f\n", (int)rleSize,
233568716beSWim van der Meer 		100.0 * rleSize / outSize);
234dcab4343SMichael Pfeiffer #endif
235dcab4343SMichael Pfeiffer #if ENABLE_DELTA_ROW_COMPRESSION
236568716beSWim van der Meer 	fprintf(stderr, "Delta Row Size %d %2.2f\n", (int)deltaRowSize,
237568716beSWim van der Meer 		100.0 * deltaRowSize / outSize);
238dcab4343SMichael Pfeiffer #endif
239568716beSWim van der Meer 	fprintf(stderr, "Data Size      %d %2.2f\n", (int)dataSize,
240568716beSWim van der Meer 		100.0 * dataSize / outSize);
241dcab4343SMichael Pfeiffer #endif
242dcab4343SMichael Pfeiffer }
243dcab4343SMichael Pfeiffer 
244dcab4343SMichael Pfeiffer 
245568716beSWim van der Meer void
_JobStart()246fefd3ba5SMichael Pfeiffer PCL6Driver::_JobStart()
2473bfe34e2SMichael Pfeiffer {
2483bfe34e2SMichael Pfeiffer 	// PCL6 begin
249b1a3ccb8SMichael Pfeiffer 	fWriter = new PCL6Writer(this);
250568716beSWim van der Meer 	PCL6Writer::ProtocolClass pc =
251fefd3ba5SMichael Pfeiffer 		(PCL6Writer::ProtocolClass)GetProtocolClass();
2524410ee12SMichael Pfeiffer 	fWriter->PJLHeader(pc, GetJobData()->GetXres(),
253fefd3ba5SMichael Pfeiffer 		"Copyright (c) 2003 - 2010 Haiku");
2544410ee12SMichael Pfeiffer 	fWriter->BeginSession(GetJobData()->GetXres(), GetJobData()->GetYres(),
255568716beSWim van der Meer 		PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage);
256b1a3ccb8SMichael Pfeiffer 	fWriter->OpenDataSource();
257b1a3ccb8SMichael Pfeiffer 	fMediaSide = PCL6Writer::kFrontMediaSide;
2583bfe34e2SMichael Pfeiffer }
2593bfe34e2SMichael Pfeiffer 
260568716beSWim van der Meer 
261568716beSWim van der Meer bool
StartPage(int)262fefd3ba5SMichael Pfeiffer PCL6Driver::StartPage(int)
2638fb205f2SMichael Pfeiffer {
264b1a3ccb8SMichael Pfeiffer 	PCL6Writer::Orientation orientation = PCL6Writer::kPortrait;
2654410ee12SMichael Pfeiffer 	if (GetJobData()->GetOrientation() == JobData::kLandscape) {
266b1a3ccb8SMichael Pfeiffer 		orientation = PCL6Writer::kLandscape;
26782f24520SMichael Pfeiffer 	}
268dcab4343SMichael Pfeiffer 
269568716beSWim van der Meer 	PCL6Writer::MediaSize mediaSize =
2704410ee12SMichael Pfeiffer 		_MediaSize(GetJobData()->GetPaper());
271568716beSWim van der Meer 	PCL6Writer::MediaSource mediaSource =
2724410ee12SMichael Pfeiffer 		_MediaSource(GetJobData()->GetPaperSource());
2734410ee12SMichael Pfeiffer 	if (GetJobData()->GetPrintStyle() == JobData::kSimplex) {
274b1a3ccb8SMichael Pfeiffer 		fWriter->BeginPage(orientation, mediaSize, mediaSource);
2754410ee12SMichael Pfeiffer 	} else if (GetJobData()->GetPrintStyle() == JobData::kDuplex) {
276eb856078SMichael Pfeiffer 		// TODO move duplex binding option to UI
277b1a3ccb8SMichael Pfeiffer 		fWriter->BeginPage(orientation, mediaSize, mediaSource,
278eb856078SMichael Pfeiffer 			PCL6Writer::kDuplexVerticalBinding, fMediaSide);
279dcab4343SMichael Pfeiffer 
280568716beSWim van der Meer 		if (fMediaSide == PCL6Writer::kFrontMediaSide)
281b1a3ccb8SMichael Pfeiffer 			fMediaSide = PCL6Writer::kBackMediaSide;
282568716beSWim van der Meer 		else
283b1a3ccb8SMichael Pfeiffer 			fMediaSide = PCL6Writer::kFrontMediaSide;
284568716beSWim van der Meer 	} else
285dcab4343SMichael Pfeiffer 		return false;
286dcab4343SMichael Pfeiffer 
2878fb205f2SMichael Pfeiffer 	// PageOrigin from Windows NT printer driver
2884410ee12SMichael Pfeiffer 	int x = 142 * GetJobData()->GetXres() / 600;
2894410ee12SMichael Pfeiffer 	int y = 100 * GetJobData()->GetYres() / 600;
290b1a3ccb8SMichael Pfeiffer 	fWriter->SetPageOrigin(x, y);
291fefd3ba5SMichael Pfeiffer 	fWriter->SetColorSpace(_UseColorMode() ? PCL6Writer::kRGB
292568716beSWim van der Meer 		: PCL6Writer::kGray);
293b1a3ccb8SMichael Pfeiffer 	fWriter->SetPaintTxMode(PCL6Writer::kOpaque);
294b1a3ccb8SMichael Pfeiffer 	fWriter->SetSourceTxMode(PCL6Writer::kOpaque);
295b1a3ccb8SMichael Pfeiffer 	fWriter->SetROP(204);
2968fb205f2SMichael Pfeiffer 	return true;
2978fb205f2SMichael Pfeiffer }
2988fb205f2SMichael Pfeiffer 
299568716beSWim van der Meer 
300568716beSWim van der Meer void
_StartRasterGraphics(int x,int y,int width,int height,PCL6Writer::Compression compressionMethod)301fefd3ba5SMichael Pfeiffer PCL6Driver::_StartRasterGraphics(int x, int y, int width, int height,
302568716beSWim van der Meer 	PCL6Writer::Compression compressionMethod)
3033bfe34e2SMichael Pfeiffer {
3042e86189fSMichael Pfeiffer 	PCL6Writer::ColorDepth colorDepth;
305fefd3ba5SMichael Pfeiffer 	if (_UseColorMode()) {
3062e86189fSMichael Pfeiffer 		#if COLOR_DEPTH == 8
3072e86189fSMichael Pfeiffer 			colorDepth = PCL6Writer::k8Bit;
3082e86189fSMichael Pfeiffer 		#elif COLOR_DEPTH == 1
3092e86189fSMichael Pfeiffer 			colorDepth = PCL6Writer::k1Bit;
3102e86189fSMichael Pfeiffer 		#else
3112e86189fSMichael Pfeiffer 			#error COLOR_DEPTH must be either 1 or 8!
3122e86189fSMichael Pfeiffer 		#endif
313568716beSWim van der Meer 	} else
3142e86189fSMichael Pfeiffer 		colorDepth = PCL6Writer::k1Bit;
315568716beSWim van der Meer 
316568716beSWim van der Meer 	fWriter->BeginImage(PCL6Writer::kDirectPixel, colorDepth, width, height,
317568716beSWim van der Meer 		width, height);
318b1a3ccb8SMichael Pfeiffer 	fWriter->ReadImage(compressionMethod, 0, height);
3193bfe34e2SMichael Pfeiffer }
3203bfe34e2SMichael Pfeiffer 
321568716beSWim van der Meer 
322568716beSWim van der Meer void
_EndRasterGraphics()323fefd3ba5SMichael Pfeiffer PCL6Driver::_EndRasterGraphics()
3243bfe34e2SMichael Pfeiffer {
325b1a3ccb8SMichael Pfeiffer 	fWriter->EndImage();
3263bfe34e2SMichael Pfeiffer }
3273bfe34e2SMichael Pfeiffer 
328568716beSWim van der Meer 
329568716beSWim van der Meer void
_RasterGraphics(const uchar * buffer,int bufferSize,int dataSize,int rowSize,int height,int compressionMethod)330fefd3ba5SMichael Pfeiffer PCL6Driver::_RasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
331568716beSWim van der Meer 	int rowSize, int height, int compressionMethod)
3323bfe34e2SMichael Pfeiffer {
333dcab4343SMichael Pfeiffer 	// write bitmap byte size
334b1a3ccb8SMichael Pfeiffer 	fWriter->EmbeddedDataPrefix32(dataSize);
335dcab4343SMichael Pfeiffer 
336dcab4343SMichael Pfeiffer 	// write data
337b1a3ccb8SMichael Pfeiffer 	if (compressionMethod == PCL6Writer::kRLECompression) {
338dcab4343SMichael Pfeiffer 		// use RLE compression
3395fc71589SMichael Pfeiffer 		uchar* outBuffer = new uchar[dataSize];
3405fc71589SMichael Pfeiffer 		pack_bits(outBuffer, buffer, bufferSize);
3415fc71589SMichael Pfeiffer 		fWriter->Append(outBuffer, dataSize);
342c9e62886SStefano Ceccherini 		delete[] outBuffer;
343b1a3ccb8SMichael Pfeiffer 		return;
344b1a3ccb8SMichael Pfeiffer 	} else if (compressionMethod == PCL6Writer::kDeltaRowCompression) {
345dcab4343SMichael Pfeiffer 		// use delta row compression
346b1a3ccb8SMichael Pfeiffer 		DeltaRowStreamCompressor compressor(rowSize, 0, fWriter);
347dcab4343SMichael Pfeiffer 		if (compressor.InitCheck() != B_OK) {
348dcab4343SMichael Pfeiffer 			return;
3493bfe34e2SMichael Pfeiffer 		}
350dcab4343SMichael Pfeiffer 
351b1a3ccb8SMichael Pfeiffer 		const uint8* row = buffer;
352dcab4343SMichael Pfeiffer 		for (int i = 0; i < height; i ++) {
353dcab4343SMichael Pfeiffer 			// write row byte count
354b1a3ccb8SMichael Pfeiffer 			int32 size = compressor.CalculateSize(row);
355b1a3ccb8SMichael Pfeiffer 			fWriter->Append((uint16)size);
356dcab4343SMichael Pfeiffer 
357dcab4343SMichael Pfeiffer 			if (size > 0) {
358dcab4343SMichael Pfeiffer 				// write delta row
359dcab4343SMichael Pfeiffer 				compressor.Compress(row);
360dcab4343SMichael Pfeiffer 			}
361dcab4343SMichael Pfeiffer 
362dcab4343SMichael Pfeiffer 			row += rowSize;
363dcab4343SMichael Pfeiffer 		}
364dcab4343SMichael Pfeiffer 	} else {
365dcab4343SMichael Pfeiffer 		// write raw data
366b1a3ccb8SMichael Pfeiffer 		fWriter->Append(buffer, bufferSize);
367dcab4343SMichael Pfeiffer 	}
3683bfe34e2SMichael Pfeiffer }
3693bfe34e2SMichael Pfeiffer 
370568716beSWim van der Meer 
371568716beSWim van der Meer bool
EndPage(int)372fefd3ba5SMichael Pfeiffer PCL6Driver::EndPage(int)
3738fb205f2SMichael Pfeiffer {
3748fb205f2SMichael Pfeiffer 	try {
3754410ee12SMichael Pfeiffer 		fWriter->EndPage(GetJobData()->GetCopies());
3768fb205f2SMichael Pfeiffer 		return true;
3778fb205f2SMichael Pfeiffer 	}
3788fb205f2SMichael Pfeiffer 	catch (TransportException& err) {
3798fb205f2SMichael Pfeiffer 		return false;
3808fb205f2SMichael Pfeiffer 	}
3818fb205f2SMichael Pfeiffer }
3828fb205f2SMichael Pfeiffer 
383568716beSWim van der Meer 
384568716beSWim van der Meer void
_JobEnd()385fefd3ba5SMichael Pfeiffer PCL6Driver::_JobEnd()
3863bfe34e2SMichael Pfeiffer {
387b1a3ccb8SMichael Pfeiffer 	fWriter->CloseDataSource();
388b1a3ccb8SMichael Pfeiffer 	fWriter->EndSession();
3892e86189fSMichael Pfeiffer 	fWriter->PJLFooter();
390b1a3ccb8SMichael Pfeiffer 	fWriter->Flush();
391b1a3ccb8SMichael Pfeiffer 	delete fWriter;
392b1a3ccb8SMichael Pfeiffer 	fWriter = NULL;
3933bfe34e2SMichael Pfeiffer }
3943bfe34e2SMichael Pfeiffer 
395568716beSWim van der Meer 
396568716beSWim van der Meer void
_Move(int x,int y)397fefd3ba5SMichael Pfeiffer PCL6Driver::_Move(int x, int y)
3983bfe34e2SMichael Pfeiffer {
399b1a3ccb8SMichael Pfeiffer 	fWriter->SetCursor(x, y);
4003bfe34e2SMichael Pfeiffer }
4013bfe34e2SMichael Pfeiffer 
402568716beSWim van der Meer 
4032e86189fSMichael Pfeiffer bool
_SupportsRLECompression()404fefd3ba5SMichael Pfeiffer PCL6Driver::_SupportsRLECompression()
405fcccd8b7SMichael Pfeiffer {
4064410ee12SMichael Pfeiffer 	return GetJobData()->GetColor() != JobData::kColorCompressionDisabled;
407fcccd8b7SMichael Pfeiffer }
408fcccd8b7SMichael Pfeiffer 
409568716beSWim van der Meer 
410fcccd8b7SMichael Pfeiffer bool
_SupportsDeltaRowCompression()411fefd3ba5SMichael Pfeiffer PCL6Driver::_SupportsDeltaRowCompression()
4122e86189fSMichael Pfeiffer {
413fefd3ba5SMichael Pfeiffer 	return GetProtocolClass() >= PCL6Writer::kProtocolClass2_1
4144410ee12SMichael Pfeiffer 		&& GetJobData()->GetColor() != JobData::kColorCompressionDisabled;
415fcccd8b7SMichael Pfeiffer }
416fcccd8b7SMichael Pfeiffer 
417568716beSWim van der Meer 
418fcccd8b7SMichael Pfeiffer bool
_UseColorMode()419fefd3ba5SMichael Pfeiffer PCL6Driver::_UseColorMode()
420fcccd8b7SMichael Pfeiffer {
4214410ee12SMichael Pfeiffer 	return GetJobData()->GetColor() != JobData::kMonochrome;
4222e86189fSMichael Pfeiffer }
4232e86189fSMichael Pfeiffer 
424568716beSWim van der Meer 
425568716beSWim van der Meer PCL6Writer::MediaSize
_MediaSize(JobData::Paper paper)426fefd3ba5SMichael Pfeiffer PCL6Driver::_MediaSize(JobData::Paper paper)
4273bfe34e2SMichael Pfeiffer {
4283bfe34e2SMichael Pfeiffer 	switch (paper) {
429568716beSWim van der Meer 		case JobData::kLetter:
430568716beSWim van der Meer 			return PCL6Writer::kLetterPaper;
431568716beSWim van der Meer 		case JobData::kLegal:
432568716beSWim van der Meer 			return PCL6Writer::kLegalPaper;
433568716beSWim van der Meer 		case JobData::kA4:
434568716beSWim van der Meer 			return PCL6Writer::kA4Paper;
435568716beSWim van der Meer 		case JobData::kExecutive:
436568716beSWim van der Meer 			return PCL6Writer::kExecPaper;
437568716beSWim van der Meer 		case JobData::kLedger:
438568716beSWim van der Meer 			return PCL6Writer::kLedgerPaper;
439568716beSWim van der Meer 		case JobData::kA3:
440568716beSWim van der Meer 			return PCL6Writer::kA3Paper;
441568716beSWim van der Meer 		case JobData::kB5:
442568716beSWim van der Meer 			return PCL6Writer::kB5Paper;
4432e86189fSMichael Pfeiffer 		case JobData::kJapanesePostcard:
4442e86189fSMichael Pfeiffer 			return PCL6Writer::kJPostcard;
445568716beSWim van der Meer 		case JobData::kA5:
446568716beSWim van der Meer 			return PCL6Writer::kA5Paper;
447568716beSWim van der Meer 		case JobData::kB4:
448568716beSWim van der Meer 			return PCL6Writer::kJB4Paper;
4493bfe34e2SMichael Pfeiffer /*
450b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kCOM10Envelope;
451b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kMonarchEnvelope;
452b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kC5Envelope;
453b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kDLEnvelope;
454b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJB4Paper;
455b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJB5Paper;
456b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kB5Envelope;
457b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJPostcard;
458b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJDoublePostcard;
459b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kA5Paper;
460b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kA6Paper;
461b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJB6Paper;
462b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJIS8KPaper;
463b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJIS16KPaper;
464b1a3ccb8SMichael Pfeiffer 		case : return PCL6Writer::kJISExecPaper;
4653bfe34e2SMichael Pfeiffer */
466d2c03b1bSMichael Pfeiffer 		default:
467b1a3ccb8SMichael Pfeiffer 			return PCL6Writer::kLegalPaper;
4683bfe34e2SMichael Pfeiffer 	}
4693bfe34e2SMichael Pfeiffer }
4703bfe34e2SMichael Pfeiffer 
471568716beSWim van der Meer 
472568716beSWim van der Meer PCL6Writer::MediaSource
_MediaSource(JobData::PaperSource source)473fefd3ba5SMichael Pfeiffer PCL6Driver::_MediaSource(JobData::PaperSource source)
474dcab4343SMichael Pfeiffer {
475dcab4343SMichael Pfeiffer 	switch (source) {
476568716beSWim van der Meer 		case JobData::kAuto:
477568716beSWim van der Meer 			return PCL6Writer::kAutoSelect;
478568716beSWim van der Meer 		case JobData::kCassette1:
479568716beSWim van der Meer 			return PCL6Writer::kDefaultSource;
480568716beSWim van der Meer 		case JobData::kCassette2:
481568716beSWim van der Meer 			return PCL6Writer::kEnvelopeTray;
482568716beSWim van der Meer 		case JobData::kLower:
483568716beSWim van der Meer 			return PCL6Writer::kLowerCassette;
484568716beSWim van der Meer 		case JobData::kUpper:
485568716beSWim van der Meer 			return PCL6Writer::kUpperCassette;
486568716beSWim van der Meer 		case JobData::kMiddle:
487568716beSWim van der Meer 			return PCL6Writer::kThirdCassette;
488568716beSWim van der Meer 		case JobData::kManual:
489568716beSWim van der Meer 			return PCL6Writer::kManualFeed;
490568716beSWim van der Meer 		case JobData::kCassette3:
491568716beSWim van der Meer 			return PCL6Writer::kMultiPurposeTray;
492dcab4343SMichael Pfeiffer 		default:
493b1a3ccb8SMichael Pfeiffer 			return PCL6Writer::kAutoSelect;
494dcab4343SMichael Pfeiffer 	}
495dcab4343SMichael Pfeiffer }
496