xref: /haiku/src/add-ons/print/drivers/pcl6/Rasterizer.h (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 #ifndef _RASTERIZER_H
2 #define _RASTERIZER_H
3 
4 
5 #include <Bitmap.h>
6 
7 #include "Halftone.h"
8 #include "ValidRect.h"
9 
10 
11 class Rasterizer {
12 public:
13 						Rasterizer(Halftone* halftone);
14 	virtual				~Rasterizer();
15 
16 	/**
17 	 *  Sets the bitmap to be rasterized
18 	 *  Either the iterator methods HasNextLine() and RasterizeNextLine()
19 	 *  can be used to rasterize the bitmap line per line or the method
20 	 *	RasterizeBitamp()
21 	 *  can be used to rasterize the entire bitmap at once.
22 	 *  @param x the x position of the image on the page.
23 	 *  @param y the y position of the image on the page.
24 	 *  @param bitmap the bitamp to be rasterized.
25 	 *  @param height the page height.
26 	 *  @return true if the bitmap is not empty and false if the bitmap is
27 	 *		empty.
28 	 */
29 			bool		SetBitmap(int x, int y, BBitmap* bitmap,
30 							int pageHeight);
31 
32 	// Is there a next line?
33 			bool		HasNextLine();
34 	// Rasterizes the next line and returns the line.
35 			const void*	RasterizeNextLine();
36 
37 	// Iterates over all lines.
38 			void		RasterizeBitmap();
39 
40 	// Returns the Halftone object specified in the constructor
41 			Halftone*	GetHalftone()
42 						{
43 							return fHalftone;
44 						}
45 	// The bounds of the bitmap to be rasterized
46 			RECT		GetBounds()
47 						{
48 							return fBounds;
49 						}
50 	// The width (in pixels) of the bounds passed to Rasterized()
51 			int			GetWidth()
52 						{
53 							return fWidth;
54 						}
55 	// The height (in pixels) of the bounds passed to Rasterize()
56 			int			GetHeight()
57 						{
58 							return fHeight;
59 						}
60 	// Returns the current x position
61 			int			GetX()
62 						{
63 							return fX;
64 						}
65 	// Returns the current y position
66 			int			GetY()
67 						{
68 							return fY;
69 						}
70 
71 	// The method is called for each line in the bitmap.
72 	virtual	const void*	RasterizeLine(int x, int y,
73 							const ColorRGB32Little* source) = 0;
74 
75 	// Returns the number of bytes to store widthInPixels pixels with
76 	// BPP = bitsPerPixel and padBytes number of pad bytes.
77 	static	int			RowBufferSize(int widthInPixels, int bitsPerPixel,
78 							int padBytes = 1)
79 						{
80 							int sizeInBytes = (widthInPixels * bitsPerPixel + 7)
81 								/ 8;
82 							return padBytes * ((sizeInBytes + padBytes - 1)
83 								/ padBytes);
84 						}
85 
86 private:
87 			Halftone*	fHalftone;
88 
89 			RECT		fBounds;
90 			int			fWidth;
91 			int			fHeight;
92 			int			fX;
93 			int			fY;
94 
95 			const uchar* fBits;
96 			int			fBPR;
97 			int			fIndex;
98 };
99 
100 #endif // _RASTERIZER_H
101