diff --git a/bazaar/PixRaster/Lept-Arith.cpp b/bazaar/PixRaster/Lept-Arith.cpp index 0f5bc9747..d993a96b5 100644 --- a/bazaar/PixRaster/Lept-Arith.cpp +++ b/bazaar/PixRaster/Lept-Arith.cpp @@ -2,108 +2,80 @@ NAMESPACE_UPP -bool PixRaster::Invert(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::Invert() { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, PIXRASTER_CLONE); - PIX *dPix = pixInvert(NULL, sPix); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixInvert(NULL, pix); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::Invert() -bool PixRaster::AddConstantGray(int val, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::AddConstantGray(int val) { if(IsEmpty()) - return false; - page = getTruePage(page); - - Dup(page); - PIX *sPix = GetPIX(PIXRASTER_LASTPAGE, PIXRASTER_CLONE); - int res = pixAddConstantGray(sPix, val); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixCopy(NULL, pix); + int res = pixAddConstantGray(dPix, val); if(res) { - Drop(); - return false; + pixDestroy(&dPix); + return Pix(); } - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(&dPix); -} +} // END Pix::AddConstantGray() -bool PixRaster::MultConstantGray(int val, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::MultConstantGray(int val) { if(IsEmpty()) - return false; - page = getTruePage(page); - - Dup(page); - PIX *sPix = GetPIX(PIXRASTER_LASTPAGE, PIXRASTER_CLONE); - int res = pixMultConstantGray(sPix, val); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixCopy(NULL, pix); + int res = pixMultConstantGray(dPix, val); if(res) { - Drop(); - return false; + pixDestroy(&dPix); + return Pix(); } - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(&dPix); -} +} // END Pix::MultConstantGray() -bool PixRaster::AddGray(int page1, int page2) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::AddGray(Pix &pix2) { if(IsEmpty()) - return false; - page1 = getTruePage(page1); - page2 = getTruePage(page2); - - PIX *sPix1 = pixaGetPix(pixa, page1, L_CLONE); - PIX *sPix2 = pixaGetPix(pixa, page2, L_CLONE); - Dup(page1); - PIX *dPix = GetPIX(PIXRASTER_LASTPAGE, PIXRASTER_CLONE); - PIX *res = pixAddGray(dPix, sPix1, sPix2); - pixDestroy(&sPix1); - pixDestroy(&sPix2); - pixDestroy(&dPix); + return Pix(); + PIX *dPix = pixCopy(NULL, pix); + PIX *res = pixAddGray(dPix, pix, pix2); if(!res) { - Drop(); - return false; + pixDestroy(&dPix); + return Pix(); } - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(&dPix); -} +} // END Pix::AddGray() -bool PixRaster::SubtractGray(int page1, int page2) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::SubtractGray(Pix &pix2) { if(IsEmpty()) - return false; - page1 = getTruePage(page1); - page2 = getTruePage(page2); - - PIX *sPix1 = pixaGetPix(pixa, page1, L_CLONE); - PIX *sPix2 = pixaGetPix(pixa, page2, L_CLONE); - PIX *dPix = pixSubtractGray(NULL, sPix1, sPix2); - pixDestroy(&sPix1); - pixDestroy(&sPix2); - if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + PIX *dPix = pixCopy(NULL, pix); + PIX *res = pixSubtractGray(dPix, pix, pix2); + if(!res) + { + pixDestroy(&dPix); + return Pix(); + } + return Pix(&dPix); -} +} // END Pix::SubtractGray() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Blend.cpp b/bazaar/PixRaster/Lept-Blend.cpp index 1480d0f84..86e3b7e8d 100644 --- a/bazaar/PixRaster/Lept-Blend.cpp +++ b/bazaar/PixRaster/Lept-Blend.cpp @@ -2,29 +2,21 @@ NAMESPACE_UPP -bool PixRaster::CombineMasked(int destPage, int sourcePage, int maskPage) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::CombineMasked(Pix &aPix, Pix &maskPix) { if(IsEmpty()) return false; - sourcePage = getTruePage(sourcePage); - destPage = getTruePage(destPage); - Dup(destPage); - PIX *dPix = GetPIX(PIXRASTER_LASTPAGE, PIXRASTER_CLONE); - PIX *sPix = pixaGetPix(pixa, sourcePage, L_CLONE); - PIX *mPix = pixaGetPix(pixa, maskPage, L_CLONE); - int res = pixCombineMasked(dPix, sPix, mPix); - pixDestroy(&sPix); - pixDestroy(&dPix); - pixDestroy(&mPix); + PIX *dPix = pixCopy(NULL, pix); + int res = pixCombineMasked(dPix, aPix, maskPix); if(res) { - Drop(); - return false; + pixDestroy(&dPix); + return Pix(); } - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(&dPix); -} +} // END Pix::CombineMasked() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Morph.cpp b/bazaar/PixRaster/Lept-Morph.cpp index 3006372cb..82a9dba7f 100644 --- a/bazaar/PixRaster/Lept-Morph.cpp +++ b/bazaar/PixRaster/Lept-Morph.cpp @@ -2,76 +2,52 @@ NAMESPACE_UPP -bool PixRaster::ErodeGray(int hsize, int vsize, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ErodeGray(int hsize, int vsize) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixErodeGray(sPix, hsize, vsize); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixErodeGray(pix, hsize, vsize); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ErodeGray() -bool PixRaster::DilateGray(int hsize, int vsize, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DilateGray(int hsize, int vsize) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDilateGray(sPix, hsize, vsize); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDilateGray(pix, hsize, vsize); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DilateGray() -bool PixRaster::OpenGray(int hsize, int vsize, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::OpenGray(int hsize, int vsize) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixOpenGray(sPix, hsize, vsize); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixOpenGray(pix, hsize, vsize); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::OpenGray() -bool PixRaster::CloseGray(int hsize, int vsize, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::CloseGray(int hsize, int vsize) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixCloseGray(sPix, hsize, vsize); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixCloseGray(pix, hsize, vsize); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::CloseGray() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-PageSeg.cpp b/bazaar/PixRaster/Lept-PageSeg.cpp index 8e22fcd09..143f7f014 100644 --- a/bazaar/PixRaster/Lept-PageSeg.cpp +++ b/bazaar/PixRaster/Lept-PageSeg.cpp @@ -2,71 +2,37 @@ NAMESPACE_UPP +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // top level page segmenting -bool PixRaster::GetRegionsBinary(int page) +PixRaster Pix::GetRegionsBinary() { + PixRaster pixRaster; + if(IsEmpty()) - return false; - page = getTruePage(page); + return PixRaster(); PIX *ht, *tl, *tb; - PIX *pix = pixaGetPix(pixa, page, L_CLONE); int res = pixGetRegionsBinary(pix, &ht, &tl, &tb, 0); - pixDestroy(&pix); if(res) - return false; - AddPIX(ht); - AddPIX(tl); - AddPIX(tb); - pixDestroy(&ht); - pixDestroy(&tl); - pixDestroy(&tb); + return PixRaster(); + Pix htPix(&ht); + Pix tlPix(&tl); + Pix tbPix(&tb); + pixRaster.Add(htPix); + pixRaster.Add(tlPix); + pixRaster.Add(tbPix); // seeks the ht page - SeekPage(-2); + pixRaster.SeekPage(-2); - return true; + return pixRaster; -} +} // END Pix::GetRegionsBinary() -/* + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // text baseline finding routine -Array PixRaster::FindBaselines(int page) -{ - PTA *pta; - NUMA *numa; - int res; - l_int32 x, y; - Array ptArray; - - if(IsEmpty()) - return Array(); - page = getTruePage(page); - - PIX *pix = pixaGetPix(pixa, page, L_CLONE); - numa = pixFindBaselines(pix, &pta, 0); - pixDestroy(&pix); - if(!numa || !pta) - return Array(); - for(int iPoint = 0; iPoint < ptaGetCount(pta); iPoint++) - { - res = ptaGetIPt(pta, iPoint, &x, &y); - if(res) - { - numaDestroy(&numa); - ptaDestroy(&pta); - return Array(); - } - ptArray.Add(Point(x, y)); - } - numaDestroy(&numa); - ptaDestroy(&pta); - return ptArray; -} -*/ - -// text baseline finding routine -Array PixRaster::FindBaselines(int page) +Array Pix::FindBaselines() { NUMA *numa; int res; @@ -75,11 +41,7 @@ Array PixRaster::FindBaselines(int page) if(IsEmpty()) return Array(); - page = getTruePage(page); - - PIX *pix = pixaGetPix(pixa, page, L_CLONE); numa = pixFindBaselines(pix, NULL, 0); - pixDestroy(&pix); if(!numa) return Array(); for(int iLine = 0; iLine < numaGetCount(numa); iLine++) @@ -94,6 +56,7 @@ Array PixRaster::FindBaselines(int page) } numaDestroy(&numa); return intArray; -} + +} // END Pix::FindBaseLines() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Rotate.cpp b/bazaar/PixRaster/Lept-Rotate.cpp index b68a70053..dd378d3e6 100644 --- a/bazaar/PixRaster/Lept-Rotate.cpp +++ b/bazaar/PixRaster/Lept-Rotate.cpp @@ -2,56 +2,41 @@ NAMESPACE_UPP +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Rotates image (2-4-8 or 32 bpp) about center. -bool PixRaster::RotateAM(double angle, BringInModes incolor, int page) +Pix Pix::RotateAM(double angle, BringInModes incolor) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixRotateAM(sPix, angle, incolor); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixRotateAM(pix, angle, incolor); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; -} + return Pix(); + return Pix(&dPix); -bool PixRaster::RotateAMColor(double angle, int incolor, int page) -{ - if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixRotateAMColor(sPix, angle, incolor); - pixDestroy(&sPix); - if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; -} +} // END Pix::RotateAM() -bool PixRaster::RotateAMGray(double angle, int incolor, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::RotateAMColor(double angle, int incolor) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixRotateAMGray(sPix, angle, incolor); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixRotateAMColor(pix, angle, incolor); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; -} + return Pix(); + return Pix(&dPix); + +} // END Pix::RotateAMColor() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::RotateAMGray(double angle, int incolor) +{ + if(IsEmpty()) + return Pix(); + PIX *dPix = pixRotateAMGray(pix, angle, incolor); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::RotateAMGray() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Skew.cpp b/bazaar/PixRaster/Lept-Skew.cpp index fd3c1d945..c28423784 100644 --- a/bazaar/PixRaster/Lept-Skew.cpp +++ b/bazaar/PixRaster/Lept-Skew.cpp @@ -2,59 +2,46 @@ NAMESPACE_UPP +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Simple top-level deskew interfaces -bool PixRaster::Deskew(int ReductionFactor, int page) +Pix Pix::Deskew(int ReductionFactor) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDeskew(sPix, ReductionFactor); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDeskew(pix, ReductionFactor); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; - -} + return Pix(); + return Pix(&dPix); -bool PixRaster::FindSkewAndDeskew(int ReductionFactor, double *skewAngle, double *confidenceFactor, int page) +} // END Pix::Deskew() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::FindSkewAndDeskew(int ReductionFactor, double *skewAngle, double *confidenceFactor) { if(IsEmpty()) - return false; - page = getTruePage(page); + return Pix(); - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); l_float32 dSkew, dConf; - PIX *dPix = pixFindSkewAndDeskew(sPix, ReductionFactor, &dSkew, &dConf); - pixDestroy(&sPix); + PIX *dPix = pixFindSkewAndDeskew(pix, ReductionFactor, &dSkew, &dConf); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); + return Pix(); if(skewAngle) *skewAngle = dSkew; if(confidenceFactor) *confidenceFactor = dConf; - return true; + return Pix(&dPix); -} +} // END Pix::FindSkewAndDeskew() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Simple top-level skew angle finding interface -bool PixRaster::FindSkew(double *pangle, double *pconf, int page) +bool Pix::FindSkew(double *pangle, double *pconf) { if(IsEmpty()) return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); + l_float32 dSkew, dConf; - int res = pixFindSkew(sPix, &dSkew, &dConf); - pixDestroy(&sPix); + int res = pixFindSkew(pix, &dSkew, &dConf); if(res) return false; if(pangle) @@ -63,43 +50,38 @@ bool PixRaster::FindSkew(double *pangle, double *pconf, int page) *pconf = dConf; return true; -} +} // END Pix::FindSkew() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Basic angle-finding functions with all parameters -bool PixRaster::FindSkewSweep(double *pangle, int reduction, double sweeprange, double sweepdelta, int page) +bool Pix::FindSkewSweep(double *pangle, int reduction, double sweeprange, double sweepdelta) { if(IsEmpty()) return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); + l_float32 dSkew; - int res = pixFindSkewSweep(sPix, &dSkew, reduction, sweeprange, sweepdelta); - pixDestroy(&sPix); + int res = pixFindSkewSweep(pix, &dSkew, reduction, sweeprange, sweepdelta); if(res) return false; if(pangle) *pangle = dSkew; return true; -} +} // END Pix::FindSkewSweep() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Angle-finding functions with all parameters -bool PixRaster::FindSkewSweepAndSearch( +bool Pix::FindSkewSweepAndSearch( double *pangle, double *pconf, int redsweep, int redsearch, double sweeprange, double sweepdelta, - double minbsdelta, - int page) + double minbsdelta) { if(IsEmpty()) return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); + l_float32 dSkew, dConf; - int res = pixFindSkewSweepAndSearch(sPix, &dSkew, &dConf, redsweep, redsearch, sweeprange, sweepdelta, minbsdelta); - pixDestroy(&sPix); + int res = pixFindSkewSweepAndSearch(pix, &dSkew, &dConf, redsweep, redsearch, sweeprange, sweepdelta, minbsdelta); if(res) return false; if(pangle) @@ -108,24 +90,19 @@ bool PixRaster::FindSkewSweepAndSearch( *pconf = dConf; return true; -} +} // END Pix::FindSkewSweepAndSearch() -bool PixRaster::DeskewLocal(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DeskewLocal() { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDeskewLocal(sPix, 0, 0, 0, 0.0, 0.0, 0.0); - pixDestroy(&sPix); - if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - SeekPage(PIXRASTER_LASTPAGE); - pixDestroy(&dPix); - return true; -} + return Pix(); + PIX *dPix = pixDeskewLocal(pix, 0, 0, 0, 0.0, 0.0, 0.0); + if(!dPix) + return Pix(); + return Pix(&dPix); + +} // END Pix::DeskewLocal() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Lept-Threshold.cpp b/bazaar/PixRaster/Lept-Threshold.cpp index 6642c93ea..6cd16a945 100644 --- a/bazaar/PixRaster/Lept-Threshold.cpp +++ b/bazaar/PixRaster/Lept-Threshold.cpp @@ -2,245 +2,167 @@ NAMESPACE_UPP -bool PixRaster::DitherToBinary(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DitherToBinary() { if(IsEmpty()) - return false; - page = getTruePage(page); + return Pix(); - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDitherToBinary(sPix); - pixDestroy(&sPix); + PIX *dPix = pixDitherToBinary(pix); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DitherToBinary() -bool PixRaster::DitherToBinarySpec(int lowerclip, int upperclip, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DitherToBinarySpec(int lowerclip, int upperclip) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDitherToBinarySpec(sPix, lowerclip, upperclip); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDitherToBinarySpec(pix, lowerclip, upperclip); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DitherToBinarySpec() // threshold the image -- warning, operates ONLY on grayscale pixmaps // original image is unchanged - a new modified image at raster's end -bool PixRaster::ThresholdToBinary(int threshold, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdToBinary(int threshold) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdToBinary(sPix, threshold); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdToBinary(pix, threshold); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; -} + return Pix(); + return Pix(&dPix); + +} // END Pix::ThresholdToBinary() -bool PixRaster::VarThresholdToBinary(int thresholdPage, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::VarThresholdToBinary(Pix &thresholdPix) { if(IsEmpty()) - return false; - page = getTruePage(page); - thresholdPage = getTruePage(thresholdPage); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *tPix = pixaGetPix(pixa, thresholdPage, L_CLONE); - PIX *dPix = pixVarThresholdToBinary(sPix, tPix); - pixDestroy(&sPix); - pixDestroy(&tPix); + return Pix(); + PIX *dPix = pixVarThresholdToBinary(pix, thresholdPix); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::VarThresholdToBinary() -bool PixRaster::DitherToBinaryLUT(int lowerclip, int upperclip, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DitherToBinaryLUT(int lowerclip, int upperclip) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDitherToBinaryLUT(sPix, lowerclip, upperclip); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDitherToBinaryLUT(pix, lowerclip, upperclip); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DitherToBinaryLUT() -bool PixRaster::GenerateMaskByValue(int val, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::GenerateMaskByValue(int val) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixGenerateMaskByValue(sPix, val); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixGenerateMaskByValue(pix, val); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::GenerateMaskByValue() -bool PixRaster::GenerateMaskByBand(int lower, int upper, int inband, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::GenerateMaskByBand(int lower, int upper, int inband) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixGenerateMaskByBand(sPix, lower, upper, inband); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixGenerateMaskByBand(pix, lower, upper, inband); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::GenerateMaskByBand() -bool PixRaster::DitherTo2bpp(int cmapflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DitherTo2bpp(int cmapflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDitherTo2bpp(sPix, cmapflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDitherTo2bpp(pix, cmapflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DitherTo2bpp() -bool PixRaster::DitherTo2bppSpec(int lowerclip, int upperclip, int cmapflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::DitherTo2bppSpec(int lowerclip, int upperclip, int cmapflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixDitherTo2bppSpec(sPix, lowerclip, upperclip, cmapflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixDitherTo2bppSpec(pix, lowerclip, upperclip, cmapflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::DitherTo2bppSpec() -bool PixRaster::ThresholdTo2bpp(int nlevels, int cmapflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdTo2bpp(int nlevels, int cmapflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdTo2bpp(sPix, nlevels, cmapflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdTo2bpp(pix, nlevels, cmapflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ThresholdTo2bpp() -bool PixRaster::ThresholdTo4bpp(int nlevels, int cmapflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdTo4bpp(int nlevels, int cmapflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdTo4bpp(sPix, nlevels, cmapflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdTo4bpp(pix, nlevels, cmapflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ThresholdTo4bpp() -bool PixRaster::ThresholdOn8bpp(int nlevels, int cmapflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdOn8bpp(int nlevels, int cmapflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdOn8bpp(sPix, nlevels, cmapflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdOn8bpp(pix, nlevels, cmapflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ThresholdOn8bpp() -bool PixRaster::ThresholdGrayArb(const char *edgevals, int outdepth, int use_average, int setblack, int setwhite, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdGrayArb(const char *edgevals, int outdepth, int use_average, int setblack, int setwhite) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdGrayArb(sPix, edgevals, outdepth, use_average, setblack, setwhite); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdGrayArb(pix, edgevals, outdepth, use_average, setblack, setwhite); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ThresholdGrayArb() -Buffer PixRaster::MakeGrayQuantIndexTable(int nlevels) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Buffer Pix::MakeGrayQuantIndexTable(int nlevels) { Bufferbuf; @@ -254,9 +176,10 @@ Buffer PixRaster::MakeGrayQuantIndexTable(int nlevels) } return buf; -} +} // END Pix::MakeGrayQuantIndexTable() -Buffer PixRaster::MakeGrayQuantTargetTable(int nlevels, int depth) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Buffer Pix::MakeGrayQuantTargetTable(int nlevels, int depth) { Bufferbuf; @@ -270,81 +193,54 @@ Buffer PixRaster::MakeGrayQuantTargetTable(int nlevels, int depth) } return buf; -} +} // END Pix::MakeGrayQuantTargetTable() -bool PixRaster::GenerateMaskByBand32(unsigned refval, int delm, int delp, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::GenerateMaskByBand32(unsigned refval, int delm, int delp) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixGenerateMaskByBand32(sPix, refval, delm, delp); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixGenerateMaskByBand32(pix, refval, delm, delp); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::GenerateMaskByBand32() -bool PixRaster::GenerateMaskByDiscr32(unsigned refval1, unsigned refval2, int distflag, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::GenerateMaskByDiscr32(unsigned refval1, unsigned refval2, int distflag) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixGenerateMaskByDiscr32(sPix, refval1, refval2, distflag); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixGenerateMaskByDiscr32(pix, refval1, refval2, distflag); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::GenerateMaskByDiscr32() -bool PixRaster::GrayQuantFromHisto(int mPage, double minfract, int maxsize, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::GrayQuantFromHisto(Pix &mPix, double minfract, int maxsize) { if(IsEmpty()) - return false; - page = getTruePage(page); - mPage = getTruePage(mPage); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *mPix = pixaGetPix(pixa, mPage, L_CLONE); - PIX *dPix = pixGrayQuantFromHisto(NULL, sPix, mPix, minfract, maxsize); - pixDestroy(&sPix); - pixDestroy(&mPix); + return Pix(); + PIX *dPix = pixGrayQuantFromHisto(NULL, pix, mPix, minfract, maxsize); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::GrayQuantFromHisto() -bool PixRaster::ThresholdToValue(int threshval, int setval, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix Pix::ThresholdToValue(int threshval, int setval) { if(IsEmpty()) - return false; - page = getTruePage(page); - - PIX *sPix = pixaGetPix(pixa, page, L_CLONE); - PIX *dPix = pixThresholdToValue(NULL, sPix, threshval, setval); - pixDestroy(&sPix); + return Pix(); + PIX *dPix = pixThresholdToValue(NULL, pix, threshval, setval); if(!dPix) - return false; - AddPIX(dPix, PIXRASTER_CLONE); - pixDestroy(&dPix); - SeekPage(PIXRASTER_LASTPAGE); - return true; + return Pix(); + return Pix(&dPix); -} +} // END Pix::ThresholdToValue() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/OldGetLine.cpp b/bazaar/PixRaster/OldGetLine.cpp deleted file mode 100644 index 63d697c73..000000000 --- a/bazaar/PixRaster/OldGetLine.cpp +++ /dev/null @@ -1,206 +0,0 @@ -Raster::Line PixRaster::GetLine(int line) -{ - RGBA *rgba, *rgbaPtr; - PIX *pix; - int width; - PIXCMAP *colormap; - l_uint32 *pixPtr; - l_int32 mask; - byte shift; - int iPix; - dword grayVal; - - // empty line on empty image - if(!pixa || !pixaGetCount(pixa)) - return Raster::Line(); - - // gets current PIX handle - pix = pixaGetPix(pixa, curPage, L_CLONE); - - // if line out of bounds, return empty line - if(line < 0 || line >= pixGetHeight(pix)) - { - pixDestroy(&pix); - return Raster::Line(); - } - - // gets image width - width = pixGetWidth(pix); - - // if PIX is already in 32 bpp format, just return - // a line with a pointer to data - if(pixGetDepth(pix) >= 24) - { - rgba = (RGBA *)(pixGetData(pix) + width * line); - pixDestroy(&pix); - return Raster::Line(rgba, false); - } - - // allocates an RGBA buffer for data - rgba = new RGBA[width]; - rgbaPtr = rgba; - - // handle differently pixs with or without colormap - colormap = pixGetColormap(pix); - pixPtr = pixGetData(pix) + line * pixGetWpl(pix); - if(colormap) - { - switch(pixGetDepth(pix)) - { - case 1: - for(iPix = 0, mask = 0x80000000; iPix < width; iPix++) - { - *rgbaPtr++ = ((RGBA *)colormap)[(*pixPtr & mask ? 1 : 0)]; - mask >>= 1; - if(!mask) - { - mask = 0x80000000; - pixPtr++; - } - } - break; - - case 2: - for(iPix = 0, mask = 0xC0000000, shift = 30; iPix < width; iPix++) - { - *rgbaPtr++ = ((RGBA *)colormap)[(*pixPtr & mask) >> shift]; - mask >>= 2; - shift -= 2; - if(!mask) - { - mask = 0xC0000000; - shift = 30; - pixPtr++; - } - } - break; - - case 4: - for(iPix = 0, mask = 0xF0000000, shift = 28; iPix < width; iPix++) - { - *rgbaPtr++ = ((RGBA *)colormap)[(*pixPtr & mask) >> shift]; - mask >>= 4; - shift -= 4; - if(!mask) - { - mask = 0xF0000000; - shift = 28; - pixPtr++; - } - } - break; - - case 8: - for(iPix = 0, mask = 0xFF000000, shift = 24; iPix < width; iPix++) - { - *rgbaPtr++ = ((RGBA *)colormap)[(*pixPtr & mask) >> shift]; - mask >>= 8; - shift -= 8; - if(!mask) - { - mask = 0xFF000000; - shift = 24; - pixPtr++; - } - } - break; - - default: - memset(rgba, 4*width, 0); - break; - - } // switch - } - else - { - switch(pixGetDepth(pix)) - { - case 1: - for(iPix = 0, mask = 0x80000000; iPix < width; iPix++) - { - *(dword *)rgbaPtr++ = *pixPtr & mask ? 0x00ffffff : 0x00000000; - mask >>= 1; - if(!mask) - { - mask = 0x80000000; - pixPtr++; - } - } - break; - - case 2: - for(iPix = 0, mask = 0xC0000000, shift = 30; iPix < width; iPix++) - { - grayVal = ((*pixPtr & mask) >> shift) << 6; - *(dword *)rgbaPtr++ = grayVal | (grayVal << 8) | (grayVal << 16); - mask >>= 2; - shift -= 2; - if(!mask) - { - mask = 0xC0000000; - shift = 30; - pixPtr++; - } - } - break; - - case 4: - for(iPix = 0, mask = 0xF0000000, shift = 28; iPix < width; iPix++) - { - grayVal = ((*pixPtr & mask) >> shift) << 4; - *(dword *)rgbaPtr++ = grayVal | (grayVal << 8) | (grayVal << 16); - mask >>= 4; - shift -= 4; - if(!mask) - { - mask = 0xF0000000; - shift = 28; - pixPtr++; - } - } - break; - - case 8: - for(iPix = 0, mask = 0xFF000000, shift = 24; iPix < width; iPix++) - { - grayVal = (*pixPtr & mask) >> shift; - *(dword *)rgbaPtr++ = grayVal | (grayVal << 8) | (grayVal << 16); - mask >>= 8; - shift -= 8; - if(!mask) - { - mask = 0xFF000000; - shift = 24; - pixPtr++; - } - } - break; - - case 16: - for(iPix = 0, mask = 0xFFFF0000, shift = 16; iPix < width; iPix++) - { - grayVal = ((*pixPtr & mask) >> shift) >> 4; - *(dword *)rgbaPtr++ = grayVal | (grayVal << 8) | (grayVal << 16); - mask >>= 16; - shift -= 16; - if(!mask) - { - mask = 0xFFFF0000; - shift = 16; - pixPtr++; - } - } - break; - - default: - memset(rgba, 4*width, 0); - break; - - } // switch - } // if colormap - - pixDestroy(&pix); - return Raster::Line(rgba, true); - -} // END PixRaster::GetLine() - diff --git a/bazaar/PixRaster/PixRaster.cpp b/bazaar/PixRaster/PixRaster.cpp index 182287f57..0a3c32a1f 100644 --- a/bazaar/PixRaster/PixRaster.cpp +++ b/bazaar/PixRaster/PixRaster.cpp @@ -2,44 +2,72 @@ NAMESPACE_UPP -// sets raster format depending on current page's pix format -void PixRaster::SetRasterFormat(int page) -{ - PIX *pix; +// used in PIX file I/O +enum { + READ_24_BIT_COLOR = 0, /* read in as 24 (really 32) bit pix */ + CONVERT_TO_PALETTE = 1, /* convert to 8 bit colormapped pix */ + READ_GRAY = 2 /* read gray only */ +}; - if (IsEmpty()) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Pix class wrapping Leptonica PIX image +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// internal destructor +void Pix::Destroy() +{ + // destroys underlying PIX + if(pix) + pixDestroy(&pix); + + // frees format and palette + if(rasterFormat) + { + delete rasterFormat; + rasterFormat = NULL; + } + if(localPalette) + { + delete[] localPalette; + localPalette = NULL; + } + polyMarkers.Clear(); + +} // END Pix::Destroy() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// sets raster format depending on current page's pix format +void Pix::SetRasterFormat() +{ + // removes old format for page + if (rasterFormat) + { + delete rasterFormat; + rasterFormat = NULL; + } + + if(IsEmpty()) return; - page = getTruePage(page); - - // removes old format for page - if (formats[page]) - { - delete formats[page]; - formats[page] = NULL; - } - - RasterFormat *format = new RasterFormat; - - pix = pixaGetPix(pixa, page, L_CLONE); + rasterFormat = new RasterFormat; switch (pixGetDepth(pix)) { case 1: - format->Set1mf(); + rasterFormat->Set1mf(); break; case 2: - format->Set2mf(); + rasterFormat->Set2mf(); break; case 4: - format->Set4mf(); + rasterFormat->Set4mf(); break; case 8: - format->Set8(); + rasterFormat->Set8(); break; case 16: @@ -47,7 +75,7 @@ void PixRaster::SetRasterFormat(int page) // MakeRGBA() will fail converting from Leptonica format anyways // we should add a 16bpp grayscale to Upp // in the meanwhile 16 bit Leptonica are converted to RGBA - format->Set32be( + rasterFormat->Set32be( 0x000000FF << L_RED_SHIFT, 0x000000FF << L_GREEN_SHIFT, 0x000000FF << L_BLUE_SHIFT @@ -55,7 +83,7 @@ void PixRaster::SetRasterFormat(int page) break; case 24: - format->Set24be( + rasterFormat->Set24be( 0x000000FF << L_RED_SHIFT, 0x000000FF << L_GREEN_SHIFT, 0x000000FF << L_BLUE_SHIFT @@ -63,134 +91,97 @@ void PixRaster::SetRasterFormat(int page) break; case 32: - format->Set32be( + rasterFormat->Set32be( 0x000000FF << L_RED_SHIFT, 0x000000FF << L_GREEN_SHIFT, 0x000000FF << L_BLUE_SHIFT ); break; + + default: + NEVER(); + } // switch - formats[page] = format; - - pixDestroy(&pix); -} - -// checks wether page format is valid -bool PixRaster::IsRasterFormatValid(int page) -{ - if (IsEmpty()) - return false; - - // gets true page number - page = getTruePage(page); - - return (formats[page] != NULL); -} - -// destroys page format -void PixRaster::DestroyRasterFormat(int page) -{ - if (IsEmpty()) - return; - - // gets true page number - page = getTruePage(page); - - if (formats[page]) - { - delete formats[page]; - formats[page] = NULL; - } -} +} // END Pix::SetRasterFormat() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // synthesyze grayscale palettes -void PixRaster::CreateGrayPalette2(int page) +void Pix::CreateGrayPalette2() { + if (localPalette) + { + delete[] localPalette; + localPalette = NULL; + } + if (IsEmpty()) return; - page = getTruePage(page); + localPalette = new RGBA[2]; - if (localPalettes[page]) + *(dword *)localPalette = 0xFFFFFFFF; + *((dword *)localPalette + 1) = 0xFF000000; + +} // END Pix::CreateGrayPalette2() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void Pix::CreateGrayPalette4() +{ + if (localPalette) { - delete[] localPalettes[page]; - localPalettes[page] = NULL; + delete[] localPalette; + localPalette = NULL; } - RGBA *pal = new RGBA[2]; - - *(dword *)pal = 0xFFFFFFFF; - *((dword *)pal + 1) = 0xFF000000; - - localPalettes[page] = pal; - -} // END PixRaster::CreateGrayPalette2() - -void PixRaster::CreateGrayPalette4(int page) -{ if (IsEmpty()) return; - page = getTruePage(page); + localPalette = new RGBA[4]; - if (localPalettes[page]) + *(dword *)localPalette = 0xFF0000; + *((dword *)localPalette + 1) = 0xFF555555; + *((dword *)localPalette + 2) = 0xFFAAAAAA; + *((dword *)localPalette + 3) = 0xFFFFFFFF; + +} // END Pix::CreateGrayPalette4() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void Pix::CreateGrayPalette16() +{ + if (localPalette) { - delete[] localPalettes[page]; - localPalettes[page] = NULL; + delete[] localPalette; + localPalette = NULL; } - RGBA *pal = new RGBA[4]; - - *(dword *)pal = 0xFF0000; - *((dword *)pal + 1) = 0xFF555555; - *((dword *)pal + 2) = 0xFFAAAAAA; - *((dword *)pal + 3) = 0xFFFFFFFF; - - localPalettes[page] = pal; - -} // END PixRaster::CreateGrayPalette4() - -void PixRaster::CreateGrayPalette16(int page) -{ if (IsEmpty()) return; - page = getTruePage(page); + localPalette = new RGBA[16]; - if (localPalettes[page]) - { - delete[] localPalettes[page]; - localPalettes[page] = NULL; - } - - RGBA *pal = new RGBA[16]; - - dword *palPnt = (dword *)pal; + dword *palPnt = (dword *)localPalette; for (dword i = 0; i < 16; i++) *palPnt++ = i << 4 | i << 12 | i << 20 | 0xff000000; - localPalettes[page] = pal; +} // END Pix::CreateGrayPalette16() -} // END PixRaster::CreateGrayPalette16() - -void PixRaster::CreateGrayPalette256(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void Pix::CreateGrayPalette256() { + if (localPalette) + { + delete[] localPalette; + localPalette = NULL; + } + if (IsEmpty()) return; - page = getTruePage(page); + localPalette = new RGBA[256]; - if (localPalettes[page]) - { - delete[] localPalettes[page]; - localPalettes[page] = NULL; - } - - RGBA *pal = new RGBA[256]; - - dword *palPnt = (dword *)pal; + dword *palPnt = (dword *)localPalette; dword val; for (dword i = 0; i < 256; i++) @@ -199,38 +190,35 @@ void PixRaster::CreateGrayPalette256(int page) *palPnt++ = val | val << 8 | val << 16 | 0xff000000; } - localPalettes[page] = pal; - -} // END PixRaster::CreateGrayPalette256() +} // END Pix::CreateGrayPalette256() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // convert PIX palette -void PixRaster::ConvertPIXPalette(PIXCMAP *colormap, int page) +void Pix::ConvertPIXPalette(PIXCMAP *colormap) { int iColor, numColors; l_int32 rval, gval, bval; RGBA *palPnt; + if (localPalette) + { + delete[] localPalette; + localPalette = NULL; + } + if (IsEmpty()) return; - page = getTruePage(page); - - if (localPalettes[page]) - { - delete[] localPalettes[page]; - localPalettes[page] = NULL; - } - // get number of entries in colormap numColors = pixcmapGetCount(colormap); if (numColors > 256) numColors = 256; - RGBA *pal = new RGBA[numColors]; + localPalette = new RGBA[numColors]; // convert and copy it to local palette - palPnt = pal; + palPnt = localPalette; for (iColor = 0; iColor < numColors; iColor++) { @@ -242,149 +230,336 @@ void PixRaster::ConvertPIXPalette(PIXCMAP *colormap, int page) palPnt++; } - localPalettes[page] = pal; +} // END Pix::ConvertPIXPalette() -} // END PixRaster::ConvertPIXPalette() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////// -// destroys local palette -void PixRaster::DestroyLocalPalette(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// loads Pix from another raster object +void Pix::Load(Raster& raster, bool deepCopy, int page) { - if (IsEmpty()) - return; + PixBase *pixBase; - // gets true page number - page = getTruePage(page); + Destroy(); + + // shortcut if raster is a pixRaster + Raster::Info info = raster.GetInfo(); - if (localPalettes[page]) + int width = raster.GetWidth(); + + // check whether we're loading from a PixBase derived raster + // the process don't require conversion then + pixBase = dynamic_cast(&raster); + if (pixBase) { - delete[] localPalettes[page]; - localPalettes[page] = NULL; - } -} - -// checks wether local palette is valid -bool PixRaster::IsLocalPaletteValid(int page) -{ - if (IsEmpty()) - return false; - - // gets true page number - page = getTruePage(page); - - return (localPalettes[page] != NULL); -} - -// check for empty pixraster -bool PixRaster::IsEmpty() -{ - return (!pixa || !pixaGetCount(pixa)); -} - -// gets real page -int PixRaster::getTruePage(int page) -{ - // if error page, throw exception - // shouldn't happen, but.... - if (page == PIXRASTER_INVALID_PAGE) - NEVER(); - - // if empty raster, returns INVALID_PAGE - else - if (IsEmpty() ) - return 0; - - // special value for current page + pix = pixBase->GetPIX(page); + if(!pix) + return; + if(deepCopy) + pix = pixCopy(NULL, pix); else - if (page == PIXRASTER_CURPAGE) - return curPage; - - // special value for last page - else - if (page == PIXRASTER_LASTPAGE) - return pixaGetCount(pixa) - 1; - - // negative values mean back offset from last page - else - if (page < 0) - { - page = pixaGetCount(pixa) - 1 + page; - - if (page < 0) - page = 0; - - return page; - } - - else - if (page >= pixaGetCount(pixa)) - return pixaGetCount(pixa) - 1; - else - return page; -} - - -void PixRaster::SeekPage(int page) -{ - if (IsEmpty()) + pix = pixClone(pix); + return; + } - // gets true page number - page = getTruePage(page); + // not a PixRaster, we should go the slow way - if (page == curPage) - return; + // stores old active page, we need to change it + int oldPage = raster.GetActivePage(); + + // gets current page on source raster + raster.SeekPage(page); + + // gets information from source object + const RasterFormat *format = raster.GetFormat(); + + // convert source image to PIX + if (!format) + { + // null RasterFormat -- standard Upp RGBA + LoadRASTER_RGBA(raster); + } + + else + { + switch (format->GetType()) + { + + case RASTER_1: + LoadRASTER_1(raster); + break; + + case RASTER_1 | RASTER_MSBFIRST: + LoadRASTER_1_MSBFIRST(raster); + break; + + case RASTER_2: + LoadRASTER_2(raster); + break; + + case RASTER_2 | RASTER_MSBFIRST: + LoadRASTER_2_MSBFIRST(raster); + break; + + case RASTER_4: + LoadRASTER_4(raster); + break; + + case RASTER_4 | RASTER_MSBFIRST: + LoadRASTER_4_MSBFIRST(raster); + break; + + case RASTER_8: + + case RASTER_8 | RASTER_MSBFIRST: + LoadRASTER_8(raster); + break; + + case RASTER_8ALPHA: + + case RASTER_8ALPHA | RASTER_MSBFIRST: + LoadRASTER_8ALPHA(raster); + break; + + case RASTER_16: + LoadRASTER_16(raster); + break; + + case RASTER_16 | RASTER_MSBFIRST: + LoadRASTER_16_MSBFIRST(raster); + break; + + case RASTER_24: + LoadRASTER_24(raster); + break; + + case RASTER_24 | RASTER_MSBFIRST: + LoadRASTER_24_MSBFIRST(raster); + break; + + case RASTER_32: + case RASTER_32ALPHA: + case RASTER_32PREMULTIPLIED: + LoadRASTER_32(raster); + break; + + case RASTER_32 | RASTER_MSBFIRST: + case RASTER_32ALPHA | RASTER_MSBFIRST: + case RASTER_32PREMULTIPLIED | RASTER_MSBFIRST: + LoadRASTER_32_MSBFIRST(raster); + break; + + default: + NEVER(); + + } // switch + } + + // if source raster has a palette, create a corresponding + // PIXCMAP and fill it + const RGBA *palette = raster.GetPalette(); + int palCount = raster.GetPaletteCount(); // needed because of bug of png plugin + if (palette && palCount) + { + int bpp = raster.GetInfo().bpp; + PIXCMAP *colorTable = pixcmapCreate(bpp); + palCount = min(1 << bpp, palCount); + + for (int iPal = 0; iPal < palCount; iPal++) + { + pixcmapAddColor(colorTable, palette->r, palette->g, palette->b); + palette++; + } + + pixSetColormap(pix, colorTable); + } + + // gets physical resolution from source raster pys dimensions, if any + int dotX = raster.GetInfo().dots.cx; + + int dotY = raster.GetInfo().dots.cy; + + int resX, resY; + + if (dotX) + resX = iscale(600, raster.GetWidth(), dotX); + else + resX = 0; + + if (dotY) + resY = iscale(600, raster.GetHeight(), dotY); + else + resY = 0; + pixSetXRes(pix, resX); + pixSetYRes(pix, resY); + + // restores old page on source raster + raster.SeekPage(oldPage); + +} // END Pix::Load() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// empty constructor -- sets NULL PIX +Pix::Pix() +{ + pix = NULL; + rasterFormat = NULL; + localPalette = NULL; + polyMarkers.Clear(); + +} // END Pix::Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// creates a PIX in given format and size +Pix::Pix(int width, int height, int depth, RGBA *colorTable) +{ + pix = pixCreate(width, height, depth); + if(colorTable) + { + NEVER(); // FIXME-- Convert color table to PIX format + } + rasterFormat = NULL; + localPalette = NULL; + polyMarkers.Clear(); + +} // END Pix::Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// constructor -- takes a Leptonica PIX +// TAKES OWNERSHIP of underlying PIX object which is NULLed +Pix::Pix(PIX **_pix) +{ + pix = *_pix; + *_pix = NULL; + rasterFormat = NULL; + localPalette = NULL; + polyMarkers.Clear(); + +} // END Pix::Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// copy constructor -- reference increments underlying PIX +Pix::Pix(Pix const &_pix) +{ + pix = pixClone((Pix &)_pix); + rasterFormat = NULL; + localPalette = NULL; + polyMarkers <<= _pix.polyMarkers; + +} // END Pix::Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// deep copy constructor -- deep copy of underlying PIX +Pix::Pix(Pix const &_pix, int i) +{ + pix = pixCopy(NULL, (Pix &)_pix); + rasterFormat = NULL; + localPalette = NULL; + polyMarkers <<= _pix.polyMarkers; + +} // END Pix::Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// creation of Pix from a raster object +Pix::Pix(Raster &raster, bool deepCopy, int page) +{ + pix = NULL; + Load(raster, deepCopy, page); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// creation of Pix from file/stream +Pix::Pix(FileIn &fs, int page) +{ + pix = NULL; + Load(fs, page); - curPage = page; } -int PixRaster::GetPageCount() +Pix::Pix(String const &fileName, int page) { - if (IsEmpty()) - return 0; + pix = NULL; + Load(fileName, page); - return pixaGetCount(pixa); } - -int PixRaster::GetActivePage() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// destructor +Pix::~Pix() { - return curPage; -} + Destroy(); -Size PixRaster::GetSize(int page) +} // END Pix::~Pix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// assignment -- increment reference of underlying PIX +Pix &Pix::operator=(Pix &_pix) { - Size sz(0, 0); + Destroy(); + if(!_pix) + return *this; + + pix = pixClone(_pix); + rasterFormat = NULL; + localPalette = NULL; + polyMarkers <<= _pix.polyMarkers; + return *this; - // if empty raster, returns a zero size +} // END Pix::operator=() - if (IsEmpty()) - return sz; +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// deep copy -- deep copies underlying PIX +Pix &Pix::operator <<=(Pix &_pix) +{ + Destroy(); + if(!_pix) + return *this; + + pix = pixCopy(NULL, _pix); + rasterFormat = NULL; + localPalette = NULL; + polyMarkers <<= _pix.polyMarkers; + return *this; - // gets true page number - page = getTruePage(page); +} // END Pix::operator <<=() - // return size of current page - PIX *pix = pixaGetPix(pixa, page, L_CLONE); +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Pix &Pix::DeepCopy(Pix &_pix) +{ + Destroy(); + if(!_pix) + return *this; + + pix = pixCopy(NULL, _pix); + rasterFormat = NULL; + localPalette = NULL; + polyMarkers <<= _pix.polyMarkers; + return *this; +} // END Pix::DeepCopy() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// standard Raster functions -- they operate on active page +Size Pix::GetSizeEx(int) +{ + Size sz; + pixGetDimensions(pix, &sz.cx, &sz.cy, NULL); - - pixDestroy(&pix); - return sz; -} // END PixRaster::GetSize() +} // END Pix::GetSizeEx() -Raster::Info PixRaster::GetInfo(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Raster::Info Pix::GetInfoEx(int) { Raster::Info info; memset(&info, sizeof(info), 0); if (IsEmpty()) - return info; - - // gets true page number - page = getTruePage(page); - - PIX *pix = pixaGetPix(pixa, page, L_CLONE); + return Raster::Info(); // image dimensions from pixel sizes and resolution info.bpp = pixGetDepth(pix); @@ -416,30 +591,20 @@ Raster::Info PixRaster::GetInfo(int page) else info.colors = 1 << pixGetDepth(pix); - pixDestroy(&pix); - return info; -} // END PixRaster::GetInfo() +} // END Pix::GetInfoEx() -Raster::Line PixRaster::GetLine(int line, int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Raster::Line Pix::GetLineEx(int line, int) { // empty line on empty image if (IsEmpty()) return Raster::Line(); - // gets true page number - page = getTruePage(page); - - // gets current PIX handle - PIX *pix = pixaGetPix(pixa, page, L_CLONE); - // if line out of bounds, return empty line if (line < 0 || line >= pixGetHeight(pix)) - { - pixDestroy(&pix); return Raster::Line(); - } // gets PIX bpp -- we must handle special case for 16bpp grayscale // which don't have an Upp counterpart @@ -478,8 +643,6 @@ Raster::Line PixRaster::GetLine(int line, int page) } } - pixDestroy(&pix); - return Raster::Line((byte *)rgba, this, true); } @@ -511,29 +674,20 @@ Raster::Line PixRaster::GetLine(int line, int page) #else Raster::Line l(pixData, this, false); #endif - pixDestroy(&pix); return l; -} // END PixRaster::GetLine() +} // END Pix::GetLineEx() -int PixRaster::GetPaletteCount(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +int Pix::GetPaletteCountEx(int) { - PIX *pix; PIXCMAP *colormap; int palCount; int bpp; - // no palette on empty image - if (IsEmpty()) return 0; - // gets true page number - page = getTruePage(page); - - // gets current PIX handle - pix = pixaGetPix(pixa, page, L_CLONE); - // get current pix's depth bpp = pixGetDepth(pix); @@ -549,33 +703,22 @@ int PixRaster::GetPaletteCount(int page) else palCount = pixcmapGetCount(colormap); - pixDestroy(&pix); - return palCount; -} // END PixRaster::GetPaletteCount() +} // END Pix::GetPaletteCountEx() -const RGBA *PixRaster::GetPalette(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +const RGBA *Pix::GetPaletteEx(int) { - PIX *pix; PIXCMAP *colormap; int bpp; - RGBA *palette; - - // no palette on empty image if (IsEmpty()) - return 0; - - // gets true page number - page = getTruePage(page); + return NULL; // if palette is up to date, just return it - if (IsLocalPaletteValid(page)) - return localPalettes[page]; - - // gets current PIX handle - pix = pixaGetPix(pixa, page, L_CLONE); + if(localPalette) + return localPalette; // get current pix's depth bpp = pixGetDepth(pix); @@ -590,27 +733,22 @@ const RGBA *PixRaster::GetPalette(int page) { case 1: - CreateGrayPalette2(page); - palette = localPalettes[page]; + CreateGrayPalette2(); break; case 2: - CreateGrayPalette4(page); - palette = localPalettes[page]; + CreateGrayPalette4(); break; case 4: - CreateGrayPalette16(page); - palette = localPalettes[page]; + CreateGrayPalette16(); break; case 8: - CreateGrayPalette256(page); - palette = localPalettes[page]; + CreateGrayPalette256(); break; default: - palette = 0; break; } } @@ -618,563 +756,71 @@ const RGBA *PixRaster::GetPalette(int page) else { // convert PIX palette - ConvertPIXPalette(colormap, page); - palette = localPalettes[page]; + ConvertPIXPalette(colormap); } - pixDestroy(&pix); + return localPalette; - return palette; +} // END Pix::GetPaletteEx() -} // END PixRaster::GetPalette() - -const RasterFormat *PixRaster::GetFormat(int page) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +const RasterFormat *Pix::GetFormatEx(int) { - if (IsEmpty()) - return NULL; - - // gets true page number - page = getTruePage(page); - - if (!IsRasterFormatValid(page)) - SetRasterFormat(page); - - return formats[page]; - -} // END PixRaster::GetFormat() - -// constructor -- empty raster -PixRaster::PixRaster() -{ - pixa = NULL; - curPage = 0; - -} // END Constructor class PixRaster - -// constructor -- takes a Leptonica Pix -// PIX get cloned and its reference count increased -PixRaster::PixRaster(PIX *pix, CopyModes copyMode) -{ - pixa = pixaCreate(0); - pixaAddPix(pixa, pix, copyMode); - - // sets the current page - curPage = 0; - - // allocates empty format and local palette - formats.Add((RasterFormat *)NULL); - localPalettes.Add((RGBA *)NULL); - -} // END Constructor class PixRaster - -// constructor -- takes an array of Leptonica Pix -PixRaster::PixRaster(PIXA *_pixa, CopyModes copyMode) -{ - pixa = pixaCopy(_pixa, copyMode); - - // sets the current page - curPage = 0; - - // allocates empty format and local palette - - for (int i = 0; i < pixaGetCount(pixa); i++) - { - formats.Add((RasterFormat *)NULL); - localPalettes.Add((RGBA *)NULL); - } - -} // END Constructor class PixRaster - -// destructor -- must free PIXA array -void PixRaster::Destroy() -{ - if(IsEmpty()) - return; + if(!rasterFormat) + SetRasterFormat(); - // frees formats and local palettes - for (int i = 0; i < pixaGetCount(pixa); i++) - { - DestroyRasterFormat(i); - DestroyLocalPalette(i); - } - formats.Clear(); - localPalettes.Clear(); + return rasterFormat; - // frees pix array - if (pixa) - pixaDestroy(&pixa); - - // sets current page - curPage = 0; +} // END Pix::GetFormatEx() -} // END Destructor class PixRaster - -// loads / appends Pix from another raster object -void PixRaster::Load(Raster& raster, bool Append, CopyModes copyMode) +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// file I/O +bool Pix::Load(FileIn &fs, int page) { - PixRaster *pixRaster; - - // if we don't want the array to be appended, - // we destroy current array, if any - - if (!Append && pixa) - Destroy(); - - // if empty raster, we create it - if (IsEmpty()) - { - pixa = pixaCreate(0); - curPage = 0; - } - - // shortcut if raster is a pixRaster - Raster::Info info = raster.GetInfo(); - - int width = raster.GetWidth(); - - pixRaster = dynamic_cast(&raster); - - if (pixRaster) - { - ASSERT(copyMode == PIXRASTER_COPY || copyMode == PIXRASTER_CLONE); - AddPIXA(pixRaster->GetPIXA(copyMode)); - return; - } - - // not a PixRaster, we should go the slow way - - // loop for all pages on source raster - int oldPage = raster.GetActivePage(); - - for (int iPage = 0; iPage < raster.GetPageCount(); iPage++) - { - PIX *pix; - - // gets current page on source raster - raster.SeekPage(iPage); - - // gets information from source object - const RasterFormat *format = raster.GetFormat(); - - // convert source image to PIX - - if (!format) - { - // null RasterFormat -- standard Upp RGBA - pix = LoadRASTER_RGBA(raster); - } - - else - { - switch (format->GetType()) - { - - case RASTER_1: - pix = LoadRASTER_1(raster); - break; - - case RASTER_1 | RASTER_MSBFIRST: - pix = LoadRASTER_1_MSBFIRST(raster); - break; - - case RASTER_2: - pix = LoadRASTER_2(raster); - break; - - case RASTER_2 | RASTER_MSBFIRST: - pix = LoadRASTER_2_MSBFIRST(raster); - break; - - case RASTER_4: - pix = LoadRASTER_4(raster); - break; - - case RASTER_4 | RASTER_MSBFIRST: - pix = LoadRASTER_4_MSBFIRST(raster); - break; - - case RASTER_8: - - case RASTER_8 | RASTER_MSBFIRST: - pix = LoadRASTER_8(raster); - break; - - case RASTER_8ALPHA: - - case RASTER_8ALPHA | RASTER_MSBFIRST: - pix = LoadRASTER_8ALPHA(raster); - break; - - case RASTER_16: - pix = LoadRASTER_16(raster); - break; - - case RASTER_16 | RASTER_MSBFIRST: - pix = LoadRASTER_16_MSBFIRST(raster); - break; - - case RASTER_24: - pix = LoadRASTER_24(raster); - break; - - case RASTER_24 | RASTER_MSBFIRST: - pix = LoadRASTER_24_MSBFIRST(raster); - break; - - case RASTER_32: - - case RASTER_32ALPHA: - - case RASTER_32PREMULTIPLIED: - pix = LoadRASTER_32(raster); - break; - - case RASTER_32 | RASTER_MSBFIRST: - - case RASTER_32ALPHA | RASTER_MSBFIRST: - - case RASTER_32PREMULTIPLIED | RASTER_MSBFIRST: - pix = LoadRASTER_32_MSBFIRST(raster); - break; - - } // switch - } - - // if source raster has a palette, create a corresponding - // PIXCMAP and fill it - const RGBA *palette = raster.GetPalette(); - - int palCount = raster.GetPaletteCount(); // needed because of bug of png plugin - - if (palette && palCount) - { - int bpp = raster.GetInfo().bpp; - PIXCMAP *colorTable = pixcmapCreate(bpp); - palCount = min(1 << bpp, palCount); - - for (int iPal = 0; iPal < palCount; iPal++) - { - pixcmapAddColor(colorTable, palette->r, palette->g, palette->b); - palette++; - } - - pixSetColormap(pix, colorTable); - } - - // gets physical resolution from source raster pys dimensions, if any - int dotX = raster.GetInfo().dots.cx; - - int dotY = raster.GetInfo().dots.cy; - - int resX, resY; - - if (dotX) - resX = iscale(600, raster.GetWidth(), dotX); - else - resX = 0; - - if (dotY) - resY = iscale(600, raster.GetHeight(), dotY); - else - resY = 0; - - pixSetXRes(pix, resX); - - pixSetYRes(pix, resY); - - // adds the newly loaded PIX to array - AddPIX(pix, copyMode); - - pixDestroy(&pix); - - } // for iPage - - raster.SeekPage(oldPage); - -} // END PixRaster::Load() - -// gets PIX and PIX array from raster -// warning -- object references are NOT changed -// so objects must NOT be destroyed -PIX *PixRaster::GetPIX(int page, CopyModes copyMode) -{ - PIX *pix; - - if (IsEmpty()) - return NULL; - - page = getTruePage(page); - - if (copyMode == PIXRASTER_COPY) - pix = pixaGetPix(pixa, page, L_COPY); - else - pix = pixaGetPix(pixa, page, L_CLONE); - - if (pix && copyMode == PIXRASTER_REF) - pix->refcount--; - - return pix; - -} // END PixRaster::GetPix() - -PIXA *PixRaster::GetPIXA(CopyModes copyMode) -{ - PIXA *_pixa; - - switch (copyMode) - { - - case PIXRASTER_REF: - return pixa; - - case PIXRASTER_CLONE: - - case PIXRASTER_COPY_CLONE: - - case PIXRASTER_COPY: - return pixaCopy(pixa, copyMode); - - default: - NEVER(); - } - - return NULL; - -} // END PixRaster::GetPIXA() - -// sets PIX and PIX array -void PixRaster::SetPIX(PIX *pix, int page, CopyModes copyMode) -{ - if (IsEmpty()) - return; - - page = getTruePage(page); - - if (copyMode == PIXRASTER_COPY) - pix = pixCopy(NULL, pix); - else - if (copyMode == PIXRASTER_CLONE) - pix = pixClone(pix); - - pixaReplacePix(pixa, page, pix, NULL); - - DestroyLocalPalette(page); - - DestroyRasterFormat(page); - -} // END PixRaster::SetPIX() - -void PixRaster::SetPIXA(PIXA *_pixa, CopyModes copyMode) -{ - Destroy(); - curPage = 0; - AddPIXA(_pixa, copyMode); - -} // END PixRaster::SetPIXA() - -// adds a PIX or a PIX array -void PixRaster::AddPIX(PIX *pix, CopyModes copyMode) -{ - if (!pixa) - pixa = pixaCreate(0); - - pixaAddPix(pixa, pix, copyMode); - - // allocates empty format and local palette - formats.Add((RasterFormat *)NULL); - - localPalettes.Add((RGBA *)NULL); - -} // END PixRaster::AddPIX() - -void PixRaster::AddPIXA(PIXA *_pixa, CopyModes copyMode) -{ - if (!pixa) - pixa = pixaCreate(0); - - pixaJoin(pixa, _pixa, 0, 0); - - // allocates empty format and local palette - for (int i = 0; i < pixaGetCount(_pixa); i++) - { - formats.Add((RasterFormat *)NULL); - localPalettes.Add((RGBA *)NULL); - } - -} // END PixRaster::AddPIXA() - -// inserts a PIX or a PIX array -void PixRaster::InsertPIX(PIX *pix, int where, CopyModes copyMode) -{ - // if adding at end, just append - if (where == PIXRASTER_END || !pixa) - { - AddPIX(pix, copyMode); - return; - } - - // gets true page - where = getTruePage(where); - - // insert pix into pixa array - pixaInsertPix(pixa, where, pix, NULL); - - // inserts empty format and palette - formats.Insert(where, (RasterFormat *)NULL); - - localPalettes.Insert(where, (RGBA *)NULL); - -} - -void PixRaster::InsertPIXA(PIXA *_pixa, int where, CopyModes copyMode) -{ - // if adding at end, just append - if (where == PIXRASTER_END || !pixa) - { - AddPIXA(_pixa, copyMode); - return; - } - - // gets true page - where = getTruePage(where); - - if (copyMode == PIXRASTER_COPY_CLONE) - copyMode = PIXRASTER_CLONE; - - for (int i = 0; i < pixaGetCount(_pixa); i++) - { - // insert pix into pixa array - PIX *pix = pixaGetPix(_pixa, i, copyMode); - pixaInsertPix(pixa, where, pix, NULL); - - // inserts empty format and palette - formats.Insert(where, (RasterFormat *)NULL); - localPalettes.Insert(where, (RGBA *)NULL); - where++; - } - -} - -// removes a PIX or a series of PIX -void PixRaster::RemovePIX(int where, int count) -{ - if (IsEmpty()) - return; - - if (where == PIXRASTER_END) - where = pixaGetCount(pixa) - 1; - - where = getTruePage(where); - - if (pixaGetCount(pixa) - where < count) - count = pixaGetCount(pixa) - where; - - for (int i = 0; i < count; i++) - { - pixaRemovePix(pixa, where); - delete formats[where]; - formats.Remove(where); - delete[] localPalettes[where]; - localPalettes.Remove(where); - } - -} - -// duplicates a page at the end of array (useful for stack-like operations) -void PixRaster::Dup(int page) -{ - PIX *pix = GetPIX(page, PIXRASTER_CLONE); - AddPIX(pix, PIXRASTER_COPY); - pixDestroy(&pix); - SeekPage(PIXRASTER_LASTPAGE); - -} - -// Drops last page(s) of array (ditto) -void PixRaster::Drop(int count) -{ - if (IsEmpty()) - return; - - int start = pixaGetCount(pixa) - count; - - if (start < 0) - { - count += start; - start = 0; - } - - RemovePIX(start, count); - - SeekPage(PIXRASTER_LASTPAGE); - -} - -enum { - READ_24_BIT_COLOR = 0, /* read in as 24 (really 32) bit pix */ - CONVERT_TO_PALETTE = 1, /* convert to 8 bit colormapped pix */ - READ_GRAY = 2 /* read gray only */ -}; - -// File I/O operations -bool PixRaster::Load(FileIn &fs, bool Append) -{ - PIX *pix; int format; #ifdef WIN32 HANDLE fh; #else int fh; #endif + + Destroy(); + fh = fs.GetHandle(); - int iPage; - if (!fh) return false; FILE *fp = fdopen(fh, "r"); if(!fp) return false; - - // if not appending, destroy actual content - if(!Append) - Destroy(); - pix = NULL; format = findFileFormat(fp); - switch (format) { case IFF_BMP: - if ((pix = pixReadStreamBmp(fp)) == NULL ) + if (page || (pix = pixReadStreamBmp(fp)) == NULL ) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); break; case IFF_JFIF_JPEG: - if ((pix = pixReadStreamJpeg(fp, READ_24_BIT_COLOR, 1, NULL, 0)) == NULL) + if (page || (pix = pixReadStreamJpeg(fp, READ_24_BIT_COLOR, 1, NULL, 0)) == NULL) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); break; case IFF_PNG: - if ((pix = pixReadStreamPng(fp)) == NULL) + if (page || (pix = pixReadStreamPng(fp)) == NULL) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); break; case IFF_TIFF: @@ -1184,47 +830,31 @@ bool PixRaster::Load(FileIn &fs, bool Append) case IFF_TIFF_G4: case IFF_TIFF_LZW: case IFF_TIFF_ZIP: - // read first page - if ((pix = pixReadStreamTiff(fp, 0)) == NULL) + // read requested page + if ((pix = pixReadStreamTiff(fp, page)) == NULL) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); - - // read next pages, if any - iPage = 1; - while((pix = pixReadStreamTiff(fp, iPage)) != NULL) - { - pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); - iPage++; - } break; case IFF_PNM: - if ((pix = pixReadStreamPnm(fp)) == NULL) + if (page || (pix = pixReadStreamPnm(fp)) == NULL) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); break; case IFF_GIF: - if ((pix = pixReadStreamGif(fp)) == NULL) + if (page || (pix = pixReadStreamGif(fp)) == NULL) { fclose(fp); return false; } pixSetInputFormat(pix, format); - AddPIX(pix, PIXRASTER_CLONE); - pixDestroy(&pix); break; case IFF_UNKNOWN: @@ -1234,19 +864,459 @@ bool PixRaster::Load(FileIn &fs, bool Append) } fclose(fp); return true; + +} // END Pix::Load() + +bool Pix::Load(String fileName, int page) +{ + FileIn f(fileName); + return Load(f, page); + +} // END Pix::Load() + +bool Pix::Save(String fileName) // @@ to do - add compression and type handling +{ + +} // END Pix::Save() + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////// PixRaster PRIVATE/PROTECTED ///////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// gets real page +int PixRaster::getTruePage(int page) +{ + // if error page, throw exception + // shouldn't happen, but.... + if (page == PIXRASTER_INVALID_PAGE) + NEVER(); + + // if empty raster, returns INVALID_PAGE + else + if (IsEmpty() ) + return 0; + + // special value for current page + else + if (page == PIXRASTER_CURPAGE) + return curPage; + + // special value for last page + else + if (page == PIXRASTER_LASTPAGE) + return pages.GetCount() - 1; + + // negative values mean back offset from last page + else + if (page < 0) + { + page = pages.GetCount() - 1 + page; + + if (page < 0) + page = 0; + + return page; + } + + else + if (page >= pages.GetCount()) + return pages.GetCount() - 1; + else + return page; } +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// gets PIX from raster +// warning -- object references are NOT changed +// so objects must NOT be destroyed +PIX *PixRaster::GetPIX(int page) +{ + if (IsEmpty()) + return NULL; + + page = getTruePage(page); + + return At(page).GetPIX(); + +} // END PixRaster::GetPix() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////// PixRaster PUBLIC //////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// loads / appends Pix from another raster object +void PixRaster::Load(Raster& raster, bool Append, bool deepCopy) +{ + if(!Append) + pages.Clear(); + + for(int page = 0; page < raster.GetPageCount(); page++) + pages.Add(new Pix(raster, deepCopy, page)); + +} // END PixRaster::Load() + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// constructor -- empty raster +PixRaster::PixRaster() +{ + curPage = 0; + +} // END Constructor class PixRaster + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// constructor -- takes a Leptonica Pix +// PixRaster TAKES OWNERSHIP of underlying PIX object which is NULLed +PixRaster::PixRaster(PIX **pix) +{ + pages.Add(new Pix(pix)); + + // sets the current page + curPage = 0; + +} // END Constructor class PixRaster + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// constructor -- takes an array of Leptonica Pix +// PIXA gets destroyed and NULLed +PixRaster::PixRaster(PIXA **pixa) +{ + PIX *pix; + + curPage = 0; + if(!pixa || !*pixa) + return; + + for(int i = 0; i < pixaGetCount(*pixa); i++) + { + pix = pixaGetPix(*pixa, i, L_CLONE); + pages.Add(new Pix(&pix)); + } + pixaDestroy(pixa); + +} // END Constructor class PixRaster + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// destructor +PixRaster::~PixRaster() +{ + +} // END Destructor class PixRaster + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void PixRaster::SeekPage(int page) +{ + if (IsEmpty()) + return; + + // gets true page number + page = getTruePage(page); + curPage = page; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +int PixRaster::GetPageCount() +{ + return pages.GetCount(); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +int PixRaster::GetActivePage() +{ + return curPage; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Size PixRaster::GetSizeEx(int page) +{ + // if empty raster, returns a zero size + if (IsEmpty()) + return Size(0,0); + + // gets true page number + page = getTruePage(page); + + return At(page).GetSize(); + +} // END PixRaster::GetSizeEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Raster::Info PixRaster::GetInfoEx(int page) +{ + if (IsEmpty()) + return Raster::Info(); + + // gets true page number + page = getTruePage(page); + + return At(page).GetInfo(); + +} // END PixRaster::GetInfoEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Raster::Line PixRaster::GetLineEx(int line, int page) +{ + // empty line on empty image + if (IsEmpty()) + return Raster::Line(); + + // gets true page number + page = getTruePage(page); + + return At(page).GetLine(line); + +} // END PixRaster::GetLineEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +int PixRaster::GetPaletteCountEx(int page) +{ + // no palette on empty image + if (IsEmpty()) + return 0; + + // gets true page number + page = getTruePage(page); + + return At(page).GetPaletteCount(); + +} // END PixRaster::GetPaletteCountEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +const RGBA *PixRaster::GetPaletteEx(int page) +{ + // no palette on empty image + if (IsEmpty()) + return 0; + + // gets true page number + page = getTruePage(page); + + return At(page).GetPalette(); + +} // END PixRaster::GetPaletteEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +const RasterFormat *PixRaster::GetFormatEx(int page) +{ + if (IsEmpty()) + return NULL; + + // gets true page number + page = getTruePage(page); + + return At(page).GetFormat(); + +} // END PixRaster::GetFormatEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// read page polymarkers +PolyMarkers *PixRaster::GetPolyMarkersEx(int page) +{ + if (IsEmpty()) + return NULL; + + // gets true page number + page = getTruePage(page); + + return At(page).GetPolyMarkers(); + +} // END PixRaster::GetPolyMarkersEx() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// sets PIX and PIX array +void PixRaster::Set(Pix &pix, int page, bool deepCopy) +{ + if (IsEmpty()) + return; + + page = getTruePage(page); + + if(deepCopy) + pages.At(page) <<= pix; + else + pages.At(page) = pix; + +} // END PixRaster::Set() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// adds a PIX or a PIX array +void PixRaster::Add(Pix &pix, bool deepCopy) +{ + if(deepCopy) + pages.Add(new Pix(pix, 1)); + else + pages.Add(new Pix(pix)); + +} // END PixRaster::Add() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void PixRaster::Add(PixRaster &pixr, bool deepCopy) +{ + for(int i = 0; i < pixr.GetPageCount(); i++) + { + if(deepCopy) + pages.Add(new Pix(pixr[i], 1)); + else + pages.Add(new Pix(pixr[i])); + } + +} // END PixRaster::Add() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// inserts a PIX or a PIX array +void PixRaster::Insert(Pix &pix, int where, bool deepCopy) +{ + // if adding at end, just append + if (where == PIXRASTER_END || !GetPageCount()) + { + Add(pix, deepCopy); + return; + } + + // gets true page + where = getTruePage(where); + + // insert pix into pixa array + if(deepCopy) + pages.Insert(where, new Pix(pix, 1)); + else + pages.Insert(where, new Pix(pix)); + +} // END PixRaster::Insert() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +void PixRaster::Insert(PixRaster &pixr, int where, bool deepCopy) +{ + // if adding at end, just append + if (where == PIXRASTER_END || !GetPageCount()) + { + Add(pixr, deepCopy); + return; + } + + // gets true page + where = getTruePage(where); + + for (int i = 0; i < pixr.GetPageCount(); i++) + { + if(deepCopy) + pages.Insert(where, new Pix(pixr[i], 1)); + else + pages.Insert(where, new Pix(pixr[i])); + where++; + } + +} // END PixRaster::Insert() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// removes a Pix or a series of Pix +void PixRaster::Remove(int where, int count) +{ + if (IsEmpty()) + return; + + if (where == PIXRASTER_END) + where = GetPageCount() - 1; + where = getTruePage(where); + + if (GetPageCount() - where < count) + count = GetPageCount() - where; + + pages.Remove(where, count); + +} // END PixRaster::Remove() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// duplicates a page at the end of array (useful for stack-like operations) +Pix &PixRaster::Dup(int page) +{ + // if raster empty, creates an empty Pix + if (IsEmpty()) + { + pages.Add(new Pix); + return pages[0]; + } + + if (page == PIXRASTER_END) + page = GetPageCount() - 1; + page = getTruePage(page); + + Pix *pix = new Pix(pages[page], 1); + pages.Add(pix); + SeekPage(PIXRASTER_LASTPAGE); + + return *this; + +} // END PixRaster::Dup() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Drops last page(s) of array (ditto) +void PixRaster::Drop(int count) +{ + if (IsEmpty()) + return; + + int start = GetPageCount() - count; + if (start < 0) + { + count += start; + start = 0; + } + Remove(start, count); + SeekPage(PIXRASTER_LASTPAGE); + +} // END PixRaster::Drop() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// array access +Pix &PixRaster::At(int page) +{ + ASSERT(!IsEmpty()); + + page = getTruePage(page); + return pages[page]; + +} // END PixRaster::At() + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// File I/O operations +bool PixRaster::Load(FileIn &fs, bool Append) +{ + // if not appending, destroy actual content + if(!Append) + pages.Clear(); + + int page = 0; + Pix *pix = new Pix(fs, page); + if(!pix) + return false; + while(pix) + { + pages.Add(pix); + page++; + pix = new Pix(fs, page); + } + return true; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// bool PixRaster::Load(String fileName, bool Append) { FileIn f(fileName); return Load(f, Append); } +///////////////////////////////////////////////////////////////////////////////////////////////////////////// bool PixRaster::Save(String fileName, int page) // @@ to do - add compression and type handling { } +///////////////////////////////////////////////////////////////////////////////////////////////////////////// bool PixRaster::SaveAll(String fileName) { diff --git a/bazaar/PixRaster/PixRaster.h b/bazaar/PixRaster/PixRaster.h index 519c83630..63b11443d 100644 --- a/bazaar/PixRaster/PixRaster.h +++ b/bazaar/PixRaster/PixRaster.h @@ -3,7 +3,11 @@ #include +#define Pix _Pix #include "lib/allheaders.h" +#undef Pix + +#include "PolyMarker.h" NAMESPACE_UPP @@ -23,168 +27,185 @@ NAMESPACE_UPP #define PIXRASTER_END 0x8ffffffc #define PIXRASTER_BEGIN 0x00000000 -// raster class wrapping Leptonica PIX and PIXA structures -class PixRaster : public Raster +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// base class for Pix and PixRaster -- used mainly to have a common base class for PixRasterCtrl +class PixBase : public Raster { + public: + typedef PixBase CLASSNAME; + + virtual void SeekPage(int page) {}; + virtual int GetPageCount() { return 1; } + virtual int GetActivePage() { return 0; } + + // gets underlying PIX object + // WARNING -- Pix has ownership of it, so DON'T free nor destroy it + virtual PIX *GetPIX(int page = PIXRASTER_CURPAGE) = 0; + + // standard Raster functions -- they operate on active page + virtual Size GetSize() { return GetSizeEx(PIXRASTER_CURPAGE); } + virtual Raster::Info GetInfo() { return GetInfoEx(PIXRASTER_CURPAGE); } + virtual Raster::Line GetLine(int line) { return GetLineEx(line, PIXRASTER_CURPAGE); } + virtual int GetPaletteCount() { return GetPaletteCountEx(PIXRASTER_CURPAGE); } + virtual const RGBA *GetPalette() { return GetPaletteEx(PIXRASTER_CURPAGE); } + virtual const RasterFormat *GetFormat() { return GetFormatEx(PIXRASTER_CURPAGE); } + virtual int GetWidth() { return GetSize().cx; } + virtual int GetHeight() { return GetSize().cy; } + virtual PolyMarkers *GetPolyMarkers() { return GetPolyMarkersEx(PIXRASTER_CURPAGE); } + + + // extended Raster functions -- they allow to query + // a given page inside raster + virtual Size GetSizeEx(int page) = 0; + virtual Info GetInfoEx(int page) = 0; + virtual Line GetLineEx(int line, int page) = 0; + virtual int GetPaletteCountEx(int page) = 0; + virtual const RGBA *GetPaletteEx(int page) = 0; + virtual const RasterFormat *GetFormatEx(int page) = 0; + virtual int GetWidthEx(int page) { return GetSizeEx(page).cx; } + virtual int GetHeightEx(int page) { return GetSizeEx(page).cy; } + virtual PolyMarkers *GetPolyMarkersEx(int page) = 0; + + virtual bool IsEmpty() = 0; + operator bool() { return !IsEmpty(); } + + virtual void Clear() = 0; + +}; // END Class PixBase + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// class wrapping Leptonica PIX image -- it's a single page raster format +class PixRaster; +class Pix : public PixBase +{ + // give PixRaster access to private members + friend class PixRaster; + + public: + typedef Pix CLASSNAME; + + private: + + // the Leptonica PIX + PIX *pix; + + // raster format + RasterFormat *rasterFormat; + + // local palette + RGBA *localPalette; + + // polygon markers + ArraypolyMarkers; + protected: - // array of Leptonica PIXs - // can contain just one PIX for single page images - PIXA *pixa; + // internal destructor + void Destroy(); - // currently active page for multipage images - int curPage; - - // raster format - Arrayformats; - - // sets raster format depending on page's pix format - void SetRasterFormat(int page); - - // checks wether page format is valid - bool IsRasterFormatValid(int page = PIXRASTER_CURPAGE); - - // destroys page format - void DestroyRasterFormat(int page = PIXRASTER_CURPAGE); - - // local copy of palettes, if any - ArraylocalPalettes; + // sets raster format depending on pix format + void SetRasterFormat(); // synthesyze grayscale palettes - void CreateGrayPalette2(int page); - void CreateGrayPalette4(int page); - void CreateGrayPalette16(int page); - void CreateGrayPalette256(int page); + void CreateGrayPalette2(); + void CreateGrayPalette4(); + void CreateGrayPalette16(); + void CreateGrayPalette256(); // convert PIX palette - void ConvertPIXPalette(PIXCMAP *colormap, int page); + void ConvertPIXPalette(PIXCMAP *colormap); - // destroys local palette - void DestroyLocalPalette(int page = PIXRASTER_CURPAGE); - - // checks wether local palette is valid - bool IsLocalPaletteValid(int page = PIXRASTER_CURPAGE); - // raster loading/conversion routines - PIX *LoadRASTER_RGBA(Raster &raster); + bool LoadRASTER_RGBA(Raster &raster); - PIX *LoadRASTER_1(Raster &raster); - PIX *LoadRASTER_2(Raster &raster); - PIX *LoadRASTER_4(Raster &raster); - PIX *LoadRASTER_8(Raster &raster); - PIX *LoadRASTER_8ALPHA(Raster &raster); - PIX *LoadRASTER_16(Raster &raster); - PIX *LoadRASTER_24(Raster &raster); - PIX *LoadRASTER_32(Raster &raster); + bool LoadRASTER_1(Raster &raster); + bool LoadRASTER_2(Raster &raster); + bool LoadRASTER_4(Raster &raster); + bool LoadRASTER_8(Raster &raster); + bool LoadRASTER_8ALPHA(Raster &raster); + bool LoadRASTER_16(Raster &raster); + bool LoadRASTER_24(Raster &raster); + bool LoadRASTER_32(Raster &raster); - PIX *LoadRASTER_1_MSBFIRST(Raster &raster); - PIX *LoadRASTER_2_MSBFIRST(Raster &raster); - PIX *LoadRASTER_4_MSBFIRST(Raster &raster); - PIX *LoadRASTER_8_MSBFIRST(Raster &raster); - PIX *LoadRASTER_8ALPHA_MSBFIRST(Raster &raster); - PIX *LoadRASTER_16_MSBFIRST(Raster &raster); - PIX *LoadRASTER_24_MSBFIRST(Raster &raster); - PIX *LoadRASTER_32_MSBFIRST(Raster &raster); - - // gets real page - int getTruePage(int page = PIXRASTER_CURPAGE); - - // internal destructor - void Destroy(void); + bool LoadRASTER_1_MSBFIRST(Raster &raster); + bool LoadRASTER_2_MSBFIRST(Raster &raster); + bool LoadRASTER_4_MSBFIRST(Raster &raster); + bool LoadRASTER_8_MSBFIRST(Raster &raster); + bool LoadRASTER_8ALPHA_MSBFIRST(Raster &raster); + bool LoadRASTER_16_MSBFIRST(Raster &raster); + bool LoadRASTER_24_MSBFIRST(Raster &raster); + bool LoadRASTER_32_MSBFIRST(Raster &raster); public: - // pixmaps copy modes - enum CopyModes { PIXRASTER_CLONE = L_CLONE, PIXRASTER_COPY = L_COPY, PIXRASTER_COPY_CLONE = L_COPY_CLONE, PIXRASTER_REF }; - + // gets underlying PIX object + // WARNING -- Pix has ownership of it, so DON'T free nor destroy it + virtual PIX *GetPIX(int page = PIXRASTER_CURPAGE) { return pix; } + operator PIX*() { return GetPIX(PIXRASTER_CURPAGE); } + // bring-in color modes enum BringInModes { PIXRASTER_BRING_IN_WHITE = L_BRING_IN_WHITE, PIXRASTER_BRING_IN_BLACK = L_BRING_IN_BLACK }; - - // constructor -- empty raster - PixRaster(); - - // constructor -- takes a Leptonica Pix - // PIX get cloned and its reference count increased or copied - PixRaster(PIX *pix, CopyModes copyMode = PIXRASTER_CLONE); - - // constructor -- takes an array of Leptonica Pix - // PIXA gets cloned and its reference count increased - PixRaster(PIXA *pixa, CopyModes copyMode = PIXRASTER_COPY_CLONE); - - // destructor -- must free PIXA array - ~PixRaster() { Destroy() ; } - - virtual void SeekPage(int page); - virtual int GetPageCount(); - virtual int GetActivePage(); - - // standard Raster functions -- they operate on active page - virtual Size GetSize(void) { return GetSize(PIXRASTER_CURPAGE); } - virtual Info GetInfo(void) { return GetInfo(PIXRASTER_CURPAGE); } - virtual Line GetLine(int line) { return GetLine(line, PIXRASTER_CURPAGE); } - virtual int GetPaletteCount() { return GetPaletteCount(PIXRASTER_CURPAGE); } - virtual const RGBA *GetPalette() { return GetPalette(PIXRASTER_CURPAGE); } - virtual const RasterFormat *GetFormat() { return GetFormat(PIXRASTER_CURPAGE); } - virtual int GetWidth() { return GetSize().cx; } - virtual int GetHeight() { return GetSize().cy; } - - // extended Raster functions -- they allow to query - // a given page inside raster - virtual Size GetSize(int page); - virtual Info GetInfo(int page); - virtual Line GetLine(int line, int page); - virtual int GetPaletteCount(int page); - virtual const RGBA *GetPalette(int page); - virtual const RasterFormat *GetFormat(int page); - virtual int GetWidth(int page) { return GetSize(page).cx; } - virtual int GetHeight(int page) { return GetSize(page).cy; } - - // check wether pixraster has images - bool IsEmpty(void); - - // gets PIX and PIX array from raster - // by default objects get it's reference count increased, so they - // must be freed by pixDestroy() - can be changed by copyMode parameter - PIX *GetPIX(int page = PIXRASTER_CURPAGE, CopyModes copyMode = PIXRASTER_REF); - PIXA *GetPIXA(CopyModes copyMode = PIXRASTER_REF); - operator PIX*(void) { return GetPIX(PIXRASTER_CURPAGE, PIXRASTER_REF); } - - // sets PIX and PIX array - void SetPIX(PIX *pix, int page = PIXRASTER_CURPAGE, CopyModes copyMode = PIXRASTER_CLONE); - void SetPIXA(PIXA *pixa, CopyModes copyMode = PIXRASTER_COPY_CLONE); - - // adds a PIX or a PIX array - void AddPIX(PIX *pix, CopyModes copyMode = PIXRASTER_CLONE); - void AddPIXA(PIXA *_pixa, CopyModes copyMode = PIXRASTER_COPY_CLONE); - - // inserts a PIX or a PIX array - void InsertPIX(PIX *pix, int where = PIXRASTER_CURPAGE, CopyModes copyMode = PIXRASTER_COPY_CLONE); - void InsertPIXA(PIXA *pixa, int where = PIXRASTER_CURPAGE, CopyModes copyMode = PIXRASTER_COPY_CLONE); - - // removes a PIX or a series of PIX - void RemovePIX(int startPage = PIXRASTER_CURPAGE, int count = 1); - - // duplicates a page at the end of array (useful for stack-like operations) - // NOTE: it seeks added page too - void Dup(int page = PIXRASTER_CURPAGE); - - // Drops last page(s) of array (ditto) - // NOTE: it seeks last page too - void Drop(int count = 1); // loads Pix from another raster object - void Load(Raster& raster, bool Append = false, CopyModes copyMode = PIXRASTER_CLONE); + void Load(Raster& raster, bool deepCopy = false, int page = PIXRASTER_CURPAGE); - // sets/appends a source raster - void operator=(Raster &raster) { Load(raster, false, PIXRASTER_COPY); } - void operator+=(Raster &raster) { Load(raster, true, PIXRASTER_COPY); } + // empty constructor -- sets NULL PIX + Pix(); + + // creates a PIX in given format and size + Pix(int width, int height, int depth, RGBA *colorTable = NULL); + + // constructor -- takes a Leptonica PIX + // TAKES OWNERSHIP of underlying PIX object which is NULLed + Pix(PIX **_pix); + + // copy constructor -- reference increments underlying PIX + Pix(Pix const &_pix); + + // deep copy constructor -- deep copy of underlying PIX + Pix(Pix const &_pix, int i); + + // creation of Pix from a raster object + Pix(Raster &raster, bool deepCopy = false, int page = PIXRASTER_CURPAGE); + + // creation of Pix from file/stream + Pix(FileIn &fs, int page = 0); + Pix(String const &fileName, int page = 0); + + // destructor + ~Pix(); + + // assignment -- increment reference of underlying PIX + Pix &operator=(Pix &pix); + + // deep copy -- deep copies underlying PIX + Pix &operator <<=(Pix &pix); + Pix &DeepCopy(Pix &pix); + + // checks wether Pix is empty + virtual bool IsEmpty() { return (pix == NULL); } + + // empties the image + virtual void Clear() { Destroy(); } + + // extended Raster functions -- they allow to query + // a given page inside raster + virtual Size GetSizeEx(int page); + virtual Info GetInfoEx(int page); + virtual Line GetLineEx(int line, int page); + virtual int GetPaletteCountEx(int page); + virtual const RGBA *GetPaletteEx(int page); + virtual const RasterFormat *GetFormatEx(int page); + + // gets polygon markers + virtual PolyMarkers *GetPolyMarkers() { return &polyMarkers; } + virtual PolyMarkers *GetPolyMarkersEx(int) { return &polyMarkers; } // file I/O - bool Load(FileIn &fs, bool Append = false); - bool Load(String fileName, bool Append = false); - bool Save(String fileName, int page = PIXRASTER_CURPAGE); // @@ to do - add compression and type handling - bool SaveAll(String fileName); - + bool Load(FileIn &fs, int page = 0); + bool Load(String fileName, int page = 0); + bool Save(String fileName); // @@ to do - add compression and type handling + ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////// LEPTONICA OPERATIONS ////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -192,53 +213,51 @@ class PixRaster : public Raster //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // IMAGE THRESHOLDING // - bool DitherToBinary(int page = PIXRASTER_CURPAGE); - bool DitherToBinarySpec(int lowerclip, int upperclip, int page = PIXRASTER_CURPAGE); + Pix DitherToBinary(); + Pix DitherToBinarySpec(int lowerclip, int upperclip); // threshold the image -- warning, operates ONLY on grayscale pixmaps - // original image is unchanged - a new modified image at raster's end - bool ThresholdToBinary(int threshold, int page = PIXRASTER_CURPAGE); + Pix ThresholdToBinary(int threshold); - bool VarThresholdToBinary(int thresholdPage, int page = PIXRASTER_CURPAGE); - bool DitherToBinaryLUT(int lowerclip, int upperclip, int page = PIXRASTER_CURPAGE); - bool GenerateMaskByValue(int val, int page = PIXRASTER_CURPAGE); - bool GenerateMaskByBand(int lower, int upper, int inband, int page = PIXRASTER_CURPAGE); - bool DitherTo2bpp(int cmapflag, int page = PIXRASTER_CURPAGE); - bool DitherTo2bppSpec(int lowerclip, int upperclip, int cmapflag, int page = PIXRASTER_CURPAGE); - bool ThresholdTo2bpp(int nlevels, int cmapflag, int page = PIXRASTER_CURPAGE); - bool ThresholdTo4bpp(int nlevels, int cmapflag, int page = PIXRASTER_CURPAGE); - bool ThresholdOn8bpp(int nlevels, int cmapflag, int page = PIXRASTER_CURPAGE); - bool ThresholdGrayArb(const char *edgevals, int outdepth, int use_average, int setblack, int setwhite, int page = PIXRASTER_CURPAGE); + Pix VarThresholdToBinary(Pix &thresholdPix); + Pix DitherToBinaryLUT(int lowerclip, int upperclip); + Pix GenerateMaskByValue(int val); + Pix GenerateMaskByBand(int lower, int upper, int inband); + Pix DitherTo2bpp(int cmapflag); + Pix DitherTo2bppSpec(int lowerclip, int upperclip, int cmapflag); + Pix ThresholdTo2bpp(int nlevels, int cmapflag); + Pix ThresholdTo4bpp(int nlevels, int cmapflag); + Pix ThresholdOn8bpp(int nlevels, int cmapflag); + Pix ThresholdGrayArb(const char *edgevals, int outdepth, int use_average, int setblack, int setwhite); Buffer MakeGrayQuantIndexTable(int nlevels); Buffer MakeGrayQuantTargetTable(int nlevels, int depth); - bool GenerateMaskByBand32(unsigned refval, int delm, int delp, int page = PIXRASTER_CURPAGE); - bool GenerateMaskByDiscr32(unsigned refval1, unsigned refval2, int distflag, int page = PIXRASTER_CURPAGE); - bool GrayQuantFromHisto(int mPage, double minfract, int maxsize, int page = PIXRASTER_CURPAGE); + Pix GenerateMaskByBand32(unsigned refval, int delm, int delp); + Pix GenerateMaskByDiscr32(unsigned refval1, unsigned refval2, int distflag); + Pix GrayQuantFromHisto(Pix &mPix, double minfract, int maxsize); - bool ThresholdToValue(int threshval, int setval, int page = PIXRASTER_CURPAGE); + Pix ThresholdToValue(int threshval, int setval); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SKEW REMOVAL // // Simple top-level deskew interfaces - bool Deskew(int ReductionFactor = 1, int page = PIXRASTER_CURPAGE); - bool FindSkewAndDeskew(int ReductionFactor, double *skewAngle = NULL, double *confidenceFactor = NULL, int page = PIXRASTER_CURPAGE); + Pix Deskew(int ReductionFactor = 1); + Pix FindSkewAndDeskew(int ReductionFactor, double *skewAngle = NULL, double *confidenceFactor = NULL); // Simple top-level skew angle finding interface - bool FindSkew(double *pangle, double *pconf = NULL, int page = PIXRASTER_CURPAGE); + bool FindSkew(double *pangle, double *pconf = NULL); // Basic angle-finding functions with all parameters - bool FindSkewSweep(double *pangle, int reduction, double sweeprange, double sweepdelta, int page = PIXRASTER_CURPAGE); + bool FindSkewSweep(double *pangle, int reduction, double sweeprange, double sweepdelta); // Angle-finding functions with all parameters bool FindSkewSweepAndSearch( double *pangle, double *pconf, int redsweep, int redsearch, double sweeprange, double sweepdelta, - double minbsdelta, - int page = PIXRASTER_CURPAGE); + double minbsdelta); - bool DeskewLocal(int page = PIXRASTER_CURPAGE); + Pix DeskewLocal(); // NOTE : Leptonica has many more skew functions.... @@ -246,40 +265,154 @@ class PixRaster : public Raster // ROTATION FUNCTIONS // Rotates image (2-4-8 or 32 bpp) about center. - bool RotateAM(double angle, BringInModes incolo = PIXRASTER_BRING_IN_WHITE, int page = PIXRASTER_CURPAGE); - bool RotateAMColor(double angle, int colorval, int page = PIXRASTER_CURPAGE); - bool RotateAMGray(double angle, int grayval, int page = PIXRASTER_CURPAGE); + Pix RotateAM(double angle, BringInModes incolor = PIXRASTER_BRING_IN_WHITE); + Pix RotateAMColor(double angle, int colorval); + Pix RotateAMGray(double angle, int grayval); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // MORPHING FUNCTIONS - bool ErodeGray(int hsize, int vsize, int page = PIXRASTER_CURPAGE); - bool DilateGray(int hsize, int vsize, int page = PIXRASTER_CURPAGE); - bool OpenGray(int hsize, int vsize, int page = PIXRASTER_CURPAGE); - bool CloseGray(int hsize, int vsize, int page = PIXRASTER_CURPAGE); + Pix ErodeGray(int hsize, int vsize); + Pix DilateGray(int hsize, int vsize); + Pix OpenGray(int hsize, int vsize); + Pix CloseGray(int hsize, int vsize); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ARITHMETIC AND ALIKE FUNCTIONS - bool Invert(int page = PIXRASTER_CURPAGE); - bool AddConstantGray(int val, int page = PIXRASTER_CURPAGE); - bool MultConstantGray(int val, int page = PIXRASTER_CURPAGE); - bool AddGray(int page1, int page2); - bool SubtractGray(int page1, int page2); + Pix Invert(); + Pix AddConstantGray(int val); + Pix MultConstantGray(int val); + Pix AddGray(Pix &pix2); + Pix SubtractGray(Pix &pix2); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BLENDING/COMBINING FUNCTIONS - bool CombineMasked(int destPage, int sourcePage, int maskPage); + Pix CombineMasked(Pix &aPix, Pix &maskPix); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // DOCUMENT PAGE SEGMENTING FUNCTIONS // top level page segmenting - bool GetRegionsBinary(int page = PIXRASTER_CURPAGE) ; + PixRaster GetRegionsBinary() ; // text baseline finding routine - Array FindBaselines(int page = PIXRASTER_CURPAGE); + Array FindBaselines(); + +}; // END Class Pix + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// raster class -- array of Pix objects +class PixRaster : public PixBase +{ + protected: + + // array of Pixs + Arraypages; + + // currently active page for multipage images + int curPage; + + // gets real page + int getTruePage(int page = PIXRASTER_CURPAGE); + + public: + + // gets PIX from PixRaster + // WARNING -- Pix has ownership of it, so DON'T free nor destroy it + PIX *GetPIX(int page = PIXRASTER_CURPAGE); + operator PIX*() { return GetPIX(PIXRASTER_CURPAGE); } + + // constructor -- empty raster + PixRaster(); + + // constructor -- takes a Leptonica Pix + // PixRaster TAKES OWNERSHIP of underlying PIX object which is NULLed + PixRaster(PIX **pix); + + // constructor -- takes an array of Leptonica Pix + // PIXA gets destroyed and NULLed + PixRaster(PIXA **pixa); + + // creation of Pix from a raster object + PixRaster(Raster &raster, bool deepCopy = false); + + // destructor + ~PixRaster(); + + // loads Pix from another raster object + void Load(Raster& raster, bool Append = false, bool deepCopy = false); + + // sets/appends a source raster + PixRaster &operator=(Raster &raster) { Load(raster, false, false); return *this; } + PixRaster &operator+=(Raster &raster) { Load(raster, true, false); return *this; } + + // deep copy of source raster + PixRaster &operator <<=(Raster &raster) { Load(raster, false, true); return *this; } + + // page handling + virtual void SeekPage(int page); + virtual int GetPageCount(); + virtual int GetActivePage(); + + // extended Raster functions -- they allow to query + // a given page inside raster + virtual Size GetSizeEx(int page); + virtual Info GetInfoEx(int page); + virtual Line GetLineEx(int line, int page); + virtual int GetPaletteCountEx(int page); + virtual const RGBA *GetPaletteEx(int page); + virtual const RasterFormat *GetFormatEx(int page); + + // gets polygon markers + virtual PolyMarkers *GetPolyMarkers() { return GetPolyMarkersEx(PIXRASTER_CURPAGE); } + virtual PolyMarkers *GetPolyMarkersEx(int page); + + // check whether pixraster has images + bool IsEmpty(void) { return !pages.GetCount(); }; + + // sets Pix + void Set(Pix &_pix, int page = PIXRASTER_CURPAGE, bool deepCopy = false); + + // adds a Pix or a PixRaster + void Add(Pix &pix, bool deepCopy = false); + void Add(PixRaster &pix, bool deepCopy = false); + + // inserts a PIX or a PIX array + void Insert(Pix &pix, int where = PIXRASTER_CURPAGE, bool deepCopy = false); + void Insert(PixRaster &pixR, int where = PIXRASTER_CURPAGE, bool deepCopy = false); + + // removes a PIX or a series of PIX + void Remove(int startPage = PIXRASTER_CURPAGE, int count = 1); + + // duplicates a page at the end of array (useful for stack-like operations) + // NOTE1: deep copy of underlying PIX + // NOTE2: it seeks added page too + Pix &Dup(int page = PIXRASTER_CURPAGE); + + // Drops last page(s) of array (ditto) + // NOTE: it seeks last page too + void Drop(int count = 1); + + // Pix access operator + Pix &operator[](int page) { return At(page); } + + // access current page + operator Pix&() { return At(PIXRASTER_CURPAGE); } + + // array access + Pix &At(int page); + + // empties the image + virtual void Clear() { pages.Clear(); } + + // file I/O + bool Load(FileIn &fs, bool Append = false); + bool Load(String fileName, bool Append = false); + bool Save(String fileName, int page = PIXRASTER_CURPAGE); // @@ to do - add compression and type handling + bool SaveAll(String fileName); + }; // END class PixRaster diff --git a/bazaar/PixRaster/PixRaster.upp b/bazaar/PixRaster/PixRaster.upp index 4a2aae078..191d16523 100644 --- a/bazaar/PixRaster/PixRaster.upp +++ b/bazaar/PixRaster/PixRaster.upp @@ -173,6 +173,8 @@ file PixRaster.h, PixRasterLoad.cpp, PixRaster.cpp, + PolyMarker.h, + PolyMarker.cpp, TiffIo.cpp, UppLept.cpp, Lept-Skew.cpp, diff --git a/bazaar/PixRaster/PixRasterLoad.cpp b/bazaar/PixRaster/PixRasterLoad.cpp index 8d3e5cfe7..43ea50876 100644 --- a/bazaar/PixRaster/PixRasterLoad.cpp +++ b/bazaar/PixRaster/PixRasterLoad.cpp @@ -2,6 +2,7 @@ NAMESPACE_UPP +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // MACROS USED TO CORRECTLY HANDLE ENDIANNESS OF THE MACHINE #ifdef L_BIG_ENDIAN #define SHIFT_START 0 @@ -13,6 +14,7 @@ NAMESPACE_UPP #define SHIFT_STEP(shift) shift -= 8 #endif +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // TRANSFER A BYTE static inline byte ReverseByte(byte sb) { @@ -29,6 +31,7 @@ static inline byte ReverseByte(byte sb) return db; } +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // transfers a byte line -- straight bit order static void TransferLine_STRAIGHT(const byte *rasPnt, l_uint32 *pixPnt, int nBytes) { @@ -52,6 +55,7 @@ static void TransferLine_STRAIGHT(const byte *rasPnt, l_uint32 *pixPnt, int nByt } // END TransferLine_STRAIGHT() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // transfers a byte line -- reverse bit order static void TransferLine_REVERSE(const byte *rasPnt, l_uint32 *pixPnt, int nBytes) { @@ -83,20 +87,26 @@ static void TransferLine_REVERSE(const byte *rasPnt, l_uint32 *pixPnt, int nByte } // END TransferLine_REVERSE() +///////////////////////////////////////////////////////////////////////////////////////////////////////////// // raster loading/conversion routines -PIX *PixRaster::LoadRASTER_RGBA(Raster &raster) +bool Pix::LoadRASTER_RGBA(Raster &raster) { + Destroy(); -} // END PixRaster::LoadRASTER_RGBA() +} // END Pix::LoadRASTER_RGBA() -PIX *PixRaster::LoadRASTER_1(Raster &raster) +bool Pix::LoadRASTER_1(Raster &raster) { + Destroy(); + // get source Raster dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 1); + pix = pixCreateNoInit(width, height, 1); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -118,18 +128,22 @@ PIX *PixRaster::LoadRASTER_1(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_1() +} // END Pix::LoadRASTER_1() -PIX *PixRaster::LoadRASTER_1_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_1_MSBFIRST(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 1); + pix = pixCreateNoInit(width, height, 1); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -151,19 +165,22 @@ PIX *PixRaster::LoadRASTER_1_MSBFIRST(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_1_MSBFIRST() +} // END Pix::LoadRASTER_1_MSBFIRST() -PIX *PixRaster::LoadRASTER_2(Raster &raster) +bool Pix::LoadRASTER_2(Raster &raster) { - + Destroy(); + // get source Raster dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height,2); + pix = pixCreateNoInit(width, height,2); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -185,19 +202,22 @@ PIX *PixRaster::LoadRASTER_2(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_2() +} // END Pix::LoadRASTER_2() -PIX *PixRaster::LoadRASTER_2_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_2_MSBFIRST(Raster &raster) { + Destroy(); // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 2); + pix = pixCreateNoInit(width, height, 2); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -219,19 +239,22 @@ PIX *PixRaster::LoadRASTER_2_MSBFIRST(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_2() +} // END Pix::LoadRASTER_2() -PIX *PixRaster::LoadRASTER_4(Raster &raster) +bool Pix::LoadRASTER_4(Raster &raster) { + Destroy(); // get source Raster dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 4); + pix = pixCreateNoInit(width, height, 4); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -253,19 +276,22 @@ PIX *PixRaster::LoadRASTER_4(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_4() +} // END Pix::LoadRASTER_4() -PIX *PixRaster::LoadRASTER_4_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_4_MSBFIRST(Raster &raster) { + Destroy(); // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 4); + pix = pixCreateNoInit(width, height, 4); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -290,18 +316,22 @@ PIX *PixRaster::LoadRASTER_4_MSBFIRST(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_4() +} // END Pix::LoadRASTER_4() -PIX *PixRaster::LoadRASTER_8(Raster &raster) +bool Pix::LoadRASTER_8(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 8); + pix = pixCreateNoInit(width, height, 8); + if(!pix) + return false; // get PIX width (in words) and pix data pointer int wpl = pixGetWpl(pix); @@ -327,39 +357,49 @@ PIX *PixRaster::LoadRASTER_8(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_8() +} // END Pix::LoadRASTER_8() -PIX *PixRaster::LoadRASTER_8ALPHA(Raster &raster) +bool Pix::LoadRASTER_8ALPHA(Raster &raster) { + Destroy(); + Cerr() << "Upp Leptonica library : 8 bpp with alpha channel still not supported"; NEVER(); -} // END PixRaster::LoadRASTER_8ALPHA() +} // END Pix::LoadRASTER_8ALPHA() -PIX *PixRaster::LoadRASTER_16(Raster &raster) +bool Pix::LoadRASTER_16(Raster &raster) { + Destroy(); + Cerr() << "Upp Leptonica library : 16 bpp still not supported"; NEVER(); -} // END PixRaster::LoadRASTER_16() +} // END Pix::LoadRASTER_16() -PIX *PixRaster::LoadRASTER_16_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_16_MSBFIRST(Raster &raster) { + Destroy(); + Cerr() << "Upp Leptonica library : 16 bpp still not supported"; NEVER(); -} // END PixRaster::LoadRASTER_16() +} // END Pix::LoadRASTER_16() -PIX *PixRaster::LoadRASTER_24(Raster &raster) +bool Pix::LoadRASTER_24(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 32); + pix = pixCreateNoInit(width, height, 32); + if(!pix) + return false; // get PIX width (in bytes) and pix data pointer int wpl = pixGetWpl(pix); @@ -388,18 +428,22 @@ PIX *PixRaster::LoadRASTER_24(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_24() +} // END Pix::LoadRASTER_24() -PIX *PixRaster::LoadRASTER_24_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_24_MSBFIRST(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 24); + pix = pixCreateNoInit(width, height, 24); + if(!pix) + return false; // get PIX width (in bytes) and pix data pointer int wpl = pixGetWpl(pix); @@ -415,18 +459,22 @@ PIX *PixRaster::LoadRASTER_24_MSBFIRST(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_24() +} // END Pix::LoadRASTER_24() -PIX *PixRaster::LoadRASTER_32(Raster &raster) +bool Pix::LoadRASTER_32(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 32); + pix = pixCreateNoInit(width, height, 32); + if(!pix) + return false; // get PIX width (in bytes) and pix data pointer int wpl = pixGetWpl(pix); @@ -454,18 +502,22 @@ PIX *PixRaster::LoadRASTER_32(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_32() +} // END Pix::LoadRASTER_32() -PIX *PixRaster::LoadRASTER_32_MSBFIRST(Raster &raster) +bool Pix::LoadRASTER_32_MSBFIRST(Raster &raster) { + Destroy(); + // get source Rastet dimensions int width = raster.GetWidth(); int height = raster.GetHeight(); // create the PIX - PIX *pix = pixCreateNoInit(width, height, 32); + pix = pixCreateNoInit(width, height, 32); + if(!pix) + return false; // get PIX width (in bytes) and pix data pointer int wpl = pixGetWpl(pix); @@ -481,8 +533,8 @@ PIX *PixRaster::LoadRASTER_32_MSBFIRST(Raster &raster) // next dest line pixLine += wpl; } - return pix; + return true; -} // END PixRaster::LoadRASTER_32() +} // END Pix::LoadRASTER_32() END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/PolyMarker.cpp b/bazaar/PixRaster/PolyMarker.cpp new file mode 100644 index 000000000..6fa114ec0 --- /dev/null +++ b/bazaar/PixRaster/PolyMarker.cpp @@ -0,0 +1,216 @@ +#include "PolyMarker.h" + +using namespace Upp; + +// constructors +PolyMarker::PolyMarker() +{ + kind = Empty; + borderThickness = 0; + borderColor = Black; + borderLineType = 0; + fillColor.a = 0; + fillColor.r = 0; + fillColor.g = 0; + fillColor.b = 0; + closed = false; +} + +PolyMarker::PolyMarker(const PolyMarker &pm) +{ + kind = pm.GetKind(); + borderThickness = pm.GetBorderThickness(); + borderColor = pm.GetBorderColor(); + borderLineType = pm.GetBorderLineType(); + fillColor = pm.GetFillColor(); + closed = pm.IsClosed(); + +} + +// test for point hit +PolyMarker::HitKind PolyMarker::Hit(const Point &p, int minDist) +{ + + switch(kind) + { + case Empty: + return Miss; + + case Rectangle: + { + Point p1 = points[0]; + Point p2 = points[1]; + int x1 = min(p1.x, p2.x); + int y1 = min(p1.y, p2.y); + int x2 = max(p1.x, p2.x); + int y2 = max(p1.y, p2.y); + if(abs(p1.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) + return Vertex; + if(abs(p2.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) + return Vertex; + if(abs(p1.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) + return Side; + if(abs(p2.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) + return Side; + if(abs(p1.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= y2 + minDist) + return Side; + if(abs(p2.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= y2 + minDist) + return Side; + if(p.x > x1 && p.x < x2 && p.y > y1 && p.y < y2) + return Inside; + return Miss; + } + + case Polygon: + // FIXME -- support polygon + default: + NEVER(); + } // switch +} + +// gets vertex or side on point +One const PolyMarker::VertexAt(const Point &p, int minDist) +{ + switch(kind) + { + case Empty: + return One(); + + case Rectangle: + { + Point p1 = points[0]; + Point p2 = points[1]; + int x1 = min(p1.x, p2.x); + int y1 = min(p1.y, p2.y); + int x2 = max(p1.x, p2.x); + int y2 = max(p1.y, p2.y); + if(abs(p1.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) + return One(new Point(p1.x, p1.y)); + else if(abs(p2.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) + return One(new Point(p2.x, p1.y)); + else if(abs(p2.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) + return One(new Point(p2.x, p2.y)); + else if(abs(p1.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) + return One(new Point(p1.x, p2.y)); + return One(); + } + + case Polygon: + { + for(int i = 0; i < points.GetCount(); i++) + { + Point pi = points[i]; + if(abs(pi.x - p.x) <= minDist && abs(pi.y - p.y) <= minDist) + return One(new Point(pi)); + } + return One(); + } + + default: + return One(); + } // switch kind +} + +One const PolyMarker::SideAt(const Point &p, int minDist) +{ + switch(kind) + { + case Empty: + return One(); + + case Rectangle: + { + Point p1 = points[0]; + Point p2 = points[1]; + int x1 = min(p1.x, p2.x); + int y1 = min(p1.y, p2.y); + int x2 = max(p1.x, p2.x); + int y2 = max(p1.y, p2.y); + if(abs(p1.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) + return One(new Rect(Point(p1.x, y1), Point(p1.x, y2))); + else if(abs(p2.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) + return One(new Rect(Point(p2.x, y1), Point(p2.x, y2))); + else if(abs(p1.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= x2 + minDist) + return One(new Rect(Point(x1, p1.y), Point(x2, p1.y))); + else if(abs(p2.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= x2 + minDist) + return One(new Rect(Point(x1, p2.y), Point(x2, p2.y))); + return One(); + } + + case Polygon: + // fixme : add support + + default: + return One(); + + } // switch kind +} + + +// open/close the polygon (invalid for rectangle markers) +bool PolyMarker::Open(void) +{ + closed = false; + +} + +bool PolyMarker::Close(void) + +{ + closed = true; + +} + +// adds a vertex to the polygon (invalid for rectangle markers) +bool PolyMarker::AddVertex(const Point &p) +{ + if(closed || kind == Rectangle) + return false; + points.Add(p); + return true; + +} + +bool PolyMarker::AddVertex(const Array &ap) +{ + if(closed || kind == Rectangle || !ap.GetCount()) + return false; + for(int i = 0; i < ap.GetCount(); i++) + points.Add(ap[i]); + return true; +} + +void PolyMarker::MakeRect(const Point &p1, const Point &p2) +{ + points.Clear(); + points.Add(p1); + points.Add(p1); + kind = Rectangle; + closed = true; +} + +// clears the marker +void PolyMarker::Clear(void) +{ + points.Clear(); + kind = Empty; + closed = false; +} + +// gets a dragged PolyMarker giving start and end point +PolyMarker PolyMarker::Drag(const Point &startP, const Point &endP) +{ + +} + +// changes the PolyMarker at end of drag ops +void PolyMarker::DoDrag(const Point &startP, const Point &endP) +{ + +} + +// paint the PolyMarker on a given viewport +void PolyMarker::Paint(const Rect &vport) +{ + +} diff --git a/bazaar/PixRaster/PolyMarker.h b/bazaar/PixRaster/PolyMarker.h new file mode 100644 index 000000000..424b906e0 --- /dev/null +++ b/bazaar/PixRaster/PolyMarker.h @@ -0,0 +1,76 @@ +#ifndef _PolyMarker_h_ +#define _PolyMarker_h_ + +#include + +NAMESPACE_UPP + +class PolyMarker +{ + public: + typedef PolyMarker CLASSNAME; + + enum HitKind { Miss, Vertex, Side, Inside }; + enum PolyKind { Empty, Rectangle, Polygon }; + + protected: + + PolyKind kind; + Array points; + int borderThickness; + Color borderColor; + int borderLineType; + RGBA fillColor; + bool closed; + + public: + + // constructors + PolyMarker(); + PolyMarker(const PolyMarker &pm); + + // test for point hit + HitKind Hit(const Point &p, int minDist); + + // gets nearest vertex or side to point + One const VertexAt(const Point &p, int minDist); + One const SideAt(const Point &p, int minDist); + + // open/close the polygon (invalid for rectangle markers) + bool Open(void); + bool Close(void); + + // adds a vertex to the polygon (invalid for rectangle markers) + bool AddVertex(const Point &p); + bool AddVertex(const Array &ap); + void MakeRect(const Point &p1, const Point &p2); + + // clears the marker + void Clear(void); + + // member read access + PolyKind GetKind(void) const { return kind; } + bool IsClosed(void) const { return closed; } + Color GetBorderColor(void) const { return borderColor; } + int GetBorderLineType(void) const { return borderLineType; } + int GetBorderThickness(void) const { return borderThickness; } + RGBA GetFillColor(void) const { return fillColor; } + Rect const &GetBoundingBox(void); + Array const &GetPoints(void); + + // gets a dragged PolyMarker giving start and end point + PolyMarker Drag(const Point &startP, const Point &endP); + + // changes the PolyMarker at end of drag ops + void DoDrag(const Point &startP, const Point &endP); + + // paint the PolyMarker on a given viewport + void Paint(const Rect &vport); + +} ; // END Class PolyMarker + +typedef Array PolyMarkers; + +END_UPP_NAMESPACE + +#endif diff --git a/bazaar/PixRaster/UppLept.cpp b/bazaar/PixRaster/UppLept.cpp index f854ca007..ae551ceea 100644 --- a/bazaar/PixRaster/UppLept.cpp +++ b/bazaar/PixRaster/UppLept.cpp @@ -1,5 +1,3 @@ -#include "lib/allheaders.h" - #include "PixRaster.h" #include diff --git a/bazaar/PixRaster/src.tpp/Arith$en-us.tpp b/bazaar/PixRaster/src.tpp/Arith$en-us.tpp index 81e41ee30..9a7a58419 100644 --- a/bazaar/PixRaster/src.tpp/Arith$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Arith$en-us.tpp @@ -8,28 +8,28 @@ topic "Image arithmetic operations"; [s0; &] [ {{10000F(128)G(128)@1 [s0;%% [* Arithmetic operations]]}}&] [s1; &] -[s2;:PixRaster`:`:Invert`(int`): [@(0.0.255) bool]_[* Invert]([@(0.0.255) int]_[*@3 page]_`=_ -PIXRASTER`_CURPAGE)&] -[s3;%% [%-*@3 page].&] +[s2;:Pix`:`:Invert`(`): [@(0.0.255) Pix]_[* Invert]()&] +[s3;%% Inverts image.&] [s4;%% &] [s1; &] -[s2;:PixRaster`:`:AddConstantGray`(int`,int`): [@(0.0.255) bool]_[* AddConstantGray]([@(0.0.255) i -nt]_[*@3 val], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3;%% [%-*@3 val] [%-*@3 page].&] +[s2;:Pix`:`:AddConstantGray`(int`): [@(0.0.255) Pix]_[* AddConstantGray]([@(0.0.255) int]_[*@3 v +al])&] +[s3;%% Adds a constant gray [%-*@3 val] value to image.&] [s4;%% &] [s1; &] -[s2;:PixRaster`:`:MultConstantGray`(int`,int`): [@(0.0.255) bool]_[* MultConstantGray]([@(0.0.255) i -nt]_[*@3 val], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3;%% [%-*@3 val] [%-*@3 page].&] +[s2;:Pix`:`:MultConstantGray`(int`): [@(0.0.255) Pix]_[* MultConstantGray]([@(0.0.255) int]_ +[*@3 val])&] +[s3;%% Multiply all image pixels by a constant [%-*@3 val] value.&] [s4;%% &] [s1; &] -[s2;:PixRaster`:`:AddGray`(int`,int`): [@(0.0.255) bool]_[* AddGray]([@(0.0.255) int]_[*@3 pa -ge1], [@(0.0.255) int]_[*@3 page2])&] -[s3;%% [%-*@3 page1] [%-*@3 page2].&] +[s2;:Pix`:`:AddGray`(Pix`&`): [@(0.0.255) Pix]_[* AddGray]([@(0.0.255) Pix`&]_[*@3 pix2])&] +[s3;%% Adds all grayscale pixels of [%-*@3 pix2] to current pix`'s +ones.&] [s4;%% &] [s1; &] -[s2;:PixRaster`:`:SubtractGray`(int`,int`): [@(0.0.255) bool]_[* SubtractGray]([@(0.0.255) i -nt]_[*@3 page1], [@(0.0.255) int]_[*@3 page2])&] -[s3;%% [%-*@3 page1] [%-*@3 page2].&] +[s2;:Pix`:`:SubtractGray`(Pix`&`): [@(0.0.255) Pix]_[* SubtractGray]([@(0.0.255) Pix`&]_[*@3 p +ix2])&] +[s3;%% Subtracts [%-*@3 pix2] grayscale pixels from current pix`'s +ones.&] [s4;%% &] [s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/Blend$en-us.tpp b/bazaar/PixRaster/src.tpp/Blend$en-us.tpp index 22d02e1d3..26d6de3a6 100644 --- a/bazaar/PixRaster/src.tpp/Blend$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Blend$en-us.tpp @@ -8,13 +8,11 @@ topic "Combining/blending functions"; [s0;%- &] [ {{10000F(128)G(128)@1 [s0; [* Combining/blending functions]]}}&] [s1;%- &] -[s2;:PixRaster`:`:CombineMasked`(int`,int`,int`):%- [@(0.0.255) bool]_[* CombineMasked]([@(0.0.255) i -nt]_[*@3 destPage], [@(0.0.255) int]_[*@3 sourcePage], [@(0.0.255) int]_[*@3 maskPage])&] -[s3; Creates an image from [%-*@3 destPage] with pixels replaced by -[%-*@3 sourcePage]`'s ones if corresponding bits of [%-*@3 maskPage -]are set.&] -[s3; The combined image is appended at the end of PixRaster.&] +[s2;:Pix`:`:CombineMasked`(Pix`&`,Pix`&`):%- [@(0.0.255) bool]_[* CombineMasked]([@(0.0.255) P +ix`&]_[*@3 aPix], [@(0.0.255) Pix`&]_[*@3 maskPix])&] +[s3; Replaces current Pix pixels from [%-*@3 aPix]`'s ones if corresponding +bits of [%-*@3 maskPix ]are set.&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns the combined Pix on success, an empty Pix otherwise.&] [s4; &] [s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/Morph$en-us.tpp b/bazaar/PixRaster/src.tpp/Morph$en-us.tpp index 9b3310572..d27387956 100644 --- a/bazaar/PixRaster/src.tpp/Morph$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Morph$en-us.tpp @@ -8,11 +8,9 @@ topic "Morphing functions"; [s0;%- &] [ {{10000F(128)G(128)@1 [s0; [* Morphing functions]]}}&] [s1;%- &] -[s2;:PixRaster`:`:ErodeGray`(int`,int`,int`):%- [@(0.0.255) bool]_[* ErodeGray]([@(0.0.255) i -nt]_[*@3 hsize], [@(0.0.255) int]_[*@3 vsize], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CU -RPAGE)&] -[s3; Apply the morphological [* erosion] operation on [%-*@3 page] grayscale -image.&] +[s2;:Pix`:`:ErodeGray`(int`,int`):%- [@(0.0.255) Pix]_[* ErodeGray]([@(0.0.255) int]_[*@3 hsi +ze], [@(0.0.255) int]_[*@3 vsize])&] +[s3; Apply the morphological [* erosion] operation on grayscale image.&] [s3; [%-*@3 hsize] and [%-*@3 vsize] are [* Sel] (structuring elements) sizes, and must be odd numbers (they`'re changed to biggest nearest odd number if not) If both [%-*@3 hsize] and [%-*@3 vsize] are equal @@ -21,15 +19,13 @@ to 1, [* ErodeGray] just returns a cloned image.&] pixels depends on size of [* Sel]s&] [s3; Eroded image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns eroded [* Pix ]on success,an empty [* Pix ]otherwise.&] [s3; &] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:DilateGray`(int`,int`,int`):%- [@(0.0.255) bool]_[* DilateGray]([@(0.0.255) i -nt]_[*@3 hsize], [@(0.0.255) int]_[*@3 vsize], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CU -RPAGE)&] -[s3; Apply the morphological [* dilation] operation on [%-*@3 page] grayscale -image.&] +[s2;:Pix`:`:DilateGray`(int`,int`):%- [@(0.0.255) Pix]_[* DilateGray]([@(0.0.255) int]_[*@3 h +size], [@(0.0.255) int]_[*@3 vsize])&] +[s3; Apply the morphological [* dilation] operation on grayscale image.&] [s3; [%-*@3 hsize] and [%-*@3 vsize] are [* Sel] (structuring elements) sizes, and must be odd numbers (they`'re changed to biggest nearest odd number if not) If both [%-*@3 hsize] and [%-*@3 vsize] are equal @@ -38,15 +34,13 @@ to 1, [* DilateGray] just returns a cloned image.&] pixels depends on size of [* Sel]s&] [s3; Dilated image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns dilated [* Pix ]on success,an empty [* Pix ]otherwise.&] [s3; &] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:OpenGray`(int`,int`,int`):%- [@(0.0.255) bool]_[* OpenGray]([@(0.0.255) i -nt]_[*@3 hsize], [@(0.0.255) int]_[*@3 vsize], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CU -RPAGE)&] -[s3; Apply the morphological [* opening] operation on [%-*@3 page] grayscale -image.&] +[s2;:Pix`:`:OpenGray`(int`,int`):%- [@(0.0.255) Pix]_[* OpenGray]([@(0.0.255) int]_[*@3 hsize +], [@(0.0.255) int]_[*@3 vsize])&] +[s3; Apply the morphological [* opening] operation on grayscale image.&] [s3; [%-*@3 hsize] and [%-*@3 vsize] are [* Sel] (structuring elements) sizes, and must be odd numbers (they`'re changed to biggest nearest odd number if not) If both [%-*@3 hsize] and [%-*@3 vsize] are equal @@ -55,15 +49,13 @@ to 1, [* OpenGray] just returns a cloned image.&] one; the amount of added/eroded pixels depends on size of [* Sel]s&] [s3; Opened image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns opened [* Pix ]on success,an empty [* Pix ]otherwise.&] [s3; &] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:CloseGray`(int`,int`,int`):%- [@(0.0.255) bool]_[* CloseGray]([@(0.0.255) i -nt]_[*@3 hsize], [@(0.0.255) int]_[*@3 vsize], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CU -RPAGE)&] -[s3; Apply the morphological [* closing] operation on [%-*@3 page] grayscale -image.&] +[s2;:Pix`:`:CloseGray`(int`,int`):%- [@(0.0.255) Pix]_[* CloseGray]([@(0.0.255) int]_[*@3 hsi +ze], [@(0.0.255) int]_[*@3 vsize])&] +[s3; Apply the morphological [* closing] operation on grayscale image.&] [s3; [%-*@3 hsize] and [%-*@3 vsize] are [* Sel] (structuring elements) sizes, and must be odd numbers (they`'re changed to biggest nearest odd number if not) If both [%-*@3 hsize] and [%-*@3 vsize] are equal @@ -72,7 +64,7 @@ to 1, [* CloseGray] just returns a cloned image.&] ]one; the amount of added/eroded pixels depends on size of [* Sel]s&] [s3; Closed image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns closed [* Pix ]on success,an empty [* Pix ]otherwise.&] [s3; &] [s4; &] [s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/PageSeg$en-us.tpp b/bazaar/PixRaster/src.tpp/PageSeg$en-us.tpp index 057d4db81..27c49828c 100644 --- a/bazaar/PixRaster/src.tpp/PageSeg$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/PageSeg$en-us.tpp @@ -1,4 +1,4 @@ -topic ""; +topic "Document analysis function"; [ $$0,0#00000000000000000000000000000000:Default] [H6;0 $$1,0#05600065144404261032431302351956:begin] [i448;a25;kKO9;2 $$2,0#37138531426314131252341829483370:codeitem] @@ -8,17 +8,22 @@ topic ""; [s0;%- &] [ {{10000F(128)G(128)@1 [s0; [* Page segmentation/layout analysis functions]]}}&] [s1;%- &] -[s2;:PixRaster`:`:GetRegionsBinary`(int`):%- [@(0.0.255) bool]_[* GetRegionsBinary]([@(0.0.255) i -nt]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; Gets layout masks for image at [%-*@3 page]. Masks are appended -at the end of PixRaster in this sequence :&] +[s2;:Pix`:`:GetRegionsBinary`(`):%- [@(0.0.255) PixRaster]_[* GetRegionsBinary]()&] +[s3; Gets layout masks for image. Masks are returned as a multipaged +PixRaster in this sequence :&] [s3;i150;O0; Halftone mask-|-|1 bpp mask for halftone page parts&] [s3;i150;O0; Textline mask-|-|1 bpp mask for text lines inside page&] [s3;i150;O0; Textblock mask-|-|1 bpp mask for text blocks inside page&] -[s3; Active PixRaster page is set to first (Halftone) of the three -resulting masks.&] +[s3; Active returned PixRaster page is set to first (Halftone) of +the three resulting masks.&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns [* Pixraster ]with masks on success, an empty [* PixRaster +]otherwise.&] [s3; &] [s4; &] -[s0; ] \ No newline at end of file +[s1;%- &] +[s2;:Pix`:`:FindBaselines`(`):%- [_^Array^ Array]<[@(0.0.255) int]>_[* FindBaselines]()&] +[s3; Finds all text baselines of image.&] +[s4;%- &] +[s3; Returns an [* array ]of [* y] coordinates on success, an empty [* array +]otherwise.] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/PixRaster$en-us.tpp b/bazaar/PixRaster/src.tpp/PixRaster$en-us.tpp index 38b83c693..bb6ab31f8 100644 --- a/bazaar/PixRaster/src.tpp/PixRaster$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/PixRaster$en-us.tpp @@ -1,4 +1,4 @@ -topic "class PixRaster"; +topic "class PixRaster : public PixBase"; [ $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9; $$1,0#37138531426314131252341829483380:structitem] [l288;2 $$2,0#27521748481378242620020725143825:desc] @@ -6,60 +6,38 @@ topic "class PixRaster"; [H6;0 $$4,0#05600065144404261032431302351956:begin] [*2 $$5,0#37138531426314131252341829483370:codeitem] [{_} -[s1;:PixRaster`:`:class: [@(0.0.255) class]_[* PixRaster]_:_[@(0.0.255) public]_[*@3 Raster]&] +[s1;:PixRaster`:`:class: [@(0.0.255) class]_[* PixRaster]_:_[@(0.0.255) public]_[*@3 PixBase]&] +[s2;%% Multipaged Leptonica raster object.&] +[s2;%% It contains an array of [* Pix] single`-page Leptonica raster +objects&] [s2;%% &] [s3; &] [s0; &] -[ {{10000F(128)G(128)@1 [s0;%% [* Public enums]]}}&] -[s0;2 &] -[s4; &] -[s5;:PixRaster`:`:PIXRASTER`_REF: [@(0.0.255) enum]_CopyModes&] -[s2;%% &] -[s2; Gives ownership of internal Leptonica PIX images and PIXA arrays -when creating or copying PixRaster objects :&] -[s0; &] -[s5; -|PIXRASTER`_CLONE -|-|[* PIX and PIXA`'s reference count gets increased]&] -[s5; -|PIXRASTER`_COPY-|-|-|[* PIX and PIXAs are deep cloned]&] -[s5; -|PIXRASTER`_COPY`_CLONE-|-|[* PIX`'s reference count increased and -PIXA deep cloned]&] -[s5; -|PIXRASTER`_REF-|-|-|[* PIX and PIXAs are just referenced by pointer]&] -[s0; &] -[s0; [2 This enum is used mostly when dealing directly with Leptonica -PIX and PIXA objects. PixRaster provides wrapping for most Leptonica -functions, so user usually don`'t care of internal objects ownership.]&] -[s0; [2 If you need to access internal objects keep in mind that cloned -or referenced objects may change by means of other calls; in -doubt use PIXRASTER`_COPY to get a full image copy.]&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:PIXRASTER`_BRING`_IN`_WHITE: [@(0.0.255) enum]_BringInModes&] -[s2;%% &] -[s2; Color filling mode in operations that adds parts to images, -for example rotations :&] -[s0; &] -[s5; -|PIXRASTER`_BRING`_IN`_WHITE-|[* Fills new parts with white color]&] -[s5; -|PIXRASTER`_BRING`_IN`_BLACK-|[* Fills new parts with black color]&] -[s2;%% &] -[s3; &] -[s0;*%% &] [ {{10000F(128)G(128)@1 [s0;%% [* Constructors and destructor]]}}&] [s4; &] [s5;:PixRaster`:`:PixRaster`(`): PixRaster()&] [s2;%% Constructs an empty PixRaster object.&] [s3; &] [s4; &] -[s5;:PixRaster`:`:PixRaster`(PIX`*`,CopyModes`): PixRaster([_^PIX^ PIX]_`*[@3 pix], -CopyModes_[@3 copyMode]_`=_PIXRASTER`_CLONE)&] +[s5;:PixRaster`:`:PixRaster`(PIX`*`*`): PixRaster([_^PIX^ PIX]_`*`*[@3 pix])&] [s2;%% [%- Constructs a single page PixRaster from a Leptonica][%-*@3 -pix] image; ownership of image is assigned by [%-*@3 copyMode] -parameter&] +pix] image.&] +[s2;%% PixRaster takes ownership of PIX object; to avoid misuse of +it, [%-*@3 pix] is cleared.&] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:PixRaster`(PIXA`*`,CopyModes`): PixRaster([_^PIXA^ PIXA]_`*[@3 pixa], -CopyModes_[@3 copyMode]_`=_PIXRASTER`_COPY`_CLONE)&] +[s5;:PixRaster`:`:PixRaster`(PIXA`*`*`): PixRaster([_^PIXA^ PIXA]_`*`*[@3 pixa])&] [s2;%% Constructs a multipage PixRaster from a Leptonica [%-*@3 pixa] -array of images; ownership of array and images is assigned by -[%-*@3 copyMode] parameter&] +array of images.&] +[s2;%% PixRaster takes ownership of array; to avoid misuse of it, +[%-*@3 pixa] is cleared.&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:PixRaster`(Raster`&`,bool`): PixRaster([_^Raster^ Raster]_`&[@3 raster], + [@(0.0.255) bool]_[@3 deepCopy]_`=_[@(0.0.255) false], [@(0.0.255) int]_[@3 page]_`=_PIXRA +STER`_CURPAGE)&] +[s2;%% Constructs PixRaster from a source [%-*@3 raster] with optional +[%-*@3 deepCopy].&] [s3;%% &] [s4; &] [s5;:PixRaster`:`:`~PixRaster`(`): [@(0.0.255) `~]PixRaster()&] @@ -67,73 +45,74 @@ array of images; ownership of array and images is assigned by [s3; &] [ {{10000F(128)G(128)@1 [s0;%% [* Internal handling of Leptonica objects]]}}&] [s4; &] -[s5;:PixRaster`:`:GetPIX`(int`,CopyModes`): [_^PIX^ PIX]_`*GetPIX([@(0.0.255) int]_[@3 page -]_`=_PIXRASTER`_CURPAGE, CopyModes_[@3 copyMode]_`=_PIXRASTER`_REF)&] -[s2;%% gets internal [* PIX] object from given [%-*@3 page] , defaulting -to current one.&] -[s2;%% [%-*@3 copyMode] sets the ownership of retrieved object, defaulting -to simple reference.&] +[s5;:PixRaster`:`:GetPIX`(int`): [_^PIX^ PIX]_`*GetPIX([@(0.0.255) int]_[@3 page]_`=_PIXRAS +TER`_CURPAGE)&] +[s2;%% Gets underlying Leptonica [* PIX ]object for [%-*@3 page].&] +[s2;%% [* WARNING], [* Pix] owns [* PIX ]object, so don`'t free it.&] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:GetPIXA`(CopyModes`): [_^PIXA^ PIXA]_`*GetPIXA(CopyModes_[@3 copyMode]_ -`=_PIXRASTER`_REF)&] -[s2;%% gets internal PIXA image array; [%-*@3 copyMode] sets the ownership -of retrieved array, defaulting to simple reference&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:operator PIX`*`(void`): operator_PIX`*([@(0.0.255) void])&] +[s5;:PixRaster`:`:operator PIX`*`(`): operator_PIX`*()&] [s2;%% same as [^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:GetPIX`(int`,CopyModes`)^ G -etPIX](PIXRASTER`_CURPAGE, PIXRASTER`_REF)&] +etPIX](PIXRASTER`_CURPAGE)&] [s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Member images access]]}}&] +[s0; &] [s4; &] -[s5;:PixRaster`:`:SetPIX`(PIX`*`,int`,CopyModes`): [@(0.0.255) void]_SetPIX([_^PIX^ PIX]_ -`*[@3 pix], [@(0.0.255) int]_[@3 page]_`=_PIXRASTER`_CURPAGE, CopyModes_[@3 copyMode]_`=_ -PIXRASTER`_CLONE)&] -[s2;%% sets [%-*@3 pix] at [%-*@3 page] with ownership given by [%-*@3 copyMode]. -Previous PIX gets it`'s reference decreased and is freed if necessary.&] +[s5;:PixRaster`:`:Set`(Pix`&`,int`,bool`):%% [%-@(0.0.255) void][%- _Set(][%-_^PIX^ Pix][%- _ +`&][%-@3 pix][%- , ][%-@(0.0.255) int][%- _][%-@3 page][%- _`=_PIXRASTER`_CURPAGE, +][%-@(0.0.255) bool] [%-@3 DeepCopy][%- `=_][%-@(0.0.255) false])&] +[s2;%% sets [%-*@3 pix] at [%-*@3 page] with optional [%-*@3 DeepCopy].&] [s0;%% &] +[s4; &] +[s5;:PixRaster`:`:Add`(Pix`&`,bool`): [@(0.0.255) void]_Add([_^PIX^ Pix]_`&[@3 pix], +[@(0.0.255) bool][%% ][@3 DeepCopy]`=_[@(0.0.255) false])&] +[s2;%% Appends a [%-*@3 pix] to the end of PixRaster with optional +[%-*@3 DeepCopy] .&] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:SetPIXA`(PIXA`*`,CopyModes`): [@(0.0.255) void]_SetPIXA([_^PIXA^ PIXA]_ -`*[@3 pixa], CopyModes_[@3 copyMode]_`=_PIXRASTER`_COPY`_CLONE)&] -[s2;%% replaces image array with [%-*@3 pixa] using ownership given -by [%-*@3 copyMode]. Previous image array gets it`'s reference -decreased and is freed if necessary.&] +[s5;:PixRaster`:`:Add`(PixRaster`&`,bool`): [@(0.0.255) void]_Add([_^PIXA^ PixRaster]_`&[@3 p +ixr], [@(0.0.255) bool][%% ][@3 DeepCopy]`=_[@(0.0.255) false])&] +[s2;%% Appends [%-*@3 pixr] PixRaster at end of current one with optional +[%-*@3 DeepCopy] &] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:AddPIX`(PIX`*`,CopyModes`): [@(0.0.255) void]_AddPIX([_^PIX^ PIX]_`*[@3 p -ix], CopyModes_[@3 copyMode]_`=_PIXRASTER`_CLONE)&] -[s2;%% Appends a [%-*@3 pix] to the end of PixRaster using ownership -given by [%-*@3 copyMode].&] +[s5;:PixRaster`:`:Insert`(Pix`&`,int`,bool`): [@(0.0.255) void]_Insert([_^PIX^ Pix]_`&[@3 p +ix], [@(0.0.255) int]_[@3 where]_`=_PIXRASTER`_CURPAGE, [@(0.0.255) bool][%% +][@3 DeepCopy]`=_[@(0.0.255) false])&] +[s2;%% Inserts Pix [%-*@3 pix] at [%-*@3 where] position with optional +[%-*@3 DeepCopy] &] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:AddPIXA`(PIXA`*`,CopyModes`): [@(0.0.255) void]_AddPIXA([_^PIXA^ PIXA]_ -`*[@3 pixa], CopyModes_[@3 copyMode]_`=_PIXRASTER`_COPY`_CLONE)&] -[s2;%% Appends a [%-*@3 pixa] image array to the end of PixRaster using -ownership given by [%-*@3 copyMode].Valid modes are only PIXRASTER`_COPY -and PIXRASTER`_CLONE.&] +[s5;:PixRaster`:`:Insert`(PixRaster`&`,int`,bool`): [@(0.0.255) void]_Insert([_^PIXA^ Pix +Raster]_`&[@3 pixr], [@(0.0.255) int]_[@3 where]_`=_PIXRASTER`_CURPAGE, +[@(0.0.255) bool][%% ][@3 DeepCopy]`=_[@(0.0.255) false])&] +[s2;%% Inserts [%-*@3 pixr] PixRaster at [%-*@3 where] position with +optional [%-*@3 DeepCopy] &] [s3;%% &] [s4; &] -[s5;:PixRaster`:`:InsertPIX`(PIX`*`,int`,CopyModes`): [@(0.0.255) void]_InsertPIX([_^PIX^ P -IX]_`*[@3 pix], [@(0.0.255) int]_[@3 where]_`=_PIXRASTER`_CURPAGE, -CopyModes_[@3 copyMode]_`=_PIXRASTER`_COPY`_CLONE)&] -[s2;%% Inserts a [%-*@3 pix] at [%-*@3 where] position using ownership -given by [%-*@3 copyMode].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:InsertPIXA`(PIXA`*`,int`,CopyModes`): [@(0.0.255) void]_InsertPIXA([_^PIXA^ P -IXA]_`*[@3 pixa], [@(0.0.255) int]_[@3 where]_`=_PIXRASTER`_CURPAGE, -CopyModes_[@3 copyMode]_`=_PIXRASTER`_COPY`_CLONE)&] -[s2;%% Inserts a [%-*@3 pixa] image array at [%-*@3 where] position using -ownership given by [%-*@3 copyMode].Valid modes are only PIXRASTER`_COPY -and PIXRASTER`_CLONE.&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:RemovePIX`(int`,int`): [@(0.0.255) void]_RemovePIX([@(0.0.255) int]_[@3 s -tartPage]_`=_PIXRASTER`_CURPAGE, [@(0.0.255) int]_[@3 count]_`=_[@3 1])&] -[s2;%% Removes [%-*@3 count ]PIX images starting at [%-*@3 startPage +[s5;:PixRaster`:`:Remove`(int`,int`): [@(0.0.255) void]_Remove([@(0.0.255) int]_[@3 startPa +ge]_`=_PIXRASTER`_CURPAGE, [@(0.0.255) int]_[@3 count]_`=_[@3 1])&] +[s2;%% Removes [%-*@3 count ]Pix images starting at [%-*@3 startPage ]position.&] [s3;%% &] +[s4; &] +[s5;:PixRaster`:`:operator`[`]`(int`): [_^Pix^ Pix]_`&operator`[`]([@(0.0.255) int]_[@3 pag +e])&] +[s2;%% Access [* Pix] at [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:operator Pix`&`(`): operator_Pix`&()&] +[s2;%% Access [* Pix ]at current page.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:At`(int`): [_^Pix^ Pix]_`&At([@(0.0.255) int]_[@3 page])&] +[s2;%% Access [* Pix ]at [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:Clear`(`): [@(0.0.255) virtual] [@(0.0.255) void]_Clear()&] +[s2;%% Clears PixRaster content.&] +[s3; &] [s0; &] [ {{10000F(128)G(128)@1 [s0;%% [* Stack`-like operations]]}}&] [s4; &] @@ -149,29 +128,161 @@ one.&] array and going backwards. Active page is set to last one.&] [s3;%% &] [s0; &] -[ {{10000F(128)G(128)@1 [s0;%% [* Conversions support from other Raster derived objects]]}}&] +[ {{10000F(128)G(128)@1 [s0;%% [* Page handling functions]]}}&] [s4; &] -[s5;:PixRaster`:`:Load`(Raster`&`,bool`,CopyModes`): [@(0.0.255) void]_Load([_^Raster^ Ra -ster][@(0.0.255) `&]_[@3 raster], [@(0.0.255) bool]_[@3 Append]_`=_[@(0.0.255) false], -CopyModes_[@3 copyMode]_`=_PIXRASTER`_CLONE)&] +[s5;:PixRaster`:`:SeekPage`(int`): [@(0.0.255) virtual] [@(0.0.255) void]_SeekPage([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Sets active [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetPageCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPageCount()&] +[s2;%% Gets number of images on PixRaster&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetActivePage`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetActivePage( +)&] +[s2;%% Gets number of currently active page&] +[s3; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Miscellaneous Raster functions]]}}&] +[s4; &] +[s5;:PixRaster`:`:GetSize`(void`): [@(0.0.255) virtual] [_^Size^ Size]_GetSize([@(0.0.255) v +oid])&] +[s2;%% Returns the size of Raster`'s active page in pixels.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetSizeEx`(int`): [@(0.0.255) virtual] [_^Size^ Size]_GetSizeEx([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the size of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetWidth`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetWidth()&] +[s2;%% Returns the width of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetWidthEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetWidthEx([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the width of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetHeight`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetHeight()&] +[s2;%% Returns the height of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetHeightEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetHeightEx([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the height of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetInfo`(void`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_GetInfo( +[@(0.0.255) void])&] +[s2;%% Returns the information about Raster`'s active page.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetInfoEx`(int`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_GetInfo +Ex([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the information about Raster for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetLine`(int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_GetLine([@(0.0.255) i +nt]_[@3 line])&] +[s2;%% Reads a single scanline [%-*@3 line] from the raster`'s active +page. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetLineEx`(int`,int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_Ge +tLineEx([@(0.0.255) int]_[@3 line], [@(0.0.255) int]_[@3 page])&] +[s2;%% Reads a single scanline [%-*@3 line] from [%-*@3 page] ot the +raster. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetPaletteCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPaletteCo +unt()&] +[s2;%% Returns the size of palette for raster`'s active page. If +there is no palette, returns 0&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetPaletteCountEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPale +tteCountEx([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the size of palette for raster`'s [%-*@3 page]. If there +is no palette, returns 0..&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetPalette`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_`* +GetPalette()&] +[s2;%% Returns active pages`'current palette, NULL if there is no +palette.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetPaletteEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGB +A]_`*GetPaletteEx([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns [%-*@3 page][%- `'s ]current palette, NULL if there is +no palette &] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:GetFormat`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ R +asterFormat]_`*GetFormat()&] +[s2;%% Returns the format of Raster`'s active page, can return NULL +if format is RGBA.&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetFormatEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ R +asterFormat]_`*GetFormatEx([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the format of Raster`'s [%-*@3 page], can return NULL +if format is RGBA.&] +[s3;%% &] +[s4; &] +[s5;:PixRaster`:`:IsEmpty`(void`): [@(0.0.255) bool]_IsEmpty([@(0.0.255) void])&] +[s2;%% Returns true if PixRaster has no images.&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Polygon markers access]]}}&] +[s0; &] +[s4; &] +[s5;:PixRaster`:`:GetPolyMarkers`(`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarkers]_`* +GetPolyMarkers()&] +[s2;%% Returns array of polygon markers for current raster page&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:GetPolyMarkersEx`(int`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarke +rs]_`*GetPolyMarkersEx([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns array of polygon markers for raster [%-*@3 page].&] +[s3;%% &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Conversion and file I/O functions]]}}&] +[s0; &] +[s4; &] +[s5;:PixRaster`:`:Load`(Raster`&`,bool`,bool`): [@(0.0.255) void]_Load([_^Raster^ Raster][@(0.0.255) `& +]_[@3 raster], [@(0.0.255) bool]_[@3 Append]_`=_[@(0.0.255) false], [@(0.0.255) bool]_[@3 Dee +pCopy]_`=_[@(0.0.255) false])&] [s2;%% Loads image array from [%-*@3 raster] object or [%-*@3 Append] -them to current one. Ownership of added images is given by [%-*@3 copyMode].&] +them to current one. Source images are referenced or deep copied +depending on [%-*@3 DeepCopy] parameter.&] [s3;%% &] [s4; &] [s5;:PixRaster`:`:operator`=`(Raster`&`): [@(0.0.255) void]_operator`=([_^Raster^ Raster]_ `&[@3 raster])&] [s2;%% Same as [*^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:Load`(Raster`&`,bool`,CopyModes`)^ L -oad][* (][%-*@3 raster][* , ][%-*@(0.0.255) false][* , PIXRASTER`_COPY)] +oad][* (][%-*@3 raster][* , ][%-*@(0.0.255) false][* , ][%-*@(0.0.255) false][* )] Sets PixRaster`'s content equal to [%-*@3 raster]`'s one.&] [s3;%% &] [s4; &] [s5;:PixRaster`:`:operator`+`=`(Raster`&`): [@(0.0.255) void]_operator`+`=([_^Raster^ Ras ter]_`&[@3 raster])&] [s2;%% Same as [*^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:Load`(Raster`&`,bool`,CopyModes`)^ L -oad][* (][%-*@3 raster], [%-*@(0.0.255) true][* , PIXRASTER`_COPY)] -Appends [%-*@3 raster]`'s content at the end of Pixraster`'s one&] -[s0; &] -[ {{10000F(128)G(128)@1 [s0;%% [* File I/O]]}}&] +oad][* (][%-*@3 raster], [%-*@(0.0.255) true][* , ][%-*@(0.0.255) false][* )] + Appends [%-*@3 raster]`'s content at the end of PixRaster`'s one&] +[s3; &] +[s4; &] +[s5;:PixRaster`:`:operator`<`<`=`(Raster`&`): [_^PixRaster^ PixRaster]_`&[@(0.0.255) oper +ator]_<<`=(Raster_`&[@3 raster])&] +[s2;%% Same as [*^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:Load`(Raster`&`,bool`,CopyModes`)^ L +oad][* (][%-*@3 raster][* , ][%-*@(0.0.255) false][* , ][%-*@(0.0.255) true][* )] + Sets PixRaster`'s content equal to [%-*@3 raster]`'s one deep +copying it.&] [s3;%% &] [s4; &] [s5;:PixRaster`:`:Load`(FileIn`&`,bool`): [@(0.0.255) bool]_Load([_^FileIn^ FileIn]_`&[@3 f @@ -209,122 +320,4 @@ choosen file format must support multiple pages.&] [s0;%% &] [s2;%% Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] [s3;%% &] -[s0; &] -[ {{10000F(128)G(128)@1 [s0;%% [* Page handling functions]]}}&] -[s4; &] -[s5;:PixRaster`:`:SeekPage`(int`): [@(0.0.255) virtual] [@(0.0.255) void]_SeekPage([@(0.0.255) i -nt]_[@3 page])&] -[s2;%% Sets active [%-*@3 page].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetPageCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPageCount()&] -[s2;%% Gets number of images on PixRaster&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetActivePage`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetActivePage( -)&] -[s2;%% Gets number of currently active page&] -[s3; &] -[ {{10000F(128)G(128)@1 [s0;%% [* Miscellaneous Raster functions]]}}&] -[s4; &] -[s5;:PixRaster`:`:GetSize`(void`): [@(0.0.255) virtual] [_^Size^ Size]_GetSize([@(0.0.255) v -oid])&] -[s2;%% Returns the size of Raster`'s active page in pixels.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetSize`(int`): [@(0.0.255) virtual] [_^Size^ Size]_GetSize([@(0.0.255) i -nt]_[@3 page])&] -[s2;%% Returns the size of Raster in pixels for [%-*@3 page].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetWidth`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetWidth()&] -[s2;%% Returns the width of Raster in pixels for active page.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetWidth`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetWidth([@(0.0.255) i -nt]_[@3 page])&] -[s2;%% Returns the width of Raster in pixels for [%-*@3 page].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetHeight`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetHeight()&] -[s2;%% Returns the height of Raster in pixels for active page.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetHeight`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetHeight([@(0.0.255) i -nt]_[@3 page])&] -[s2;%% Returns the height of Raster in pixels for [%-*@3 page].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetInfo`(void`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_GetInfo( -[@(0.0.255) void])&] -[s2;%% Returns the information about Raster`'s active page.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetInfo`(int`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_GetInfo([@(0.0.255) i -nt]_[@3 page])&] -[s2;%% Returns the information about Raster for [%-*@3 page].&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetLine`(int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_GetLine([@(0.0.255) i -nt]_[@3 line])&] -[s2;%% Reads a single scanline [%-*@3 line] from the raster`'s active -page. If possible, Raster should be optimized for reading scanlines -in ascending order `- this what most processing functions (should) -require.&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetLine`(int`,int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_GetL -ine([@(0.0.255) int]_[@3 line], [@(0.0.255) int]_[@3 page])&] -[s2;%% Reads a single scanline [%-*@3 line] from [%-*@3 page] ot the -raster. If possible, Raster should be optimized for reading scanlines -in ascending order `- this what most processing functions (should) -require.&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetPaletteCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPaletteCo -unt()&] -[s2;%% Returns the size of palette for raster`'s active page. If -there is no palette, returns 0&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetPaletteCount`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_GetPalett -eCount([@(0.0.255) int]_[@3 page])&] -[s2;%% Returns the size of palette for raster`'s [%-*@3 page]. If there -is no palette, returns 0..&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetPalette`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_`* -GetPalette()&] -[s2;%% Returns active pages`'current palette, NULL if there is no -palette.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetPalette`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_ -`*GetPalette([@(0.0.255) int]_[@3 page])&] -[s2;%% Returns [%-*@3 page][%- `'s ]current palette, NULL if there is -no palette &] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:GetFormat`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ R -asterFormat]_`*GetFormat()&] -[s2;%% Returns the format of Raster`'s active page, can return NULL -if format is RGBA.&] -[s3; &] -[s4; &] -[s5;:PixRaster`:`:GetFormat`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ R -asterFormat]_`*GetFormat([@(0.0.255) int]_[@3 page])&] -[s2;%% Returns the format of Raster`'s [%-*@3 page], can return NULL -if format is RGBA.&] -[s3;%% &] -[s4; &] -[s5;:PixRaster`:`:IsEmpty`(void`): [@(0.0.255) bool]_IsEmpty([@(0.0.255) void])&] -[s2;%% Returns true if PixRaster has no images.&] -[s3; &] -[s0; &] -[ {{10000F(128)G(128)@1 [s0;%% [* Leptonica functions wrappers]]}}&] -[s0; &] -[s2; [*^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:class^ Pixraster] -provides wrappers to many Leptonica image handling functions; -as the list is huge it has been divided by cathegories; see Leptonica -wrappers index.&] [s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/Rotate$en-us.tpp b/bazaar/PixRaster/src.tpp/Rotate$en-us.tpp index 61b21018b..0e9e0d65f 100644 --- a/bazaar/PixRaster/src.tpp/Rotate$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Rotate$en-us.tpp @@ -8,42 +8,37 @@ topic "Image rotation functions"; [s0;%- &] [ {{10000F(128)G(128)@1 [s0; [* Image rotation functions]]}}&] [s1;%- &] -[s2;:PixRaster`:`:RotateAM`(double`,BringInModes`,int`):%- [@(0.0.255) bool]_[* RotateAM]( -[@(0.0.255) double]_[*@3 angle], [@(0.0.255) BringInModes]_[*@3 incolor], -[@(0.0.255) int]_[*@3 page])&] -[s3; Rotates image at [%-*@3 page] around its center by [%-*@3 angle] -in radians, positive clockwise; created image pixels are filled -in black or white depending on [%-*@3 incolor] parameter.&] +[s2;:Pix`:`:RotateAM`(double`,BringInModes`):%- [@(0.0.255) Pix]_[* RotateAM]([@(0.0.255) d +ouble]_[*@3 angle], [@(0.0.255) BringInModes]_[*@3 incolor])&] +[s3; Rotates image around its center by [%-*@3 angle] in radians, positive +clockwise; created image pixels are filled in black or white +depending on [%-*@3 incolor] parameter.&] [s3; Image must be in 2, 4, 8 or 32 bpp format, either paletted or grayscale. The rotated image is appended to PixRaster and active page is set to it.&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns rotated [* Pix ]on success,an empty [* Pix ]otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:RotateAMColor`(double`,int`,int`):%- [@(0.0.255) bool]_[* RotateAMColor -]([@(0.0.255) double]_[*@3 angle], [@(0.0.255) int]_[*@3 colorval], [@(0.0.255) int]_[*@3 pag -e]_`=_PIXRASTER`_CURPAGE)&] -[s3; Rotates image at [%-*@3 page] around its center by [%-*@3 angle] -in radians, positive clockwise; created image pixels are color -filled with [%-*@3 colorval].&] +[s2;:Pix`:`:RotateAMColor`(double`,int`):%- [@(0.0.255) Pix]_[* RotateAMColor]([@(0.0.255) d +ouble]_[*@3 angle], [@(0.0.255) int]_[*@3 colorval])&] +[s3; Rotates image around its center by [%-*@3 angle] in radians, positive +clockwise; created image pixels are color filled with [%-*@3 colorval].&] [s3; Image must be in 2, 4, 8 or 32 bpp format, either paletted or grayscale. The rotated image is appended to PixRaster and active page is set to it.&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns rotated [* Pix ]on success,an empty [* Pix ]otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:RotateAMGray`(double`,int`,int`):%- [@(0.0.255) bool]_[* RotateAMGray]( -[@(0.0.255) double]_[*@3 angle], [@(0.0.255) int]_[*@3 grayval], [@(0.0.255) int]_[*@3 page]_ -`=_PIXRASTER`_CURPAGE)&] -[s3; Rotates image at [%-*@3 page] around its center by [%-*@3 angle] -in radians, positive clockwise; created image pixels are gray -filled with [%-*@3 grayval].&] +[s2;:Pix`:`:RotateAMGray`(double`,int`):%- [@(0.0.255) Pix]_[* RotateAMGray]([@(0.0.255) do +uble]_[*@3 angle], [@(0.0.255) int]_[*@3 grayval])&] +[s3; Rotates image around its center by [%-*@3 angle] in radians, positive +clockwise; created image pixels are gray filled with [%-*@3 grayval].&] [s3; Image must be in 2, 4, 8 or 32 bpp format, either paletted or grayscale. The rotated image is appended to PixRaster and active page is set to it.&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns rotated [* Pix ]on success,an empty [* Pix ]otherwise.&] [s4; &] [s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/Skew$en-us.tpp b/bazaar/PixRaster/src.tpp/Skew$en-us.tpp index a0f131b47..f9d56611d 100644 --- a/bazaar/PixRaster/src.tpp/Skew$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Skew$en-us.tpp @@ -8,62 +8,56 @@ topic "Skew finding/removal functions"; [s0;%- &] [ {{10000F(128)G(128)@1 [s0; [* Skew finding/removal functions]]}}&] [s1;%- &] -[s2;:PixRaster`:`:Deskew`(int`,int`):%- [@(0.0.255) bool]_[* Deskew]([@(0.0.255) int]_[*@3 Re -ductionFactor]_`=_1, [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; Try to find skew of [%-*@3 page] and remove it. If succeed, it -creates a new de`-skewed image and appends it at the end of PixRaster. -It uses [%-*@3 ReductionFactor] value while binary`-searching for -the skew factor.&] +[s2;:Pix`:`:Deskew`(int`):%- [@(0.0.255) Pix]_[* Deskew]([@(0.0.255) int]_[*@3 ReductionFacto +r]_`=_1)&] +[s3; Try to find skew of image and remove it. If succeed, it returns +a new de`-skewed image It uses [%-*@3 ReductionFactor] value while +binary`-searching for the skew factor.&] [s3; [* WARNINGS ]: it operates [* ONLY ]on [* 1bpp monochromatic] images; if the skew factor is too low or not found, it just returns a clone of source image.&] -[s3; Deskewed image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns deskewed [* Pix ]on success, empty [* Pix ]otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:FindSkewAndDeskew`(int`,double`*`,double`*`,int`):%- [@(0.0.255) bool -]_[* FindSkewAndDeskew]([@(0.0.255) int]_[*@3 ReductionFactor], [@(0.0.255) double]_`*[*@3 s -kewAngle]_`=_NULL, [@(0.0.255) double]_`*[*@3 confidenceFactor]_`=_NULL, -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; Try to find skew of [%-*@3 page] and remove it. If succeed, it -creates a new de`-skewed image and appends it at the end of PixRaster. -It uses [%-*@3 ReductionFactor] value while binary`-searching for -the skew factor. If [%-*@3 skewAngle] and [%-*@3 confidenceFactor] +[s2;:Pix`:`:FindSkewAndDeskew`(int`,double`*`,double`*`):%- [@(0.0.255) Pix]_[* FindSkewA +ndDeskew]([@(0.0.255) int]_[*@3 ReductionFactor], [@(0.0.255) double]_`*[*@3 skewAngle]_`= +_NULL, [@(0.0.255) double]_`*[*@3 confidenceFactor]_`=_NULL)&] +[s3; Try to find skew of image and remove it. If succeed, it returns +a new de`-skewed image.&] +[s3; It uses [%-*@3 ReductionFactor] value while binary`-searching +for the skew factor. If [%-*@3 skewAngle] and [%-*@3 confidenceFactor] pointers are non`-NULL, it sets them to the skew angle and the confidence value found when de`-skewing&] -[s3; Deskewed image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns deskewed [* Pix ]on success, empty [* Pix ]otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:FindSkew`(double`*`,double`*`,int`):%- [@(0.0.255) bool]_[* FindSkew]([@(0.0.255) d -ouble]_`*[*@3 pangle], [@(0.0.255) double]_`*[*@3 pconf]_`=_NULL, [@(0.0.255) int]_[*@3 pag -e]_`=_PIXRASTER`_CURPAGE)&] -[s3; Try to find skew of [%-*@3 page] and returns it`'s value in [%-*@3 pangle] +[s2;:PixRaster`:`:FindSkew`(double`*`,double`*`):%- [@(0.0.255) bool]_[* FindSkew]([@(0.0.255) d +ouble]_`*[*@3 pangle], [@(0.0.255) double]_`*[*@3 pconf]_`=_NULL)&] +[s3; Try to find skew of image and returns it`'s value in [%-*@3 pangle] ; confidence factor is returned in [%-*@3 pconf].&] [s3; &] [s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:FindSkewSweep`(double`*`,int`,double`,double`,int`):%- [@(0.0.255) bo -ol]_[* FindSkewSweep]([@(0.0.255) double]_`*[*@3 pangle], [@(0.0.255) int]_[*@3 reduction], - [@(0.0.255) double]_[*@3 sweeprange], [@(0.0.255) double]_[*@3 sweepdelta], -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] +[s2;:Pix`:`:FindSkewSweep`(double`*`,int`,double`,double`,int`):%- [@(0.0.255) bool]_[* F +indSkewSweep]([@(0.0.255) double]_`*[*@3 pangle], [@(0.0.255) int]_[*@3 reduction], +[@(0.0.255) double]_[*@3 sweeprange], [@(0.0.255) double]_[*@3 sweepdelta])&] [s3; Basic full`-parameters skew finding function.Try to find skew -of [%-*@3 page] and returns it`'s value in [%-*@3 pangle] ; Uses -[%-*@3 reduction] factor in binary searching, a semi`-range of -[%-*@3 sweeprange] skew angle and steps by [%-*@3 sweepdelta] value.&] +of image and returns it`'s value in [%-*@3 pangle] ; Uses [%-*@3 reduction] +factor in binary searching, a semi`-range of [%-*@3 sweeprange] +skew angle and steps by [%-*@3 sweepdelta] value.&] [s3; &] [s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:FindSkewSweepAndSearch`(double`*`,double`*`,int`,int`,double`,double`,double`,int`):%- [@(0.0.255) b +[s2;:Pix`:`:FindSkewSweepAndSearch`(double`*`,double`*`,int`,int`,double`,double`,double`):%- [@(0.0.255) b ool]_[* FindSkewSweepAndSearch](_[@(0.0.255) double]_`*[*@3 pangle], [@(0.0.255) double]_`*[*@3 pconf], [@(0.0.255) int]_[*@3 redsweep], [@(0.0.255) int]_[*@3 red search], [@(0.0.255) double]_[*@3 sweeprange], [@(0.0.255) double]_[*@3 sweepdelta], -[@(0.0.255) double]_[*@3 minbsdelta], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; Full parameters skew finding function.Try to find skew of [%-*@3 page] +[@(0.0.255) double]_[*@3 minbsdelta])&] +[s3; Full parameters skew finding function.Try to find skew of image and returns it`'s value in [%-*@3 pangle] and confidence value in [%-*@3 pconf].[%-*@3 redsweep] is the sweep reduction factor (1, 2, 4 or 8), [%-*@3 redsearch] is the binary search reduction factor diff --git a/bazaar/PixRaster/src.tpp/Thresholding$en-us.tpp b/bazaar/PixRaster/src.tpp/Thresholding$en-us.tpp index 52af30c89..84f98140b 100644 --- a/bazaar/PixRaster/src.tpp/Thresholding$en-us.tpp +++ b/bazaar/PixRaster/src.tpp/Thresholding$en-us.tpp @@ -9,123 +9,108 @@ topic "Image thresholding functions"; [ {{10000F(128)G(128)@1 [s0; [* Image thresholding functions]]}}&] [s1;%- &] [s1;%- &] -[s2;:PixRaster`:`:DitherToBinary`(int`):%- [@(0.0.255) bool]_[* DitherToBinary]([@(0.0.255) i -nt]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 page].&] +[s2;:Pix`:`:DitherToBinary`(`):%- [@(0.0.255) Pix]_[* DitherToBinary]()&] +[s3; &] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:DitherToBinarySpec`(int`,int`,int`):%- [@(0.0.255) bool]_[* DitherToBin -arySpec]([@(0.0.255) int]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip], -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 lowerclip] [%-*@3 upperclip] [%-*@3 page].&] +[s2;:Pix`:`:DitherToBinarySpec`(int`,int`):%- [@(0.0.255) Pix]_[* DitherToBinarySpec]([@(0.0.255) i +nt]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip])&] +[s3; [%-*@3 lowerclip] [%-*@3 upperclip] &] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdToBinary`(int`,int`):%- [@(0.0.255) bool]_[* ThresholdToBinary -]([@(0.0.255) int]_[*@3 threshold], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] +[s2;:Pix`:`:ThresholdToBinary`(int`):%- [@(0.0.255) Pix]_[* ThresholdToBinary]([@(0.0.255) i +nt]_[*@3 threshold])&] [s3; Creates a new 1bpp black/white image from source`'s grayscale -[%-*@3 page] using [%-*@3 threshold] as limiting value. Newly created -image is appended at the end of PixRaster, and currently active -page is set to it.&] +using [%-*@3 threshold] as limiting value.&] [s3; [* WARNING], it operates [* ONLY ]on grayscale source images.&] -[s3; Thresholded image is appended at the end of PixRaster&] [s3; &] -[s3; Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&] +[s3; Returns thresholded [* Pix ]on success, an empty [* Pix ]on failure +.&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:VarThresholdToBinary`(int`,int`):%- [@(0.0.255) bool]_[* VarThresholdTo -Binary]([@(0.0.255) int]_[*@3 thresholdPage], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_C -URPAGE)&] -[s3; [%-*@3 thresholdPage] [%-*@3 page].&] +[s2;:Pix`:`:VarThresholdToBinary`(Pix`&`):%- [@(0.0.255) Pix]_[* VarThresholdToBinary]([@(0.0.255) P +ix`&]_[*@3 thresholdPix])&] +[s3; [%-*@3 thresholdPix].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:DitherToBinaryLUT`(int`,int`,int`):%- [@(0.0.255) bool]_[* DitherToBina -ryLUT]([@(0.0.255) int]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip], -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 lowerclip] [%-*@3 upperclip] [%-*@3 page].&] +[s2;:Pix`:`:DitherToBinaryLUT`(int`,int`):%- [@(0.0.255) Pix]_[* DitherToBinaryLUT]([@(0.0.255) i +nt]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip])&] +[s3; [%-*@3 lowerclip] [%-*@3 upperclip].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:GenerateMaskByValue`(int`,int`):%- [@(0.0.255) bool]_[* GenerateMaskByV -alue]([@(0.0.255) int]_[*@3 val], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 val] [%-*@3 page].&] +[s2;:Pix`:`:GenerateMaskByValue`(int`):%- [@(0.0.255) Pix]_[* GenerateMaskByValue]([@(0.0.255) i +nt]_[*@3 val])&] +[s3; [%-*@3 val].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:GenerateMaskByBand`(int`,int`,int`,int`):%- [@(0.0.255) bool]_[* Genera -teMaskByBand]([@(0.0.255) int]_[*@3 lower], [@(0.0.255) int]_[*@3 upper], -[@(0.0.255) int]_[*@3 inband], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 lower] [%-*@3 upper] [%-*@3 inband] [%-*@3 page].&] +[s2;:Pix`:`:GenerateMaskByBand`(int`,int`,int`):%- [@(0.0.255) Pix]_[* GenerateMaskByBand +]([@(0.0.255) int]_[*@3 lower], [@(0.0.255) int]_[*@3 upper], [@(0.0.255) int]_[*@3 inband])&] +[s3; [%-*@3 lower] [%-*@3 upper] [%-*@3 inband].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:DitherTo2bpp`(int`,int`):%- [@(0.0.255) bool]_[* DitherTo2bpp]([@(0.0.255) i -nt]_[*@3 cmapflag], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 cmapflag] [%-*@3 page].&] +[s2;:Pix`:`:DitherTo2bpp`(int`):%- [@(0.0.255) Pix]_[* DitherTo2bpp]([@(0.0.255) int]_[*@3 cm +apflag])&] +[s3; [%-*@3 cmapflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:DitherTo2bppSpec`(int`,int`,int`,int`):%- [@(0.0.255) bool]_[* DitherTo -2bppSpec]([@(0.0.255) int]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip], -[@(0.0.255) int]_[*@3 cmapflag], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 lowerclip] [%-*@3 upperclip] [%-*@3 cmapflag] [%-*@3 page].&] +[s2;:Pix`:`:DitherTo2bppSpec`(int`,int`,int`):%- [@(0.0.255) Pix]_[* DitherTo2bppSpec]([@(0.0.255) i +nt]_[*@3 lowerclip], [@(0.0.255) int]_[*@3 upperclip], [@(0.0.255) int]_[*@3 cmapflag])&] +[s3; [%-*@3 lowerclip] [%-*@3 upperclip] [%-*@3 cmapflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdTo2bpp`(int`,int`,int`):%- [@(0.0.255) bool]_[* ThresholdTo2bp -p]([@(0.0.255) int]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag], [@(0.0.255) int]_[*@3 pag -e]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 nlevels] [%-*@3 cmapflag] [%-*@3 page].&] +[s2;:Pix`:`:ThresholdTo2bpp`(int`,int`):%- [@(0.0.255) Pix]_[* ThresholdTo2bpp]([@(0.0.255) i +nt]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag])&] +[s3; [%-*@3 nlevels] [%-*@3 cmapflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdTo4bpp`(int`,int`,int`):%- [@(0.0.255) bool]_[* ThresholdTo4bp -p]([@(0.0.255) int]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag], [@(0.0.255) int]_[*@3 pag -e]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 nlevels] [%-*@3 cmapflag] [%-*@3 page].&] +[s2;:Pix`:`:ThresholdTo4bpp`(int`,int`):%- [@(0.0.255) Pix]_[* ThresholdTo4bpp]([@(0.0.255) i +nt]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag])&] +[s3; [%-*@3 nlevels] [%-*@3 cmapflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdOn8bpp`(int`,int`,int`):%- [@(0.0.255) bool]_[* ThresholdOn8bp -p]([@(0.0.255) int]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag], [@(0.0.255) int]_[*@3 pag -e]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 nlevels] [%-*@3 cmapflag] [%-*@3 page].&] +[s2;:Pix`:`:ThresholdOn8bpp`(int`,int`):%- [@(0.0.255) Pix]_[* ThresholdOn8bpp]([@(0.0.255) i +nt]_[*@3 nlevels], [@(0.0.255) int]_[*@3 cmapflag])&] +[s3; [%-*@3 nlevels] [%-*@3 cmapflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdGrayArb`(const char`*`,int`,int`,int`,int`,int`):%- [@(0.0.255) b -ool]_[* ThresholdGrayArb]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 edgevals], +[s2;:Pix`:`:ThresholdGrayArb`(const char`*`,int`,int`,int`,int`):%- [@(0.0.255) Pix]_[* T +hresholdGrayArb]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 edgevals], [@(0.0.255) int]_[*@3 outdepth], [@(0.0.255) int]_[*@3 use`_average], -[@(0.0.255) int]_[*@3 setblack], [@(0.0.255) int]_[*@3 setwhite], [@(0.0.255) int]_[*@3 page]_ -`=_PIXRASTER`_CURPAGE)&] +[@(0.0.255) int]_[*@3 setblack], [@(0.0.255) int]_[*@3 setwhite])&] [s3; [%-*@3 edgevals] [%-*@3 outdepth] [%-*@3 use`_average] [%-*@3 setblack] -[%-*@3 setwhite] [%-*@3 page].&] +[%-*@3 setwhite].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:MakeGrayQuantIndexTable`(int`):%- [_^Buffer^ Buffer]<[@(0.0.255) int]>_ -[* MakeGrayQuantIndexTable]([@(0.0.255) int]_[*@3 nlevels])&] +[s2;:Pix`:`:MakeGrayQuantIndexTable`(int`):%- [_^Buffer^ Buffer]<[@(0.0.255) int]>_[* MakeG +rayQuantIndexTable]([@(0.0.255) int]_[*@3 nlevels])&] [s3; [%-*@3 nlevels].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:MakeGrayQuantTargetTable`(int`,int`):%- [_^Buffer^ Buffer]<[@(0.0.255) i -nt]>_[* MakeGrayQuantTargetTable]([@(0.0.255) int]_[*@3 nlevels], [@(0.0.255) int]_[*@3 dep -th])&] +[s2;:Pix`:`:MakeGrayQuantTargetTable`(int`,int`):%- [_^Buffer^ Buffer]<[@(0.0.255) int]>_ +[* MakeGrayQuantTargetTable]([@(0.0.255) int]_[*@3 nlevels], [@(0.0.255) int]_[*@3 depth])&] [s3; [%-*@3 nlevels] [%-*@3 depth].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:GenerateMaskByBand32`(unsigned`,int`,int`,int`):%- [@(0.0.255) bool]_ -[* GenerateMaskByBand32]([@(0.0.255) unsigned]_[*@3 refval], [@(0.0.255) int]_[*@3 delm], -[@(0.0.255) int]_[*@3 delp], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 refval] [%-*@3 delm] [%-*@3 delp] [%-*@3 page].&] +[s2;:Pix`:`:GenerateMaskByBand32`(unsigned`,int`,int`):%- [@(0.0.255) Pix]_[* GenerateMas +kByBand32]([@(0.0.255) unsigned]_[*@3 refval], [@(0.0.255) int]_[*@3 delm], +[@(0.0.255) int]_[*@3 delp])&] +[s3; [%-*@3 refval] [%-*@3 delm] [%-*@3 delp].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:GenerateMaskByDiscr32`(unsigned`,unsigned`,int`,int`):%- [@(0.0.255) b -ool]_[* GenerateMaskByDiscr32]([@(0.0.255) unsigned]_[*@3 refval1], -[@(0.0.255) unsigned]_[*@3 refval2], [@(0.0.255) int]_[*@3 distflag], -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 refval1] [%-*@3 refval2] [%-*@3 distflag] [%-*@3 page].&] +[s2;:Pix`:`:GenerateMaskByDiscr32`(unsigned`,unsigned`,int`):%- [@(0.0.255) Pix]_[* Gener +ateMaskByDiscr32]([@(0.0.255) unsigned]_[*@3 refval1], [@(0.0.255) unsigned]_[*@3 refval2 +], [@(0.0.255) int]_[*@3 distflag])&] +[s3; [%-*@3 refval1] [%-*@3 refval2] [%-*@3 distflag].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:GrayQuantFromHisto`(int`,double`,int`,int`):%- [@(0.0.255) bool]_[* Gra -yQuantFromHisto]([@(0.0.255) int]_[*@3 mPage], [@(0.0.255) double]_[*@3 minfract], -[@(0.0.255) int]_[*@3 maxsize], [@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 mPage] [%-*@3 minfract] [%-*@3 maxsize] [%-*@3 page].&] +[s2;:Pix`:`:GrayQuantFromHisto`(Pix`&`,double`,int`):%- [@(0.0.255) Pix]_[* GrayQuantFrom +Histo]([@(0.0.255) Pix `&][*@3 mPaix], [@(0.0.255) double]_[*@3 minfract], +[@(0.0.255) int]_[*@3 maxsize])&] +[s3; [%-*@3 mPix] [%-*@3 minfract] [%-*@3 maxsize].&] [s4; &] [s1;%- &] -[s2;:PixRaster`:`:ThresholdToValue`(int`,int`,int`):%- [@(0.0.255) bool]_[* ThresholdToVa -lue]([@(0.0.255) int]_[*@3 threshval], [@(0.0.255) int]_[*@3 setval], -[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] -[s3; [%-*@3 threshval] [%-*@3 setval] [%-*@3 page].&] +[s2;:Pix`:`:ThresholdToValue`(int`,int`):%- [@(0.0.255) Pix]_[* ThresholdToValue]([@(0.0.255) i +nt]_[*@3 threshval], [@(0.0.255) int]_[*@3 setval])&] +[s3; [%-*@3 threshval] [%-*@3 setval].&] [s4; &] -[s0;%- ] \ No newline at end of file +[s0; ] \ No newline at end of file diff --git a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp index c867d9a45..0b92d6150 100644 --- a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp @@ -112,7 +112,7 @@ void PixRasterBaseCtrl::PaintCache() Array rects; // if no associated PixRaster object, do nothing - if(!pixRasterCtrl || !pixRasterCtrl->GetPixRaster()) + if(!pixRasterCtrl || !pixRasterCtrl->GetPixBase()) return; // backups old imageCache positions inside the full tiff image @@ -169,16 +169,16 @@ void PixRasterBaseCtrl::PaintCache() } // gets associated PixRaster object - PixRaster *pixRaster = pixRasterCtrl->GetPixRaster(); + PixBase *pixBase = pixRasterCtrl->GetPixBase(); // scans the PixRaster pages to see if some of them fits in // rectangles that must be repainted int currentTop = 0; - int currentPage = pixRaster->GetActivePage(); - for(int i = 0 ; i < pixRaster->GetPageCount() ; i++) + int currentPage = pixBase->GetActivePage(); + for(int i = 0 ; i < pixBase->GetPageCount() ; i++) { // sets the active page - pixRaster->SeekPage(i); + pixBase->SeekPage(i); // translates current top of page in view coordinates int viewCurrentTop = iscale(currentTop, imageScale, 1000); @@ -187,8 +187,8 @@ void PixRasterBaseCtrl::PaintCache() Rect viewPageRect( -cacheLeft, -cacheTop + viewCurrentTop, - iscale(pixRaster->GetSize().cx, imageScale, 1000) - cacheLeft, - iscale(pixRaster->GetSize().cy, imageScale, 1000) - cacheTop + viewCurrentTop + iscale(pixBase->GetSize().cx, imageScale, 1000) - cacheLeft, + iscale(pixBase->GetSize().cy, imageScale, 1000) - cacheTop + viewCurrentTop ); // now scans the rectangles that must be repainted @@ -214,7 +214,7 @@ void PixRasterBaseCtrl::PaintCache() // rescales the image area ImageEncoder t; - Rescale(t, rect.GetSize(), *pixRaster, tiffRect); + Rescale(t, rect.GetSize(), *pixBase, tiffRect); // and copies insiede the cache area Image img = Image(t); @@ -223,15 +223,22 @@ void PixRasterBaseCtrl::PaintCache() imageCache.Copy(Point(rect.left, rect.top), Rect(0, 0, img.GetWidth(), img.GetHeight()), img); } } - currentTop += pixRaster->GetHeight() + iscale(10, 1000, imageScale); + currentTop += pixBase->GetHeight() + iscale(10, 1000, imageScale); } // restore PixRaster's active page - pixRaster->SeekPage(currentPage); + pixBase->SeekPage(currentPage); } // END PixRasterBaseCtrl::PaintCache() +/////////////////////////////////////////////////////////////////////////////////////////////// +// repaint polygon markers over the images +void PixRasterBaseCtrl::PaintMarkers(void) +{ + +} // END PixRasterBaseCtrl::PaintMarkers() + /////////////////////////////////////////////////////////////////////////////////////////////// // paint routine void PixRasterBaseCtrl::Paint(Draw &d) @@ -240,7 +247,7 @@ void PixRasterBaseCtrl::Paint(Draw &d) d.DrawRect(GetSize(), SColorFace()); // if no associated PixRaster, does nothing - if(!pixRasterCtrl->GetPixRaster()) + if(!pixRasterCtrl->GetPixBase()) return; // paints image inside cache, if needed @@ -270,7 +277,7 @@ void PixRasterBaseCtrl::Layout(void) static bool inside = false; // if no associated PixRaster or no pages to display, hides scrollbar and return - if(!pixRasterCtrl->GetPixRaster() || !pixRasterCtrl->GetPageCount()) + if(!pixRasterCtrl->GetPixBase() || !pixRasterCtrl->GetPageCount()) { hScrollBar.Hide(); vScrollBar.Hide(); @@ -292,21 +299,21 @@ void PixRasterBaseCtrl::Layout(void) int vScrollMax = vScrollBar.GetTotal(); // gets the PixRaster object - PixRaster *pixRaster = pixRasterCtrl->GetPixRaster(); + PixBase *pixBase = pixRasterCtrl->GetPixBase(); // calculates max width and height // and total Tiff height, for all pages, with no gaps by now int rasterWidth = 0; int rasterHeight = 0; int maxHeight = 0; - int pageCount = pixRaster->GetPageCount(); + int pageCount = pixBase->GetPageCount(); for(int i = 0 ; i < pageCount ; i++) { // sets current page - pixRaster->SeekPage(i); + pixBase->SeekPage(i); // gets page size - Size sz = pixRaster->GetSize(i); + Size sz = pixBase->GetSizeEx(i); // updates width, maximum height and total height if(sz.cx > rasterWidth) diff --git a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h index edc7eee6d..8458bbcbb 100644 --- a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h @@ -48,6 +48,9 @@ class PixRasterBaseCtrl : public Ctrl // repaint images on image cache virtual void PaintCache(void); + // repaint polygon markers over the images + virtual void PaintMarkers(void); + // mouse wheel handler virtual void MouseWheel(Point p, int zdelta, dword keyflags); diff --git a/bazaar/PixRasterCtrl/PixRasterCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterCtrl.cpp index 282658a45..30b24c78c 100644 --- a/bazaar/PixRasterCtrl/PixRasterCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterCtrl.cpp @@ -4,10 +4,10 @@ #include "PixRasterViewCtrl.h" // initialize the control -void PixRasterCtrl::Create(PixRaster *_pixRaster) +void PixRasterCtrl::Create(PixBase *_pixBase) { - // sets the PixRaster object - pixRaster = _pixRaster; + // sets the PixBase object + pixBase = _pixBase; // creates child controls and inserts them in splitter thumbs = new PixRasterThumbsCtrl(this); @@ -27,9 +27,9 @@ void PixRasterCtrl::Create(PixRaster *_pixRaster) /////////////////////////////////////////////////////////////////////////////////////////////// // constructors -PixRasterCtrl::PixRasterCtrl(PixRaster *_pixRaster) +PixRasterCtrl::PixRasterCtrl(PixBase *_pixBase) { - Create(_pixRaster); + Create(_pixBase); } // END Constructor class PixRasterCtrl @@ -52,10 +52,10 @@ PixRasterCtrl::~PixRasterCtrl() } // END Destructor class PixRasterCtrl /////////////////////////////////////////////////////////////////////////////////////////////// -// sets the PixRaster object -void PixRasterCtrl::SetPixRaster(PixRaster *_pixRaster) +// sets the PixBase object +void PixRasterCtrl::SetPixBase(PixBase *_pixBase) { - pixRaster = _pixRaster; + pixBase = _pixBase; // signals image change to thumbs and view thumbs->Layout(); @@ -82,8 +82,8 @@ bool PixRasterCtrl::ShowThumbnails(bool s) // gets page count int PixRasterCtrl::GetPageCount() { - if(pixRaster) - return pixRaster->GetPageCount(); + if(pixBase) + return pixBase->GetPageCount(); else return 0; @@ -145,7 +145,7 @@ void PixRasterCtrl::SetPage(int page) /////////////////////////////////////////////////////////////////////////////////////////////// // reloads ctrl content -- needed when changing images in -// associated PixRaster control +// associated PixBase control void PixRasterCtrl::Reload(void) { thumbs->Layout(); diff --git a/bazaar/PixRasterCtrl/PixRasterCtrl.h b/bazaar/PixRasterCtrl/PixRasterCtrl.h index 37940ff49..5ae56c685 100644 --- a/bazaar/PixRasterCtrl/PixRasterCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterCtrl.h @@ -27,18 +27,18 @@ class PixRasterCtrl : public Ctrl Splitter hSplitter; // PixRaster object associated to the control - PixRaster *pixRaster; + PixBase *pixBase; // thumbnail panel flag bool hasThumbnails; // initialize the control - void Create(PixRaster *_pixRaster); + void Create(PixBase *_pixBase); public : // constructors - PixRasterCtrl(PixRaster *pixRaster); + PixRasterCtrl(PixBase *pixBase); PixRasterCtrl(); // destructor @@ -70,10 +70,10 @@ class PixRasterCtrl : public Ctrl int GetPageCount(); // sets the PixRaster object - void SetPixRaster(PixRaster *_pixRaster); + void SetPixBase(PixBase *_pixBase); // gets the PixRaster object - PixRaster *GetPixRaster() { return pixRaster; } + PixBase *GetPixBase() { return pixBase; } // sets current page void SetPage(int page); diff --git a/bazaar/PixRasterCtrl/PixRasterCtrl.upp b/bazaar/PixRasterCtrl/PixRasterCtrl.upp index 27f6cd6d9..510a6ddf3 100755 --- a/bazaar/PixRasterCtrl/PixRasterCtrl.upp +++ b/bazaar/PixRasterCtrl/PixRasterCtrl.upp @@ -13,3 +13,4 @@ file PixRasterViewCtrl.cpp, PixRasterCtrl.h, PixRasterCtrl.cpp; + diff --git a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp index a3c20a626..ab6a53d53 100644 --- a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp @@ -42,20 +42,20 @@ void PixRasterThumbsCtrl::LeftDown(Point p, dword keyflags) int gapSize = iscale(10, 1000, imageScale); // gets the PixRaster object - PixRaster *pixRaster = pixRasterCtrl->GetPixRaster(); + PixBase *pixBase = pixRasterCtrl->GetPixBase(); // iterates through page positions to find the requested one int top = 0; - for(int iPage = 0; iPage < pixRaster->GetPageCount(); iPage++) + for(int iPage = 0; iPage < pixBase->GetPageCount(); iPage++) { - int bottom = top + pixRaster->GetHeight(iPage); + int bottom = top + pixBase->GetHeightEx(iPage); if(clickPos >= top && clickPos <= bottom) { pixRasterCtrl->SetPage(iPage); break; } - top += pixRaster->GetHeight(iPage) + gapSize; + top += pixBase->GetHeightEx(iPage) + gapSize; } } // END PixRasterThumbsCtrl::LeftDown() diff --git a/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp index 5e05f18c5..f7c445d98 100644 --- a/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp @@ -163,20 +163,20 @@ int PixRasterViewCtrl::GetZoomFactor(void) void PixRasterViewCtrl::SetPage(int page) { // gets the PixRaster object - PixRaster *pixRaster = pixRasterCtrl->GetPixRaster(); + PixBase *pixBase = pixRasterCtrl->GetPixBase(); // calculate gaps to be exactly 10 pixels in every zoom factor int gapSize = iscale(10, 1000, imageScale); // iterate thru pages to find requested page position int rasterPos = 0; - int pageCount = pixRaster->GetPageCount(); + int pageCount = pixBase->GetPageCount(); if(page > pageCount) page = pageCount; for(int i = 0 ; i < page ; i++) { // gets page size - Size sz = pixRaster->GetSize(i); + Size sz = pixBase->GetSizeEx(i); rasterPos += sz.cy + gapSize; } diff --git a/bazaar/PixRasterCtrl/init b/bazaar/PixRasterCtrl/init index 1c150507d..a1da64bff 100755 --- a/bazaar/PixRasterCtrl/init +++ b/bazaar/PixRasterCtrl/init @@ -1,5 +1,5 @@ -#ifndef _GatoFax_icpp_init_stub -#define _GatoFax_icpp_init_stub +#ifndef _PixRasterCtrl_icpp_init_stub +#define _PixRasterCtrl_icpp_init_stub #include "CtrlLib/init" -#include "plugin/tif/init" +#include "PixRaster/init" #endif diff --git a/bazaar/TestLeptonica/BaseLine.cpp b/bazaar/TestLeptonica/BaseLine.cpp index ad2d77ee9..a7d3eaf47 100644 --- a/bazaar/TestLeptonica/BaseLine.cpp +++ b/bazaar/TestLeptonica/BaseLine.cpp @@ -1,18 +1,28 @@ #include "TestLeptonica.h" -static void BaseLine(PixRaster &pixRaster) +static void BaseLine(Pix & source, PixRaster &pixRaster) { - CHECKR(pixRaster.DeskewLocal(), "Deskew error"); - Array intArray = pixRaster.FindBaselines(); + pixRaster.Add(source); + + Pix deskewed = source.DeskewLocal(); + CHECKR(deskewed, "Deskew error"); + pixRaster.Add(deskewed); + + Array intArray = deskewed.FindBaselines(); CHECKR(intArray.GetCount(), "FindBaselines error"); - PIX *pix = pixRaster; - int width = pixRaster.GetWidth(); + + // deep copy source + Pix copied(deskewed, 1); + + PIX *pix = copied; + int width = copied.GetWidth(); for(int iLine = 0; iLine < intArray.GetCount(); iLine++) { int y = intArray[iLine]; for(int x = 0; x < width; x++) pixSetPixel(pix, x, y, 1); } + pixRaster.Add(copied); } @@ -20,7 +30,8 @@ void TestLeptonica::onBaseLine() { String fileName; FileSelector fs; - PIX *pix; + + Pix source; if(!PromptYesNo( "[= [* Text baseline analysis demo]&&" @@ -42,11 +53,12 @@ void TestLeptonica::onBaseLine() } // Loads pixraster from source raster - CHECKR(pixRaster.Load(s), "Error loading image"); + CHECKR(source.Load(s), "Error loading image"); s.Close(); // apply line removal algothithm - BaseLine(pixRaster); + pixRaster.Clear(); + BaseLine(source, pixRaster); // refresh the PixRasterCtrl control with the new image contents pixRasterCtrl.Reload(); diff --git a/bazaar/TestLeptonica/LineRemoval.cpp b/bazaar/TestLeptonica/LineRemoval.cpp index cf45d1cb1..96f5e4d96 100644 --- a/bazaar/TestLeptonica/LineRemoval.cpp +++ b/bazaar/TestLeptonica/LineRemoval.cpp @@ -1,72 +1,83 @@ #include "TestLeptonica.h" -static void RemoveLines(PixRaster &pixRaster) +static void RemoveLines(Pix &source, PixRaster &dest) { - // gets source image page - int source = pixRaster.GetActivePage(); - + dest.Add(source); + // threshold the image - CHECKR(pixRaster.ThresholdToBinary(170), "Error thresholding the image"); - int thresholded = pixRaster.GetActivePage(); + Pix thresholded = source.ThresholdToBinary(170); + CHECKR(thresholded, "Error thresholding the image"); + dest.Add(thresholded); // find image skew of thresholded image double angle; - CHECKR(pixRaster.FindSkew(&angle, NULL, thresholded), "Error finding skew value"); + CHECKR(thresholded.FindSkew(&angle, NULL), "Error finding skew value"); // rotate original image using found threshold value double deg2rad = M_PI / 180.0; - CHECKR(pixRaster.RotateAMGray(deg2rad * angle, 255, source), "Error rotating image"); - int rotated = pixRaster.GetActivePage(); + Pix rotated = source.RotateAMGray(deg2rad * angle, 255); + CHECKR(rotated, "Error rotating image"); + dest.Add(rotated); // extract the lines to be removed - CHECKR(pixRaster.CloseGray(51, 1, rotated), "CloseGray error"); - int closed = pixRaster.GetActivePage(); + Pix closed = rotated.CloseGray(51, 1); + CHECKR(closed, "CloseGray error"); + dest.Add(closed); // solidify the lines to be removed - CHECKR(pixRaster.ErodeGray(1, 5, closed), "ErodeGray error"); - int eroded = pixRaster.GetActivePage(); + Pix eroded = closed.ErodeGray(1, 5); + CHECKR(eroded, "ErodeGray error"); + dest.Add(eroded); // clean the background of those lines - CHECKR(pixRaster.ThresholdToValue(210, 255, eroded), "ThresholdToValue error"); - int thresh2 = pixRaster.GetActivePage(); + Pix thresh2 = eroded.ThresholdToValue(210, 255); + CHECKR(thresh2, "ThresholdToValue error"); + dest.Add(thresh2); - CHECKR(pixRaster.ThresholdToValue(200, 0, thresh2), "ThresholdToValue error"); - int thresh3 = pixRaster.GetActivePage(); + Pix thresh3 = thresh2.ThresholdToValue(200, 0); + CHECKR(thresh3, "ThresholdToValue error"); + dest.Add(thresh3); // get paint-through mask for changed pixels - CHECKR(pixRaster.ThresholdToBinary(210, thresh3), "ThresholdToBinary error"); - int thresh4 = pixRaster.GetActivePage(); + Pix thresh4 = thresh3.ThresholdToBinary(210); + CHECKR(thresh4, "ThresholdToBinary error"); + dest.Add(thresh4); // invert the gray line image in order to whiten // the lines in the origina image - CHECKR(pixRaster.Invert(thresh3), "Invert error"); - int inverted = pixRaster.GetActivePage(); + Pix inverted = thresh3.Invert(); + CHECKR(inverted, "Invert error"); + dest.Add(inverted); // add inverted line image to original (deskewed) one // so all horizontal black lines will be erased // unrderlying parts of image are erase too - CHECKR(pixRaster.AddGray(rotated, inverted), "AddGray error"); - int grayAdded = pixRaster.GetActivePage(); + Pix grayAdded = rotated.AddGray(inverted); + CHECKR(grayAdded, "AddGray error"); + dest.Add(grayAdded); // "opens" the image with wite stripes, so the stripes // gets closed my surrounding pixels. As this changes // also the rest of image, we will use that one just for // filling the stripes. That's done by aid of mask created before... - CHECKR(pixRaster.OpenGray(1, 9, grayAdded), "OpenGray error"); - int opened2 = pixRaster.GetActivePage(); + Pix opened2 = grayAdded.OpenGray(1, 9); + CHECKR(opened2, "OpenGray error"); + dest.Add(opened2); // now to get the final result, we must combine the image with black stripes // removed with the one with grays opened to fill the stripes; we use the mask // created before to fill just the stripes and leave the rest of image unchanged - CHECKR(pixRaster.CombineMasked(grayAdded, opened2, thresh4), "CombineMasked error"); - int final = pixRaster.GetActivePage(); + Pix final = grayAdded.CombineMasked(opened2, thresh4); + CHECKR(final, "CombineMasked error"); + dest.Add(final); } void TestLeptonica::onLineRemoval() { String fileName; FileSelector fs; - PIX *pix; + + Pix source; if(!PromptYesNo( "[= [* Line removal demo]&&" @@ -88,11 +99,12 @@ void TestLeptonica::onLineRemoval() } // Loads pixraster from source raster - CHECKR(pixRaster.Load(s), "Error loading image"); + CHECKR(source.Load(s), "Error loading image"); s.Close(); // apply line removal algothithm - RemoveLines(pixRaster); + pixRaster.Clear(); + RemoveLines(source, pixRaster); // refresh the PixRasterCtrl control with the new image contents pixRasterCtrl.Reload(); diff --git a/bazaar/TestLeptonica/PageLayout.cpp b/bazaar/TestLeptonica/PageLayout.cpp index e7a31be07..5e835f224 100644 --- a/bazaar/TestLeptonica/PageLayout.cpp +++ b/bazaar/TestLeptonica/PageLayout.cpp @@ -1,15 +1,19 @@ #include "TestLeptonica.h" -static void PageLayout(PixRaster &pixRaster) +static void PageLayout(Pix &source, PixRaster &pixRaster) { - CHECKR(pixRaster.GetRegionsBinary(), "Error getting page layout"); + pixRaster.Add(source); + PixRaster regions = source.GetRegionsBinary(); + CHECKR(regions, "Error getting page layout"); + pixRaster.Add(regions); } void TestLeptonica::onPageLayout() { String fileName; FileSelector fs; - PIX *pix; + + Pix source; if(!PromptYesNo( "[= [* Page layout analysis demo]&&" @@ -31,11 +35,12 @@ void TestLeptonica::onPageLayout() } // Loads pixraster from source raster - CHECKR(pixRaster.Load(s), "Error loading image"); + CHECKR(source.Load(s), "Error loading image"); s.Close(); // apply line removal algothithm - PageLayout(pixRaster); + pixRaster.Clear(); + PageLayout(source, pixRaster); // refresh the PixRasterCtrl control with the new image contents pixRasterCtrl.Reload(); diff --git a/bazaar/TestLeptonica/main.cpp b/bazaar/TestLeptonica/main.cpp index ed5505e60..ab4004ec1 100644 --- a/bazaar/TestLeptonica/main.cpp +++ b/bazaar/TestLeptonica/main.cpp @@ -10,7 +10,7 @@ TestLeptonica::TestLeptonica() CtrlLayout(*this, "Leptonica library example suite"); // sets PixRaster in PixRasterCtrl - pixRasterCtrl.SetPixRaster(&pixRaster); + pixRasterCtrl.SetPixBase(&pixRaster); pixRasterCtrl.ShowThumbnails(true); // connects button handlers