xref: /haiku/src/add-ons/print/drivers/pcl6/Rasterizer.h (revision 568716bed76d9711e95cd1604313be2f142505c0)
12e86189fSMichael Pfeiffer #ifndef _RASTERIZER_H
22e86189fSMichael Pfeiffer #define _RASTERIZER_H
32e86189fSMichael Pfeiffer 
42e86189fSMichael Pfeiffer 
52e86189fSMichael Pfeiffer #include <Bitmap.h>
62e86189fSMichael Pfeiffer 
7*568716beSWim van der Meer #include "Halftone.h"
8*568716beSWim van der Meer #include "ValidRect.h"
9*568716beSWim van der Meer 
10*568716beSWim van der Meer 
112e86189fSMichael Pfeiffer class Rasterizer {
122e86189fSMichael Pfeiffer public:
132e86189fSMichael Pfeiffer 						Rasterizer(Halftone* halftone);
142e86189fSMichael Pfeiffer 	virtual				~Rasterizer();
152e86189fSMichael Pfeiffer 
162e86189fSMichael Pfeiffer 	/**
172e86189fSMichael Pfeiffer 	 *  Sets the bitmap to be rasterized
182e86189fSMichael Pfeiffer 	 *  Either the iterator methods HasNextLine() and RasterizeNextLine()
19*568716beSWim van der Meer 	 *  can be used to rasterize the bitmap line per line or the method
20*568716beSWim van der Meer 	 *	RasterizeBitamp()
212e86189fSMichael Pfeiffer 	 *  can be used to rasterize the entire bitmap at once.
222e86189fSMichael Pfeiffer 	 *  @param x the x position of the image on the page.
232e86189fSMichael Pfeiffer 	 *  @param y the y position of the image on the page.
242e86189fSMichael Pfeiffer 	 *  @param bitmap the bitamp to be rasterized.
252e86189fSMichael Pfeiffer 	 *  @param height the page height.
26*568716beSWim van der Meer 	 *  @return true if the bitmap is not empty and false if the bitmap is
27*568716beSWim van der Meer 	 *		empty.
282e86189fSMichael Pfeiffer 	 */
29*568716beSWim van der Meer 			bool		SetBitmap(int x, int y, BBitmap* bitmap,
30*568716beSWim van der Meer 							int pageHeight);
312e86189fSMichael Pfeiffer 
322e86189fSMichael Pfeiffer 	// Is there a next line?
332e86189fSMichael Pfeiffer 			bool		HasNextLine();
342e86189fSMichael Pfeiffer 	// Rasterizes the next line and returns the line.
352e86189fSMichael Pfeiffer 			const void*	RasterizeNextLine();
362e86189fSMichael Pfeiffer 
372e86189fSMichael Pfeiffer 	// Iterates over all lines.
382e86189fSMichael Pfeiffer 			void		RasterizeBitmap();
392e86189fSMichael Pfeiffer 
402e86189fSMichael Pfeiffer 	// Returns the Halftone object specified in the constructor
GetHalftone()41*568716beSWim van der Meer 			Halftone*	GetHalftone()
42*568716beSWim van der Meer 						{
43*568716beSWim van der Meer 							return fHalftone;
44*568716beSWim van der Meer 						}
452e86189fSMichael Pfeiffer 	// The bounds of the bitmap to be rasterized
GetBounds()46*568716beSWim van der Meer 			RECT		GetBounds()
47*568716beSWim van der Meer 						{
48*568716beSWim van der Meer 							return fBounds;
49*568716beSWim van der Meer 						}
502e86189fSMichael Pfeiffer 	// The width (in pixels) of the bounds passed to Rasterized()
GetWidth()51*568716beSWim van der Meer 			int			GetWidth()
52*568716beSWim van der Meer 						{
53*568716beSWim van der Meer 							return fWidth;
54*568716beSWim van der Meer 						}
552e86189fSMichael Pfeiffer 	// The height (in pixels) of the bounds passed to Rasterize()
GetHeight()56*568716beSWim van der Meer 			int			GetHeight()
57*568716beSWim van der Meer 						{
58*568716beSWim van der Meer 							return fHeight;
59*568716beSWim van der Meer 						}
602e86189fSMichael Pfeiffer 	// Returns the current x position
GetX()61*568716beSWim van der Meer 			int			GetX()
62*568716beSWim van der Meer 						{
63*568716beSWim van der Meer 							return fX;
64*568716beSWim van der Meer 						}
652e86189fSMichael Pfeiffer 	// Returns the current y position
GetY()66*568716beSWim van der Meer 			int			GetY()
67*568716beSWim van der Meer 						{
68*568716beSWim van der Meer 							return fY;
69*568716beSWim van der Meer 						}
702e86189fSMichael Pfeiffer 
712e86189fSMichael Pfeiffer 	// The method is called for each line in the bitmap.
72*568716beSWim van der Meer 	virtual	const void*	RasterizeLine(int x, int y,
73*568716beSWim van der Meer 							const ColorRGB32Little* source) = 0;
742e86189fSMichael Pfeiffer 
75*568716beSWim van der Meer 	// Returns the number of bytes to store widthInPixels pixels with
76*568716beSWim van der Meer 	// BPP = bitsPerPixel and padBytes number of pad bytes.
77*568716beSWim van der Meer 	static	int			RowBufferSize(int widthInPixels, int bitsPerPixel,
78*568716beSWim van der Meer 							int padBytes = 1)
79*568716beSWim van der Meer 						{
80*568716beSWim van der Meer 							int sizeInBytes = (widthInPixels * bitsPerPixel + 7)
81*568716beSWim van der Meer 								/ 8;
82*568716beSWim van der Meer 							return padBytes * ((sizeInBytes + padBytes - 1)
83*568716beSWim van der Meer 								/ padBytes);
842e86189fSMichael Pfeiffer 						}
852e86189fSMichael Pfeiffer 
862e86189fSMichael Pfeiffer private:
872e86189fSMichael Pfeiffer 			Halftone*	fHalftone;
882e86189fSMichael Pfeiffer 
892e86189fSMichael Pfeiffer 			RECT		fBounds;
902e86189fSMichael Pfeiffer 			int			fWidth;
912e86189fSMichael Pfeiffer 			int			fHeight;
922e86189fSMichael Pfeiffer 			int			fX;
932e86189fSMichael Pfeiffer 			int			fY;
942e86189fSMichael Pfeiffer 
952e86189fSMichael Pfeiffer 			const uchar* fBits;
962e86189fSMichael Pfeiffer 			int			fBPR;
972e86189fSMichael Pfeiffer 			int			fIndex;
982e86189fSMichael Pfeiffer };
992e86189fSMichael Pfeiffer 
100*568716beSWim van der Meer #endif // _RASTERIZER_H
101