Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37370 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Wim van der Meer
2010-07-03 10:23:04 +00:00
parent 4225e5b785
commit 568716bed7
14 changed files with 1179 additions and 888 deletions
@@ -1,45 +1,57 @@
/* /*
** DeltaRowCompression.cpp ** DeltaRowCompression.cpp
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#include "DeltaRowCompression.h"
#include <SupportDefs.h>
#include "DeltaRowCompression.h"
#include <memory.h> #include <memory.h>
AbstractDeltaRowCompressor::AbstractDeltaRowCompressor(int rowSize, uchar initialSeed) #include <SupportDefs.h>
: fSeedRow(new uchar[rowSize])
, fSize(rowSize)
, fInitialSeed(initialSeed) AbstractDeltaRowCompressor::AbstractDeltaRowCompressor(int rowSize,
uchar initialSeed)
:
fSeedRow(new uchar[rowSize]),
fSize(rowSize),
fInitialSeed(initialSeed)
{ {
Reset(); Reset();
} }
AbstractDeltaRowCompressor::~AbstractDeltaRowCompressor() AbstractDeltaRowCompressor::~AbstractDeltaRowCompressor()
{ {
delete fSeedRow; delete fSeedRow;
fSeedRow = NULL; fSeedRow = NULL;
} }
status_t AbstractDeltaRowCompressor::InitCheck()
status_t
AbstractDeltaRowCompressor::InitCheck()
{ {
if (fSeedRow != NULL) { if (fSeedRow != NULL)
return B_OK; return B_OK;
} else { else
return B_NO_MEMORY; return B_NO_MEMORY;
} }
}
void AbstractDeltaRowCompressor::Reset()
void
AbstractDeltaRowCompressor::Reset()
{ {
if (fSeedRow != NULL) { if (fSeedRow != NULL)
memset(fSeedRow, fInitialSeed, fSize); 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); int index = DiffersIndex(row, 0);
if (index == -1) { if (index == -1) {
@@ -56,21 +68,18 @@ int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow
// delta starts at index and contains length bytes // delta starts at index and contains length bytes
do { do {
// control byte limits data bytes to 8 bytes // control byte limits data bytes to 8 bytes
int deltaBytes = length; int deltaBytes = length;
if (length > 8) { if (length > 8)
deltaBytes = 8; deltaBytes = 8;
}
// calculate offset // calculate offset
int totalOffset = index - seedRowIndex; int totalOffset = index - seedRowIndex;
bool needsOffsetBytes = totalOffset > 30; bool needsOffsetBytes = totalOffset > 30;
int offset = totalOffset; int offset = totalOffset;
// control byte limits offset value to 31 // control byte limits offset value to 31
if (needsOffsetBytes) { if (needsOffsetBytes)
offset = 31; offset = 31;
}
// write control byte (delta bytes bits 5-7; offset bits 0-4) // write control byte (delta bytes bits 5-7; offset bits 0-4)
Put(((deltaBytes - 1) << 5) | offset); Put(((deltaBytes - 1) << 5) | offset);
@@ -112,18 +121,25 @@ int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow
return fDeltaRowIndex; return fDeltaRowIndex;
} }
int AbstractDeltaRowCompressor::CalculateSize(const uchar* row, bool updateSeedRow)
int
AbstractDeltaRowCompressor::CalculateSize(const uchar* row, bool updateSeedRow)
{ {
return CompressRaw(row, updateSeedRow, false); return CompressRaw(row, updateSeedRow, false);
} }
void AbstractDeltaRowCompressor::Compress(const uchar* row)
void
AbstractDeltaRowCompressor::Compress(const uchar* row)
{ {
CompressRaw(row, true, true); CompressRaw(row, true, true);
} }
#ifdef TEST_DELTA_ROW_COMPRESSION #ifdef TEST_DELTA_ROW_COMPRESSION
void test(AbstractDeltaRowCompressor* compressor, uchar* row) {
void
test(AbstractDeltaRowCompressor* compressor, uchar* row) {
int size = compressor->CalculateSize(row); int size = compressor->CalculateSize(row);
printf("size %d\n", size); printf("size %d\n", size);
@@ -139,7 +155,9 @@ void test(AbstractDeltaRowCompressor* compressor, uchar* row) {
printf("\n"); printf("\n");
} }
int main(int argc, char *argv[])
int
main(int argc, char* argv[])
{ {
int n = 5; int n = 5;
uchar row1[] = {0, 0, 0, 0, 0}; uchar row1[] = {0, 0, 0, 0, 0};
@@ -152,4 +170,4 @@ int main(int argc, char *argv[])
test(&compressor, row3); test(&compressor, row3);
} }
#endif #endif // TEST_DELTA_ROW_COMPRESSION
@@ -1,16 +1,20 @@
/* /*
** DeltaRowCompression.h ** DeltaRowCompression.h
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#ifndef _DELTA_ROW_COMPRESSION_H #ifndef _DELTA_ROW_COMPRESSION_H
#define _DELTA_ROW_COMPRESSION_H #define _DELTA_ROW_COMPRESSION_H
#include <Debug.h> #include <Debug.h>
class AbstractDeltaRowCompressor { class AbstractDeltaRowCompressor {
public: public:
AbstractDeltaRowCompressor(int rowSize, uchar initialSeed); AbstractDeltaRowCompressor(int rowSize,
uchar initialSeed);
virtual ~AbstractDeltaRowCompressor(); virtual ~AbstractDeltaRowCompressor();
// InitCheck returns B_OK on successful construction of this object or // InitCheck returns B_OK on successful construction of this object or
@@ -23,7 +27,8 @@ public:
// Returns the size of the delta row. // Returns the size of the delta row.
// The size is 0 if the row is equal to the seed row (previous 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. // 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. // Compresses the row using the delta row compression algorithm.
// The seed row is updated. // The seed row is updated.
@@ -34,7 +39,8 @@ protected:
virtual void AppendByteToDeltaRow(uchar byte) = 0; virtual void AppendByteToDeltaRow(uchar byte) = 0;
// returns the current size of the delta row // returns the current size of the delta row
inline int CurrentDeltaRowSize() { inline int CurrentDeltaRowSize()
{
return fDeltaRowIndex; return fDeltaRowIndex;
} }
@@ -44,13 +50,10 @@ private:
inline int DiffersIndex(const uchar* row, int index) inline int DiffersIndex(const uchar* row, int index)
{ {
while (index < fSize) { while (index < fSize) {
if (fSeedRow[index] != row[index]) { if (fSeedRow[index] != row[index])
return index; return index;
}
index ++; index ++;
} }
return -1; return -1;
} }
@@ -59,12 +62,9 @@ private:
inline int DiffersLength(const uchar* row, int index) inline int DiffersLength(const uchar* row, int index)
{ {
int startIndex = index; int startIndex = index;
while (index < fSize) { while (index < fSize) {
if (fSeedRow[index] == row[index]) { if (fSeedRow[index] == row[index])
break; break;
}
index ++; index ++;
} }
return index - startIndex; return index - startIndex;
@@ -73,40 +73,46 @@ private:
// Compresses row with delta row compression algorithm. // Compresses row with delta row compression algorithm.
// The seed row is updated only if updateSeedRow is true. // The seed row is updated only if updateSeedRow is true.
// If updateDeltaRow is true the method AppendByteToDeltaRow is called. // 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 // write byte to delta row and calculate size of delta row
void Put(uchar byte) { void Put(uchar byte)
if (fUpdateDeltaRow) { {
if (fUpdateDeltaRow)
AppendByteToDeltaRow(byte); AppendByteToDeltaRow(byte);
}
fDeltaRowIndex ++; fDeltaRowIndex ++;
} }
uchar* fSeedRow; // the seed row uchar* fSeedRow; // the seed row
int fSize; // the size of the seed row in bytes int fSize; // the size of the seed row in bytes
uchar fInitialSeed; // the value to initialize the seed row with 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 int fDeltaRowIndex;
// the index of the next byte to be written into
// the delta row
bool fUpdateDeltaRow; // write delta row bool fUpdateDeltaRow; // write delta row
}; };
class DeltaRowCompressor : public AbstractDeltaRowCompressor class DeltaRowCompressor : public AbstractDeltaRowCompressor
{ {
public: public:
DeltaRowCompressor(int rowSize, uchar initialSeed) DeltaRowCompressor(int rowSize, uchar initialSeed)
: AbstractDeltaRowCompressor(rowSize, initialSeed) :
{ AbstractDeltaRowCompressor(rowSize, initialSeed)
// nothing to do {}
}
// The delta row to be written to. // The delta row to be written to.
void SetDeltaRow(uchar* deltaRow) { void SetDeltaRow(uchar* deltaRow)
{
fDeltaRow = deltaRow; fDeltaRow = deltaRow;
} }
protected: protected:
virtual void AppendByteToDeltaRow(uchar byte) { virtual void AppendByteToDeltaRow(uchar byte)
{
fDeltaRow[CurrentDeltaRowSize()] = byte; fDeltaRow[CurrentDeltaRowSize()] = byte;
} }
@@ -115,4 +121,3 @@ private:
}; };
#endif #endif
+150 -85
View File
@@ -4,22 +4,24 @@
* Copyright 2003 Michael Pfeiffer. * Copyright 2003 Michael Pfeiffer.
*/ */
#include "PCL6.h"
#include <memory.h>
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <File.h> #include <File.h>
#include <memory>
#include "DbgMsg.h" #include "DbgMsg.h"
#include "DeltaRowCompression.h" #include "DeltaRowCompression.h"
#include "Halftone.h" #include "Halftone.h"
#include "JobData.h" #include "JobData.h"
#include "PackBits.h" #include "PackBits.h"
#include "PCL6.h"
#include "PCL6Cap.h" #include "PCL6Cap.h"
#include "PCL6Config.h" #include "PCL6Config.h"
#include "PrinterData.h"
#include "PCL6Rasterizer.h" #include "PCL6Rasterizer.h"
#include "PrinterData.h"
#include "UIDriver.h" #include "UIDriver.h"
#include "ValidRect.h" #include "ValidRect.h"
@@ -29,20 +31,22 @@ using namespace std;
#define std #define std
#endif #endif
// DeltaRowStreamCompressor writes the delta row directly to the // DeltaRowStreamCompressor writes the delta row directly to the
// in the contructor specified stream. // in the contructor specified stream.
class DeltaRowStreamCompressor : public AbstractDeltaRowCompressor class DeltaRowStreamCompressor : public AbstractDeltaRowCompressor
{ {
public: public:
DeltaRowStreamCompressor(int rowSize, uchar initialSeed, PCL6Writer *writer) DeltaRowStreamCompressor(int rowSize, uchar initialSeed,
: AbstractDeltaRowCompressor(rowSize, initialSeed) PCL6Writer* writer)
, fWriter(writer) :
{ AbstractDeltaRowCompressor(rowSize, initialSeed),
// nothing to do fWriter(writer)
} {}
protected: protected:
void AppendByteToDeltaRow(uchar byte) { void AppendByteToDeltaRow(uchar byte)
{
fWriter->Append(byte); fWriter->Append(byte);
} }
@@ -51,23 +55,31 @@ private:
}; };
PCL6Driver::PCL6Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap) PCL6Driver::PCL6Driver(BMessage* msg, PrinterData* printer_data,
: GraphicsDriver(msg, printer_data, printer_cap) const PrinterCap* printer_cap)
:
GraphicsDriver(msg, printer_data, printer_cap)
{ {
fHalftone = NULL; fHalftone = NULL;
fWriter = NULL; fWriter = NULL;
} }
void PCL6Driver::write(const uint8 *data, uint32 size)
void
PCL6Driver::write(const uint8* data, uint32 size)
{ {
writeSpoolData(data, size); writeSpoolData(data, size);
} }
bool PCL6Driver::startDoc()
bool
PCL6Driver::startDoc()
{ {
try { try {
jobStart(); 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; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -75,12 +87,13 @@ bool PCL6Driver::startDoc()
} }
} }
bool PCL6Driver::endDoc(bool)
bool
PCL6Driver::endDoc(bool)
{ {
try { try {
if (fHalftone) { if (fHalftone)
delete fHalftone; delete fHalftone;
}
jobEnd(); jobEnd();
return true; return true;
} }
@@ -89,7 +102,9 @@ bool PCL6Driver::endDoc(bool)
} }
} }
bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
bool
PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -105,11 +120,12 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
#else #else
#error COLOR_DEPTH must be either 1 or 8! #error COLOR_DEPTH must be either 1 or 8!
#endif #endif
} else { } else
rasterizer = new MonochromeRasterizer(fHalftone); rasterizer = new MonochromeRasterizer(fHalftone);
}
auto_ptr<Rasterizer> _rasterizer(rasterizer); auto_ptr<Rasterizer> _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) { if (valid) {
rasterizer->InitializeBuffer(); rasterizer->InitializeBuffer();
@@ -117,7 +133,8 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
// Use compressor to calculate delta row size // Use compressor to calculate delta row size
DeltaRowCompressor* deltaRowCompressor = NULL; DeltaRowCompressor* deltaRowCompressor = NULL;
if (supportsDeltaRowCompression()) { if (supportsDeltaRowCompression()) {
deltaRowCompressor = new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0); deltaRowCompressor =
new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0);
if (deltaRowCompressor->InitCheck() != B_OK) { if (deltaRowCompressor->InitCheck() != B_OK) {
delete deltaRowCompressor; delete deltaRowCompressor;
return false; return false;
@@ -131,11 +148,14 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
int yPage = rasterizer->GetY(); int yPage = rasterizer->GetY();
while (rasterizer->HasNextLine()) { while (rasterizer->HasNextLine()) {
const uchar *rowBuffer = (uchar*)rasterizer->RasterizeNextLine(); const uchar* rowBuffer =
static_cast<const uchar*>(rasterizer->RasterizeNextLine());
if (deltaRowCompressor != NULL) { if (deltaRowCompressor != NULL) {
int size = deltaRowCompressor->CalculateSize(rowBuffer, true); int size =
deltaRowSize += size + 2; // two bytes for the row byte count deltaRowCompressor->CalculateSize(rowBuffer, true);
deltaRowSize += size + 2;
// two bytes for the row byte count
} }
} }
@@ -146,7 +166,8 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
int outRowSize = rasterizer->GetOutRowSize(); int outRowSize = rasterizer->GetOutRowSize();
int width = rasterizer->GetWidth(); int width = rasterizer->GetWidth();
int height = rasterizer->GetHeight(); 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()) { if (y >= getPageHeight()) {
@@ -165,7 +186,10 @@ bool PCL6Driver::nextBand(BBitmap *bitmap, BPoint *offset)
} }
} }
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 // choose the best compression method
PCL6Writer::Compression compressionMethod = PCL6Writer::kNoCompression; 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); startRasterGraphics(x, y, width, height, compressionMethod);
rasterGraphics(buffer, outSize, dataSize, rowSize, height, compressionMethod); rasterGraphics(buffer, outSize, dataSize, rowSize, height,
compressionMethod);
endRasterGraphics(); endRasterGraphics();
#if DISPLAY_COMPRESSION_STATISTICS #if DISPLAY_COMPRESSION_STATISTICS
fprintf(stderr, "Out Size %d %2.2f\n", (int)outSize, 100.0); fprintf(stderr, "Out Size %d %2.2f\n", (int)outSize, 100.0);
#if ENABLE_RLE_COMPRESSION #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 #endif
#if ENABLE_DELTA_ROW_COMPRESSION #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 #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 #endif
} }
void PCL6Driver::jobStart() void
PCL6Driver::jobStart()
{ {
// PCL6 begin // PCL6 begin
fWriter = new PCL6Writer(this); fWriter = new PCL6Writer(this);
PCL6Writer::ProtocolClass pc = (PCL6Writer::ProtocolClass)getProtocolClass(); PCL6Writer::ProtocolClass pc =
fWriter->PJLHeader(pc, getJobData()->getXres(), "Copyright (c) 2003, 2004 Haiku"); (PCL6Writer::ProtocolClass)getProtocolClass();
fWriter->BeginSession(getJobData()->getXres(), getJobData()->getYres(), PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage); fWriter->PJLHeader(pc, getJobData()->getXres(),
"Copyright (c) 2003, 2004 Haiku");
fWriter->BeginSession(getJobData()->getXres(), getJobData()->getYres(),
PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage);
fWriter->OpenDataSource(); fWriter->OpenDataSource();
fMediaSide = PCL6Writer::kFrontMediaSide; fMediaSide = PCL6Writer::kFrontMediaSide;
} }
bool PCL6Driver::startPage(int)
bool
PCL6Driver::startPage(int)
{ {
PCL6Writer::Orientation orientation = PCL6Writer::kPortrait; PCL6Writer::Orientation orientation = PCL6Writer::kPortrait;
if (getJobData()->getOrientation() == JobData::kLandscape) { if (getJobData()->getOrientation() == JobData::kLandscape) {
orientation = PCL6Writer::kLandscape; orientation = PCL6Writer::kLandscape;
} }
PCL6Writer::MediaSize mediaSize = PCL6Driver::mediaSize(getJobData()->getPaper()); PCL6Writer::MediaSize mediaSize =
PCL6Writer::MediaSource mediaSource = PCL6Driver::mediaSource(getJobData()->getPaperSource()); PCL6Driver::mediaSize(getJobData()->getPaper());
PCL6Writer::MediaSource mediaSource =
PCL6Driver::mediaSource(getJobData()->getPaperSource());
if (getJobData()->getPrintStyle() == JobData::kSimplex) { if (getJobData()->getPrintStyle() == JobData::kSimplex) {
fWriter->BeginPage(orientation, mediaSize, mediaSource); fWriter->BeginPage(orientation, mediaSize, mediaSource);
} else if (getJobData()->getPrintStyle() == JobData::kDuplex) { } else if (getJobData()->getPrintStyle() == JobData::kDuplex) {
@@ -237,27 +273,29 @@ bool PCL6Driver::startPage(int)
fWriter->BeginPage(orientation, mediaSize, mediaSource, fWriter->BeginPage(orientation, mediaSize, mediaSource,
PCL6Writer::kDuplexVerticalBinding, fMediaSide); PCL6Writer::kDuplexVerticalBinding, fMediaSide);
if (fMediaSide == PCL6Writer::kFrontMediaSide) { if (fMediaSide == PCL6Writer::kFrontMediaSide)
fMediaSide = PCL6Writer::kBackMediaSide; fMediaSide = PCL6Writer::kBackMediaSide;
} else { else
fMediaSide = PCL6Writer::kFrontMediaSide; fMediaSide = PCL6Writer::kFrontMediaSide;
} } else
} else {
return false; return false;
}
// PageOrigin from Windows NT printer driver // PageOrigin from Windows NT printer driver
int x = 142 * getJobData()->getXres() / 600; int x = 142 * getJobData()->getXres() / 600;
int y = 100 * getJobData()->getYres() / 600; int y = 100 * getJobData()->getYres() / 600;
fWriter->SetPageOrigin(x, y); fWriter->SetPageOrigin(x, y);
fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB : PCL6Writer::kGray); fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB
: PCL6Writer::kGray);
fWriter->SetPaintTxMode(PCL6Writer::kOpaque); fWriter->SetPaintTxMode(PCL6Writer::kOpaque);
fWriter->SetSourceTxMode(PCL6Writer::kOpaque); fWriter->SetSourceTxMode(PCL6Writer::kOpaque);
fWriter->SetROP(204); fWriter->SetROP(204);
return true; 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; PCL6Writer::ColorDepth colorDepth;
if (useColorMode()) { if (useColorMode()) {
@@ -268,26 +306,25 @@ void PCL6Driver::startRasterGraphics(int x, int y, int width, int height, PCL6Wr
#else #else
#error COLOR_DEPTH must be either 1 or 8! #error COLOR_DEPTH must be either 1 or 8!
#endif #endif
} else { } else
colorDepth = PCL6Writer::k1Bit; 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); fWriter->ReadImage(compressionMethod, 0, height);
} }
void PCL6Driver::endRasterGraphics()
void
PCL6Driver::endRasterGraphics()
{ {
fWriter->EndImage(); fWriter->EndImage();
} }
void PCL6Driver::rasterGraphics(
const uchar *buffer, void
int bufferSize, PCL6Driver::rasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
int dataSize, int rowSize, int height, int compressionMethod)
int rowSize,
int height,
int compressionMethod
)
{ {
// write bitmap byte size // write bitmap byte size
fWriter->EmbeddedDataPrefix32(dataSize); fWriter->EmbeddedDataPrefix32(dataSize);
@@ -326,7 +363,9 @@ void PCL6Driver::rasterGraphics(
} }
} }
bool PCL6Driver::endPage(int)
bool
PCL6Driver::endPage(int)
{ {
try { try {
fWriter->EndPage(getJobData()->getCopies()); fWriter->EndPage(getJobData()->getCopies());
@@ -337,7 +376,9 @@ bool PCL6Driver::endPage(int)
} }
} }
void PCL6Driver::jobEnd()
void
PCL6Driver::jobEnd()
{ {
fWriter->CloseDataSource(); fWriter->CloseDataSource();
fWriter->EndSession(); fWriter->EndSession();
@@ -347,44 +388,60 @@ void PCL6Driver::jobEnd()
fWriter = NULL; fWriter = NULL;
} }
void PCL6Driver::move(int x, int y)
void
PCL6Driver::move(int x, int y)
{ {
fWriter->SetCursor(x, y); fWriter->SetCursor(x, y);
} }
bool bool
PCL6Driver::supportsRLECompression() PCL6Driver::supportsRLECompression()
{ {
return getJobData()->getColor() != JobData::kColorCompressionDisabled; return getJobData()->getColor() != JobData::kColorCompressionDisabled;
} }
bool bool
PCL6Driver::supportsDeltaRowCompression() PCL6Driver::supportsDeltaRowCompression()
{ {
return getProtocolClass() >= PCL6Writer::kProtocolClass2_1 && return getProtocolClass() >= PCL6Writer::kProtocolClass2_1
getJobData()->getColor() != JobData::kColorCompressionDisabled; && getJobData()->getColor() != JobData::kColorCompressionDisabled;
} }
bool bool
PCL6Driver::useColorMode() PCL6Driver::useColorMode()
{ {
return getJobData()->getColor() != JobData::kMonochrome; return getJobData()->getColor() != JobData::kMonochrome;
} }
PCL6Writer::MediaSize PCL6Driver::mediaSize(JobData::Paper paper)
PCL6Writer::MediaSize
PCL6Driver::mediaSize(JobData::Paper paper)
{ {
switch (paper) { switch (paper) {
case JobData::kLetter: return PCL6Writer::kLetterPaper; case JobData::kLetter:
case JobData::kLegal: return PCL6Writer::kLegalPaper; return PCL6Writer::kLetterPaper;
case JobData::kA4: return PCL6Writer::kA4Paper; case JobData::kLegal:
case JobData::kExecutive: return PCL6Writer::kExecPaper; return PCL6Writer::kLegalPaper;
case JobData::kLedger: return PCL6Writer::kLedgerPaper; case JobData::kA4:
case JobData::kA3: return PCL6Writer::kA3Paper; return PCL6Writer::kA4Paper;
case JobData::kB5: return PCL6Writer::kB5Paper; 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: case JobData::kJapanesePostcard:
return PCL6Writer::kJPostcard; return PCL6Writer::kJPostcard;
case JobData::kA5: return PCL6Writer::kA5Paper; case JobData::kA5:
case JobData::kB4: return PCL6Writer::kJB4Paper; return PCL6Writer::kA5Paper;
case JobData::kB4:
return PCL6Writer::kJB4Paper;
/* /*
case : return PCL6Writer::kCOM10Envelope; case : return PCL6Writer::kCOM10Envelope;
case : return PCL6Writer::kMonarchEnvelope; 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) { switch (source) {
case JobData::kAuto: return PCL6Writer::kAutoSelect; case JobData::kAuto:
case JobData::kCassette1: return PCL6Writer::kDefaultSource; return PCL6Writer::kAutoSelect;
case JobData::kCassette2: return PCL6Writer::kEnvelopeTray; case JobData::kCassette1:
case JobData::kLower: return PCL6Writer::kLowerCassette; return PCL6Writer::kDefaultSource;
case JobData::kUpper: return PCL6Writer::kUpperCassette; case JobData::kCassette2:
case JobData::kMiddle: return PCL6Writer::kThirdCassette; return PCL6Writer::kEnvelopeTray;
case JobData::kManual: return PCL6Writer::kManualFeed; case JobData::kLower:
case JobData::kCassette3: return PCL6Writer::kMultiPurposeTray; 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: default:
return PCL6Writer::kAutoSelect; return PCL6Writer::kAutoSelect;
} }
} }
+11 -11
View File
@@ -3,7 +3,6 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
* Copyright 2003 Michael Pfeiffer. * Copyright 2003 Michael Pfeiffer.
*/ */
#ifndef __PCL6_H #ifndef __PCL6_H
#define __PCL6_H #define __PCL6_H
@@ -12,12 +11,15 @@
#include "PCL6Cap.h" #include "PCL6Cap.h"
#include "PCL6Writer.h" #include "PCL6Writer.h"
class Halftone; class Halftone;
class PCL6Driver : public GraphicsDriver, public PCL6WriterStream class PCL6Driver : public GraphicsDriver, public PCL6WriterStream
{ {
public: 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);
@@ -36,15 +38,13 @@ private:
PCL6Writer::MediaSource mediaSource(JobData::PaperSource source); PCL6Writer::MediaSource mediaSource(JobData::PaperSource source);
void move(int x, int y); void move(int x, int y);
void jobStart(); void jobStart();
void writeBitmap(const uchar* buffer, int outSize, int rowSize, int x, int y, int width, int height, int deltaRowSize); void writeBitmap(const uchar* buffer, int outSize, int rowSize,
void startRasterGraphics(int x, int y, int width, int height, PCL6Writer::Compression compressionMethod); 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 endRasterGraphics();
void rasterGraphics( void rasterGraphics(const uchar* buffer, int bufferSize,
const uchar *buffer, int dataSize, int rowSize, int height,
int bufferSize,
int dataSize,
int rowSize,
int height,
int compression_method); int compression_method);
void jobEnd(); void jobEnd();
@@ -53,4 +53,4 @@ private:
Halftone* fHalftone; Halftone* fHalftone;
}; };
#endif /* __PCL6_H */ #endif // __PCL6_H
+39 -27
View File
@@ -3,8 +3,8 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
* Copyright 2003-2007 Michael Pfeiffer. * Copyright 2003-2007 Michael Pfeiffer.
*/ */
#include "PCL6Cap.h" #include "PCL6Cap.h"
#include "PCL6Config.h" #include "PCL6Config.h"
#include "PCL6Writer.h" #include "PCL6Writer.h"
#include "PrinterData.h" #include "PrinterData.h"
@@ -136,10 +136,12 @@ const PaperCap b4(
const PaperSourceCap defaultSource("Default", false, JobData::kCassette1); const PaperSourceCap defaultSource("Default", false, JobData::kCassette1);
const PaperSourceCap autobin("Auto", true, JobData::kAuto); const PaperSourceCap autobin("Auto", true, JobData::kAuto);
const PaperSourceCap manualFeed("Manual Feed", false, JobData::kManual); const PaperSourceCap manualFeed("Manual Feed", false, JobData::kManual);
const PaperSourceCap multiPurposeTray("Multi Purpose Tray", false, JobData::kCassette3); const PaperSourceCap multiPurposeTray("Multi Purpose Tray", false,
JobData::kCassette3);
const PaperSourceCap upperCassette("Upper Cassette", false, JobData::kUpper); const PaperSourceCap upperCassette("Upper Cassette", false, JobData::kUpper);
const PaperSourceCap lowerCassette("Lower Cassette", false, JobData::kLower); const PaperSourceCap lowerCassette("Lower Cassette", false, JobData::kLower);
const PaperSourceCap envelopeTray("Envelope Tray", false, JobData::kCassette2); const PaperSourceCap envelopeTray("Envelope Tray", false,
JobData::kCassette2);
// since 2.0: // since 2.0:
const PaperSourceCap thridCassette("Thrid Cassette", false, JobData::kMiddle); const PaperSourceCap thridCassette("Thrid Cassette", false, JobData::kMiddle);
@@ -151,11 +153,14 @@ const ResolutionCap dpi1200("1200dpi", false, 1200, 1200);
const PrintStyleCap simplex("Simplex", true, JobData::kSimplex); const PrintStyleCap simplex("Simplex", true, JobData::kSimplex);
const PrintStyleCap duplex("Duplex", false, JobData::kDuplex); const PrintStyleCap duplex("Duplex", false, JobData::kDuplex);
const ProtocolClassCap pc1_1("PCL 6 Protocol Class 1.1", true, PCL6Writer::kProtocolClass1_1, const ProtocolClassCap pc1_1("PCL 6 Protocol Class 1.1", true,
"The printer driver supports the following features of protocol class 1.1:\n" PCL6Writer::kProtocolClass1_1,
"The printer driver supports the following features of protocol class 1.1:"
"\n"
"* Monochrome and Color Printing.\n" "* Monochrome and Color Printing.\n"
"* Paper Formats: Letter, Legal, A4, A3, A5 and Japanese Postcard.\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" "* Paper Sources: Auto, Default, Manual Feed, Multi-Purpose Tray, Upper "
"and Lower Cassette and Envelope Tray.\n"
"* Resolutions: 150, 300, 600 and 1200 DPI." "* Resolutions: 150, 300, 600 and 1200 DPI."
#if ENABLE_RLE_COMPRESSION #if ENABLE_RLE_COMPRESSION
"\n* Compression Method: RLE." "\n* Compression Method: RLE."
@@ -164,16 +169,18 @@ const ProtocolClassCap pc1_1("PCL 6 Protocol Class 1.1", true, PCL6Writer::kProt
#endif #endif
); );
const ProtocolClassCap pc2_0("PCL 6 Protocol Class 2.0", false, PCL6Writer::kProtocolClass2_0, const ProtocolClassCap pc2_0("PCL 6 Protocol Class 2.0", false,
"In addition to features of protocol class 1.1, the printer driver supports the " PCL6Writer::kProtocolClass2_0,
"following features of protocol class 2.0:\n" "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." "* Additonal Paper Source: Third Cassette."
// "\n* JPEG compression (not implemented yet)" // "\n* JPEG compression (not implemented yet)"
); );
const ProtocolClassCap pc2_1("PCL 6 Protocol Class 2.1", false, PCL6Writer::kProtocolClass2_1, const ProtocolClassCap pc2_1("PCL 6 Protocol Class 2.1", false,
"In addition to features of previous protocol classes, the printer driver supports the " PCL6Writer::kProtocolClass2_1,
"following features of protocol class 2.1:\n" "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." "* Additional Paper Format: B5."
#if ENABLE_DELTA_ROW_COMPRESSION #if ENABLE_DELTA_ROW_COMPRESSION
"\n* Additional Compression Method: Delta Row Compression." "\n* Additional Compression Method: Delta Row Compression."
@@ -181,8 +188,8 @@ const ProtocolClassCap pc2_1("PCL 6 Protocol Class 2.1", false, PCL6Writer::kPro
); );
// Disable until driver supports new features of protocol class 3.0 // 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, // const ProtocolClassCap pc3_0("PCL 6 Protocol Class 3.0", false,
//"Protocol Class 3.0"); // PCL6Writer::kProtocolClass3_0, "Protocol Class 3.0");
const PaperCap* papers1_1[] = { const PaperCap* papers1_1[] = {
&letter, &letter,
@@ -247,7 +254,8 @@ const ProtocolClassCap *protocolClasses[] = {
}; };
const ColorCap color("Color", false, JobData::kColor); 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 monochrome("Shades of Gray", true, JobData::kMonochrome);
const ColorCap* colors[] = { const ColorCap* colors[] = {
@@ -256,23 +264,25 @@ const ColorCap *colors[] = {
&monochrome &monochrome
}; };
PCL6Cap::PCL6Cap(const PrinterData* printer_data) PCL6Cap::PCL6Cap(const PrinterData* printer_data)
: PrinterCap(printer_data) :
PrinterCap(printer_data)
{ {
} }
int PCL6Cap::countCap(CapID capid) const
int
PCL6Cap::countCap(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) { if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1)
return sizeof(papers2_1) / sizeof(papers2_1[0]); return sizeof(papers2_1) / sizeof(papers2_1[0]);
}
return sizeof(papers1_1) / sizeof(papers1_1[0]); return sizeof(papers1_1) / sizeof(papers1_1[0]);
case kPaperSource: case kPaperSource:
if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) { if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0)
return sizeof(paperSources2_0) / sizeof(paperSources2_0[0]); return sizeof(paperSources2_0) / sizeof(paperSources2_0[0]);
}
return sizeof(paperSources1_1) / sizeof(paperSources1_1[0]); return sizeof(paperSources1_1) / sizeof(paperSources1_1[0]);
case kResolution: case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]); return sizeof(resolutions) / sizeof(resolutions[0]);
@@ -287,18 +297,18 @@ int PCL6Cap::countCap(CapID capid) const
} }
} }
const BaseCap **PCL6Cap::enumCap(CapID capid) const
const BaseCap**
PCL6Cap::enumCap(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1) { if (getProtocolClass() >= PCL6Writer::kProtocolClass2_1)
return (const BaseCap **)papers2_1; return (const BaseCap **)papers2_1;
}
return (const BaseCap**)papers1_1; return (const BaseCap**)papers1_1;
case kPaperSource: case kPaperSource:
if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0) { if (getProtocolClass() >= PCL6Writer::kProtocolClass2_0)
return (const BaseCap **)paperSources2_0; return (const BaseCap **)paperSources2_0;
}
return (const BaseCap**)paperSources1_1; return (const BaseCap**)paperSources1_1;
case kResolution: case kResolution:
return (const BaseCap**)resolutions; return (const BaseCap**)resolutions;
@@ -313,7 +323,9 @@ const BaseCap **PCL6Cap::enumCap(CapID capid) const
} }
} }
bool PCL6Cap::isSupport(CapID capid) const
bool
PCL6Cap::isSupport(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
+3 -2
View File
@@ -2,12 +2,13 @@
* PCL6Cap.h * PCL6Cap.h
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/ */
#ifndef __PCL6CAP_H #ifndef __PCL6CAP_H
#define __PCL6CAP_H #define __PCL6CAP_H
#include "PrinterCap.h" #include "PrinterCap.h"
class PCL6Cap : public PrinterCap { class PCL6Cap : public PrinterCap {
public: public:
PCL6Cap(const PrinterData* printer_data); PCL6Cap(const PrinterData* printer_data);
@@ -16,4 +17,4 @@ public:
virtual const BaseCap **enumCap(CapID) const; virtual const BaseCap **enumCap(CapID) const;
}; };
#endif /* __PCL6CAP_H */ #endif // __PCL6CAP_H
+2 -3
View File
@@ -2,13 +2,13 @@
* PCL6Config.cpp * PCL6Config.cpp
* Copyright 2005 Michael Pfeiffer. * Copyright 2005 Michael Pfeiffer.
*/ */
#ifndef _PCL6_CONFIG #ifndef _PCL6_CONFIG
#define _PCL6_CONFIG #define _PCL6_CONFIG
// Compression method configuration // Compression method configuration
// Set to 0 to disable compression and to 1 to enable compression // 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 // Run-Length-Encoding Compression
#define ENABLE_RLE_COMPRESSION 1 #define ENABLE_RLE_COMPRESSION 1
@@ -27,4 +27,3 @@
#define DISPLAY_COMPRESSION_STATISTICS 0 #define DISPLAY_COMPRESSION_STATISTICS 0
#endif #endif
+11 -4
View File
@@ -4,14 +4,19 @@
* Copyright 2003 Michael Pfeiffer. * Copyright 2003 Michael Pfeiffer.
*/ */
#include "PCL6.h" #include "PCL6.h"
#include "PCL6Cap.h" #include "PCL6Cap.h"
#include "PrinterDriver.h" #include "PrinterDriver.h"
class PCL6PrinterDriver : public PrinterDriver class PCL6PrinterDriver : public PrinterDriver
{ {
public: public:
PCL6PrinterDriver(BNode* printerFolder) : PrinterDriver(printerFolder) {} PCL6PrinterDriver(BNode* printerFolder)
:
PrinterDriver(printerFolder)
{}
const char* GetSignature() const const char* GetSignature() const
{ {
@@ -38,14 +43,16 @@ public:
return new PCL6Cap(printerData); 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); return new PCL6Driver(settings, printerData, printerCap);
} }
}; };
PrinterDriver* instantiate_printer_driver(BNode* printerFolder)
PrinterDriver*
instantiate_printer_driver(BNode* printerFolder)
{ {
return new PCL6PrinterDriver(printerFolder); return new PCL6PrinterDriver(printerFolder);
} }
@@ -1,8 +1,11 @@
/* /*
** PCL6Rasterizer.cpp ** PCL6Rasterizer.cpp
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#include "PCL6Rasterizer.h" #include "PCL6Rasterizer.h"
#include <stdio.h> #include <stdio.h>
@@ -22,17 +25,22 @@ static void dump_bits(uchar *buffer, int size);
#endif #endif
// MonochromeRasterizer
// #pragma - MonochromeRasterizer
MonochromeRasterizer::MonochromeRasterizer(Halftone* halftone) MonochromeRasterizer::MonochromeRasterizer(Halftone* halftone)
: PCL6Rasterizer(halftone) :
, fOutBuffer(NULL) PCL6Rasterizer(halftone),
fOutBuffer(NULL)
{} {}
void void
MonochromeRasterizer::InitializeBuffer() { MonochromeRasterizer::InitializeBuffer()
{
fWidthByte = RowBufferSize(GetWidth(), 1, 1); 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); fOutRowSize = RowBufferSize(GetWidth(), 1, 4);
fPadBytes = fOutRowSize - fWidthByte; fPadBytes = fOutRowSize - fWidthByte;
// Total size // Total size
@@ -41,21 +49,22 @@ MonochromeRasterizer::InitializeBuffer() {
fCurrentLine = GetOutBuffer(); fCurrentLine = GetOutBuffer();
} }
const void* const void*
MonochromeRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) { MonochromeRasterizer::RasterizeLine(int x, int y,
const ColorRGB32Little* source)
{
GetHalftone()->dither(fCurrentLine, (const uchar*)source, x, y, GetWidth()); GetHalftone()->dither(fCurrentLine, (const uchar*)source, x, y, GetWidth());
uchar* out = fCurrentLine; uchar* out = fCurrentLine;
// invert pixels // invert pixels
for (int w = fWidthByte; w > 0; w --, out ++) { for (int w = fWidthByte; w > 0; w --, out ++)
*out = ~*out; *out = ~*out;
}
// pad with 0s // pad with zeros
for (int w = fPadBytes; w > 0; w --, out ++) { for (int w = fPadBytes; w > 0; w --, out ++)
*out = 0; *out = 0;
}
void* result = fCurrentLine; void* result = fCurrentLine;
fCurrentLine += fOutRowSize; fCurrentLine += fOutRowSize;
@@ -63,12 +72,15 @@ MonochromeRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source
} }
// ColorRGBRasterizer // #pragma - ColorRGBRasterizer
ColorRGBRasterizer::ColorRGBRasterizer(Halftone* halftone) ColorRGBRasterizer::ColorRGBRasterizer(Halftone* halftone)
: PCL6Rasterizer(halftone) :
PCL6Rasterizer(halftone)
{} {}
void void
ColorRGBRasterizer::InitializeBuffer() { ColorRGBRasterizer::InitializeBuffer() {
fWidthByte = RowBufferSize(GetWidth(), 24, 1); fWidthByte = RowBufferSize(GetWidth(), 24, 1);
@@ -81,9 +93,11 @@ ColorRGBRasterizer::InitializeBuffer() {
fCurrentLine = GetOutBuffer(); fCurrentLine = GetOutBuffer();
} }
const void *
ColorRGBRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) {
const void*
ColorRGBRasterizer::RasterizeLine(int x, int y,
const ColorRGB32Little* source)
{
uchar* out = fCurrentLine; uchar* out = fCurrentLine;
int width = GetWidth(); int width = GetWidth();
for (int w = width; w > 0; w --) { for (int w = width; w > 0; w --) {
@@ -94,9 +108,8 @@ ColorRGBRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source)
} }
// pad with 0s // pad with 0s
for (int w = fPadBytes; w > 0; w --, out ++) { for (int w = fPadBytes; w > 0; w --, out ++)
*out = 0; *out = 0;
}
void* result = fCurrentLine; void* result = fCurrentLine;
fCurrentLine += fOutRowSize; fCurrentLine += fOutRowSize;
@@ -104,19 +117,21 @@ ColorRGBRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source)
} }
// ColorRasterizer // #pragma - ColorRasterizer
ColorRasterizer::ColorRasterizer::ColorRasterizer(Halftone* halftone) ColorRasterizer::ColorRasterizer::ColorRasterizer(Halftone* halftone)
: PCL6Rasterizer(halftone) :
PCL6Rasterizer(halftone)
{ {
for (int plane = 0; plane < 3; plane ++) { for (int plane = 0; plane < 3; plane ++)
fPlaneBuffers[plane] = NULL; fPlaneBuffers[plane] = NULL;
}
halftone->setPlanes(Halftone::kPlaneRGB1); halftone->setPlanes(Halftone::kPlaneRGB1);
halftone->setBlackValue(Halftone::kLowValueMeansBlack); halftone->setBlackValue(Halftone::kLowValueMeansBlack);
} }
ColorRasterizer::~ColorRasterizer() { ColorRasterizer::~ColorRasterizer() {
for (int plane = 0; plane < 3; plane ++) { for (int plane = 0; plane < 3; plane ++) {
delete fPlaneBuffers[plane]; delete fPlaneBuffers[plane];
@@ -124,6 +139,7 @@ ColorRasterizer::~ColorRasterizer() {
} }
} }
void void
ColorRasterizer::InitializeBuffer() { ColorRasterizer::InitializeBuffer() {
fWidthByte = RowBufferSize(GetWidth(), 3, 1); fWidthByte = RowBufferSize(GetWidth(), 3, 1);
@@ -141,21 +157,24 @@ ColorRasterizer::InitializeBuffer() {
} }
} }
enum { enum {
kRed = 1, kRed = 1,
kGreen = 2, kGreen = 2,
kBlue = 4, 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 // dither each color component
for (int plane = 0; plane < 3; plane ++) { for (int plane = 0; plane < 3; plane ++)
GetHalftone()->dither(fPlaneBuffers[plane], (const uchar*)source, x, y, GetWidth()); GetHalftone()->dither(fPlaneBuffers[plane], (const uchar*)source, x, y,
} GetWidth());
DUMP_BITS((stderr, "red "), fPlaneBuffers[0], fPlaneBufferSize); DUMP_BITS((stderr, "red "), fPlaneBuffers[0], fPlaneBufferSize);
DUMP_BITS((stderr, "green "), fPlaneBuffers[1], fPlaneBufferSize); DUMP_BITS((stderr, "green "), fPlaneBuffers[1], fPlaneBufferSize);
@@ -171,6 +190,7 @@ ColorRasterizer::RasterizeLine(int x, int y, const ColorRGB32Little* source) {
return result; return result;
} }
void void
ColorRasterizer::MergePlaneBuffersToCurrentLine() ColorRasterizer::MergePlaneBuffersToCurrentLine()
{ {
@@ -183,9 +203,9 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
// iterate over the three plane buffers // iterate over the three plane buffers
for (int i = 0; i < fPlaneBufferSize; i ++) { for (int i = 0; i < fPlaneBufferSize; i ++) {
int pixels = 8; int pixels = 8;
if (remainingPixels < 8) { if (remainingPixels < 8)
pixels = remainingPixels; pixels = remainingPixels;
}
remainingPixels -= pixels; remainingPixels -= pixels;
if (remainingPixels >= 8) { if (remainingPixels >= 8) {
@@ -244,21 +264,17 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
for (; pixels > 0; pixels --) { for (; pixels > 0; pixels --) {
int rgb = 0; int rgb = 0;
if (red & mask) { if (red & mask)
rgb |= kRed; rgb |= kRed;
} if (green & mask)
if (green & mask) {
rgb |= kGreen; rgb |= kGreen;
} if (blue & mask)
if (blue & mask) {
rgb |= kBlue; rgb |= kBlue;
}
for (int plane = 0; plane < 3; plane ++) { for (int plane = 0; plane < 3; plane ++) {
// copy pixel value to output value // copy pixel value to output value
if (rgb & (1 << plane)) { if (rgb & (1 << plane))
value |= outMask; value |= outMask;
}
// increment output mask // increment output mask
if (outMask == 0x01) { if (outMask == 0x01) {
@@ -267,10 +283,9 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
*out = value; *out = value;
out ++; out ++;
value = 0; value = 0;
} else { } else
outMask >>= 1; outMask >>= 1;
} }
}
mask >>= 1; mask >>= 1;
} }
} }
@@ -287,19 +302,19 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
out ++; out ++;
} }
if (out - fCurrentLine != fWidthByte) { if (out - fCurrentLine != fWidthByte)
fprintf(stderr, "Error buffer overflow: %d != %d\n", fWidthByte, (int)(out - fCurrentLine)); fprintf(stderr, "Error buffer overflow: %d != %d\n", fWidthByte,
} static_cast<int>(out - fCurrentLine));
// pad with 0s // pad with zeros
for (int w = fPadBytes; w > 0; w --, out ++) { for (int w = fPadBytes; w > 0; w --, out ++)
*out = 0xff; *out = 0xff;
if (out - fCurrentLine != fOutRowSize)
fprintf(stderr, "Error buffer overflow: %d != %d\n", fOutRowSize,
static_cast<int>(out - fCurrentLine));
} }
if (out - fCurrentLine != fOutRowSize) {
fprintf(stderr, "Error buffer overflow: %d != %d\n", fOutRowSize, (int)(out - fCurrentLine));
}
}
#ifdef _PCL6_RASTERIZER_TEST_ #ifdef _PCL6_RASTERIZER_TEST_
#include <Application.h> #include <Application.h>
@@ -309,7 +324,9 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
#define COLUMNS 40 #define COLUMNS 40
#define BIT_COLUMNS 6 #define BIT_COLUMNS 6
static void dump(uchar *buffer, int size)
static void
dump(uchar* buffer, int size)
{ {
int x = 0; int x = 0;
for (int i = 0; i < size; i ++) { for (int i = 0; i < size; i ++) {
@@ -328,7 +345,9 @@ static void dump(uchar *buffer, int size)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
static void dump_bits(uchar *buffer, int size)
static void
dump_bits(uchar* buffer, int size)
{ {
int x = 0; int x = 0;
for (int i = 0; i < size; i ++) { for (int i = 0; i < size; i ++) {
@@ -354,16 +373,20 @@ static void dump_bits(uchar *buffer, int size)
fprintf(stderr, "\n"); 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<ColorRGB32Little*>(_row);
for (int i = 0; i < width; i ++) { for (int i = 0; i < width; i ++) {
*row = color; *row = color;
row ++; row ++;
} }
} }
static void initializeBitmap(BBitmap *bitmap, int width, int height)
static void
initializeBitmap(BBitmap* bitmap, int width, int height)
{ {
int bpr = bitmap->BytesPerRow(); int bpr = bitmap->BytesPerRow();
uchar* row = (uchar*)bitmap->Bits(); uchar* row = (uchar*)bitmap->Bits();
@@ -404,7 +427,9 @@ static void initializeBitmap(BBitmap *bitmap, int width, int height)
} }
} }
int main()
int
main()
{ {
const int width = 10; const int width = 10;
const int height = 4; const int height = 4;
@@ -428,4 +453,4 @@ int main()
} }
} }
#endif #endif // _PCL6_RASTERIZER_TEST_
+47 -19
View File
@@ -1,21 +1,25 @@
/* /*
** PCL6Rasterizer.h ** PCL6Rasterizer.h
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#ifndef _PCL6_RASTERIZER_H #ifndef _PCL6_RASTERIZER_H
#define _PCL6_RASTERIZER_H #define _PCL6_RASTERIZER_H
#include "Rasterizer.h" #include "Rasterizer.h"
class PCL6Rasterizer : public Rasterizer class PCL6Rasterizer : public Rasterizer
{ {
public: public:
PCL6Rasterizer(Halftone* halftone) PCL6Rasterizer(Halftone* halftone)
: Rasterizer(halftone) :
, fOutBuffer(NULL) Rasterizer(halftone),
, fOutBufferSize(0) fOutBuffer(NULL),
{ fOutBufferSize(0)
} {}
~PCL6Rasterizer() ~PCL6Rasterizer()
{ {
@@ -23,23 +27,32 @@ public:
fOutBuffer = NULL; fOutBuffer = NULL;
} }
void SetOutBufferSize(int size) { fOutBufferSize = size; } void SetOutBufferSize(int size)
int GetOutBufferSize() { return fOutBufferSize; } {
fOutBufferSize = size;
}
int GetOutBufferSize()
{
return fOutBufferSize;
}
uchar* GetOutBuffer()
{
return fOutBuffer;
}
uchar *GetOutBuffer() { return fOutBuffer; } virtual void InitializeBuffer()
{
virtual void InitializeBuffer() {
fOutBuffer = new uchar[fOutBufferSize]; fOutBuffer = new uchar[fOutBufferSize];
} }
virtual int GetOutRowSize() = 0; virtual int GetOutRowSize() = 0;
private: private:
uchar* fOutBuffer; uchar* fOutBuffer;
int fOutBufferSize; int fOutBufferSize;
}; };
class MonochromeRasterizer : public PCL6Rasterizer class MonochromeRasterizer : public PCL6Rasterizer
{ {
public: public:
@@ -47,9 +60,13 @@ public:
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: private:
int fWidthByte; int fWidthByte;
@@ -60,6 +77,7 @@ private:
uchar* fCurrentLine; uchar* fCurrentLine;
}; };
// Output format RGB 8bit per channel // Output format RGB 8bit per channel
class ColorRGBRasterizer : public PCL6Rasterizer class ColorRGBRasterizer : public PCL6Rasterizer
{ {
@@ -68,9 +86,13 @@ public:
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: private:
int fWidthByte; int fWidthByte;
@@ -79,8 +101,10 @@ private:
uchar* fCurrentLine; uchar* fCurrentLine;
}; };
typedef uchar* PlaneBuffer; typedef uchar* PlaneBuffer;
// Output format: RGB 1bit per channel // Output format: RGB 1bit per channel
// Class Halftone is used for dithering // Class Halftone is used for dithering
class ColorRasterizer : public PCL6Rasterizer class ColorRasterizer : public PCL6Rasterizer
@@ -92,9 +116,13 @@ public:
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: private:
void MergePlaneBuffersToCurrentLine(); void MergePlaneBuffersToCurrentLine();
@@ -108,4 +136,4 @@ private:
PlaneBuffer fPlaneBuffers[3]; PlaneBuffer fPlaneBuffers[3];
}; };
#endif #endif // _PCL6_RASTERIZER_H
+143 -56
View File
@@ -1,8 +1,11 @@
/* /*
** PCL6Writer.cpp ** PCL6Writer.cpp
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#include "PCL6Writer.h" #include "PCL6Writer.h"
#include <ByteOrder.h> #include <ByteOrder.h>
@@ -10,53 +13,66 @@
#define BYTE_AT(lvalue, index) (((uint8*)(&lvalue))[index]) #define BYTE_AT(lvalue, index) (((uint8*)(&lvalue))[index])
PCL6Writer::PCL6Writer(PCL6WriterStream* stream, uint32 bufferSize) PCL6Writer::PCL6Writer(PCL6WriterStream* stream, uint32 bufferSize)
: fStream(stream), :
fStream(stream),
fBuffer(new uint8[bufferSize]), fBuffer(new uint8[bufferSize]),
fSize(bufferSize), fSize(bufferSize),
fIndex(0) fIndex(0)
{ {
} }
PCL6Writer::~PCL6Writer() {
PCL6Writer::~PCL6Writer()
{
delete fBuffer; delete fBuffer;
fBuffer = NULL; fBuffer = NULL;
} }
// throws TransportException // throws TransportException
void void
PCL6Writer::Append(uint8 value) { PCL6Writer::Append(uint8 value)
if (fIndex == fSize) { {
if (fIndex == fSize)
Flush(); Flush();
}
fBuffer[fIndex] = value; fBuffer[fIndex] = value;
fIndex ++; fIndex ++;
} }
void void
PCL6Writer::Flush() { PCL6Writer::Flush()
{
if (fIndex > 0) { if (fIndex > 0) {
fStream->write(fBuffer, fIndex); fStream->write(fBuffer, fIndex);
fIndex = 0; fIndex = 0;
} }
} }
void void
PCL6Writer::Append(int16 value) { PCL6Writer::Append(int16 value)
{
int16 v = B_HOST_TO_LENDIAN_INT16(value); int16 v = B_HOST_TO_LENDIAN_INT16(value);
Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 0));
Append(BYTE_AT(v, 1)); Append(BYTE_AT(v, 1));
} }
void void
PCL6Writer::Append(uint16 value) { PCL6Writer::Append(uint16 value)
{
int16 v = B_HOST_TO_LENDIAN_INT16(value); int16 v = B_HOST_TO_LENDIAN_INT16(value);
Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 0));
Append(BYTE_AT(v, 1)); Append(BYTE_AT(v, 1));
} }
void void
PCL6Writer::Append(int32 value) { PCL6Writer::Append(int32 value)
{
int32 v = B_HOST_TO_LENDIAN_INT32(value); int32 v = B_HOST_TO_LENDIAN_INT32(value);
Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 0));
Append(BYTE_AT(v, 1)); Append(BYTE_AT(v, 1));
@@ -64,8 +80,10 @@ PCL6Writer::Append(int32 value) {
Append(BYTE_AT(v, 3)); Append(BYTE_AT(v, 3));
} }
void void
PCL6Writer::Append(uint32 value) { PCL6Writer::Append(uint32 value)
{
int32 v = B_HOST_TO_LENDIAN_INT32(value); int32 v = B_HOST_TO_LENDIAN_INT32(value);
Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 0));
Append(BYTE_AT(v, 1)); Append(BYTE_AT(v, 1));
@@ -73,8 +91,10 @@ PCL6Writer::Append(uint32 value) {
Append(BYTE_AT(v, 3)); Append(BYTE_AT(v, 3));
} }
void void
PCL6Writer::Append(float value) { PCL6Writer::Append(float value)
{
float v = B_HOST_TO_LENDIAN_FLOAT(value); float v = B_HOST_TO_LENDIAN_FLOAT(value);
Append(BYTE_AT(v, 0)); Append(BYTE_AT(v, 0));
Append(BYTE_AT(v, 1)); Append(BYTE_AT(v, 1));
@@ -82,8 +102,10 @@ PCL6Writer::Append(float value) {
Append(BYTE_AT(v, 3)); Append(BYTE_AT(v, 3));
} }
void void
PCL6Writer::Append(const uint8* data, uint32 size) { PCL6Writer::Append(const uint8* data, uint32 size)
{
for (uint32 i = 0; i < size; i++) { for (uint32 i = 0; i < size; i++) {
Append(data[i]); Append(data[i]);
} }
@@ -91,7 +113,8 @@ PCL6Writer::Append(const uint8* data, uint32 size) {
void void
PCL6Writer::AppendString(const char *string) { PCL6Writer::AppendString(const char* string)
{
uint8 ch = *string; uint8 ch = *string;
while (ch != 0) { while (ch != 0) {
Append(ch); Append(ch);
@@ -100,60 +123,80 @@ PCL6Writer::AppendString(const char *string) {
} }
} }
void void
PCL6Writer::AppendOperator(Operator op) { PCL6Writer::AppendOperator(Operator op)
{
Append((uint8)op); Append((uint8)op);
} }
void void
PCL6Writer::AppendAttribute(Attribute attr) { PCL6Writer::AppendAttribute(Attribute attr)
{
AppendDataTag(k8BitAttrId); AppendDataTag(k8BitAttrId);
Append((uint8)attr); Append((uint8)attr);
} }
void void
PCL6Writer::AppendDataTag(DataTag tag) { PCL6Writer::AppendDataTag(DataTag tag)
{
Append((uint8)tag); Append((uint8)tag);
} }
void void
PCL6Writer::AppendData(uint8 value) { PCL6Writer::AppendData(uint8 value)
{
AppendDataTag(kUByteData); AppendDataTag(kUByteData);
Append(value); Append(value);
} }
void void
PCL6Writer::AppendData(int16 value) { PCL6Writer::AppendData(int16 value)
{
AppendDataTag(kSInt16Data); AppendDataTag(kSInt16Data);
Append(value); Append(value);
} }
void void
PCL6Writer::AppendData(uint16 value) { PCL6Writer::AppendData(uint16 value)
{
AppendDataTag(kUInt16Data); AppendDataTag(kUInt16Data);
Append(value); Append(value);
} }
void void
PCL6Writer::AppendData(int32 value) { PCL6Writer::AppendData(int32 value)
{
AppendDataTag(kSInt32Data); AppendDataTag(kSInt32Data);
Append(value); Append(value);
} }
void void
PCL6Writer::AppendData(uint32 value) { PCL6Writer::AppendData(uint32 value)
{
AppendDataTag(kUInt32Data); AppendDataTag(kUInt32Data);
Append(value); Append(value);
} }
void void
PCL6Writer::AppendData(float value) { PCL6Writer::AppendData(float value)
{
AppendDataTag(kReal32Data); AppendDataTag(kReal32Data);
Append(value); Append(value);
} }
void void
PCL6Writer::EmbeddedDataPrefix(uint32 size) { PCL6Writer::EmbeddedDataPrefix(uint32 size)
{
if (size < 256) { if (size < 256) {
AppendDataTag(kEmbeddedDataByte); AppendDataTag(kEmbeddedDataByte);
Append((uint8)size); Append((uint8)size);
@@ -163,59 +206,71 @@ PCL6Writer::EmbeddedDataPrefix(uint32 size) {
} }
} }
void void
PCL6Writer::EmbeddedDataPrefix32(uint32 size) { PCL6Writer::EmbeddedDataPrefix32(uint32 size)
{
AppendDataTag(kEmbeddedData); AppendDataTag(kEmbeddedData);
Append(size); Append(size);
} }
void void
PCL6Writer::AppendDataXY(uint8 x, uint8 y) { PCL6Writer::AppendDataXY(uint8 x, uint8 y)
{
AppendDataTag(kUByteXY); AppendDataTag(kUByteXY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::AppendDataXY(int16 x, int16 y) { PCL6Writer::AppendDataXY(int16 x, int16 y)
{
AppendDataTag(kSInt16XY); AppendDataTag(kSInt16XY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::AppendDataXY(uint16 x, uint16 y) { PCL6Writer::AppendDataXY(uint16 x, uint16 y)
{
AppendDataTag(kUInt16XY); AppendDataTag(kUInt16XY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::AppendDataXY(int32 x, int32 y) { PCL6Writer::AppendDataXY(int32 x, int32 y)
{
AppendDataTag(kSInt32XY); AppendDataTag(kSInt32XY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::AppendDataXY(uint32 x, uint32 y) { PCL6Writer::AppendDataXY(uint32 x, uint32 y)
{
AppendDataTag(kUInt32XY); AppendDataTag(kUInt32XY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::AppendDataXY(float x, float y) { PCL6Writer::AppendDataXY(float x, float y)
{
AppendDataTag(kReal32XY); AppendDataTag(kReal32XY);
Append(x); Append(y); Append(x); Append(y);
} }
void void
PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char* comment) PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char* comment)
{ {
BString string; BString string;
AppendString("\033%-12345X@PJL JOB\n" AppendString("\033%-12345X@PJL JOB\n@PJL SET RESOLUTION=");
"@PJL SET RESOLUTION=");
string << dpi; string << dpi;
AppendString(string.String()); AppendString(string.String());
AppendString("\n" AppendString("\n@PJL ENTER LANGUAGE=PCLXL\n) HP-PCL XL;");
"@PJL ENTER LANGUAGE=PCLXL\n"
") HP-PCL XL;");
const char* pc = ""; const char* pc = "";
switch (protocolClass) { switch (protocolClass) {
@@ -242,16 +297,18 @@ PCL6Writer::PJLHeader(ProtocolClass protocolClass, int dpi, const char *comment)
AppendString("\n"); AppendString("\n");
} }
void void
PCL6Writer::PJLFooter() PCL6Writer::PJLFooter()
{ {
AppendString("\033%-12345X@PJL EOJ\n" AppendString("\033%-12345X@PJL EOJ\n\033%-12345X");
"\033%-12345X");
} }
void void
PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, ErrorReporting errorReporting) { PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure,
ErrorReporting errorReporting)
{
AppendDataXY(xres, yres); AppendDataXY(xres, yres);
AppendAttribute(kUnitsPerMeasure); AppendAttribute(kUnitsPerMeasure);
@@ -264,13 +321,17 @@ PCL6Writer::BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure,
AppendOperator(kBeginSession); AppendOperator(kBeginSession);
} }
void void
PCL6Writer::EndSession() { PCL6Writer::EndSession()
{
AppendOperator(kEndSession); AppendOperator(kEndSession);
} }
void void
PCL6Writer::OpenDataSource() { PCL6Writer::OpenDataSource()
{
AppendData((uint8)kDefaultDataSource); AppendData((uint8)kDefaultDataSource);
AppendAttribute(kSourceType); AppendAttribute(kSourceType);
@@ -280,14 +341,18 @@ PCL6Writer::OpenDataSource() {
AppendOperator(kOpenDataSource); AppendOperator(kOpenDataSource);
} }
void void
PCL6Writer::CloseDataSource() { PCL6Writer::CloseDataSource()
{
AppendOperator(kCloseDataSource); AppendOperator(kCloseDataSource);
} }
void void
PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource) { PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize,
MediaSource mediaSource)
{
AppendData((uint8)orientation); AppendData((uint8)orientation);
AppendAttribute(kOrientation); AppendAttribute(kOrientation);
@@ -300,8 +365,11 @@ PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource
AppendOperator(kBeginPage); AppendOperator(kBeginPage);
} }
void 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); AppendData((uint8)orientation);
AppendAttribute(kOrientation); AppendAttribute(kOrientation);
@@ -320,8 +388,10 @@ PCL6Writer::BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource
AppendOperator(kBeginPage); AppendOperator(kBeginPage);
} }
void void
PCL6Writer::EndPage(uint16 copies) { PCL6Writer::EndPage(uint16 copies)
{
// if (copies != 1) { // if (copies != 1) {
AppendData(copies); AppendData(copies);
AppendAttribute(kPageCopies); AppendAttribute(kPageCopies);
@@ -332,47 +402,58 @@ PCL6Writer::EndPage(uint16 copies) {
void void
PCL6Writer::SetPageOrigin(int16 x, int16 y) { PCL6Writer::SetPageOrigin(int16 x, int16 y)
{
AppendDataXY(x, y); AppendDataXY(x, y);
AppendAttribute(kPageOrigin); AppendAttribute(kPageOrigin);
AppendOperator(kSetPageOrigin); AppendOperator(kSetPageOrigin);
} }
void void
PCL6Writer::SetColorSpace(ColorSpace colorSpace) { PCL6Writer::SetColorSpace(ColorSpace colorSpace)
{
AppendData((uint8)colorSpace); AppendData((uint8)colorSpace);
AppendAttribute(kColorSpace); AppendAttribute(kColorSpace);
AppendOperator(kSetColorSpace); AppendOperator(kSetColorSpace);
} }
void void
PCL6Writer::SetPaintTxMode(Transparency transparency) { PCL6Writer::SetPaintTxMode(Transparency transparency)
{
AppendData((uint8)transparency); AppendData((uint8)transparency);
AppendAttribute(kTxMode); AppendAttribute(kTxMode);
AppendOperator(kSetPaintTxMode); AppendOperator(kSetPaintTxMode);
} }
void void
PCL6Writer::SetSourceTxMode(Transparency transparency) { PCL6Writer::SetSourceTxMode(Transparency transparency)
{
AppendData((uint8)transparency); AppendData((uint8)transparency);
AppendAttribute(kTxMode); AppendAttribute(kTxMode);
AppendOperator(kSetSourceTxMode); AppendOperator(kSetSourceTxMode);
} }
void void
PCL6Writer::SetROP(uint8 rop) { PCL6Writer::SetROP(uint8 rop)
{
AppendData((uint8)rop); AppendData((uint8)rop);
AppendAttribute(kROP3); AppendAttribute(kROP3);
AppendOperator(kSetROP); AppendOperator(kSetROP);
} }
void void
PCL6Writer::SetCursor(int16 x, int16 y) { PCL6Writer::SetCursor(int16 x, int16 y)
{
AppendDataXY(x, y); AppendDataXY(x, y);
AppendAttribute(kPoint); AppendAttribute(kPoint);
@@ -381,7 +462,10 @@ PCL6Writer::SetCursor(int16 x, int16 y) {
void void
PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth, uint16 destHeight) { PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth,
uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth,
uint16 destHeight)
{
AppendData((uint8)colorMapping); AppendData((uint8)colorMapping);
AppendAttribute(kColorMapping); AppendAttribute(kColorMapping);
@@ -400,8 +484,11 @@ PCL6Writer::BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16
AppendOperator(kBeginImage); AppendOperator(kBeginImage);
} }
void void
PCL6Writer::ReadImage(Compression compression, uint16 startLine, uint16 blockHeight, uint8 padBytes) { PCL6Writer::ReadImage(Compression compression, uint16 startLine,
uint16 blockHeight, uint8 padBytes)
{
AppendData(startLine); AppendData(startLine);
AppendAttribute(kStartLine); AppendAttribute(kStartLine);
@@ -423,9 +510,9 @@ PCL6Writer::ReadImage(Compression compression, uint16 startLine, uint16 blockHei
AppendOperator(kReadImage); AppendOperator(kReadImage);
} }
void void
PCL6Writer::EndImage() { PCL6Writer::EndImage()
{
AppendOperator(kEndImage); AppendOperator(kEndImage);
} }
+25 -11
View File
@@ -1,13 +1,16 @@
/* /*
** PCL6Writer.h ** PCL6Writer.h
** Copyright 2005, Michael Pfeiffer, [email protected]. All rights reserved. ** Copyright 2005, Michael Pfeiffer, [email protected].
** All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
*/ */
#ifndef _PCL6_WRITER_H #ifndef _PCL6_WRITER_H
#define _PCL6_WRITER_H #define _PCL6_WRITER_H
#include <SupportDefs.h> #include <SupportDefs.h>
class PCL6Driver; class PCL6Driver;
@@ -17,6 +20,7 @@ public:
virtual void write(const uint8* data, uint32 size) = 0; virtual void write(const uint8* data, uint32 size) = 0;
}; };
class PCL6Writer { class PCL6Writer {
public: public:
// DO NOT change this enumerations the order is important!!! // DO NOT change this enumerations the order is important!!!
@@ -144,24 +148,31 @@ public:
kProtocolClass3_0, kProtocolClass3_0,
}; };
PCL6Writer(PCL6WriterStream* stream, uint32 bufferSize = 16 * 1024); PCL6Writer(PCL6WriterStream* stream,
uint32 bufferSize = 16 * 1024);
virtual ~PCL6Writer(); virtual ~PCL6Writer();
// these methods throw TransportException if data could not // these methods throw TransportException if data could not
// be written // be written
void Flush(); void Flush();
void PJLHeader(ProtocolClass protocolClass, int dpi, const char *comment = NULL); void PJLHeader(ProtocolClass protocolClass, int dpi,
const char* comment = NULL);
void PJLFooter(); void PJLFooter();
void BeginSession(uint16 xres, uint16 yres, UnitOfMeasure unitOfMeasure, ErrorReporting errorReporting); void BeginSession(uint16 xres, uint16 yres,
UnitOfMeasure unitOfMeasure,
ErrorReporting errorReporting);
void EndSession(); void EndSession();
void OpenDataSource(); void OpenDataSource();
void CloseDataSource(); void CloseDataSource();
void BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource); void BeginPage(Orientation orientation, MediaSize mediaSize,
void BeginPage(Orientation orientation, MediaSize mediaSize, MediaSource mediaSource, DuplexPageMode duplexPageMode, MediaSide mediaSide); MediaSource mediaSource);
void BeginPage(Orientation orientation, MediaSize mediaSize,
MediaSource mediaSource, DuplexPageMode duplexPageMode,
MediaSide mediaSide);
void EndPage(uint16 copies); void EndPage(uint16 copies);
void SetPageOrigin(int16 x, int16 y); void SetPageOrigin(int16 x, int16 y);
@@ -171,8 +182,11 @@ public:
void SetROP(uint8 rop); void SetROP(uint8 rop);
void SetCursor(int16 x, int16 y); void SetCursor(int16 x, int16 y);
void BeginImage(ColorMapping colorMapping, ColorDepth colorDepth, uint16 sourceWidth, uint16 sourceHeight, uint16 destWidth, uint16 destHeight); void BeginImage(ColorMapping colorMapping, ColorDepth colorDepth,
void ReadImage(Compression compression, uint16 startLine, uint16 blockHeight, uint8 padBytes = 4); uint16 sourceWidth, uint16 sourceHeight,
uint16 destWidth, uint16 destHeight);
void ReadImage(Compression compression, uint16 startLine,
uint16 blockHeight, uint8 padBytes = 4);
void EndImage(); void EndImage();
void EmbeddedDataPrefix(uint32 size); void EmbeddedDataPrefix(uint32 size);
void EmbeddedDataPrefix32(uint32 size); void EmbeddedDataPrefix32(uint32 size);
@@ -352,11 +366,11 @@ private:
void AppendAttribute(Attribute attr); void AppendAttribute(Attribute attr);
void AppendDataTag(DataTag tag); void AppendDataTag(DataTag tag);
PCL6WriterStream *fStream; // the stream used for writing the generated PCL6 data PCL6WriterStream* fStream;
// the stream used for writing the generated PCL6 data
uint8* fBuffer; // the buffer uint8* fBuffer; // the buffer
uint32 fSize; // the size of the buffer uint32 fSize; // the size of the buffer
uint32 fIndex; // the index of the next byte to be written uint32 fIndex; // the index of the next byte to be written
}; };
#endif #endif // _PCL6_WRITER_H
+12 -8
View File
@@ -2,17 +2,21 @@
#include <stdio.h> #include <stdio.h>
Rasterizer::Rasterizer(Halftone* halftone) Rasterizer::Rasterizer(Halftone* halftone)
: fHalftone(halftone) :
, fIndex(-1) fHalftone(halftone),
fIndex(-1)
{ {
fBounds.bottom = -2; fBounds.bottom = -2;
} }
Rasterizer::~Rasterizer() Rasterizer::~Rasterizer()
{ {
} }
bool bool
Rasterizer::SetBitmap(int x, int y, BBitmap* bitmap, int pageHeight) Rasterizer::SetBitmap(int x, int y, BBitmap* bitmap, int pageHeight)
{ {
@@ -33,9 +37,8 @@ Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight)
fBounds.bottom = fBounds.top + height - 1; fBounds.bottom = fBounds.top + height - 1;
} }
if (!get_valid_rect(bitmap, &fBounds)) { if (!get_valid_rect(bitmap, &fBounds))
return false; return false;
}
fWidth = fBounds.right - fBounds.left + 1; fWidth = fBounds.right - fBounds.left + 1;
fHeight = fBounds.bottom - fBounds.top + 1; fHeight = fBounds.bottom - fBounds.top + 1;
@@ -52,18 +55,19 @@ Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight)
return true; return true;
} }
bool bool
Rasterizer::HasNextLine() Rasterizer::HasNextLine()
{ {
return fIndex <= fBounds.bottom; return fIndex <= fBounds.bottom;
} }
const void* const void*
Rasterizer::RasterizeNextLine() Rasterizer::RasterizeNextLine()
{ {
if (!HasNextLine()) { if (!HasNextLine())
return NULL; return NULL;
}
const void* result; const void* result;
result = RasterizeLine(fX, fY, (const ColorRGB32Little*)fBits); result = RasterizeLine(fX, fY, (const ColorRGB32Little*)fBits);
@@ -73,10 +77,10 @@ Rasterizer::RasterizeNextLine()
return result; return result;
} }
void void
Rasterizer::RasterizeBitmap() Rasterizer::RasterizeBitmap()
{ {
while (HasNextLine()) { while (HasNextLine())
RasterizeNextLine(); RasterizeNextLine();
} }
}
+45 -19
View File
@@ -1,12 +1,13 @@
#ifndef _RASTERIZER_H #ifndef _RASTERIZER_H
#define _RASTERIZER_H #define _RASTERIZER_H
#include <Bitmap.h>
#include "Halftone.h" #include "Halftone.h"
#include "ValidRect.h" #include "ValidRect.h"
#include <Bitmap.h>
//
class Rasterizer { class Rasterizer {
public: public:
Rasterizer(Halftone* halftone); Rasterizer(Halftone* halftone);
@@ -15,15 +16,18 @@ public:
/** /**
* Sets the bitmap to be rasterized * Sets the bitmap to be rasterized
* Either the iterator methods HasNextLine() and RasterizeNextLine() * 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. * can be used to rasterize the entire bitmap at once.
* @param x the x position of the image on the page. * @param x the x position of the image on the page.
* @param y the y 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 bitmap the bitamp to be rasterized.
* @param height the page height. * @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? // Is there a next line?
bool HasNextLine(); bool HasNextLine();
@@ -34,26 +38,49 @@ public:
void RasterizeBitmap(); void RasterizeBitmap();
// Returns the Halftone object specified in the constructor // Returns the Halftone object specified in the constructor
Halftone *GetHalftone() { return fHalftone; } Halftone* GetHalftone()
{
return fHalftone;
}
// The bounds of the bitmap to be rasterized // 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() // 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() // The height (in pixels) of the bounds passed to Rasterize()
int GetHeight() { return fHeight; } int GetHeight()
{
return fHeight;
}
// Returns the current x position // Returns the current x position
int GetX() { return fX; } int GetX()
{
return fX;
}
// Returns the current y position // Returns the current y position
int GetY() { return fY; } int GetY()
{
return fY;
}
// The method is called for each line in the bitmap. // 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 // Returns the number of bytes to store widthInPixels pixels with
// and padBytes number of pad bytes. // BPP = bitsPerPixel and padBytes number of pad bytes.
static int RowBufferSize(int widthInPixels, int bitsPerPixel, int padBytes = 1) { static int RowBufferSize(int widthInPixels, int bitsPerPixel,
int sizeInBytes = (widthInPixels * bitsPerPixel + 7) / 8; int padBytes = 1)
return padBytes * ((sizeInBytes + padBytes - 1) / padBytes); {
int sizeInBytes = (widthInPixels * bitsPerPixel + 7)
/ 8;
return padBytes * ((sizeInBytes + padBytes - 1)
/ padBytes);
} }
private: private:
@@ -70,5 +97,4 @@ private:
int fIndex; int fIndex;
}; };
#endif // _RASTERIZER_H
#endif