bool Rasterizer::SetBitmap(int x, int y, BBitmap* bitmap, int pageHeight) { fX = x; fY = y; BRect bounds = bitmap->Bounds(); fBounds.left = (int)bounds.left; fBounds.top = (int)bounds.top; fBounds.right = (int)bounds.right; fBounds.bottom = (int)bounds.bottom; int height = fBounds.bottom - fBounds.top + 1; if (y + height > pageHeight) { height = pageHeight - y; fBounds.bottom = fBounds.top + height - 1; } if (!get_valid_rect(bitmap, &fBounds)) return false; fWidth = fBounds.right - fBounds.left + 1; fHeight = fBounds.bottom - fBounds.top + 1; fBPR = bitmap->BytesPerRow(); fBits = (uchar*)bitmap->Bits(); // offset to top, left point of rect fBits += fBounds.top * fBPR + fBounds.left * 4; // XXX why not fX += ...? fX = fBounds.left; fY += fBounds.top; fIndex = fBounds.top; return true; }
bool PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset) { DBGMSG(("> nextBand\n")); try { BRect bounds = bitmap->Bounds(); RECT rc; rc.left = (int)bounds.left; rc.top = (int)bounds.top; rc.right = (int)bounds.right; rc.bottom = (int)bounds.bottom; int height = rc.bottom - rc.top + 1; int x = (int)offset->x; int y = (int)offset->y; int pageHeight = GetPageHeight(); if (y + height > pageHeight) height = pageHeight - y; rc.bottom = height - 1; DBGMSG(("height = %d\n", height)); DBGMSG(("x = %d\n", x)); DBGMSG(("y = %d\n", y)); if (get_valid_rect(bitmap, &rc)) { DBGMSG(("validate rect = %d, %d, %d, %d\n", rc.left, rc.top, rc.right, rc.bottom)); x = rc.left; y += rc.top; int width = rc.right - rc.left + 1; int widthByte = (width + 7) / 8; // byte boundary int height = rc.bottom - rc.top + 1; int in_size = widthByte; int out_size = (widthByte * 6 + 4) / 5; int delta = bitmap->BytesPerRow(); DBGMSG(("width = %d\n", width)); DBGMSG(("widthByte = %d\n", widthByte)); DBGMSG(("height = %d\n", height)); DBGMSG(("in_size = %d\n", in_size)); DBGMSG(("out_size = %d\n", out_size)); DBGMSG(("delta = %d\n", delta)); DBGMSG(("renderobj->Get_pixel_depth() = %d\n", fHalftone->GetPixelDepth())); uchar* ptr = static_cast<uchar*>(bitmap->Bits()) + rc.top * delta + (rc.left * fHalftone->GetPixelDepth()) / 8; int compressionMethod; int compressedSize; const uchar* buffer; uchar* in_buffer = new uchar[in_size]; uchar* out_buffer = new uchar[out_size]; auto_ptr<uchar> _in_buffer (in_buffer); auto_ptr<uchar> _out_buffer(out_buffer); DBGMSG(("move\n")); _Move(x, y); _StartRasterGraphics(width, height); const bool color = GetJobData()->GetColor() == JobData::kColor; const int num_planes = color ? 3 : 1; if (color) { fHalftone->SetPlanes(Halftone::kPlaneRGB1); fHalftone->SetBlackValue(Halftone::kLowValueMeansBlack); } for (int i = rc.top; i <= rc.bottom; i++) { for (int plane = 0; plane < num_planes; plane ++) { fHalftone->Dither(in_buffer, ptr, x, y, width); compressedSize = pack_bits(out_buffer, in_buffer, in_size); if (compressedSize + _BytesToEnterCompressionMethod(2) < in_size + _BytesToEnterCompressionMethod(0)) { compressionMethod = 2; // back bits buffer = out_buffer; } else { compressionMethod = 0; // uncompressed buffer = in_buffer; compressedSize = in_size; } _RasterGraphics( compressionMethod, buffer, compressedSize, plane == num_planes - 1); } ptr += delta; y++; } _EndRasterGraphics(); } else DBGMSG(("band bitmap is clean.\n")); if (y >= pageHeight) { offset->x = -1.0; offset->y = -1.0; } else offset->y += height; DBGMSG(("< nextBand\n")); return true; } catch (TransportException& err) { BAlert* alert = new BAlert("", err.What(), "OK"); alert->Go(); return false; } }