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