diff --git a/src/add-ons/print/drivers/pcl6/DeltaRowCompression.cpp b/src/add-ons/print/drivers/pcl6/DeltaRowCompression.cpp index 5f87b947ed..f33fe18634 100644 --- a/src/add-ons/print/drivers/pcl6/DeltaRowCompression.cpp +++ b/src/add-ons/print/drivers/pcl6/DeltaRowCompression.cpp @@ -1,45 +1,57 @@ /* ** DeltaRowCompression.cpp -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ -#include "DeltaRowCompression.h" -#include + +#include "DeltaRowCompression.h" #include -AbstractDeltaRowCompressor::AbstractDeltaRowCompressor(int rowSize, uchar initialSeed) - : fSeedRow(new uchar[rowSize]) - , fSize(rowSize) - , fInitialSeed(initialSeed) +#include + + +AbstractDeltaRowCompressor::AbstractDeltaRowCompressor(int rowSize, + uchar initialSeed) + : + fSeedRow(new uchar[rowSize]), + fSize(rowSize), + fInitialSeed(initialSeed) { Reset(); } + AbstractDeltaRowCompressor::~AbstractDeltaRowCompressor() { delete fSeedRow; fSeedRow = NULL; } -status_t AbstractDeltaRowCompressor::InitCheck() + +status_t +AbstractDeltaRowCompressor::InitCheck() { - if (fSeedRow != NULL) { + if (fSeedRow != NULL) return B_OK; - } else { + else return B_NO_MEMORY; - } } -void AbstractDeltaRowCompressor::Reset() + +void +AbstractDeltaRowCompressor::Reset() { - if (fSeedRow != NULL) { + if (fSeedRow != NULL) memset(fSeedRow, fInitialSeed, fSize); - } } -int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow, bool updateDeltaRow) + +int +AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow, + bool updateDeltaRow) { int index = DiffersIndex(row, 0); if (index == -1) { @@ -56,24 +68,21 @@ int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow // delta starts at index and contains length bytes do { - // control byte limits data bytes to 8 bytes int deltaBytes = length; - if (length > 8) { + if (length > 8) deltaBytes = 8; - } - + // calculate offset int totalOffset = index - seedRowIndex; bool needsOffsetBytes = totalOffset > 30; int offset = totalOffset; // control byte limits offset value to 31 - if (needsOffsetBytes) { + if (needsOffsetBytes) offset = 31; - } // write control byte (delta bytes bits 5-7; offset bits 0-4) - Put(((deltaBytes-1) << 5) | offset); + Put(((deltaBytes - 1) << 5) | offset); if (needsOffsetBytes) { // write additional offset bytes after control byte @@ -112,18 +121,25 @@ int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow return fDeltaRowIndex; } -int AbstractDeltaRowCompressor::CalculateSize(const uchar* row, bool updateSeedRow) + +int +AbstractDeltaRowCompressor::CalculateSize(const uchar* row, bool updateSeedRow) { return CompressRaw(row, updateSeedRow, false); } -void AbstractDeltaRowCompressor::Compress(const uchar* row) + +void +AbstractDeltaRowCompressor::Compress(const uchar* row) { CompressRaw(row, true, true); } + #ifdef TEST_DELTA_ROW_COMPRESSION -void test(AbstractDeltaRowCompressor* compressor, uchar* row) { + +void +test(AbstractDeltaRowCompressor* compressor, uchar* row) { int size = compressor->CalculateSize(row); printf("size %d\n", size); @@ -139,7 +155,9 @@ void test(AbstractDeltaRowCompressor* compressor, uchar* row) { printf("\n"); } -int main(int argc, char *argv[]) + +int +main(int argc, char* argv[]) { int n = 5; uchar row1[] = {0, 0, 0, 0, 0}; @@ -152,4 +170,4 @@ int main(int argc, char *argv[]) test(&compressor, row3); } -#endif +#endif // TEST_DELTA_ROW_COMPRESSION diff --git a/src/add-ons/print/drivers/pcl6/DeltaRowCompression.h b/src/add-ons/print/drivers/pcl6/DeltaRowCompression.h index 5fd446cc65..9a56c9e66a 100644 --- a/src/add-ons/print/drivers/pcl6/DeltaRowCompression.h +++ b/src/add-ons/print/drivers/pcl6/DeltaRowCompression.h @@ -1,118 +1,123 @@ /* ** DeltaRowCompression.h -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ #ifndef _DELTA_ROW_COMPRESSION_H #define _DELTA_ROW_COMPRESSION_H + #include + class AbstractDeltaRowCompressor { public: - AbstractDeltaRowCompressor(int rowSize, uchar initialSeed); - virtual ~AbstractDeltaRowCompressor(); + AbstractDeltaRowCompressor(int rowSize, + uchar initialSeed); + virtual ~AbstractDeltaRowCompressor(); // InitCheck returns B_OK on successful construction of this object or // B_NO_MEMORY if the buffer for the seed row could not be allocated. - status_t InitCheck(); + status_t InitCheck(); // Clears the seed row to the initial seed specified in the constructor - void Reset(); + void Reset(); // Returns the size of the delta row. // The size is 0 if the row is equal to the seed row (previous row). // The seed row is updated only if updateSeedRow is true. - int CalculateSize(const uchar* row, bool updateSeedRow = false); + int CalculateSize(const uchar* row, + bool updateSeedRow = false); // Compresses the row using the delta row compression algorithm. // The seed row is updated. - void Compress(const uchar* row); + void Compress(const uchar* row); protected: // append byte to delta row - virtual void AppendByteToDeltaRow(uchar byte) = 0; + virtual void AppendByteToDeltaRow(uchar byte) = 0; // returns the current size of the delta row - inline int CurrentDeltaRowSize() { - return fDeltaRowIndex; - } + inline int CurrentDeltaRowSize() + { + return fDeltaRowIndex; + } private: // Returns the index where seed row and row differ // or -1 if both arrays are equal. - inline int DiffersIndex(const uchar* row, int index) - { - while (index < fSize) { - if (fSeedRow[index] != row[index]) { - return index; - } - - index ++; - } - - return -1; - } + inline int DiffersIndex(const uchar* row, int index) + { + while (index < fSize) { + if (fSeedRow[index] != row[index]) + return index; + index ++; + } + return -1; + } // Returns the number of bytes that row differs from seed row // starting at the specified index. - inline int DiffersLength(const uchar* row, int index) - { - int startIndex = index; - - while (index < fSize) { - if (fSeedRow[index] == row[index]) { - break; - } - - index ++; - } - return index - startIndex; - } + inline int DiffersLength(const uchar* row, int index) + { + int startIndex = index; + while (index < fSize) { + if (fSeedRow[index] == row[index]) + break; + index ++; + } + return index - startIndex; + } // Compresses row with delta row compression algorithm. // The seed row is updated only if updateSeedRow is true. // If updateDeltaRow is true the method AppendByteToDeltaRow is called. - int CompressRaw(const uchar* row, bool updateSeedRow, bool updateDeltaRow); + int CompressRaw(const uchar* row, bool updateSeedRow, + bool updateDeltaRow); // write byte to delta row and calculate size of delta row - void Put(uchar byte) { - if (fUpdateDeltaRow) { - AppendByteToDeltaRow(byte); - } - fDeltaRowIndex ++; - } + void Put(uchar byte) + { + if (fUpdateDeltaRow) + AppendByteToDeltaRow(byte); + fDeltaRowIndex ++; + } - uchar* fSeedRow; // the seed row - int fSize; // the size of the seed row in bytes - uchar fInitialSeed; // the value to initialize the seed row with + uchar* fSeedRow; // the seed row + int fSize; // the size of the seed row in bytes + uchar fInitialSeed; + // the value to initialize the seed row with - int fDeltaRowIndex; // the index of the next byte to be written into the delta row - bool fUpdateDeltaRow; // write delta row + int fDeltaRowIndex; + // the index of the next byte to be written into + // the delta row + bool fUpdateDeltaRow; // write delta row }; + class DeltaRowCompressor : public AbstractDeltaRowCompressor { public: - DeltaRowCompressor(int rowSize, uchar initialSeed) - : AbstractDeltaRowCompressor(rowSize, initialSeed) - { - // nothing to do - } + DeltaRowCompressor(int rowSize, uchar initialSeed) + : + AbstractDeltaRowCompressor(rowSize, initialSeed) + {} // The delta row to be written to. - void SetDeltaRow(uchar* deltaRow) { - fDeltaRow = deltaRow; - } + void SetDeltaRow(uchar* deltaRow) + { + fDeltaRow = deltaRow; + } protected: - virtual void AppendByteToDeltaRow(uchar byte) { - fDeltaRow[CurrentDeltaRowSize()] = byte; - } + virtual void AppendByteToDeltaRow(uchar byte) + { + fDeltaRow[CurrentDeltaRowSize()] = byte; + } private: - uchar* fDeltaRow; // the delta row + uchar* fDeltaRow; // the delta row }; #endif - diff --git a/src/add-ons/print/drivers/pcl6/PCL6.cpp b/src/add-ons/print/drivers/pcl6/PCL6.cpp index 09b8509395..ea8274f099 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6.cpp @@ -4,22 +4,24 @@ * Copyright 2003 Michael Pfeiffer. */ + +#include "PCL6.h" + +#include + #include #include #include -#include - #include "DbgMsg.h" #include "DeltaRowCompression.h" #include "Halftone.h" #include "JobData.h" #include "PackBits.h" -#include "PCL6.h" #include "PCL6Cap.h" #include "PCL6Config.h" -#include "PrinterData.h" #include "PCL6Rasterizer.h" +#include "PrinterData.h" #include "UIDriver.h" #include "ValidRect.h" @@ -29,74 +31,87 @@ using namespace std; #define std #endif + // DeltaRowStreamCompressor writes the delta row directly to the // in the contructor specified stream. class DeltaRowStreamCompressor : public AbstractDeltaRowCompressor { public: - DeltaRowStreamCompressor(int rowSize, uchar initialSeed, PCL6Writer *writer) - : AbstractDeltaRowCompressor(rowSize, initialSeed) - , fWriter(writer) - { - // nothing to do - } + DeltaRowStreamCompressor(int rowSize, uchar initialSeed, + PCL6Writer* writer) + : + AbstractDeltaRowCompressor(rowSize, initialSeed), + fWriter(writer) + {} protected: - void AppendByteToDeltaRow(uchar byte) { - fWriter->Append(byte); - } + void AppendByteToDeltaRow(uchar byte) + { + fWriter->Append(byte); + } private: - PCL6Writer *fWriter; + PCL6Writer* fWriter; }; -PCL6Driver::PCL6Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap) - : GraphicsDriver(msg, printer_data, printer_cap) +PCL6Driver::PCL6Driver(BMessage* msg, PrinterData* printer_data, + const PrinterCap* printer_cap) + : + GraphicsDriver(msg, printer_data, printer_cap) { fHalftone = NULL; fWriter = NULL; } -void PCL6Driver::write(const uint8 *data, uint32 size) + +void +PCL6Driver::write(const uint8* data, uint32 size) { writeSpoolData(data, size); } -bool PCL6Driver::startDoc() + +bool +PCL6Driver::startDoc() { try { jobStart(); - fHalftone = new Halftone(getJobData()->getSurfaceType(), getJobData()->getGamma(), getJobData()->getInkDensity(), getJobData()->getDitherType()); + fHalftone = new Halftone(getJobData()->getSurfaceType(), + getJobData()->getGamma(), getJobData()->getInkDensity(), + getJobData()->getDitherType()); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool PCL6Driver::endDoc(bool) + +bool +PCL6Driver::endDoc(bool) { try { - if (fHalftone) { + if (fHalftone) delete fHalftone; - } jobEnd(); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset) + +bool +PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset) { DBGMSG(("> nextBand\n")); try { int y = (int)offset->y; - PCL6Rasterizer *rasterizer; + PCL6Rasterizer* rasterizer; if (useColorMode()) { #if COLOR_DEPTH == 8 rasterizer = new ColorRGBRasterizer(fHalftone); @@ -105,25 +120,27 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset) #else #error COLOR_DEPTH must be either 1 or 8! #endif - } else { + } else rasterizer = new MonochromeRasterizer(fHalftone); - } + auto_ptr _rasterizer(rasterizer); - bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y, bitmap, getPageHeight()); + bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y, + bitmap, getPageHeight()); if (valid) { rasterizer->InitializeBuffer(); // Use compressor to calculate delta row size - DeltaRowCompressor *deltaRowCompressor = NULL; + DeltaRowCompressor* deltaRowCompressor = NULL; if (supportsDeltaRowCompression()) { - deltaRowCompressor = new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0); + deltaRowCompressor = + new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0); if (deltaRowCompressor->InitCheck() != B_OK) { delete deltaRowCompressor; return false; } } - auto_ptr _deltaRowCompressor(deltaRowCompressor); + auto_ptr_deltaRowCompressor(deltaRowCompressor); int deltaRowSize = 0; // remember position @@ -131,22 +148,26 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset) int yPage = rasterizer->GetY(); while (rasterizer->HasNextLine()) { - const uchar *rowBuffer = (uchar*)rasterizer->RasterizeNextLine(); + const uchar* rowBuffer = + static_cast(rasterizer->RasterizeNextLine()); if (deltaRowCompressor != NULL) { - int size = deltaRowCompressor->CalculateSize(rowBuffer, true); - deltaRowSize += size + 2; // two bytes for the row byte count + int size = + deltaRowCompressor->CalculateSize(rowBuffer, true); + deltaRowSize += size + 2; + // two bytes for the row byte count } } y = rasterizer->GetY(); - uchar *outBuffer = rasterizer->GetOutBuffer(); + uchar* outBuffer = rasterizer->GetOutBuffer(); int outBufferSize = rasterizer->GetOutBufferSize(); int outRowSize = rasterizer->GetOutRowSize(); int width = rasterizer->GetWidth(); int height = rasterizer->GetHeight(); - writeBitmap(outBuffer, outBufferSize, outRowSize, xPage, yPage, width, height, deltaRowSize); + writeBitmap(outBuffer, outBufferSize, outRowSize, xPage, yPage, + width, height, deltaRowSize); } if (y >= getPageHeight()) { @@ -158,14 +179,17 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset) return true; } - catch (TransportException &err) { - BAlert *alert = new BAlert("", err.what(), "OK"); + catch (TransportException& err) { + BAlert* alert = new BAlert("", err.what(), "OK"); alert->Go(); return false; } } -void PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x, int y, int width, int height, int deltaRowSize) + +void +PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x, + int y, int width, int height, int deltaRowSize) { // choose the best compression method PCL6Writer::Compression compressionMethod = PCL6Writer::kNoCompression; @@ -193,43 +217,55 @@ void PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int startRasterGraphics(x, y, width, height, compressionMethod); - rasterGraphics(buffer, outSize, dataSize, rowSize, height, compressionMethod); + rasterGraphics(buffer, outSize, dataSize, rowSize, height, + compressionMethod); endRasterGraphics(); #if DISPLAY_COMPRESSION_STATISTICS fprintf(stderr, "Out Size %d %2.2f\n", (int)outSize, 100.0); #if ENABLE_RLE_COMPRESSION - fprintf(stderr, "RLE Size %d %2.2f\n", (int)rleSize, 100.0 * rleSize / outSize); + fprintf(stderr, "RLE Size %d %2.2f\n", (int)rleSize, + 100.0 * rleSize / outSize); #endif #if ENABLE_DELTA_ROW_COMPRESSION - fprintf(stderr, "Delta Row Size %d %2.2f\n", (int)deltaRowSize, 100.0 * deltaRowSize / outSize); + fprintf(stderr, "Delta Row Size %d %2.2f\n", (int)deltaRowSize, + 100.0 * deltaRowSize / outSize); #endif - fprintf(stderr, "Data Size %d %2.2f\n", (int)dataSize, 100.0 * dataSize / outSize); + fprintf(stderr, "Data Size %d %2.2f\n", (int)dataSize, + 100.0 * dataSize / outSize); #endif } -void PCL6Driver::jobStart() +void +PCL6Driver::jobStart() { // PCL6 begin fWriter = new PCL6Writer(this); - PCL6Writer::ProtocolClass pc = (PCL6Writer::ProtocolClass)getProtocolClass(); - fWriter->PJLHeader(pc, getJobData()->getXres(), "Copyright (c) 2003, 2004 Haiku"); - fWriter->BeginSession(getJobData()->getXres(), getJobData()->getYres(), PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage); + PCL6Writer::ProtocolClass pc = + (PCL6Writer::ProtocolClass)getProtocolClass(); + fWriter->PJLHeader(pc, getJobData()->getXres(), + "Copyright (c) 2003, 2004 Haiku"); + fWriter->BeginSession(getJobData()->getXres(), getJobData()->getYres(), + PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage); fWriter->OpenDataSource(); fMediaSide = PCL6Writer::kFrontMediaSide; } -bool PCL6Driver::startPage(int) + +bool +PCL6Driver::startPage(int) { PCL6Writer::Orientation orientation = PCL6Writer::kPortrait; if (getJobData()->getOrientation() == JobData::kLandscape) { orientation = PCL6Writer::kLandscape; } - PCL6Writer::MediaSize mediaSize = PCL6Driver::mediaSize(getJobData()->getPaper()); - PCL6Writer::MediaSource mediaSource = PCL6Driver::mediaSource(getJobData()->getPaperSource()); + PCL6Writer::MediaSize mediaSize = + PCL6Driver::mediaSize(getJobData()->getPaper()); + PCL6Writer::MediaSource mediaSource = + PCL6Driver::mediaSource(getJobData()->getPaperSource()); if (getJobData()->getPrintStyle() == JobData::kSimplex) { fWriter->BeginPage(orientation, mediaSize, mediaSource); } else if (getJobData()->getPrintStyle() == JobData::kDuplex) { @@ -237,27 +273,29 @@ bool PCL6Driver::startPage(int) fWriter->BeginPage(orientation, mediaSize, mediaSource, PCL6Writer::kDuplexVerticalBinding, fMediaSide); - if (fMediaSide == PCL6Writer::kFrontMediaSide) { + if (fMediaSide == PCL6Writer::kFrontMediaSide) fMediaSide = PCL6Writer::kBackMediaSide; - } else { + else fMediaSide = PCL6Writer::kFrontMediaSide; - } - } else { + } else return false; - } // PageOrigin from Windows NT printer driver int x = 142 * getJobData()->getXres() / 600; int y = 100 * getJobData()->getYres() / 600; fWriter->SetPageOrigin(x, y); - fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB : PCL6Writer::kGray); + fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB + : PCL6Writer::kGray); fWriter->SetPaintTxMode(PCL6Writer::kOpaque); fWriter->SetSourceTxMode(PCL6Writer::kOpaque); fWriter->SetROP(204); return true; } -void PCL6Driver::startRasterGraphics(int x, int y, int width, int height, PCL6Writer::Compression compressionMethod) + +void +PCL6Driver::startRasterGraphics(int x, int y, int width, int height, + PCL6Writer::Compression compressionMethod) { PCL6Writer::ColorDepth colorDepth; if (useColorMode()) { @@ -268,26 +306,25 @@ void PCL6Driver::startRasterGraphics(int x, int y, int width, int height, PCL6Wr #else #error COLOR_DEPTH must be either 1 or 8! #endif - } else { + } else colorDepth = PCL6Writer::k1Bit; - } - fWriter->BeginImage(PCL6Writer::kDirectPixel, colorDepth, width, height, width, height); + + fWriter->BeginImage(PCL6Writer::kDirectPixel, colorDepth, width, height, + width, height); fWriter->ReadImage(compressionMethod, 0, height); } -void PCL6Driver::endRasterGraphics() + +void +PCL6Driver::endRasterGraphics() { fWriter->EndImage(); } -void PCL6Driver::rasterGraphics( - const uchar *buffer, - int bufferSize, - int dataSize, - int rowSize, - int height, - int compressionMethod -) + +void +PCL6Driver::rasterGraphics(const uchar* buffer, int bufferSize, int dataSize, + int rowSize, int height, int compressionMethod) { // write bitmap byte size fWriter->EmbeddedDataPrefix32(dataSize); @@ -295,7 +332,7 @@ void PCL6Driver::rasterGraphics( // write data if (compressionMethod == PCL6Writer::kRLECompression) { // use RLE compression - uchar *outBuffer = new uchar[dataSize]; + uchar* outBuffer = new uchar[dataSize]; pack_bits(outBuffer, buffer, bufferSize); fWriter->Append(outBuffer, dataSize); delete[] outBuffer; @@ -326,18 +363,22 @@ void PCL6Driver::rasterGraphics( } } -bool PCL6Driver::endPage(int) + +bool +PCL6Driver::endPage(int) { try { fWriter->EndPage(getJobData()->getCopies()); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -void PCL6Driver::jobEnd() + +void +PCL6Driver::jobEnd() { fWriter->CloseDataSource(); fWriter->EndSession(); @@ -347,44 +388,60 @@ void PCL6Driver::jobEnd() fWriter = NULL; } -void PCL6Driver::move(int x, int y) + +void +PCL6Driver::move(int x, int y) { fWriter->SetCursor(x, y); } + bool PCL6Driver::supportsRLECompression() { return getJobData()->getColor() != JobData::kColorCompressionDisabled; } + bool PCL6Driver::supportsDeltaRowCompression() { - return getProtocolClass() >= PCL6Writer::kProtocolClass2_1 && - getJobData()->getColor() != JobData::kColorCompressionDisabled; + return getProtocolClass() >= PCL6Writer::kProtocolClass2_1 + && getJobData()->getColor() != JobData::kColorCompressionDisabled; } + bool PCL6Driver::useColorMode() { return getJobData()->getColor() != JobData::kMonochrome; } -PCL6Writer::MediaSize PCL6Driver::mediaSize(JobData::Paper paper) + +PCL6Writer::MediaSize +PCL6Driver::mediaSize(JobData::Paper paper) { switch (paper) { - case JobData::kLetter: return PCL6Writer::kLetterPaper; - case JobData::kLegal: return PCL6Writer::kLegalPaper; - case JobData::kA4: return PCL6Writer::kA4Paper; - case JobData::kExecutive: return PCL6Writer::kExecPaper; - case JobData::kLedger: return PCL6Writer::kLedgerPaper; - case JobData::kA3: return PCL6Writer::kA3Paper; - case JobData::kB5: return PCL6Writer::kB5Paper; - case JobData::kJapanesePostcard: - return PCL6Writer::kJPostcard; - case JobData::kA5: return PCL6Writer::kA5Paper; - case JobData::kB4: return PCL6Writer::kJB4Paper; + case JobData::kLetter: + return PCL6Writer::kLetterPaper; + case JobData::kLegal: + return PCL6Writer::kLegalPaper; + case JobData::kA4: + return PCL6Writer::kA4Paper; + case JobData::kExecutive: + return PCL6Writer::kExecPaper; + case JobData::kLedger: + return PCL6Writer::kLedgerPaper; + case JobData::kA3: + return PCL6Writer::kA3Paper; + case JobData::kB5: + return PCL6Writer::kB5Paper; + case JobData::kJapanesePostcard: + return PCL6Writer::kJPostcard; + case JobData::kA5: + return PCL6Writer::kA5Paper; + case JobData::kB4: + return PCL6Writer::kJB4Paper; /* case : return PCL6Writer::kCOM10Envelope; case : return PCL6Writer::kMonarchEnvelope; @@ -407,20 +464,28 @@ PCL6Writer::MediaSize PCL6Driver::mediaSize(JobData::Paper paper) } } -PCL6Writer::MediaSource PCL6Driver::mediaSource(JobData::PaperSource source) + +PCL6Writer::MediaSource +PCL6Driver::mediaSource(JobData::PaperSource source) { switch (source) { - case JobData::kAuto: return PCL6Writer::kAutoSelect; - case JobData::kCassette1: return PCL6Writer::kDefaultSource; - case JobData::kCassette2: return PCL6Writer::kEnvelopeTray; - case JobData::kLower: return PCL6Writer::kLowerCassette; - case JobData::kUpper: return PCL6Writer::kUpperCassette; - case JobData::kMiddle: return PCL6Writer::kThirdCassette; - case JobData::kManual: return PCL6Writer::kManualFeed; - case JobData::kCassette3: return PCL6Writer::kMultiPurposeTray; - + case JobData::kAuto: + return PCL6Writer::kAutoSelect; + case JobData::kCassette1: + return PCL6Writer::kDefaultSource; + case JobData::kCassette2: + return PCL6Writer::kEnvelopeTray; + case JobData::kLower: + return PCL6Writer::kLowerCassette; + case JobData::kUpper: + return PCL6Writer::kUpperCassette; + case JobData::kMiddle: + return PCL6Writer::kThirdCassette; + case JobData::kManual: + return PCL6Writer::kManualFeed; + case JobData::kCassette3: + return PCL6Writer::kMultiPurposeTray; default: return PCL6Writer::kAutoSelect; } } - diff --git a/src/add-ons/print/drivers/pcl6/PCL6.h b/src/add-ons/print/drivers/pcl6/PCL6.h index 7e5f04b8cf..eec249418f 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6.h +++ b/src/add-ons/print/drivers/pcl6/PCL6.h @@ -3,7 +3,6 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 2003 Michael Pfeiffer. */ - #ifndef __PCL6_H #define __PCL6_H @@ -12,45 +11,46 @@ #include "PCL6Cap.h" #include "PCL6Writer.h" + class Halftone; -class PCL6Driver : public GraphicsDriver, public PCL6WriterStream + +class PCL6Driver : public GraphicsDriver, public PCL6WriterStream { public: - PCL6Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap); + PCL6Driver(BMessage* msg, PrinterData* printer_data, + const PrinterCap* printer_cap); - void write(const uint8 *data, uint32 size); + void write(const uint8* data, uint32 size); protected: - virtual bool startDoc(); - virtual bool startPage(int page); - virtual bool nextBand(BBitmap *bitmap, BPoint *offset); - virtual bool endPage(int page); - virtual bool endDoc(bool success); + virtual bool startDoc(); + virtual bool startPage(int page); + virtual bool nextBand(BBitmap* bitmap, BPoint* offset); + virtual bool endPage(int page); + virtual bool endDoc(bool success); private: - bool supportsRLECompression(); - bool supportsDeltaRowCompression(); - bool useColorMode(); - PCL6Writer::MediaSize mediaSize(JobData::Paper paper); - PCL6Writer::MediaSource mediaSource(JobData::PaperSource source); - void move(int x, int y); - void jobStart(); - void writeBitmap(const uchar* buffer, int outSize, int rowSize, int x, int y, int width, int height, int deltaRowSize); - void startRasterGraphics(int x, int y, int width, int height, PCL6Writer::Compression compressionMethod); - void endRasterGraphics(); - void rasterGraphics( - const uchar *buffer, - int bufferSize, - int dataSize, - int rowSize, - int height, - int compression_method); - void jobEnd(); + bool supportsRLECompression(); + bool supportsDeltaRowCompression(); + bool useColorMode(); + PCL6Writer::MediaSize mediaSize(JobData::Paper paper); + PCL6Writer::MediaSource mediaSource(JobData::PaperSource source); + void move(int x, int y); + void jobStart(); + void writeBitmap(const uchar* buffer, int outSize, int rowSize, + int x, int y, int width, int height, int deltaRowSize); + void startRasterGraphics(int x, int y, int width, int height, + PCL6Writer::Compression compressionMethod); + void endRasterGraphics(); + void rasterGraphics(const uchar* buffer, int bufferSize, + int dataSize, int rowSize, int height, + int compression_method); + void jobEnd(); - PCL6Writer *fWriter; - PCL6Writer::MediaSide fMediaSide; // side if in duplex mode - Halftone *fHalftone; + PCL6Writer* fWriter; + PCL6Writer::MediaSide fMediaSide; // side if in duplex mode + Halftone* fHalftone; }; -#endif /* __PCL6_H */ +#endif // __PCL6_H diff --git a/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp b/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp index 01fc3a5164..ea32b981a4 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Cap.cpp @@ -3,8 +3,8 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 2003-2007 Michael Pfeiffer. */ - #include "PCL6Cap.h" + #include "PCL6Config.h" #include "PCL6Writer.h" #include "PrinterData.h" @@ -133,58 +133,65 @@ const PaperCap b4( // since 2.1 // since 1.1 -const PaperSourceCap defaultSource("Default", false, JobData::kCassette1); -const PaperSourceCap autobin("Auto", true, JobData::kAuto); -const PaperSourceCap manualFeed("Manual Feed", false, JobData::kManual); -const PaperSourceCap multiPurposeTray("Multi Purpose Tray", false, JobData::kCassette3); -const PaperSourceCap upperCassette("Upper Cassette", false, JobData::kUpper); -const PaperSourceCap lowerCassette("Lower Cassette", false, JobData::kLower); -const PaperSourceCap envelopeTray("Envelope Tray", false, JobData::kCassette2); +const PaperSourceCap defaultSource("Default", false, JobData::kCassette1); +const PaperSourceCap autobin("Auto", true, JobData::kAuto); +const PaperSourceCap manualFeed("Manual Feed", false, JobData::kManual); +const PaperSourceCap multiPurposeTray("Multi Purpose Tray", false, + JobData::kCassette3); +const PaperSourceCap upperCassette("Upper Cassette", false, JobData::kUpper); +const PaperSourceCap lowerCassette("Lower Cassette", false, JobData::kLower); +const PaperSourceCap envelopeTray("Envelope Tray", false, + JobData::kCassette2); // since 2.0: const PaperSourceCap thridCassette("Thrid Cassette", false, JobData::kMiddle); -const ResolutionCap dpi150("150dpi", false, 150, 150); -const ResolutionCap dpi300("300dpi", true, 300, 300); -const ResolutionCap dpi600("600dpi", false, 600, 600); +const ResolutionCap dpi150("150dpi", false, 150, 150); +const ResolutionCap dpi300("300dpi", true, 300, 300); +const ResolutionCap dpi600("600dpi", false, 600, 600); const ResolutionCap dpi1200("1200dpi", false, 1200, 1200); const PrintStyleCap simplex("Simplex", true, JobData::kSimplex); const PrintStyleCap duplex("Duplex", false, JobData::kDuplex); -const ProtocolClassCap pc1_1("PCL 6 Protocol Class 1.1", true, PCL6Writer::kProtocolClass1_1, -"The printer driver supports the following features of protocol class 1.1:\n" -"* Monochrome and Color Printing.\n" -"* Paper Formats: Letter, Legal, A4, A3, A5 and Japanese Postcard.\n" -"* Paper Sources: Auto, Default, Manual Feed, Multi-Purpose Tray, Upper and Lower Cassette and Envelope Tray.\n" -"* Resolutions: 150, 300, 600 and 1200 DPI." +const ProtocolClassCap pc1_1("PCL 6 Protocol Class 1.1", true, + PCL6Writer::kProtocolClass1_1, + "The printer driver supports the following features of protocol class 1.1:" + "\n" + "* Monochrome and Color Printing.\n" + "* Paper Formats: Letter, Legal, A4, A3, A5 and Japanese Postcard.\n" + "* Paper Sources: Auto, Default, Manual Feed, Multi-Purpose Tray, Upper " + "and Lower Cassette and Envelope Tray.\n" + "* Resolutions: 150, 300, 600 and 1200 DPI." #if ENABLE_RLE_COMPRESSION -"\n* Compression Method: RLE." + "\n* Compression Method: RLE." #else -"\n* Compression Method: None." + "\n* Compression Method: None." #endif ); -const ProtocolClassCap pc2_0("PCL 6 Protocol Class 2.0", false, PCL6Writer::kProtocolClass2_0, -"In addition to features of protocol class 1.1, the printer driver supports the " -"following features of protocol class 2.0:\n" -"* Additonal Paper Source: Third Cassette." -// "\n* JPEG compression (not implemented yet)" +const ProtocolClassCap pc2_0("PCL 6 Protocol Class 2.0", false, + PCL6Writer::kProtocolClass2_0, + "In addition to features of protocol class 1.1, the printer driver " + "supports the following features of protocol class 2.0:\n" + "* Additonal Paper Source: Third Cassette." +// "\n* JPEG compression (not implemented yet)" ); -const ProtocolClassCap pc2_1("PCL 6 Protocol Class 2.1", false, PCL6Writer::kProtocolClass2_1, -"In addition to features of previous protocol classes, the printer driver supports the " -"following features of protocol class 2.1:\n" -"* Additional Paper Format: B5." +const ProtocolClassCap pc2_1("PCL 6 Protocol Class 2.1", false, + PCL6Writer::kProtocolClass2_1, + "In addition to features of previous protocol classes, the printer driver " + "supports the following features of protocol class 2.1:\n" + "* Additional Paper Format: B5." #if ENABLE_DELTA_ROW_COMPRESSION -"\n* Additional Compression Method: Delta Row Compression." + "\n* Additional Compression Method: Delta Row Compression." #endif ); // Disable until driver supports new features of protocol class 3.0 -//const ProtocolClassCap pc3_0("PCL 6 Protocol Class 3.0", false, PCL6Writer::kProtocolClass3_0, -//"Protocol Class 3.0"); +// const ProtocolClassCap pc3_0("PCL 6 Protocol Class 3.0", false, +// PCL6Writer::kProtocolClass3_0, "Protocol Class 3.0"); -const PaperCap *papers1_1[] = { +const PaperCap* papers1_1[] = { &letter, &legal, &a4, @@ -194,7 +201,7 @@ const PaperCap *papers1_1[] = { &japanese_postcard }; -const PaperCap *papers2_1[] = { +const PaperCap* papers2_1[] = { &letter, &legal, &a4, @@ -205,7 +212,7 @@ const PaperCap *papers2_1[] = { &japanese_postcard }; -const PaperSourceCap *paperSources1_1[] = { +const PaperSourceCap* paperSources1_1[] = { &autobin, &defaultSource, &envelopeTray, @@ -215,7 +222,7 @@ const PaperSourceCap *paperSources1_1[] = { &multiPurposeTray }; -const PaperSourceCap *paperSources2_0[] = { +const PaperSourceCap* paperSources2_0[] = { &autobin, &defaultSource, &envelopeTray, @@ -226,19 +233,19 @@ const PaperSourceCap *paperSources2_0[] = { &multiPurposeTray }; -const ResolutionCap *resolutions[] = { +const ResolutionCap* resolutions[] = { &dpi150, &dpi300, &dpi600, &dpi1200, }; -const PrintStyleCap *printStyles[] = { +const PrintStyleCap* printStyles[] = { &simplex, &duplex }; -const ProtocolClassCap *protocolClasses[] = { +const ProtocolClassCap* protocolClasses[] = { &pc1_1, &pc2_0, &pc2_1 @@ -247,84 +254,89 @@ const ProtocolClassCap *protocolClasses[] = { }; const ColorCap color("Color", false, JobData::kColor); -const ColorCap colorCompressionDisabled("Color (No Compression)", false, JobData::kColorCompressionDisabled); +const ColorCap colorCompressionDisabled("Color (No Compression)", false, + JobData::kColorCompressionDisabled); const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome); -const ColorCap *colors[] = { +const ColorCap* colors[] = { &color, &colorCompressionDisabled, &monochrome }; -PCL6Cap::PCL6Cap(const PrinterData *printer_data) - : PrinterCap(printer_data) + +PCL6Cap::PCL6Cap(const PrinterData* printer_data) + : + PrinterCap(printer_data) { } -int PCL6Cap::countCap(CapID capid) const + +int +PCL6Cap::countCap(CapID capid) const { switch (capid) { - case kPaper: - if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) { - return sizeof(papers2_1) / sizeof(papers2_1[0]); - } - return sizeof(papers1_1) / sizeof(papers1_1[0]); - case kPaperSource: - if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) { - return sizeof(paperSources2_0) / sizeof(paperSources2_0[0]); - } - return sizeof(paperSources1_1) / sizeof(paperSources1_1[0]); - case kResolution: - return sizeof(resolutions) / sizeof(resolutions[0]); - case kColor: - return sizeof(colors) / sizeof(colors[0]); - case kPrintStyle: - return sizeof(printStyles) / sizeof(printStyles[0]); - case kProtocolClass: - return sizeof(protocolClasses) / sizeof(protocolClasses[0]); - default: - return 0; + case kPaper: + if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) + return sizeof(papers2_1) / sizeof(papers2_1[0]); + return sizeof(papers1_1) / sizeof(papers1_1[0]); + case kPaperSource: + if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) + return sizeof(paperSources2_0) / sizeof(paperSources2_0[0]); + return sizeof(paperSources1_1) / sizeof(paperSources1_1[0]); + case kResolution: + return sizeof(resolutions) / sizeof(resolutions[0]); + case kColor: + return sizeof(colors) / sizeof(colors[0]); + case kPrintStyle: + return sizeof(printStyles) / sizeof(printStyles[0]); + case kProtocolClass: + return sizeof(protocolClasses) / sizeof(protocolClasses[0]); + default: + return 0; } } -const BaseCap **PCL6Cap::enumCap(CapID capid) const + +const BaseCap** +PCL6Cap::enumCap(CapID capid) const { switch (capid) { - case kPaper: - if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) { - return (const BaseCap **)papers2_1; - } - return (const BaseCap **)papers1_1; - case kPaperSource: - if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) { - return (const BaseCap **)paperSources2_0; - } - return (const BaseCap **)paperSources1_1; - case kResolution: - return (const BaseCap **)resolutions; - case kColor: - return (const BaseCap **)colors; - case kPrintStyle: - return (const BaseCap **)printStyles; - case kProtocolClass: - return (const BaseCap **)protocolClasses; - default: - return NULL; + case kPaper: + if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) + return (const BaseCap **)papers2_1; + return (const BaseCap**)papers1_1; + case kPaperSource: + if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) + return (const BaseCap **)paperSources2_0; + return (const BaseCap**)paperSources1_1; + case kResolution: + return (const BaseCap**)resolutions; + case kColor: + return (const BaseCap**)colors; + case kPrintStyle: + return (const BaseCap**)printStyles; + case kProtocolClass: + return (const BaseCap**)protocolClasses; + default: + return NULL; } } -bool PCL6Cap::isSupport(CapID capid) const + +bool +PCL6Cap::isSupport(CapID capid) const { switch (capid) { - case kPaper: - case kPaperSource: - case kResolution: - case kColor: - case kCopyCommand: - case kPrintStyle: - case kProtocolClass: - return true; - default: - return false; + case kPaper: + case kPaperSource: + case kResolution: + case kColor: + case kCopyCommand: + case kPrintStyle: + case kProtocolClass: + return true; + default: + return false; } } diff --git a/src/add-ons/print/drivers/pcl6/PCL6Cap.h b/src/add-ons/print/drivers/pcl6/PCL6Cap.h index 667ee03a79..4c832a7ded 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Cap.h +++ b/src/add-ons/print/drivers/pcl6/PCL6Cap.h @@ -2,18 +2,19 @@ * PCL6Cap.h * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ - #ifndef __PCL6CAP_H #define __PCL6CAP_H + #include "PrinterCap.h" + class PCL6Cap : public PrinterCap { public: - PCL6Cap(const PrinterData *printer_data); - virtual int countCap(CapID) const; - virtual bool isSupport(CapID) const; - virtual const BaseCap **enumCap(CapID) const; + PCL6Cap(const PrinterData* printer_data); + virtual int countCap(CapID) const; + virtual bool isSupport(CapID) const; + virtual const BaseCap **enumCap(CapID) const; }; -#endif /* __PCL6CAP_H */ +#endif // __PCL6CAP_H diff --git a/src/add-ons/print/drivers/pcl6/PCL6Config.h b/src/add-ons/print/drivers/pcl6/PCL6Config.h index 24595311ac..7f5ee3a491 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Config.h +++ b/src/add-ons/print/drivers/pcl6/PCL6Config.h @@ -2,29 +2,28 @@ * PCL6Config.cpp * Copyright 2005 Michael Pfeiffer. */ - #ifndef _PCL6_CONFIG #define _PCL6_CONFIG // Compression method configuration // Set to 0 to disable compression and to 1 to enable compression -// Note compression takes place only if it takes less space than uncompressed data! +// Note compression takes place only if it takes less space than uncompressed +// data! // Run-Length-Encoding Compression -#define ENABLE_RLE_COMPRESSION 1 -//#define ENABLE_RLE_COMPRESSION 0 +#define ENABLE_RLE_COMPRESSION 1 +//#define ENABLE_RLE_COMPRESSION 0 // Delta Row Compression -#define ENABLE_DELTA_ROW_COMPRESSION 1 +#define ENABLE_DELTA_ROW_COMPRESSION 1 // Color depth for color printing. // Use either 1 or 8. // If 1 bit depth is used, the class Halftone is used for dithering // otherwise dithering is not performed. -#define COLOR_DEPTH 1 -//#define COLOR_DEPTH 8 +#define COLOR_DEPTH 1 +//#define COLOR_DEPTH 8 -#define DISPLAY_COMPRESSION_STATISTICS 0 +#define DISPLAY_COMPRESSION_STATISTICS 0 #endif - diff --git a/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp b/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp index beb451e09d..c294db293a 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Entry.cpp @@ -4,14 +4,19 @@ * Copyright 2003 Michael Pfeiffer. */ + #include "PCL6.h" #include "PCL6Cap.h" #include "PrinterDriver.h" + class PCL6PrinterDriver : public PrinterDriver { public: - PCL6PrinterDriver(BNode* printerFolder) : PrinterDriver(printerFolder) {} + PCL6PrinterDriver(BNode* printerFolder) + : + PrinterDriver(printerFolder) + {} const char* GetSignature() const { @@ -23,7 +28,7 @@ public: return "PCL6 compatible"; } - const char* GetVersion() const + const char* GetVersion() const { return "0.2"; } @@ -38,14 +43,16 @@ public: return new PCL6Cap(printerData); } - GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, PrinterData* printerData, PrinterCap* printerCap) + GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, + PrinterData* printerData, PrinterCap* printerCap) { return new PCL6Driver(settings, printerData, printerCap); } }; -PrinterDriver* instantiate_printer_driver(BNode* printerFolder) + +PrinterDriver* +instantiate_printer_driver(BNode* printerFolder) { return new PCL6PrinterDriver(printerFolder); } - diff --git a/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.cpp b/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.cpp index 89679286fa..5c2d95faaf 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.cpp @@ -1,16 +1,19 @@ /* ** PCL6Rasterizer.cpp -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ + + #include "PCL6Rasterizer.h" #include #ifdef _PCL6_RASTERIZER_TEST_ -static void dump(uchar *buffer, int size); -static void dump_bits(uchar *buffer, int size); +static void dump(uchar* buffer, int size); +static void dump_bits(uchar* buffer, int size); #define DUMP(text, buffer, size) { fprintf text; dump(buffer, size); } #define DUMP_BITS(text, buffer, size) { fprintf text; dump_bits(buffer, size); } @@ -22,17 +25,22 @@ static void dump_bits(uchar *buffer, int size); #endif -// MonochromeRasterizer -MonochromeRasterizer::MonochromeRasterizer(Halftone *halftone) - : PCL6Rasterizer(halftone) - , fOutBuffer(NULL) -{ } +// #pragma - MonochromeRasterizer + + +MonochromeRasterizer::MonochromeRasterizer(Halftone* halftone) + : + PCL6Rasterizer(halftone), + fOutBuffer(NULL) +{} + void -MonochromeRasterizer::InitializeBuffer() { +MonochromeRasterizer::InitializeBuffer() +{ fWidthByte = RowBufferSize(GetWidth(), 1, 1); - /* line length is a multiple of 4 bytes */ + // line length is a multiple of 4 bytes fOutRowSize = RowBufferSize(GetWidth(), 1, 4); fPadBytes = fOutRowSize - fWidthByte; // Total size @@ -41,38 +49,42 @@ MonochromeRasterizer::InitializeBuffer() { fCurrentLine = GetOutBuffer(); } -const void * -MonochromeRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) { + +const void* +MonochromeRasterizer::RasterizeLine(int x, int y, + const ColorRGB32Little* source) +{ GetHalftone()->dither(fCurrentLine, (const uchar*)source, x, y, GetWidth()); - uchar *out = fCurrentLine; + uchar* out = fCurrentLine; // invert pixels - for (int w = fWidthByte; w > 0; w --, out ++) { + for (int w = fWidthByte; w > 0; w --, out ++) *out = ~*out; - } - // pad with 0s - for (int w = fPadBytes; w > 0; w --, out ++) { + // pad with zeros + for (int w = fPadBytes; w > 0; w --, out ++) *out = 0; - } - void *result = fCurrentLine; + void* result = fCurrentLine; fCurrentLine += fOutRowSize; return result; } -// ColorRGBRasterizer +// #pragma - ColorRGBRasterizer + + +ColorRGBRasterizer::ColorRGBRasterizer(Halftone* halftone) + : + PCL6Rasterizer(halftone) +{} -ColorRGBRasterizer::ColorRGBRasterizer(Halftone *halftone) - : PCL6Rasterizer(halftone) -{ } void ColorRGBRasterizer::InitializeBuffer() { fWidthByte = RowBufferSize(GetWidth(), 24, 1); - // line length is a multiple of 4 bytes + // line length is a multiple of 4 bytes fOutRowSize = RowBufferSize(GetWidth(), 24, 4); fPadBytes = fOutRowSize - fWidthByte; // Total size @@ -81,10 +93,12 @@ ColorRGBRasterizer::InitializeBuffer() { fCurrentLine = GetOutBuffer(); } -const void * -ColorRGBRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) { - - uchar *out = fCurrentLine; + +const void* +ColorRGBRasterizer::RasterizeLine(int x, int y, + const ColorRGB32Little* source) +{ + uchar* out = fCurrentLine; int width = GetWidth(); for (int w = width; w > 0; w --) { *out++ = source->red; @@ -94,29 +108,30 @@ ColorRGBRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) } // pad with 0s - for (int w = fPadBytes; w > 0; w --, out ++) { + for (int w = fPadBytes; w > 0; w --, out ++) *out = 0; - } - void *result = fCurrentLine; + void* result = fCurrentLine; fCurrentLine += fOutRowSize; return result; } -// ColorRasterizer +// #pragma - ColorRasterizer -ColorRasterizer::ColorRasterizer::ColorRasterizer(Halftone *halftone) - : PCL6Rasterizer(halftone) -{ - for (int plane = 0; plane < 3; plane ++) { + +ColorRasterizer::ColorRasterizer::ColorRasterizer(Halftone* halftone) + : + PCL6Rasterizer(halftone) +{ + for (int plane = 0; plane < 3; plane ++) fPlaneBuffers[plane] = NULL; - } halftone->setPlanes(Halftone::kPlaneRGB1); halftone->setBlackValue(Halftone::kLowValueMeansBlack); } + ColorRasterizer::~ColorRasterizer() { for (int plane = 0; plane < 3; plane ++) { delete fPlaneBuffers[plane]; @@ -124,10 +139,11 @@ ColorRasterizer::~ColorRasterizer() { } } + void ColorRasterizer::InitializeBuffer() { fWidthByte = RowBufferSize(GetWidth(), 3, 1); - // line length is a multiple of 4 bytes + // line length is a multiple of 4 bytes fOutRowSize = RowBufferSize(GetWidth(), 3, 4); fPadBytes = fOutRowSize - fWidthByte; // Total size @@ -141,21 +157,24 @@ ColorRasterizer::InitializeBuffer() { } } + enum { kRed = 1, kGreen = 2, kBlue = 4, }; -const void * -ColorRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) { - - DUMP((stderr, "\nRGB32 row at x %d y %d:\n", x, y), (uchar*)source, GetWidth() * 4); + +const void* +ColorRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) +{ + DUMP((stderr, "\nRGB32 row at x %d y %d:\n", x, y), (uchar*)source, + GetWidth() * 4); // dither each color component - for (int plane = 0; plane < 3; plane ++) { - GetHalftone()->dither(fPlaneBuffers[plane], (const uchar*)source, x, y, GetWidth()); - } + for (int plane = 0; plane < 3; plane ++) + GetHalftone()->dither(fPlaneBuffers[plane], (const uchar*)source, x, y, + GetWidth()); DUMP_BITS((stderr, "red "), fPlaneBuffers[0], fPlaneBufferSize); DUMP_BITS((stderr, "green "), fPlaneBuffers[1], fPlaneBufferSize); @@ -166,56 +185,57 @@ ColorRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) { DUMP_BITS((stderr, "merged\n"), fCurrentLine, fOutRowSize); DUMP((stderr, "\n"), fCurrentLine, fOutRowSize); - void *result = fCurrentLine; + void* result = fCurrentLine; fCurrentLine += fOutRowSize; return result; } + void ColorRasterizer::MergePlaneBuffersToCurrentLine() { // merge the three planes into output buffer int remainingPixels = GetWidth(); - uchar *out = fCurrentLine; + uchar* out = fCurrentLine; uchar value = 0; uchar outMask = 0x80; // current bit mask (1 << (8 - bit)) in output buffer // iterate over the three plane buffers for (int i = 0; i < fPlaneBufferSize; i ++) { int pixels = 8; - if (remainingPixels < 8) { + if (remainingPixels < 8) pixels = remainingPixels; - } + remainingPixels -= pixels; if (remainingPixels >= 8) { register const uchar - red = fPlaneBuffers[0][i], + red = fPlaneBuffers[0][i], green = fPlaneBuffers[1][i], - blue = fPlaneBuffers[2][i]; + blue = fPlaneBuffers[2][i]; register uchar value = 0; - if (red & 0x80) value = 0x80; - if (red & 0x40) value |= 0x10; - if (red & 0x20) value |= 0x02; + if (red & 0x80) value = 0x80; + if (red & 0x40) value |= 0x10; + if (red & 0x20) value |= 0x02; if (green & 0x80) value |= 0x40; if (green & 0x40) value |= 0x08; if (green & 0x20) value |= 0x01; - if (blue & 0x80) value |= 0x20; - if (blue & 0x40) value |= 0x04; + if (blue & 0x80) value |= 0x20; + if (blue & 0x40) value |= 0x04; *out++ = value; value = 0; - if (blue & 0x20) value = 0x80; - if (blue & 0x10) value |= 0x10; - if (blue & 0x08) value |= 0x02; + if (blue & 0x20) value = 0x80; + if (blue & 0x10) value |= 0x10; + if (blue & 0x08) value |= 0x02; - if (red & 0x10) value |= 0x40; - if (red & 0x08) value |= 0x08; - if (red & 0x04) value |= 0x01; + if (red & 0x10) value |= 0x40; + if (red & 0x08) value |= 0x08; + if (red & 0x04) value |= 0x01; if (green & 0x10) value |= 0x20; if (green & 0x08) value |= 0x04; @@ -226,39 +246,35 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine() if (green & 0x02) value |= 0x10; if (green & 0x01) value |= 0x02; - if (blue & 0x04) value |= 0x40; - if (blue & 0x02) value |= 0x08; - if (blue & 0x01) value |= 0x01; + if (blue & 0x04) value |= 0x40; + if (blue & 0x02) value |= 0x08; + if (blue & 0x01) value |= 0x01; - if (red & 0x02) value |= 0x20; - if (red & 0x01) value |= 0x04; + if (red & 0x02) value |= 0x20; + if (red & 0x01) value |= 0x04; *out++ = value; } else { register const uchar - red = fPlaneBuffers[0][i], + red = fPlaneBuffers[0][i], green = fPlaneBuffers[1][i], - blue = fPlaneBuffers[2][i]; + blue = fPlaneBuffers[2][i]; // for each bit in the current byte of each plane uchar mask = 0x80; for (; pixels > 0; pixels --) { int rgb = 0; - if (red & mask) { + if (red & mask) rgb |= kRed; - } - if (green & mask) { + if (green & mask) rgb |= kGreen; - } - if (blue & mask) { + if (blue & mask) rgb |= kBlue; - } for (int plane = 0; plane < 3; plane ++) { // copy pixel value to output value - if (rgb & (1 << plane)) { + if (rgb & (1 << plane)) value |= outMask; - } // increment output mask if (outMask == 0x01) { @@ -267,9 +283,8 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine() *out = value; out ++; value = 0; - } else { + } else outMask >>= 1; - } } mask >>= 1; } @@ -287,20 +302,20 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine() out ++; } - if (out - fCurrentLine != fWidthByte) { - fprintf(stderr, "Error buffer overflow: %d != %d\n", fWidthByte, (int)(out - fCurrentLine)); - } + if (out - fCurrentLine != fWidthByte) + fprintf(stderr, "Error buffer overflow: %d != %d\n", fWidthByte, + static_cast(out - fCurrentLine)); - // pad with 0s - for (int w = fPadBytes; w > 0; w --, out ++) { + // pad with zeros + for (int w = fPadBytes; w > 0; w --, out ++) *out = 0xff; - } - if (out - fCurrentLine != fOutRowSize) { - fprintf(stderr, "Error buffer overflow: %d != %d\n", fOutRowSize, (int)(out - fCurrentLine)); - } + if (out - fCurrentLine != fOutRowSize) + fprintf(stderr, "Error buffer overflow: %d != %d\n", fOutRowSize, + static_cast(out - fCurrentLine)); } + #ifdef _PCL6_RASTERIZER_TEST_ #include #include @@ -309,7 +324,9 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine() #define COLUMNS 40 #define BIT_COLUMNS 6 -static void dump(uchar *buffer, int size) + +static void +dump(uchar* buffer, int size) { int x = 0; for (int i = 0; i < size; i ++) { @@ -328,7 +345,9 @@ static void dump(uchar *buffer, int size) fprintf(stderr, "\n"); } -static void dump_bits(uchar *buffer, int size) + +static void +dump_bits(uchar* buffer, int size) { int x = 0; for (int i = 0; i < size; i ++) { @@ -354,25 +373,29 @@ static void dump_bits(uchar *buffer, int size) fprintf(stderr, "\n"); } -static void fill(uchar *_row, int width, ColorRGB32Little color) + +static void +fill(uchar* _row, int width, ColorRGB32Little color) { - ColorRGB32Little *row = (ColorRGB32Little *)_row; + ColorRGB32Little* row = static_cast(_row); for (int i = 0; i < width; i ++) { *row = color; row ++; } } -static void initializeBitmap(BBitmap *bitmap, int width, int height) + +static void +initializeBitmap(BBitmap* bitmap, int width, int height) { int bpr = bitmap->BytesPerRow(); - uchar *row = (uchar*)bitmap->Bits(); + uchar* row = (uchar*)bitmap->Bits(); // BGRA ColorRGB32Little black = {0, 0, 0, 0}; ColorRGB32Little white = {255, 255, 255, 0}; - ColorRGB32Little red = {0, 0, 255, 0}; + ColorRGB32Little red = {0, 0, 255, 0}; ColorRGB32Little green = {0, 255, 0, 0}; - ColorRGB32Little blue = {255, 0, 0, 0}; + ColorRGB32Little blue = {255, 0, 0, 0}; fprintf(stderr, "black row\n"); fill(row, width, black); @@ -387,7 +410,7 @@ static void initializeBitmap(BBitmap *bitmap, int width, int height) row += bpr; fprintf(stderr, "red green blue pattern"); - ColorRGB32Little *color = (ColorRGB32Little*)row; + ColorRGB32Little* color = (ColorRGB32Little*)row; for (int i = 0; i < width; i++) { switch (i % 3) { case 0: @@ -404,7 +427,9 @@ static void initializeBitmap(BBitmap *bitmap, int width, int height) } } -int main() + +int +main() { const int width = 10; const int height = 4; @@ -417,7 +442,7 @@ int main() Halftone halftone(B_RGB32, 0.25f, 0.0f, Halftone::kTypeFloydSteinberg); #endif ColorRasterizer rasterizer(&halftone); - BBitmap bitmap(BRect(0, 0, width-1, height-1), B_RGB32); + BBitmap bitmap(BRect(0, 0, width - 1, height - 1), B_RGB32); initializeBitmap(&bitmap, width, height); @@ -428,4 +453,4 @@ int main() } } -#endif +#endif // _PCL6_RASTERIZER_TEST_ diff --git a/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.h b/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.h index 4e7ed4c461..fad7ec9282 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.h +++ b/src/add-ons/print/drivers/pcl6/PCL6Rasterizer.h @@ -1,111 +1,139 @@ /* ** PCL6Rasterizer.h -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ #ifndef _PCL6_RASTERIZER_H #define _PCL6_RASTERIZER_H + + #include "Rasterizer.h" + class PCL6Rasterizer : public Rasterizer { public: - PCL6Rasterizer(Halftone *halftone) - : Rasterizer(halftone) - , fOutBuffer(NULL) - , fOutBufferSize(0) - { - } + PCL6Rasterizer(Halftone* halftone) + : + Rasterizer(halftone), + fOutBuffer(NULL), + fOutBufferSize(0) + {} - ~PCL6Rasterizer() - { - delete fOutBuffer; - fOutBuffer = NULL; - } + ~PCL6Rasterizer() + { + delete fOutBuffer; + fOutBuffer = NULL; + } - void SetOutBufferSize(int size) { fOutBufferSize = size; } - int GetOutBufferSize() { return fOutBufferSize; } - - uchar *GetOutBuffer() { return fOutBuffer; } + void SetOutBufferSize(int size) + { + fOutBufferSize = size; + } + int GetOutBufferSize() + { + return fOutBufferSize; + } + uchar* GetOutBuffer() + { + return fOutBuffer; + } - virtual void InitializeBuffer() { - fOutBuffer = new uchar[fOutBufferSize]; - } + virtual void InitializeBuffer() + { + fOutBuffer = new uchar[fOutBufferSize]; + } - virtual int GetOutRowSize() = 0; + virtual int GetOutRowSize() = 0; - private: - uchar *fOutBuffer; - int fOutBufferSize; + uchar* fOutBuffer; + int fOutBufferSize; }; + class MonochromeRasterizer : public PCL6Rasterizer { public: - MonochromeRasterizer(Halftone *halftone); + MonochromeRasterizer(Halftone* halftone); + + void InitializeBuffer(); - void InitializeBuffer(); - - int GetOutRowSize() { return fOutRowSize; } + int GetOutRowSize() + { + return fOutRowSize; + } - const void *RasterizeLine(int x, int y, const ColorRGB32Little* source); + const void* RasterizeLine(int x, int y, + const ColorRGB32Little* source); private: - int fWidthByte; - int fOutRowSize; - int fPadBytes; - int fOutSize; - uchar *fOutBuffer; - uchar *fCurrentLine; + int fWidthByte; + int fOutRowSize; + int fPadBytes; + int fOutSize; + uchar* fOutBuffer; + uchar* fCurrentLine; }; + // Output format RGB 8bit per channel class ColorRGBRasterizer : public PCL6Rasterizer { public: - ColorRGBRasterizer(Halftone *halftone) ; + ColorRGBRasterizer(Halftone* halftone); - void InitializeBuffer(); + void InitializeBuffer(); - int GetOutRowSize() { return fOutRowSize; } + int GetOutRowSize() + { + return fOutRowSize; + } - const void *RasterizeLine(int x, int y, const ColorRGB32Little* source); + const void* RasterizeLine(int x, int y, + const ColorRGB32Little* source); private: - int fWidthByte; - int fOutRowSize; - int fPadBytes; - uchar *fCurrentLine; + int fWidthByte; + int fOutRowSize; + int fPadBytes; + uchar* fCurrentLine; }; -typedef uchar *PlaneBuffer; + +typedef uchar* PlaneBuffer; + // Output format: RGB 1bit per channel // Class Halftone is used for dithering class ColorRasterizer : public PCL6Rasterizer { public: - ColorRasterizer(Halftone *halftone); + ColorRasterizer(Halftone* halftone); - ~ColorRasterizer(); + ~ColorRasterizer(); - void InitializeBuffer(); + void InitializeBuffer(); - int GetOutRowSize() { return fOutRowSize; } + int GetOutRowSize() + { + return fOutRowSize; + } - const void *RasterizeLine(int x, int y, const ColorRGB32Little* source); + const void* RasterizeLine(int x, int y, + const ColorRGB32Little* source); private: - void MergePlaneBuffersToCurrentLine(); + void MergePlaneBuffersToCurrentLine(); - int fWidthByte; - int fOutRowSize; - int fPadBytes; - uchar *fCurrentLine; + int fWidthByte; + int fOutRowSize; + int fPadBytes; + uchar* fCurrentLine; - int fPlaneBufferSize; - PlaneBuffer fPlaneBuffers[3]; + int fPlaneBufferSize; + PlaneBuffer fPlaneBuffers[3]; }; -#endif +#endif // _PCL6_RASTERIZER_H diff --git a/src/add-ons/print/drivers/pcl6/PCL6Writer.cpp b/src/add-ons/print/drivers/pcl6/PCL6Writer.cpp index 6b006b1bac..74b1007aff 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Writer.cpp +++ b/src/add-ons/print/drivers/pcl6/PCL6Writer.cpp @@ -1,8 +1,11 @@ /* ** PCL6Writer.cpp -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ + + #include "PCL6Writer.h" #include @@ -10,53 +13,66 @@ #define BYTE_AT(lvalue, index) (((uint8*)(&lvalue))[index]) -PCL6Writer::PCL6Writer(PCL6WriterStream *stream, uint32 bufferSize) - : fStream(stream), - fBuffer(new uint8[bufferSize]), - fSize(bufferSize), - fIndex(0) + +PCL6Writer::PCL6Writer(PCL6WriterStream* stream, uint32 bufferSize) + : + fStream(stream), + fBuffer(new uint8[bufferSize]), + fSize(bufferSize), + fIndex(0) { } -PCL6Writer::~PCL6Writer() { + +PCL6Writer::~PCL6Writer() +{ delete fBuffer; fBuffer = NULL; } + // throws TransportException void -PCL6Writer::Append(uint8 value) { - if (fIndex == fSize) { +PCL6Writer::Append(uint8 value) +{ + if (fIndex == fSize) Flush(); - } fBuffer[fIndex] = value; fIndex ++; } + void -PCL6Writer::Flush() { +PCL6Writer::Flush() +{ if (fIndex > 0) { fStream->write(fBuffer, fIndex); fIndex = 0; } } + void -PCL6Writer::Append(int16 value) { +PCL6Writer::Append(int16 value) +{ int16 v = B_HOST_TO_LENDIAN_INT16(value); Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 1)); } + void -PCL6Writer::Append(uint16 value) { +PCL6Writer::Append(uint16 value) +{ int16 v = B_HOST_TO_LENDIAN_INT16(value); Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 1)); } + void -PCL6Writer::Append(int32 value) { +PCL6Writer::Append(int32 value) +{ int32 v = B_HOST_TO_LENDIAN_INT32(value); Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 1)); @@ -64,8 +80,10 @@ PCL6Writer::Append(int32 value) { Append(BYTE_AT(v, 3)); } + void -PCL6Writer::Append(uint32 value) { +PCL6Writer::Append(uint32 value) +{ int32 v = B_HOST_TO_LENDIAN_INT32(value); Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 1)); @@ -73,8 +91,10 @@ PCL6Writer::Append(uint32 value) { Append(BYTE_AT(v, 3)); } + void -PCL6Writer::Append(float value) { +PCL6Writer::Append(float value) +{ float v = B_HOST_TO_LENDIAN_FLOAT(value); Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 1)); @@ -82,8 +102,10 @@ PCL6Writer::Append(float value) { Append(BYTE_AT(v, 3)); } + void -PCL6Writer::Append(const uint8* data, uint32 size) { +PCL6Writer::Append(const uint8* data, uint32 size) +{ for (uint32 i = 0; i < size; i++) { Append(data[i]); } @@ -91,7 +113,8 @@ PCL6Writer::Append(const uint8* data, uint32 size) { void -PCL6Writer::AppendString(const char *string) { +PCL6Writer::AppendString(const char* string) +{ uint8 ch = *string; while (ch != 0) { Append(ch); @@ -100,60 +123,80 @@ PCL6Writer::AppendString(const char *string) { } } + void -PCL6Writer::AppendOperator(Operator op) { +PCL6Writer::AppendOperator(Operator op) +{ Append((uint8)op); } + void -PCL6Writer::AppendAttribute(Attribute attr) { +PCL6Writer::AppendAttribute(Attribute attr) +{ AppendDataTag(k8BitAttrId); Append((uint8)attr); } + void -PCL6Writer::AppendDataTag(DataTag tag) { +PCL6Writer::AppendDataTag(DataTag tag) +{ Append((uint8)tag); } + void -PCL6Writer::AppendData(uint8 value) { +PCL6Writer::AppendData(uint8 value) +{ AppendDataTag(kUByteData); Append(value); } + void -PCL6Writer::AppendData(int16 value) { +PCL6Writer::AppendData(int16 value) +{ AppendDataTag(kSInt16Data); Append(value); } + void -PCL6Writer::AppendData(uint16 value) { +PCL6Writer::AppendData(uint16 value) +{ AppendDataTag(kUInt16Data); Append(value); } + void -PCL6Writer::AppendData(int32 value) { +PCL6Writer::AppendData(int32 value) +{ AppendDataTag(kSInt32Data); Append(value); } + void -PCL6Writer::AppendData(uint32 value) { +PCL6Writer::AppendData(uint32 value) +{ AppendDataTag(kUInt32Data); Append(value); } + void -PCL6Writer::AppendData(float value) { +PCL6Writer::AppendData(float value) +{ AppendDataTag(kReal32Data); Append(value); } + void -PCL6Writer::EmbeddedDataPrefix(uint32 size) { +PCL6Writer::EmbeddedDataPrefix(uint32 size) +{ if (size < 256) { AppendDataTag(kEmbeddedDataByte); Append((uint8)size); @@ -163,60 +206,72 @@ PCL6Writer::EmbeddedDataPrefix(uint32 size) { } } + void -PCL6Writer::EmbeddedDataPrefix32(uint32 size) { +PCL6Writer::EmbeddedDataPrefix32(uint32 size) +{ AppendDataTag(kEmbeddedData); Append(size); } + void -PCL6Writer::AppendDataXY(uint8 x, uint8 y) { +PCL6Writer::AppendDataXY(uint8 x, uint8 y) +{ AppendDataTag(kUByteXY); Append(x); Append(y); } + void -PCL6Writer::AppendDataXY(int16 x, int16 y) { +PCL6Writer::AppendDataXY(int16 x, int16 y) +{ AppendDataTag(kSInt16XY); Append(x); Append(y); } + void -PCL6Writer::AppendDataXY(uint16 x, uint16 y) { +PCL6Writer::AppendDataXY(uint16 x, uint16 y) +{ AppendDataTag(kUInt16XY); Append(x); Append(y); } + void -PCL6Writer::AppendDataXY(int32 x, int32 y) { +PCL6Writer::AppendDataXY(int32 x, int32 y) +{ AppendDataTag(kSInt32XY); Append(x); Append(y); } + void -PCL6Writer::AppendDataXY(uint32 x, uint32 y) { +PCL6Writer::AppendDataXY(uint32 x, uint32 y) +{ AppendDataTag(kUInt32XY); Append(x); Append(y); } + void -PCL6Writer::AppendDataXY(float x, float y) { +PCL6Writer::AppendDataXY(float x, float y) +{ AppendDataTag(kReal32XY); Append(x); Append(y); } + void -PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char *comment) +PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char* comment) { BString string; - AppendString("\033%-12345X@PJL JOB\n" - "@PJL SET RESOLUTION="); + AppendString("\033%-12345X@PJL JOB\n@PJL SET RESOLUTION="); string << dpi; AppendString(string.String()); - AppendString("\n" - "@PJL ENTER LANGUAGE=PCLXL\n" - ") HP-PCL XL;"); - + AppendString("\n@PJL ENTER LANGUAGE=PCLXL\n) HP-PCL XL;"); + const char* pc = ""; switch (protocolClass) { case kProtocolClass1_1: @@ -242,16 +297,18 @@ PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char *comment) AppendString("\n"); } + void PCL6Writer::PJLFooter() { - AppendString("\033%-12345X@PJL EOJ\n" - "\033%-12345X"); + AppendString("\033%-12345X@PJL EOJ\n\033%-12345X"); } void -PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, ErrorReporting errorReporting) { +PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, + ErrorReporting errorReporting) +{ AppendDataXY(xres, yres); AppendAttribute(kUnitsPerMeasure); @@ -264,13 +321,17 @@ PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, AppendOperator(kBeginSession); } + void -PCL6Writer::EndSession() { +PCL6Writer::EndSession() +{ AppendOperator(kEndSession); } + void -PCL6Writer::OpenDataSource() { +PCL6Writer::OpenDataSource() +{ AppendData((uint8)kDefaultDataSource); AppendAttribute(kSourceType); @@ -280,14 +341,18 @@ PCL6Writer::OpenDataSource() { AppendOperator(kOpenDataSource); } + void -PCL6Writer::CloseDataSource() { +PCL6Writer::CloseDataSource() +{ AppendOperator(kCloseDataSource); } void -PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource) { +PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, + MediaSource mediaSource) +{ AppendData((uint8)orientation); AppendAttribute(kOrientation); @@ -300,8 +365,11 @@ PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource AppendOperator(kBeginPage); } + void -PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource, DuplexPageMode duplexPageMode, MediaSide mediaSide) { +PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, + MediaSource mediaSource, DuplexPageMode duplexPageMode, MediaSide mediaSide) +{ AppendData((uint8)orientation); AppendAttribute(kOrientation); @@ -320,8 +388,10 @@ PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource AppendOperator(kBeginPage); } + void -PCL6Writer::EndPage(uint16 copies) { +PCL6Writer::EndPage(uint16 copies) +{ // if (copies != 1) { AppendData(copies); AppendAttribute(kPageCopies); @@ -332,47 +402,58 @@ PCL6Writer::EndPage(uint16 copies) { void -PCL6Writer::SetPageOrigin(int16 x, int16 y) { +PCL6Writer::SetPageOrigin(int16 x, int16 y) +{ AppendDataXY(x, y); AppendAttribute(kPageOrigin); AppendOperator(kSetPageOrigin); } + void -PCL6Writer::SetColorSpace(ColorSpace colorSpace) { +PCL6Writer::SetColorSpace(ColorSpace colorSpace) +{ AppendData((uint8)colorSpace); AppendAttribute(kColorSpace); AppendOperator(kSetColorSpace); } + void -PCL6Writer::SetPaintTxMode(Transparency transparency) { +PCL6Writer::SetPaintTxMode(Transparency transparency) +{ AppendData((uint8)transparency); AppendAttribute(kTxMode); AppendOperator(kSetPaintTxMode); } + void -PCL6Writer::SetSourceTxMode(Transparency transparency) { +PCL6Writer::SetSourceTxMode(Transparency transparency) +{ AppendData((uint8)transparency); AppendAttribute(kTxMode); AppendOperator(kSetSourceTxMode); } + void -PCL6Writer::SetROP(uint8 rop) { +PCL6Writer::SetROP(uint8 rop) +{ AppendData((uint8)rop); AppendAttribute(kROP3); AppendOperator(kSetROP); } + void -PCL6Writer::SetCursor(int16 x, int16 y) { +PCL6Writer::SetCursor(int16 x, int16 y) +{ AppendDataXY(x, y); AppendAttribute(kPoint); @@ -380,8 +461,11 @@ PCL6Writer::SetCursor(int16 x, int16 y) { } -void -PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth, uint16 destHeight) { +void +PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, + uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth, + uint16 destHeight) +{ AppendData((uint8)colorMapping); AppendAttribute(kColorMapping); @@ -400,8 +484,11 @@ PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16 AppendOperator(kBeginImage); } + void -PCL6Writer::ReadImage(Compression compression, uint16 startLine, uint16 blockHeight, uint8 padBytes) { +PCL6Writer::ReadImage(Compression compression, uint16 startLine, + uint16 blockHeight, uint8 padBytes) +{ AppendData(startLine); AppendAttribute(kStartLine); @@ -423,9 +510,9 @@ PCL6Writer::ReadImage(Compression compression, uint16 startLine, uint16 blockHei AppendOperator(kReadImage); } + void -PCL6Writer::EndImage() { +PCL6Writer::EndImage() +{ AppendOperator(kEndImage); } - - diff --git a/src/add-ons/print/drivers/pcl6/PCL6Writer.h b/src/add-ons/print/drivers/pcl6/PCL6Writer.h index 08f27b9f7f..acf59ae816 100644 --- a/src/add-ons/print/drivers/pcl6/PCL6Writer.h +++ b/src/add-ons/print/drivers/pcl6/PCL6Writer.h @@ -1,362 +1,376 @@ /* ** PCL6Writer.h -** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved. +** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net. +** All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ #ifndef _PCL6_WRITER_H #define _PCL6_WRITER_H + #include + class PCL6Driver; class PCL6WriterStream { public: - virtual ~PCL6WriterStream() {} - virtual void write(const uint8 *data, uint32 size) = 0; + virtual ~PCL6WriterStream() {} + virtual void write(const uint8* data, uint32 size) = 0; }; + class PCL6Writer { public: // DO NOT change this enumerations the order is important!!! - enum Orientation { - kPortrait, - kLandscape, - kReversePortrait, - kReverseLandscape - }; + enum Orientation { + kPortrait, + kLandscape, + kReversePortrait, + kReverseLandscape + }; - enum MediaSize { - kLetterPaper, - kLegalPaper, - kA4Paper, - kExecPaper, - kLedgerPaper, - kA3Paper, - kCOM10Envelope, - kMonarchEnvelope, - kC5Envelope, - kDLEnvelope, - kJB4Paper, - kJB5Paper, - kB5Envelope, - kB5Paper, - kJPostcard, - kJDoublePostcard, - kA5Paper, - kA6Paper, - kJB6Paper, - kJIS8KPaper, - kJIS16KPaper, - kJISExecPaper - }; + enum MediaSize { + kLetterPaper, + kLegalPaper, + kA4Paper, + kExecPaper, + kLedgerPaper, + kA3Paper, + kCOM10Envelope, + kMonarchEnvelope, + kC5Envelope, + kDLEnvelope, + kJB4Paper, + kJB5Paper, + kB5Envelope, + kB5Paper, + kJPostcard, + kJDoublePostcard, + kA5Paper, + kA6Paper, + kJB6Paper, + kJIS8KPaper, + kJIS16KPaper, + kJISExecPaper + }; - enum MediaSource { - kDefaultSource, - kAutoSelect, - kManualFeed, - kMultiPurposeTray, - kUpperCassette, - kLowerCassette, - kEnvelopeTray, - kThirdCassette - }; + enum MediaSource { + kDefaultSource, + kAutoSelect, + kManualFeed, + kMultiPurposeTray, + kUpperCassette, + kLowerCassette, + kEnvelopeTray, + kThirdCassette + }; - enum Compression { - kNoCompression, - kRLECompression, - kJPEGCompression, - kDeltaRowCompression - }; + enum Compression { + kNoCompression, + kRLECompression, + kJPEGCompression, + kDeltaRowCompression + }; - enum ColorSpace { - kBiLevel, - kGray, - kRGB, - kCMY, - kCIELab, - kCRGB, - kSRGB - }; + enum ColorSpace { + kBiLevel, + kGray, + kRGB, + kCMY, + kCIELab, + kCRGB, + kSRGB + }; - enum ColorDepth { - k1Bit, - k4Bit, - k8Bit - }; + enum ColorDepth { + k1Bit, + k4Bit, + k8Bit + }; - enum ColorMapping { - kDirectPixel, - kIndexedPixel, - kDirectPlane - }; + enum ColorMapping { + kDirectPixel, + kIndexedPixel, + kDirectPlane + }; - enum Transparency { - kOpaque, - kTransparent - }; + enum Transparency { + kOpaque, + kTransparent + }; - enum DuplexPageMode { - kDuplexHorizontalBinding, - kDuplexVerticalBinding - }; + enum DuplexPageMode { + kDuplexHorizontalBinding, + kDuplexVerticalBinding + }; - enum MediaSide { - kFrontMediaSide, - kBackMediaSide - }; + enum MediaSide { + kFrontMediaSide, + kBackMediaSide + }; - enum SimplexPageMode { - kSimplexFrontSide - }; + enum SimplexPageMode { + kSimplexFrontSide + }; - enum UnitOfMeasure { - kInch, - kMillimeter, - kTenthsOfAMillimeter - }; + enum UnitOfMeasure { + kInch, + kMillimeter, + kTenthsOfAMillimeter + }; - enum ErrorReporting { - kNoReporting, - kBackChannel, - kErrorPage, - kBackChAndErrPage, - kNWBackChannel, - kNWErrorPage, - kNWBackChAndErrPage - }; + enum ErrorReporting { + kNoReporting, + kBackChannel, + kErrorPage, + kBackChAndErrPage, + kNWBackChannel, + kNWErrorPage, + kNWBackChAndErrPage + }; - enum Enable { - kOn, - kOff - }; + enum Enable { + kOn, + kOff + }; - enum Boolean { - kFalse, - kTrue - }; + enum Boolean { + kFalse, + kTrue + }; - enum ProtocolClass { - kProtocolClass1_1, - kProtocolClass2_0, - kProtocolClass2_1, - kProtocolClass3_0, - }; + enum ProtocolClass { + kProtocolClass1_1, + kProtocolClass2_0, + kProtocolClass2_1, + kProtocolClass3_0, + }; - PCL6Writer(PCL6WriterStream* stream, uint32 bufferSize = 16 * 1024); - virtual ~PCL6Writer(); + PCL6Writer(PCL6WriterStream* stream, + uint32 bufferSize = 16 * 1024); + virtual ~PCL6Writer(); // these methods throw TransportException if data could not // be written - void Flush(); + void Flush(); - void PJLHeader(ProtocolClass protocolClass, int dpi, const char *comment = NULL); - void PJLFooter(); + void PJLHeader(ProtocolClass protocolClass, int dpi, + const char* comment = NULL); + void PJLFooter(); - void BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, ErrorReporting errorReporting); - void EndSession(); + void BeginSession(uint16 xres, uint16 yres, + UnitOfMeasure unitOfMeasure, + ErrorReporting errorReporting); + void EndSession(); - void OpenDataSource(); - void CloseDataSource(); + void OpenDataSource(); + void CloseDataSource(); - void BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource); - void BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource, DuplexPageMode duplexPageMode, MediaSide mediaSide); - void EndPage(uint16 copies); + void BeginPage(Orientation orientation, MediaSize mediaSize, + MediaSource mediaSource); + void BeginPage(Orientation orientation, MediaSize mediaSize, + MediaSource mediaSource, DuplexPageMode duplexPageMode, + MediaSide mediaSide); + void EndPage(uint16 copies); - void SetPageOrigin(int16 x, int16 y); - void SetColorSpace(ColorSpace colorSpace); - void SetPaintTxMode(Transparency transparency); - void SetSourceTxMode(Transparency transparency); - void SetROP(uint8 rop); - void SetCursor(int16 x, int16 y); + void SetPageOrigin(int16 x, int16 y); + void SetColorSpace(ColorSpace colorSpace); + void SetPaintTxMode(Transparency transparency); + void SetSourceTxMode(Transparency transparency); + void SetROP(uint8 rop); + void SetCursor(int16 x, int16 y); - void BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth, uint16 destHeight); - void ReadImage(Compression compression, uint16 startLine, uint16 blockHeight, uint8 padBytes = 4); - void EndImage(); - void EmbeddedDataPrefix(uint32 size); - void EmbeddedDataPrefix32(uint32 size); + void BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, + uint16 sourceWidth, uint16 sourceHeight, + uint16 destWidth, uint16 destHeight); + void ReadImage(Compression compression, uint16 startLine, + uint16 blockHeight, uint8 padBytes = 4); + void EndImage(); + void EmbeddedDataPrefix(uint32 size); + void EmbeddedDataPrefix32(uint32 size); - void Append(uint8 value); - void Append(int16 value); - void Append(uint16 value); - void Append(int32 value); - void Append(uint32 value); - void Append(float value); - void Append(const uint8* data, uint32 size); + void Append(uint8 value); + void Append(int16 value); + void Append(uint16 value); + void Append(int32 value); + void Append(uint32 value); + void Append(float value); + void Append(const uint8* data, uint32 size); - void AppendData(uint8 value); - void AppendData(int16 value); - void AppendData(uint16 value); - void AppendData(int32 value); - void AppendData(uint32 value); - void AppendData(float value); + void AppendData(uint8 value); + void AppendData(int16 value); + void AppendData(uint16 value); + void AppendData(int32 value); + void AppendData(uint32 value); + void AppendData(float value); - void AppendDataXY(uint8 x, uint8 y); - void AppendDataXY(int16 x, int16 y); - void AppendDataXY(uint16 x, uint16 y); - void AppendDataXY(int32 x, int32 y); - void AppendDataXY(uint32 x, uint32 y); - void AppendDataXY(float x, float y); + void AppendDataXY(uint8 x, uint8 y); + void AppendDataXY(int16 x, int16 y); + void AppendDataXY(uint16 x, uint16 y); + void AppendDataXY(int32 x, int32 y); + void AppendDataXY(uint32 x, uint32 y); + void AppendDataXY(float x, float y); private: - enum Operator { - kBeginSession = 0x41, - kEndSession, - kBeginPage, - kEndPage, - - kVendorUnique = 0x46, - kComment, - kOpenDataSource, - kCloseDataSource, - kEchoComment, - kQuery, - kDiagnostic3, - - kBeginStream = 0x5b, - kReadStream, - kEndStream, - - kSetColorSpace = 0x6a, - kSetCursor, - - kSetPageOrigin = 0x75, - kSetPageRotation, - kSetPageScale, - kSetPaintTxMode, - kSetPenSource, - kSetPenWidth, - kSetROP, - kSetSourceTxMode, + enum Operator { + kBeginSession = 0x41, + kEndSession, + kBeginPage, + kEndPage, - kBeginImage = 0xb0, - kReadImage, - kEndImage, - }; + kVendorUnique = 0x46, + kComment, + kOpenDataSource, + kCloseDataSource, + kEchoComment, + kQuery, + kDiagnostic3, + + kBeginStream = 0x5b, + kReadStream, + kEndStream, + + kSetColorSpace = 0x6a, + kSetCursor, + + kSetPageOrigin = 0x75, + kSetPageRotation, + kSetPageScale, + kSetPaintTxMode, + kSetPenSource, + kSetPenWidth, + kSetROP, + kSetSourceTxMode, + + kBeginImage = 0xb0, + kReadImage, + kEndImage, + }; - enum DataTag { - kUByteData = 0xc0, - kUInt16Data, - kUInt32Data, - kSInt16Data, - kSInt32Data, - kReal32Data, + enum DataTag { + kUByteData = 0xc0, + kUInt16Data, + kUInt32Data, + kSInt16Data, + kSInt32Data, + kReal32Data, - kString = 0xc7, - kUByteArray, - kUInt16Array, - kUInt32Array, - kSInt16Array, - kSInt32Array, - kReal32Array, + kString = 0xc7, + kUByteArray, + kUInt16Array, + kUInt32Array, + kSInt16Array, + kSInt32Array, + kReal32Array, - kUByteXY = 0xd0, - kUInt16XY, - kUInt32XY, - kSInt16XY, - kSInt32XY, - kReal32XY, + kUByteXY = 0xd0, + kUInt16XY, + kUInt32XY, + kSInt16XY, + kSInt32XY, + kReal32XY, - kUByteBox = 0xe0, - kUInt16Box, - kUInt32Box, - kSInt16Box, - kSInt32Box, - kReal32Box, + kUByteBox = 0xe0, + kUInt16Box, + kUInt32Box, + kSInt16Box, + kSInt32Box, + kReal32Box, - k8BitAttrId = 0xf8, + k8BitAttrId = 0xf8, - kEmbeddedData = 0xfa, - kEmbeddedDataByte, - }; + kEmbeddedData = 0xfa, + kEmbeddedDataByte, + }; - enum DataType { - kUByte, - kSByte, - kUInt16, - kSInt16, - kReal32 - }; + enum DataType { + kUByte, + kSByte, + kUInt16, + kSInt16, + kReal32 + }; - enum Attribute { - kCMYColor = 1, - kPaletteDepth, - kColorSpace, + enum Attribute { + kCMYColor = 1, + kPaletteDepth, + kColorSpace, - kRGBColor = 11, + kRGBColor = 11, - kMediaDest = 36, - kMediaSize, - kMediaSource, - kMediaType, - kOrientation, - kPageAngle, - kPageOrigin, - kPageScale, - kROP3, - kTxMode, + kMediaDest = 36, + kMediaSize, + kMediaSource, + kMediaType, + kOrientation, + kPageAngle, + kPageOrigin, + kPageScale, + kROP3, + kTxMode, - kCustomMediaSize = 47, - kCustomMediaSizeUnits, - kPageCopies, - kDitherMatrixSize, - kDitherMatrixDepth, - kSimplexPageMode, - kDuplexPageMode, - kDuplexPageSide, + kCustomMediaSize = 47, + kCustomMediaSizeUnits, + kPageCopies, + kDitherMatrixSize, + kDitherMatrixDepth, + kSimplexPageMode, + kDuplexPageMode, + kDuplexPageSide, - kPoint = 76, + kPoint = 76, - kColorDepth = 98, - kBlockHeight, - kColorMapping, - kCompressMode, - kDestinationBox, - kDestinationSize, + kColorDepth = 98, + kBlockHeight, + kColorMapping, + kCompressMode, + kDestinationBox, + kDestinationSize, - kSourceHeight = 107, - kSourceWidth, - kStartLine, - kPadBytesMultiple, - kBlockByteLength, + kSourceHeight = 107, + kSourceWidth, + kStartLine, + kPadBytesMultiple, + kBlockByteLength, - kNumberOfScanLines = 115, + kNumberOfScanLines = 115, - kDataOrg = 130, - kMeasure = 134, + kDataOrg = 130, + kMeasure = 134, - kSourceType = 136, - kUnitsPerMeasure, - kQueryKey, - kStreamName, - kStreamDataLength, + kSourceType = 136, + kUnitsPerMeasure, + kQueryKey, + kStreamName, + kStreamDataLength, - kErrorReport = 143, - kIOReadTimeOut, + kErrorReport = 143, + kIOReadTimeOut, - kWritingMode = 173 - }; + kWritingMode = 173 + }; - enum DataSource { - kDefaultDataSource - }; + enum DataSource { + kDefaultDataSource + }; - enum DataOrganization { - kBinaryHighByteFirst, - kBinaryLowByteFirst - }; + enum DataOrganization { + kBinaryHighByteFirst, + kBinaryLowByteFirst + }; - void AppendString(const char* string); - void AppendOperator(Operator op); - void AppendAttribute(Attribute attr); - void AppendDataTag(DataTag tag); + void AppendString(const char* string); + void AppendOperator(Operator op); + void AppendAttribute(Attribute attr); + void AppendDataTag(DataTag tag); - PCL6WriterStream *fStream; // the stream used for writing the generated PCL6 data - uint8 *fBuffer; // the buffer - uint32 fSize; // the size of the buffer - uint32 fIndex; // the index of the next byte to be written + PCL6WriterStream* fStream; + // the stream used for writing the generated PCL6 data + uint8* fBuffer; // the buffer + uint32 fSize; // the size of the buffer + uint32 fIndex; // the index of the next byte to be written }; -#endif - +#endif // _PCL6_WRITER_H diff --git a/src/add-ons/print/drivers/pcl6/Rasterizer.cpp b/src/add-ons/print/drivers/pcl6/Rasterizer.cpp index c5ac5f6c5f..80554d53e8 100644 --- a/src/add-ons/print/drivers/pcl6/Rasterizer.cpp +++ b/src/add-ons/print/drivers/pcl6/Rasterizer.cpp @@ -2,28 +2,32 @@ #include + Rasterizer::Rasterizer(Halftone* halftone) - : fHalftone(halftone) - , fIndex(-1) + : + fHalftone(halftone), + fIndex(-1) { fBounds.bottom = -2; } + Rasterizer::~Rasterizer() { } + bool -Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight) +Rasterizer::SetBitmap(int x, int y, BBitmap* bitmap, int pageHeight) { fX = x; fY = y; BRect bounds = bitmap->Bounds(); - fBounds.left = (int)bounds.left; - fBounds.top = (int)bounds.top; - fBounds.right = (int)bounds.right; + fBounds.left = (int)bounds.left; + fBounds.top = (int)bounds.top; + fBounds.right = (int)bounds.right; fBounds.bottom = (int)bounds.bottom; int height = fBounds.bottom - fBounds.top + 1; @@ -33,9 +37,8 @@ Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight) fBounds.bottom = fBounds.top + height - 1; } - if (!get_valid_rect(bitmap, &fBounds)) { + if (!get_valid_rect(bitmap, &fBounds)) return false; - } fWidth = fBounds.right - fBounds.left + 1; fHeight = fBounds.bottom - fBounds.top + 1; @@ -52,20 +55,21 @@ Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight) return true; } + bool Rasterizer::HasNextLine() { return fIndex <= fBounds.bottom; } + const void* Rasterizer::RasterizeNextLine() { - if (!HasNextLine()) { + if (!HasNextLine()) return NULL; - } - const void *result; + const void* result; result = RasterizeLine(fX, fY, (const ColorRGB32Little*)fBits); fBits += fBPR; fY ++; @@ -73,10 +77,10 @@ Rasterizer::RasterizeNextLine() return result; } + void Rasterizer::RasterizeBitmap() { - while (HasNextLine()) { + while (HasNextLine()) RasterizeNextLine(); - } } diff --git a/src/add-ons/print/drivers/pcl6/Rasterizer.h b/src/add-ons/print/drivers/pcl6/Rasterizer.h index deff722509..3d8beabcf3 100644 --- a/src/add-ons/print/drivers/pcl6/Rasterizer.h +++ b/src/add-ons/print/drivers/pcl6/Rasterizer.h @@ -1,74 +1,100 @@ #ifndef _RASTERIZER_H #define _RASTERIZER_H + +#include + #include "Halftone.h" #include "ValidRect.h" -#include -// class Rasterizer { public: - Rasterizer(Halftone *halftone); - virtual ~Rasterizer(); + Rasterizer(Halftone* halftone); + virtual ~Rasterizer(); /** * Sets the bitmap to be rasterized * Either the iterator methods HasNextLine() and RasterizeNextLine() - * can be used to rasterize the bitmap line per line or the method RasterizeBitamp() + * can be used to rasterize the bitmap line per line or the method + * RasterizeBitamp() * can be used to rasterize the entire bitmap at once. * @param x the x position of the image on the page. * @param y the y position of the image on the page. * @param bitmap the bitamp to be rasterized. * @param height the page height. - * @return true if the bitmap is not empty and false if the bitmap is empty. + * @return true if the bitmap is not empty and false if the bitmap is + * empty. */ - bool SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight); + bool SetBitmap(int x, int y, BBitmap* bitmap, + int pageHeight); // Is there a next line? - bool HasNextLine(); + bool HasNextLine(); // Rasterizes the next line and returns the line. - const void *RasterizeNextLine(); + const void* RasterizeNextLine(); // Iterates over all lines. - void RasterizeBitmap(); + void RasterizeBitmap(); // Returns the Halftone object specified in the constructor - Halftone *GetHalftone() { return fHalftone; } + Halftone* GetHalftone() + { + return fHalftone; + } // The bounds of the bitmap to be rasterized - RECT GetBounds() { return fBounds; } + RECT GetBounds() + { + return fBounds; + } // The width (in pixels) of the bounds passed to Rasterized() - int GetWidth() { return fWidth; } + int GetWidth() + { + return fWidth; + } // The height (in pixels) of the bounds passed to Rasterize() - int GetHeight() { return fHeight; } + int GetHeight() + { + return fHeight; + } // Returns the current x position - int GetX() { return fX; } + int GetX() + { + return fX; + } // Returns the current y position - int GetY() { return fY; } + int GetY() + { + return fY; + } // The method is called for each line in the bitmap. - virtual const void *RasterizeLine(int x, int y, const ColorRGB32Little* source) = 0; + virtual const void* RasterizeLine(int x, int y, + const ColorRGB32Little* source) = 0; - // Returns the number of bytes to store widthInPixels pixels with BPP = bitsPerPixel - // and padBytes number of pad bytes. - static int RowBufferSize(int widthInPixels, int bitsPerPixel, int padBytes = 1) { - int sizeInBytes = (widthInPixels * bitsPerPixel + 7) / 8; - return padBytes * ((sizeInBytes + padBytes - 1) / padBytes); - } + // Returns the number of bytes to store widthInPixels pixels with + // BPP = bitsPerPixel and padBytes number of pad bytes. + static int RowBufferSize(int widthInPixels, int bitsPerPixel, + int padBytes = 1) + { + int sizeInBytes = (widthInPixels * bitsPerPixel + 7) + / 8; + return padBytes * ((sizeInBytes + padBytes - 1) + / padBytes); + } private: - Halftone *fHalftone; + Halftone* fHalftone; - RECT fBounds; - int fWidth; - int fHeight; - int fX; - int fY; - - const uchar *fBits; - int fBPR; - int fIndex; + RECT fBounds; + int fWidth; + int fHeight; + int fX; + int fY; + + const uchar* fBits; + int fBPR; + int fIndex; }; - -#endif +#endif // _RASTERIZER_H