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