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