xref: /haiku/src/add-ons/print/drivers/pcl6/Rasterizer.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 #include "Rasterizer.h"
2 
3 #include <stdio.h>
4 
5 Rasterizer::Rasterizer(Halftone* halftone)
6 	: fHalftone(halftone)
7 	, fIndex(-1)
8 {
9 	fBounds.bottom = -2;
10 }
11 
12 Rasterizer::~Rasterizer()
13 {
14 }
15 
16 bool
17 Rasterizer::SetBitmap(int x, int y, BBitmap *bitmap, int pageHeight)
18 {
19 	fX = x;
20 	fY = y;
21 
22 	BRect bounds = bitmap->Bounds();
23 
24 	fBounds.left   = (int)bounds.left;
25 	fBounds.top    = (int)bounds.top;
26 	fBounds.right  = (int)bounds.right;
27 	fBounds.bottom = (int)bounds.bottom;
28 
29 	int height = fBounds.bottom - fBounds.top + 1;
30 
31 	if (y + height > pageHeight) {
32 		height = pageHeight - y;
33 		fBounds.bottom = fBounds.top + height - 1;
34 	}
35 
36 	if (!get_valid_rect(bitmap, &fBounds)) {
37 		return false;
38 	}
39 
40 	fWidth = fBounds.right - fBounds.left + 1;
41 	fHeight = fBounds.bottom - fBounds.top + 1;
42 
43 	fBPR = bitmap->BytesPerRow();
44 	fBits = (uchar*)bitmap->Bits();
45 	// offset to top, left point of rect
46 	fBits += fBounds.top * fBPR + fBounds.left * 4;
47 
48 	// XXX why not fX += ...?
49 	fX = fBounds.left;
50 	fY += fBounds.top;
51 	fIndex = fBounds.top;
52 	return true;
53 }
54 
55 bool
56 Rasterizer::HasNextLine()
57 {
58 	return fIndex <= fBounds.bottom;
59 }
60 
61 const void*
62 Rasterizer::RasterizeNextLine()
63 {
64 	if (!HasNextLine()) {
65 		return NULL;
66 	}
67 
68 	const void *result;
69 	result = RasterizeLine(fX, fY, (const ColorRGB32Little*)fBits);
70 	fBits += fBPR;
71 	fY ++;
72 	fIndex ++;
73 	return result;
74 }
75 
76 void
77 Rasterizer::RasterizeBitmap()
78 {
79 	while (HasNextLine()) {
80 		RasterizeNextLine();
81 	}
82 }
83