diff --git a/bazaar/PixRaster/Lept-Blend.cpp b/bazaar/PixRaster/Lept-Blend.cpp index 86e3b7e8d..915407fbe 100644 --- a/bazaar/PixRaster/Lept-Blend.cpp +++ b/bazaar/PixRaster/Lept-Blend.cpp @@ -19,4 +19,23 @@ Pix Pix::CombineMasked(Pix &aPix, Pix &maskPix) } // END Pix::CombineMasked() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// extracts a rectangular area from PIX +Pix Pix::ClipRectangle(Rect r) +{ + if(IsEmpty()) + return Pix(); + + BOX box; + box.x = r.left; + box.y = r.top; + box.w = r.right - r.left; + box.h = r.bottom - r.top; + + PIX *dPix = pixClipRectangle(pix, &box, NULL); + if(!dPix) + return Pix(); + return Pix(&dPix); +} + END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Morph.cpp b/bazaar/PixRaster/Lept-Morph.cpp index 82a9dba7f..ac8b47c47 100644 --- a/bazaar/PixRaster/Lept-Morph.cpp +++ b/bazaar/PixRaster/Lept-Morph.cpp @@ -50,4 +50,54 @@ Pix Pix::CloseGray(int hsize, int vsize) } // END Pix::CloseGray() + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ErodeBrick(int hsize, int vsize) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixErodeBrick(NULL, pix, hsize, vsize); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::ErodeBrick() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DilateBrick(int hsize, int vsize) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixDilateBrick(NULL, pix, hsize, vsize); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::DilateBrick() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::OpenBrick(int hsize, int vsize) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixOpenBrick(NULL, pix, hsize, vsize); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::OpenBrick() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::CloseBrick(int hsize, int vsize) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixCloseBrick(NULL, pix, hsize, vsize); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::CloseBrick() + END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-PageSeg.cpp b/bazaar/PixRaster/Lept-PageSeg.cpp index 143f7f014..2efa1a441 100644 --- a/bazaar/PixRaster/Lept-PageSeg.cpp +++ b/bazaar/PixRaster/Lept-PageSeg.cpp @@ -59,4 +59,17 @@ Array Pix::FindBaselines() } // END Pix::FindBaseLines() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// foreground bounding box locating routine +// scans from a given border through image center to locate +// first non-background pixel. +// scanFlag is one of L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_FROM_BOTTOM +// returns true on success, false otherwise +bool Pix::ScanForForeground(int &loc, enum ScanModes scanMode) +{ + int res = pixScanForForeground(pix, NULL, (l_int32)scanMode, (l_int32 *)&loc); + return (res == 0); +} + END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Rotate.cpp b/bazaar/PixRaster/Lept-Rotate.cpp index dd378d3e6..741dd7267 100644 --- a/bazaar/PixRaster/Lept-Rotate.cpp +++ b/bazaar/PixRaster/Lept-Rotate.cpp @@ -39,4 +39,17 @@ Pix Pix::RotateAMGray(double angle, int incolor) } // END Pix::RotateAMGray() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Rotates image (any kind) about center. +Pix Pix::Rotate(double angle, int type, int incolor, int width, int height) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixRotate(pix, angle, type, incolor, width, height); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::Rotate() + END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/PixRaster.h b/bazaar/PixRaster/PixRaster.h index 0007d790b..1650ad50e 100644 --- a/bazaar/PixRaster/PixRaster.h +++ b/bazaar/PixRaster/PixRaster.h @@ -146,6 +146,12 @@ class Pix : public PixBase // bring-in color modes enum BringInModes { PIXRASTER_BRING_IN_WHITE = L_BRING_IN_WHITE, PIXRASTER_BRING_IN_BLACK = L_BRING_IN_BLACK }; + // rotate modes + enum RotateModes { PIXRASTER_ROTATE_AREA_MAP = L_ROTATE_AREA_MAP, PIXRASTER_ROTATE_SHEAR = L_ROTATE_SHEAR, PIXRASTER_ROTATE_SAMPLING = L_ROTATE_SAMPLING }; + + // scan direction modes + enum ScanModes { PIXRASTER_FROM_LEFT = L_FROM_LEFT, PIXRASTER_FROM_RIGHT = L_FROM_RIGHT, PIXRASTER_FROM_TOP = L_FROM_TOP, PIXRASTER_FROM_BOTTOM = L_FROM_BOTTOM }; + // loads Pix from another raster object void Load(Raster& raster, bool deepCopy = false, int page = PIXRASTER_CURPAGE); @@ -268,6 +274,7 @@ class Pix : public PixBase Pix RotateAM(double angle, BringInModes incolor = PIXRASTER_BRING_IN_WHITE); Pix RotateAMColor(double angle, int colorval); Pix RotateAMGray(double angle, int grayval); + Pix Rotate(double angle, int type = PIXRASTER_ROTATE_SHEAR, int incolor = PIXRASTER_BRING_IN_WHITE, int width = 0, int height = 0); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // MORPHING FUNCTIONS @@ -277,6 +284,11 @@ class Pix : public PixBase Pix OpenGray(int hsize, int vsize); Pix CloseGray(int hsize, int vsize); + Pix ErodeBrick(int hsize, int vsize); + Pix DilateBrick(int hsize, int vsize); + Pix OpenBrick(int hsize, int vsize); + Pix CloseBrick(int hsize, int vsize); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ARITHMETIC AND ALIKE FUNCTIONS @@ -290,6 +302,9 @@ class Pix : public PixBase // BLENDING/COMBINING FUNCTIONS Pix CombineMasked(Pix &aPix, Pix &maskPix); + + // extracts a rectangular area from PIX + Pix ClipRectangle(Rect r); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // DOCUMENT PAGE SEGMENTING FUNCTIONS @@ -300,6 +315,13 @@ class Pix : public PixBase // text baseline finding routine Array FindBaselines(); + // foreground bounding box locating routine + // scans from a given border through image center to locate + // first non-background pixel. + // scanFlag is one of PIXRASTER_FROM_LEFT, PIXRASTER_FROM_RIGHT, PIXRASTER_FROM_TOP, PIXRASTER_FROM_BOTTOM + // returns true on success, false otherwise + bool ScanForForeground(int &loc, enum ScanModes scanMode); + }; // END Class Pix /////////////////////////////////////////////////////////////////////////////////////////////////////////////