print addons: remove invalid use of auto_ptr
GCC 13 warns that the use of auto_ptr on an array can lead to undefined behavior, because auto_ptr will use `delete` instead of `delete[]`. Replaced the use with `std::vector` instead. Since the `data()` member was only introduced in C++11, the solution uses the [] operator instead to get the address of the beginning of the array. Change-Id: Ib457580eedb03338a454fb96b27602c3830c1634 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6644 Reviewed-by: Adrien Destugues <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
1f2e9ca260
commit
fdc8b001a9
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "Lips3.h"
|
#include "Lips3.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <vector>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -51,7 +51,7 @@ LIPS3Driver::StartDocument()
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ LIPS3Driver::StartPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ LIPS3Driver::EndPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ LIPS3Driver::EndDocument(bool)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,13 +162,10 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
int compressedSize;
|
int compressedSize;
|
||||||
const uchar* buffer;
|
const uchar* buffer;
|
||||||
|
|
||||||
uchar* in_buffer = new uchar[in_size];
|
std::vector<uchar> in_buffer(in_size);
|
||||||
uchar* out_buffer = new uchar[out_size];
|
std::vector<uchar> out_buffer(out_size);
|
||||||
|
|
||||||
auto_ptr<uchar> _in_buffer (in_buffer);
|
uchar* ptr2 = &in_buffer[0];
|
||||||
auto_ptr<uchar> _out_buffer(out_buffer);
|
|
||||||
|
|
||||||
uchar* ptr2 = static_cast<uchar*>(in_buffer);
|
|
||||||
|
|
||||||
DBGMSG(("move\n"));
|
DBGMSG(("move\n"));
|
||||||
|
|
||||||
@@ -181,12 +178,12 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
compressedSize = compress3(out_buffer, in_buffer, in_size);
|
compressedSize = compress3(&out_buffer[0], &in_buffer[0], in_size);
|
||||||
|
|
||||||
if (compressedSize < in_size) {
|
if (compressedSize < in_size) {
|
||||||
compressionMethod = 9;
|
compressionMethod = 9;
|
||||||
// compress3
|
// compress3
|
||||||
buffer = out_buffer;
|
buffer = &out_buffer[0];
|
||||||
} else if (compressedSize > out_size) {
|
} else if (compressedSize > out_size) {
|
||||||
BAlert* alert = new BAlert("memory overrun!!!", "warning",
|
BAlert* alert = new BAlert("memory overrun!!!", "warning",
|
||||||
"OK");
|
"OK");
|
||||||
@@ -195,7 +192,7 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
compressionMethod = 0;
|
compressionMethod = 0;
|
||||||
buffer = in_buffer;
|
buffer = &in_buffer[0];
|
||||||
compressedSize = in_size;
|
compressedSize = in_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +225,7 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "Lips4Cap.h"
|
#include "Lips4Cap.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <vector>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -53,7 +53,7 @@ LIPS4Driver::StartDocument()
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ LIPS4Driver::StartPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ LIPS4Driver::EndPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ LIPS4Driver::EndDocument(bool)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,13 +172,10 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
int compressed_size;
|
int compressed_size;
|
||||||
const uchar* buffer;
|
const uchar* buffer;
|
||||||
|
|
||||||
uchar* in_buffer = new uchar[in_size];
|
std::vector<uchar> in_buffer(in_size);
|
||||||
uchar* out_buffer = new uchar[out_size];
|
std::vector<uchar> out_buffer(out_size);
|
||||||
|
|
||||||
auto_ptr<uchar> _in_buffer (in_buffer);
|
uchar* ptr2 = &in_buffer[0];
|
||||||
auto_ptr<uchar> _out_buffer(out_buffer);
|
|
||||||
|
|
||||||
uchar* ptr2 = static_cast<uchar *>(in_buffer);
|
|
||||||
|
|
||||||
DBGMSG(("move\n"));
|
DBGMSG(("move\n"));
|
||||||
|
|
||||||
@@ -193,11 +190,11 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
|
|
||||||
DBGMSG(("PackBits\n"));
|
DBGMSG(("PackBits\n"));
|
||||||
|
|
||||||
compressed_size = pack_bits(out_buffer, in_buffer, in_size);
|
compressed_size = pack_bits(&out_buffer[0], &in_buffer[0], in_size);
|
||||||
|
|
||||||
if (compressed_size < in_size) {
|
if (compressed_size < in_size) {
|
||||||
compression_method = 11;
|
compression_method = 11;
|
||||||
buffer = out_buffer;
|
buffer = &out_buffer[0];
|
||||||
} else if (compressed_size > out_size) {
|
} else if (compressed_size > out_size) {
|
||||||
BAlert* alert = new BAlert("memory overrun!!!", "warning", "OK");
|
BAlert* alert = new BAlert("memory overrun!!!", "warning", "OK");
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
@@ -205,7 +202,7 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
compression_method = 0;
|
compression_method = 0;
|
||||||
buffer = in_buffer;
|
buffer = &in_buffer[0];
|
||||||
compressed_size = in_size;
|
compressed_size = in_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +235,7 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "PCL5.h"
|
#include "PCL5.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <vector>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -45,7 +45,7 @@ PCL5Driver::StartDocument()
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ PCL5Driver::EndPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ PCL5Driver::EndDocument(bool)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,11 +148,8 @@ PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
int compressedSize;
|
int compressedSize;
|
||||||
const uchar* buffer;
|
const uchar* buffer;
|
||||||
|
|
||||||
uchar* in_buffer = new uchar[in_size];
|
std::vector<uchar> in_buffer(in_size);
|
||||||
uchar* out_buffer = new uchar[out_size];
|
std::vector<uchar> out_buffer(out_size);
|
||||||
|
|
||||||
auto_ptr<uchar> _in_buffer (in_buffer);
|
|
||||||
auto_ptr<uchar> _out_buffer(out_buffer);
|
|
||||||
|
|
||||||
DBGMSG(("move\n"));
|
DBGMSG(("move\n"));
|
||||||
|
|
||||||
@@ -161,36 +158,36 @@ PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
|
|
||||||
const bool color = GetJobData()->GetColor() == JobData::kColor;
|
const bool color = GetJobData()->GetColor() == JobData::kColor;
|
||||||
const int num_planes = color ? 3 : 1;
|
const int num_planes = color ? 3 : 1;
|
||||||
|
|
||||||
if (color) {
|
if (color) {
|
||||||
fHalftone->SetPlanes(Halftone::kPlaneRGB1);
|
fHalftone->SetPlanes(Halftone::kPlaneRGB1);
|
||||||
fHalftone->SetBlackValue(Halftone::kLowValueMeansBlack);
|
fHalftone->SetBlackValue(Halftone::kLowValueMeansBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = rc.top; i <= rc.bottom; i++) {
|
for (int i = rc.top; i <= rc.bottom; i++) {
|
||||||
|
|
||||||
for (int plane = 0; plane < num_planes; plane ++) {
|
for (int plane = 0; plane < num_planes; plane ++) {
|
||||||
|
|
||||||
fHalftone->Dither(in_buffer, ptr, x, y, width);
|
fHalftone->Dither(&in_buffer[0], ptr, x, y, width);
|
||||||
|
|
||||||
compressedSize = pack_bits(out_buffer, in_buffer, in_size);
|
compressedSize = pack_bits(&out_buffer[0], &in_buffer[0], in_size);
|
||||||
|
|
||||||
if (compressedSize + _BytesToEnterCompressionMethod(2)
|
if (compressedSize + _BytesToEnterCompressionMethod(2)
|
||||||
< in_size + _BytesToEnterCompressionMethod(0)) {
|
< in_size + _BytesToEnterCompressionMethod(0)) {
|
||||||
compressionMethod = 2; // back bits
|
compressionMethod = 2; // back bits
|
||||||
buffer = out_buffer;
|
buffer = &out_buffer[0];
|
||||||
} else {
|
} else {
|
||||||
compressionMethod = 0; // uncompressed
|
compressionMethod = 0; // uncompressed
|
||||||
buffer = in_buffer;
|
buffer = &in_buffer[0];
|
||||||
compressedSize = in_size;
|
compressedSize = in_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
_RasterGraphics(
|
_RasterGraphics(
|
||||||
compressionMethod,
|
compressionMethod,
|
||||||
buffer,
|
buffer,
|
||||||
compressedSize,
|
compressedSize,
|
||||||
plane == num_planes - 1);
|
plane == num_planes - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr += delta;
|
ptr += delta;
|
||||||
@@ -216,7 +213,7 @@ PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "ValidRect.h"
|
#include "ValidRect.h"
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
{
|
{
|
||||||
@@ -37,15 +37,15 @@ public:
|
|||||||
AbstractDeltaRowCompressor(rowSize, initialSeed),
|
AbstractDeltaRowCompressor(rowSize, initialSeed),
|
||||||
fWriter(writer)
|
fWriter(writer)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void AppendByteToDeltaRow(uchar byte)
|
void AppendByteToDeltaRow(uchar byte)
|
||||||
{
|
{
|
||||||
fWriter->Append(byte);
|
fWriter->Append(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PCL6Writer* fWriter;
|
PCL6Writer* fWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ PCL6Driver::StartDocument()
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ PCL6Driver::EndDocument(bool)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int y = (int)offset->y;
|
int y = (int)offset->y;
|
||||||
|
|
||||||
PCL6Rasterizer* rasterizer;
|
PCL6Rasterizer* rasterizer;
|
||||||
if (_UseColorMode()) {
|
if (_UseColorMode()) {
|
||||||
#if COLOR_DEPTH == 8
|
#if COLOR_DEPTH == 8
|
||||||
@@ -113,7 +113,7 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
#elif COLOR_DEPTH == 1
|
#elif COLOR_DEPTH == 1
|
||||||
rasterizer = new ColorRasterizer(fHalftone);
|
rasterizer = new ColorRasterizer(fHalftone);
|
||||||
#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);
|
||||||
@@ -121,14 +121,14 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
auto_ptr<Rasterizer> _rasterizer(rasterizer);
|
auto_ptr<Rasterizer> _rasterizer(rasterizer);
|
||||||
bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y,
|
bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y,
|
||||||
bitmap, GetPageHeight());
|
bitmap, GetPageHeight());
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
rasterizer->InitializeBuffer();
|
rasterizer->InitializeBuffer();
|
||||||
|
|
||||||
// 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 =
|
deltaRowCompressor =
|
||||||
new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0);
|
new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0);
|
||||||
if (deltaRowCompressor->InitCheck() != B_OK) {
|
if (deltaRowCompressor->InitCheck() != B_OK) {
|
||||||
delete deltaRowCompressor;
|
delete deltaRowCompressor;
|
||||||
@@ -137,15 +137,15 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
}
|
}
|
||||||
auto_ptr<DeltaRowCompressor>_deltaRowCompressor(deltaRowCompressor);
|
auto_ptr<DeltaRowCompressor>_deltaRowCompressor(deltaRowCompressor);
|
||||||
int deltaRowSize = 0;
|
int deltaRowSize = 0;
|
||||||
|
|
||||||
// remember position
|
// remember position
|
||||||
int xPage = rasterizer->GetX();
|
int xPage = rasterizer->GetX();
|
||||||
int yPage = rasterizer->GetY();
|
int yPage = rasterizer->GetY();
|
||||||
|
|
||||||
while (rasterizer->HasNextLine()) {
|
while (rasterizer->HasNextLine()) {
|
||||||
const uchar* rowBuffer =
|
const uchar* rowBuffer =
|
||||||
static_cast<const uchar*>(rasterizer->RasterizeNextLine());
|
static_cast<const uchar*>(rasterizer->RasterizeNextLine());
|
||||||
|
|
||||||
if (deltaRowCompressor != NULL) {
|
if (deltaRowCompressor != NULL) {
|
||||||
int size =
|
int size =
|
||||||
deltaRowCompressor->CalculateSize(rowBuffer, true);
|
deltaRowCompressor->CalculateSize(rowBuffer, true);
|
||||||
@@ -153,9 +153,9 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
// two bytes for the row byte count
|
// two bytes for the row byte count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y = rasterizer->GetY();
|
y = rasterizer->GetY();
|
||||||
|
|
||||||
uchar* outBuffer = rasterizer->GetOutBuffer();
|
uchar* outBuffer = rasterizer->GetOutBuffer();
|
||||||
int outBufferSize = rasterizer->GetOutBufferSize();
|
int outBufferSize = rasterizer->GetOutBufferSize();
|
||||||
int outRowSize = rasterizer->GetOutRowSize();
|
int outRowSize = rasterizer->GetOutRowSize();
|
||||||
@@ -179,7 +179,7 @@ PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -207,17 +207,17 @@ PCL6Driver::_WriteBitmap(const uchar* buffer, int outSize, int rowSize, int x,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// write bitmap
|
// write bitmap
|
||||||
_Move(x, y);
|
_Move(x, y);
|
||||||
|
|
||||||
_StartRasterGraphics(x, y, width, height, compressionMethod);
|
_StartRasterGraphics(x, y, width, height, compressionMethod);
|
||||||
|
|
||||||
_RasterGraphics(buffer, outSize, dataSize, rowSize, height,
|
_RasterGraphics(buffer, outSize, dataSize, rowSize, height,
|
||||||
compressionMethod);
|
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
|
||||||
@@ -257,16 +257,16 @@ PCL6Driver::StartPage(int)
|
|||||||
if (GetJobData()->GetOrientation() == JobData::kLandscape) {
|
if (GetJobData()->GetOrientation() == JobData::kLandscape) {
|
||||||
orientation = PCL6Writer::kLandscape;
|
orientation = PCL6Writer::kLandscape;
|
||||||
}
|
}
|
||||||
|
|
||||||
PCL6Writer::MediaSize mediaSize =
|
PCL6Writer::MediaSize mediaSize =
|
||||||
_MediaSize(GetJobData()->GetPaper());
|
_MediaSize(GetJobData()->GetPaper());
|
||||||
PCL6Writer::MediaSource mediaSource =
|
PCL6Writer::MediaSource mediaSource =
|
||||||
_MediaSource(GetJobData()->GetPaperSource());
|
_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) {
|
||||||
// TODO move duplex binding option to UI
|
// TODO move duplex binding option to UI
|
||||||
fWriter->BeginPage(orientation, mediaSize, mediaSource,
|
fWriter->BeginPage(orientation, mediaSize, mediaSource,
|
||||||
PCL6Writer::kDuplexVerticalBinding, fMediaSide);
|
PCL6Writer::kDuplexVerticalBinding, fMediaSide);
|
||||||
|
|
||||||
if (fMediaSide == PCL6Writer::kFrontMediaSide)
|
if (fMediaSide == PCL6Writer::kFrontMediaSide)
|
||||||
@@ -275,7 +275,7 @@ PCL6Driver::StartPage(int)
|
|||||||
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;
|
||||||
@@ -300,7 +300,7 @@ PCL6Driver::_StartRasterGraphics(int x, int y, int width, int height,
|
|||||||
#elif COLOR_DEPTH == 1
|
#elif COLOR_DEPTH == 1
|
||||||
colorDepth = PCL6Writer::k1Bit;
|
colorDepth = PCL6Writer::k1Bit;
|
||||||
#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;
|
||||||
@@ -324,7 +324,7 @@ PCL6Driver::_RasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
|
|||||||
{
|
{
|
||||||
// write bitmap byte size
|
// write bitmap byte size
|
||||||
fWriter->EmbeddedDataPrefix32(dataSize);
|
fWriter->EmbeddedDataPrefix32(dataSize);
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
if (compressionMethod == PCL6Writer::kRLECompression) {
|
if (compressionMethod == PCL6Writer::kRLECompression) {
|
||||||
// use RLE compression
|
// use RLE compression
|
||||||
@@ -339,18 +339,18 @@ PCL6Driver::_RasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
|
|||||||
if (compressor.InitCheck() != B_OK) {
|
if (compressor.InitCheck() != B_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8* row = buffer;
|
const uint8* row = buffer;
|
||||||
for (int i = 0; i < height; i ++) {
|
for (int i = 0; i < height; i ++) {
|
||||||
// write row byte count
|
// write row byte count
|
||||||
int32 size = compressor.CalculateSize(row);
|
int32 size = compressor.CalculateSize(row);
|
||||||
fWriter->Append((uint16)size);
|
fWriter->Append((uint16)size);
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
// write delta row
|
// write delta row
|
||||||
compressor.Compress(row);
|
compressor.Compress(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
row += rowSize;
|
row += rowSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -369,7 +369,7 @@ PCL6Driver::EndPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "PS.h"
|
#include "PS.h"
|
||||||
|
|
||||||
#include <memory.h>
|
#include <vector>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ PSDriver::_WritePSString(const char* format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_WritePSData(const void* data, size_t size)
|
PSDriver::_WritePSData(const void* data, size_t size)
|
||||||
{
|
{
|
||||||
if (fFilterIO)
|
if (fFilterIO)
|
||||||
@@ -120,7 +120,7 @@ PSDriver::StartDocument()
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ PSDriver::EndPage(int)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ PSDriver::_SetupCTM()
|
|||||||
GetJobData()->GetPaperRect().Height()-topMargin);
|
GetJobData()->GetPaperRect().Height()-topMargin);
|
||||||
} else {
|
} else {
|
||||||
// landscape:
|
// landscape:
|
||||||
// move origin from bottom left to margin top and left
|
// move origin from bottom left to margin top and left
|
||||||
// and rotate page contents
|
// and rotate page contents
|
||||||
_WritePSString("%f %f translate\n", topMargin, leftMargin);
|
_WritePSString("%f %f translate\n", topMargin, leftMargin);
|
||||||
_WritePSString("90 rotate\n");
|
_WritePSString("90 rotate\n");
|
||||||
@@ -190,7 +190,7 @@ PSDriver::EndDocument(bool)
|
|||||||
}
|
}
|
||||||
catch (TransportException& err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ ToHexDigit(uchar value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
||||||
{
|
{
|
||||||
DBGMSG(("> nextBand\n"));
|
DBGMSG(("> nextBand\n"));
|
||||||
@@ -266,14 +266,11 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
int compressed_size;
|
int compressed_size;
|
||||||
const uchar* buffer;
|
const uchar* buffer;
|
||||||
|
|
||||||
uchar* in_buffer = new uchar[in_size];
|
std::vector<uchar> in_buffer(in_size);
|
||||||
// gray values
|
// gray values
|
||||||
uchar* out_buffer = new uchar[out_size];
|
std::vector<uchar> out_buffer(out_size);
|
||||||
// gray values in hexadecimal
|
// gray values in hexadecimal
|
||||||
|
|
||||||
auto_ptr<uchar> _in_buffer(in_buffer);
|
|
||||||
auto_ptr<uchar> _out_buffer(out_buffer);
|
|
||||||
|
|
||||||
DBGMSG(("move\n"));
|
DBGMSG(("move\n"));
|
||||||
|
|
||||||
int size = color ? width * 3 : in_size;
|
int size = color ? width * 3 : in_size;
|
||||||
@@ -281,7 +278,7 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
|
|
||||||
for (int i = rc.top; i <= rc.bottom; i++) {
|
for (int i = rc.top; i <= rc.bottom; i++) {
|
||||||
if (color) {
|
if (color) {
|
||||||
uchar* out = out_buffer;
|
uchar* out = &out_buffer[0];
|
||||||
uchar* in = ptr;
|
uchar* in = ptr;
|
||||||
for (int w = width; w > 0; w --) {
|
for (int w = width; w > 0; w --) {
|
||||||
*out++ = ToHexDigit((in[2]) >> 4);
|
*out++ = ToHexDigit((in[2]) >> 4);
|
||||||
@@ -293,21 +290,21 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
in += 4;
|
in += 4;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fHalftone->Dither(in_buffer, ptr, x, y, width);
|
fHalftone->Dither(&in_buffer[0], ptr, x, y, width);
|
||||||
|
|
||||||
|
uchar* in = &in_buffer[0];
|
||||||
|
uchar* out = &out_buffer[0];
|
||||||
|
|
||||||
uchar* in = in_buffer;
|
|
||||||
uchar* out = out_buffer;
|
|
||||||
|
|
||||||
for (int w = in_size; w > 0; w --, in ++) {
|
for (int w = in_size; w > 0; w --, in ++) {
|
||||||
*in = ~*in; // invert pixels
|
*in = ~*in; // invert pixels
|
||||||
*out++ = ToHexDigit((*in) >> 4);
|
*out++ = ToHexDigit((*in) >> 4);
|
||||||
*out++ = ToHexDigit((*in) & 15);
|
*out++ = ToHexDigit((*in) & 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
compression_method = 0; // uncompressed
|
compression_method = 0; // uncompressed
|
||||||
buffer = out_buffer;
|
buffer = &out_buffer[0];
|
||||||
compressed_size = out_size;
|
compressed_size = out_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,11 +336,11 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
|
|||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_JobStart()
|
PSDriver::_JobStart()
|
||||||
{
|
{
|
||||||
// PostScript header
|
// PostScript header
|
||||||
@@ -360,14 +357,14 @@ PSDriver::_JobStart()
|
|||||||
GetJobData()->GetPaperRect().IntegerHeight());
|
GetJobData()->GetPaperRect().IntegerHeight());
|
||||||
_WritePSString("%%%%Pages: (atend)\n");
|
_WritePSString("%%%%Pages: (atend)\n");
|
||||||
_WritePSString("%%%%EndComments\n");
|
_WritePSString("%%%%EndComments\n");
|
||||||
|
|
||||||
_WritePSString("%%%%BeginDefaults\n");
|
_WritePSString("%%%%BeginDefaults\n");
|
||||||
_WritePSString("%%%%PageMedia: Plain\n");
|
_WritePSString("%%%%PageMedia: Plain\n");
|
||||||
_WritePSString("%%%%EndDefaults\n");
|
_WritePSString("%%%%EndDefaults\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_StartRasterGraphics(int x, int y, int width, int height,
|
PSDriver::_StartRasterGraphics(int x, int y, int width, int height,
|
||||||
int widthByte)
|
int widthByte)
|
||||||
{
|
{
|
||||||
@@ -391,14 +388,14 @@ PSDriver::_StartRasterGraphics(int x, int y, int width, int height,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_EndRasterGraphics()
|
PSDriver::_EndRasterGraphics()
|
||||||
{
|
{
|
||||||
_WritePSString("grestore\n");
|
_WritePSString("grestore\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_RasterGraphics(int compression_method, const uchar* buffer,
|
PSDriver::_RasterGraphics(int compression_method, const uchar* buffer,
|
||||||
int size)
|
int size)
|
||||||
{
|
{
|
||||||
@@ -410,7 +407,7 @@ PSDriver::_RasterGraphics(int compression_method, const uchar* buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::_JobEnd()
|
PSDriver::_JobEnd()
|
||||||
{
|
{
|
||||||
_WritePSString("%%%%Pages: %d\n", fPrintedPages);
|
_WritePSString("%%%%Pages: %d\n", fPrintedPages);
|
||||||
|
|||||||
Reference in New Issue
Block a user