tesseract_bin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/ext/tesseract_bin/extconf.rb +17 -0
- data/lib/tesseract_bin.rb +12 -0
- data/tesseract_bin.gemspec +660 -0
- data/test/helper.rb +18 -0
- data/test/test_tesseract_bin.rb +7 -0
- data/vendor/tesseract-2.04/AUTHORS +8 -0
- data/vendor/tesseract-2.04/COPYING +23 -0
- data/vendor/tesseract-2.04/ChangeLog +71 -0
- data/vendor/tesseract-2.04/INSTALL +229 -0
- data/vendor/tesseract-2.04/Makefile.am +20 -0
- data/vendor/tesseract-2.04/Makefile.in +641 -0
- data/vendor/tesseract-2.04/NEWS +1 -0
- data/vendor/tesseract-2.04/README +138 -0
- data/vendor/tesseract-2.04/ReleaseNotes +213 -0
- data/vendor/tesseract-2.04/StdAfx.cpp +8 -0
- data/vendor/tesseract-2.04/StdAfx.h +24 -0
- data/vendor/tesseract-2.04/ccmain/Makefile.am +63 -0
- data/vendor/tesseract-2.04/ccmain/Makefile.in +735 -0
- data/vendor/tesseract-2.04/ccmain/adaptions.cpp +1082 -0
- data/vendor/tesseract-2.04/ccmain/adaptions.h +109 -0
- data/vendor/tesseract-2.04/ccmain/applybox.cpp +891 -0
- data/vendor/tesseract-2.04/ccmain/applybox.h +73 -0
- data/vendor/tesseract-2.04/ccmain/baseapi.cpp +1105 -0
- data/vendor/tesseract-2.04/ccmain/baseapi.h +256 -0
- data/vendor/tesseract-2.04/ccmain/blobcmp.cpp +76 -0
- data/vendor/tesseract-2.04/ccmain/blobcmp.h +29 -0
- data/vendor/tesseract-2.04/ccmain/callnet.cpp +93 -0
- data/vendor/tesseract-2.04/ccmain/callnet.h +32 -0
- data/vendor/tesseract-2.04/ccmain/charcut.cpp +704 -0
- data/vendor/tesseract-2.04/ccmain/charcut.h +120 -0
- data/vendor/tesseract-2.04/ccmain/charsample.cpp +699 -0
- data/vendor/tesseract-2.04/ccmain/control.cpp +1842 -0
- data/vendor/tesseract-2.04/ccmain/control.h +198 -0
- data/vendor/tesseract-2.04/ccmain/docqual.cpp +1481 -0
- data/vendor/tesseract-2.04/ccmain/docqual.h +155 -0
- data/vendor/tesseract-2.04/ccmain/expandblob.cpp +82 -0
- data/vendor/tesseract-2.04/ccmain/expandblob.h +13 -0
- data/vendor/tesseract-2.04/ccmain/fixspace.cpp +989 -0
- data/vendor/tesseract-2.04/ccmain/fixspace.h +72 -0
- data/vendor/tesseract-2.04/ccmain/fixxht.cpp +825 -0
- data/vendor/tesseract-2.04/ccmain/fixxht.h +93 -0
- data/vendor/tesseract-2.04/ccmain/imgscale.cpp +154 -0
- data/vendor/tesseract-2.04/ccmain/imgscale.h +32 -0
- data/vendor/tesseract-2.04/ccmain/matmatch.cpp +391 -0
- data/vendor/tesseract-2.04/ccmain/matmatch.h +48 -0
- data/vendor/tesseract-2.04/ccmain/output.cpp +1273 -0
- data/vendor/tesseract-2.04/ccmain/output.h +116 -0
- data/vendor/tesseract-2.04/ccmain/pagewalk.cpp +666 -0
- data/vendor/tesseract-2.04/ccmain/pagewalk.h +155 -0
- data/vendor/tesseract-2.04/ccmain/paircmp.cpp +107 -0
- data/vendor/tesseract-2.04/ccmain/paircmp.h +43 -0
- data/vendor/tesseract-2.04/ccmain/pgedit.cpp +1867 -0
- data/vendor/tesseract-2.04/ccmain/pgedit.h +181 -0
- data/vendor/tesseract-2.04/ccmain/reject.cpp +1775 -0
- data/vendor/tesseract-2.04/ccmain/reject.h +181 -0
- data/vendor/tesseract-2.04/ccmain/scaleimg.cpp +366 -0
- data/vendor/tesseract-2.04/ccmain/scaleimg.h +35 -0
- data/vendor/tesseract-2.04/ccmain/tessbox.cpp +375 -0
- data/vendor/tesseract-2.04/ccmain/tessbox.h +110 -0
- data/vendor/tesseract-2.04/ccmain/tessedit.cpp +278 -0
- data/vendor/tesseract-2.04/ccmain/tessedit.h +49 -0
- data/vendor/tesseract-2.04/ccmain/tessembedded.cpp +110 -0
- data/vendor/tesseract-2.04/ccmain/tessembedded.h +38 -0
- data/vendor/tesseract-2.04/ccmain/tesseractfull.cc +37 -0
- data/vendor/tesseract-2.04/ccmain/tesseractmain.cpp +387 -0
- data/vendor/tesseract-2.04/ccmain/tesseractmain.h +58 -0
- data/vendor/tesseract-2.04/ccmain/tessio.h +110 -0
- data/vendor/tesseract-2.04/ccmain/tessvars.cpp +38 -0
- data/vendor/tesseract-2.04/ccmain/tessvars.h +48 -0
- data/vendor/tesseract-2.04/ccmain/tfacep.h +62 -0
- data/vendor/tesseract-2.04/ccmain/tfacepp.cpp +443 -0
- data/vendor/tesseract-2.04/ccmain/tfacepp.h +85 -0
- data/vendor/tesseract-2.04/ccmain/tstruct.cpp +549 -0
- data/vendor/tesseract-2.04/ccmain/tstruct.h +108 -0
- data/vendor/tesseract-2.04/ccmain/varabled.cpp +346 -0
- data/vendor/tesseract-2.04/ccmain/varabled.h +125 -0
- data/vendor/tesseract-2.04/ccmain/werdit.cpp +193 -0
- data/vendor/tesseract-2.04/ccmain/werdit.h +67 -0
- data/vendor/tesseract-2.04/ccstruct/Makefile.am +25 -0
- data/vendor/tesseract-2.04/ccstruct/Makefile.in +650 -0
- data/vendor/tesseract-2.04/ccstruct/blckerr.h +29 -0
- data/vendor/tesseract-2.04/ccstruct/blobbox.cpp +778 -0
- data/vendor/tesseract-2.04/ccstruct/blobbox.h +381 -0
- data/vendor/tesseract-2.04/ccstruct/blobs.cpp +247 -0
- data/vendor/tesseract-2.04/ccstruct/blobs.h +119 -0
- data/vendor/tesseract-2.04/ccstruct/blread.cpp +537 -0
- data/vendor/tesseract-2.04/ccstruct/blread.h +63 -0
- data/vendor/tesseract-2.04/ccstruct/callcpp.cpp +252 -0
- data/vendor/tesseract-2.04/ccstruct/coutln.cpp +650 -0
- data/vendor/tesseract-2.04/ccstruct/coutln.h +186 -0
- data/vendor/tesseract-2.04/ccstruct/crakedge.h +39 -0
- data/vendor/tesseract-2.04/ccstruct/genblob.cpp +133 -0
- data/vendor/tesseract-2.04/ccstruct/genblob.h +52 -0
- data/vendor/tesseract-2.04/ccstruct/hpddef.h +39 -0
- data/vendor/tesseract-2.04/ccstruct/hpdsizes.h +8 -0
- data/vendor/tesseract-2.04/ccstruct/ipoints.h +479 -0
- data/vendor/tesseract-2.04/ccstruct/labls.cpp +188 -0
- data/vendor/tesseract-2.04/ccstruct/labls.h +38 -0
- data/vendor/tesseract-2.04/ccstruct/linlsq.cpp +249 -0
- data/vendor/tesseract-2.04/ccstruct/linlsq.h +102 -0
- data/vendor/tesseract-2.04/ccstruct/lmedsq.cpp +453 -0
- data/vendor/tesseract-2.04/ccstruct/lmedsq.h +84 -0
- data/vendor/tesseract-2.04/ccstruct/mod128.cpp +100 -0
- data/vendor/tesseract-2.04/ccstruct/mod128.h +85 -0
- data/vendor/tesseract-2.04/ccstruct/normalis.cpp +176 -0
- data/vendor/tesseract-2.04/ccstruct/normalis.h +108 -0
- data/vendor/tesseract-2.04/ccstruct/ocrblock.cpp +369 -0
- data/vendor/tesseract-2.04/ccstruct/ocrblock.h +235 -0
- data/vendor/tesseract-2.04/ccstruct/ocrrow.cpp +216 -0
- data/vendor/tesseract-2.04/ccstruct/ocrrow.h +133 -0
- data/vendor/tesseract-2.04/ccstruct/pageblk.cpp +879 -0
- data/vendor/tesseract-2.04/ccstruct/pageblk.h +318 -0
- data/vendor/tesseract-2.04/ccstruct/pageres.cpp +330 -0
- data/vendor/tesseract-2.04/ccstruct/pageres.h +313 -0
- data/vendor/tesseract-2.04/ccstruct/pdblock.cpp +361 -0
- data/vendor/tesseract-2.04/ccstruct/pdblock.h +181 -0
- data/vendor/tesseract-2.04/ccstruct/pdclass.h +54 -0
- data/vendor/tesseract-2.04/ccstruct/points.cpp +102 -0
- data/vendor/tesseract-2.04/ccstruct/points.h +299 -0
- data/vendor/tesseract-2.04/ccstruct/polyaprx.cpp +588 -0
- data/vendor/tesseract-2.04/ccstruct/polyaprx.h +51 -0
- data/vendor/tesseract-2.04/ccstruct/polyblk.cpp +398 -0
- data/vendor/tesseract-2.04/ccstruct/polyblk.h +122 -0
- data/vendor/tesseract-2.04/ccstruct/polyblob.cpp +357 -0
- data/vendor/tesseract-2.04/ccstruct/polyblob.h +102 -0
- data/vendor/tesseract-2.04/ccstruct/polyvert.cpp +23 -0
- data/vendor/tesseract-2.04/ccstruct/polyvert.h +58 -0
- data/vendor/tesseract-2.04/ccstruct/poutline.cpp +441 -0
- data/vendor/tesseract-2.04/ccstruct/poutline.h +125 -0
- data/vendor/tesseract-2.04/ccstruct/quadlsq.cpp +147 -0
- data/vendor/tesseract-2.04/ccstruct/quadlsq.h +67 -0
- data/vendor/tesseract-2.04/ccstruct/quadratc.cpp +21 -0
- data/vendor/tesseract-2.04/ccstruct/quadratc.h +63 -0
- data/vendor/tesseract-2.04/ccstruct/quspline.cpp +382 -0
- data/vendor/tesseract-2.04/ccstruct/quspline.h +113 -0
- data/vendor/tesseract-2.04/ccstruct/ratngs.cpp +372 -0
- data/vendor/tesseract-2.04/ccstruct/ratngs.h +198 -0
- data/vendor/tesseract-2.04/ccstruct/rect.cpp +229 -0
- data/vendor/tesseract-2.04/ccstruct/rect.h +320 -0
- data/vendor/tesseract-2.04/ccstruct/rejctmap.cpp +545 -0
- data/vendor/tesseract-2.04/ccstruct/rejctmap.h +284 -0
- data/vendor/tesseract-2.04/ccstruct/rwpoly.cpp +89 -0
- data/vendor/tesseract-2.04/ccstruct/rwpoly.h +45 -0
- data/vendor/tesseract-2.04/ccstruct/statistc.cpp +905 -0
- data/vendor/tesseract-2.04/ccstruct/statistc.h +135 -0
- data/vendor/tesseract-2.04/ccstruct/stepblob.cpp +296 -0
- data/vendor/tesseract-2.04/ccstruct/stepblob.h +88 -0
- data/vendor/tesseract-2.04/ccstruct/txtregn.cpp +230 -0
- data/vendor/tesseract-2.04/ccstruct/txtregn.h +155 -0
- data/vendor/tesseract-2.04/ccstruct/vecfuncs.cpp +63 -0
- data/vendor/tesseract-2.04/ccstruct/vecfuncs.h +91 -0
- data/vendor/tesseract-2.04/ccstruct/werd.cpp +967 -0
- data/vendor/tesseract-2.04/ccstruct/werd.h +277 -0
- data/vendor/tesseract-2.04/ccutil/Makefile.am +19 -0
- data/vendor/tesseract-2.04/ccutil/Makefile.in +626 -0
- data/vendor/tesseract-2.04/ccutil/basedir.cpp +118 -0
- data/vendor/tesseract-2.04/ccutil/basedir.h +32 -0
- data/vendor/tesseract-2.04/ccutil/bits16.cpp +30 -0
- data/vendor/tesseract-2.04/ccutil/bits16.h +61 -0
- data/vendor/tesseract-2.04/ccutil/boxread.cpp +105 -0
- data/vendor/tesseract-2.04/ccutil/boxread.h +44 -0
- data/vendor/tesseract-2.04/ccutil/clst.cpp +626 -0
- data/vendor/tesseract-2.04/ccutil/clst.h +1085 -0
- data/vendor/tesseract-2.04/ccutil/debugwin.cpp +500 -0
- data/vendor/tesseract-2.04/ccutil/debugwin.h +103 -0
- data/vendor/tesseract-2.04/ccutil/elst.cpp +593 -0
- data/vendor/tesseract-2.04/ccutil/elst.h +1125 -0
- data/vendor/tesseract-2.04/ccutil/elst2.cpp +606 -0
- data/vendor/tesseract-2.04/ccutil/elst2.h +1121 -0
- data/vendor/tesseract-2.04/ccutil/errcode.cpp +104 -0
- data/vendor/tesseract-2.04/ccutil/errcode.h +104 -0
- data/vendor/tesseract-2.04/ccutil/fileerr.h +34 -0
- data/vendor/tesseract-2.04/ccutil/globaloc.cpp +115 -0
- data/vendor/tesseract-2.04/ccutil/globaloc.h +40 -0
- data/vendor/tesseract-2.04/ccutil/hashfn.cpp +57 -0
- data/vendor/tesseract-2.04/ccutil/hashfn.h +30 -0
- data/vendor/tesseract-2.04/ccutil/host.h +180 -0
- data/vendor/tesseract-2.04/ccutil/hosthplb.h +1 -0
- data/vendor/tesseract-2.04/ccutil/lsterr.h +43 -0
- data/vendor/tesseract-2.04/ccutil/mainblk.cpp +126 -0
- data/vendor/tesseract-2.04/ccutil/mainblk.h +39 -0
- data/vendor/tesseract-2.04/ccutil/memblk.cpp +1106 -0
- data/vendor/tesseract-2.04/ccutil/memblk.h +189 -0
- data/vendor/tesseract-2.04/ccutil/memry.cpp +532 -0
- data/vendor/tesseract-2.04/ccutil/memry.h +192 -0
- data/vendor/tesseract-2.04/ccutil/memryerr.h +38 -0
- data/vendor/tesseract-2.04/ccutil/mfcpch.cpp +5 -0
- data/vendor/tesseract-2.04/ccutil/mfcpch.h +37 -0
- data/vendor/tesseract-2.04/ccutil/ndminx.h +31 -0
- data/vendor/tesseract-2.04/ccutil/notdll.h +28 -0
- data/vendor/tesseract-2.04/ccutil/nwmain.h +176 -0
- data/vendor/tesseract-2.04/ccutil/ocrclass.h +345 -0
- data/vendor/tesseract-2.04/ccutil/ocrshell.cpp +772 -0
- data/vendor/tesseract-2.04/ccutil/ocrshell.h +191 -0
- data/vendor/tesseract-2.04/ccutil/platform.h +18 -0
- data/vendor/tesseract-2.04/ccutil/scanutils.cpp +543 -0
- data/vendor/tesseract-2.04/ccutil/scanutils.h +55 -0
- data/vendor/tesseract-2.04/ccutil/secname.h +9 -0
- data/vendor/tesseract-2.04/ccutil/serialis.cpp +117 -0
- data/vendor/tesseract-2.04/ccutil/serialis.h +93 -0
- data/vendor/tesseract-2.04/ccutil/stderr.h +26 -0
- data/vendor/tesseract-2.04/ccutil/strngs.cpp +495 -0
- data/vendor/tesseract-2.04/ccutil/strngs.h +138 -0
- data/vendor/tesseract-2.04/ccutil/tessclas.h +135 -0
- data/vendor/tesseract-2.04/ccutil/tessopt.cpp +61 -0
- data/vendor/tesseract-2.04/ccutil/tessopt.h +30 -0
- data/vendor/tesseract-2.04/ccutil/tprintf.cpp +122 -0
- data/vendor/tesseract-2.04/ccutil/tprintf.h +35 -0
- data/vendor/tesseract-2.04/ccutil/unichar.cpp +144 -0
- data/vendor/tesseract-2.04/ccutil/unichar.h +84 -0
- data/vendor/tesseract-2.04/ccutil/unicharmap.cpp +172 -0
- data/vendor/tesseract-2.04/ccutil/unicharmap.h +82 -0
- data/vendor/tesseract-2.04/ccutil/unicharset.cpp +307 -0
- data/vendor/tesseract-2.04/ccutil/unicharset.h +267 -0
- data/vendor/tesseract-2.04/ccutil/varable.cpp +672 -0
- data/vendor/tesseract-2.04/ccutil/varable.h +419 -0
- data/vendor/tesseract-2.04/classify/Makefile.am +24 -0
- data/vendor/tesseract-2.04/classify/Makefile.in +647 -0
- data/vendor/tesseract-2.04/classify/adaptive.cpp +535 -0
- data/vendor/tesseract-2.04/classify/adaptive.h +199 -0
- data/vendor/tesseract-2.04/classify/adaptmatch.cpp +2958 -0
- data/vendor/tesseract-2.04/classify/adaptmatch.h +86 -0
- data/vendor/tesseract-2.04/classify/baseline.cpp +58 -0
- data/vendor/tesseract-2.04/classify/baseline.h +91 -0
- data/vendor/tesseract-2.04/classify/blobclass.cpp +123 -0
- data/vendor/tesseract-2.04/classify/blobclass.h +49 -0
- data/vendor/tesseract-2.04/classify/chartoname.cpp +74 -0
- data/vendor/tesseract-2.04/classify/chartoname.h +21 -0
- data/vendor/tesseract-2.04/classify/cluster.cpp +2834 -0
- data/vendor/tesseract-2.04/classify/cluster.h +158 -0
- data/vendor/tesseract-2.04/classify/clusttool.cpp +507 -0
- data/vendor/tesseract-2.04/classify/clusttool.h +70 -0
- data/vendor/tesseract-2.04/classify/cutoffs.cpp +73 -0
- data/vendor/tesseract-2.04/classify/cutoffs.h +49 -0
- data/vendor/tesseract-2.04/classify/extern.h +32 -0
- data/vendor/tesseract-2.04/classify/extract.cpp +100 -0
- data/vendor/tesseract-2.04/classify/extract.h +36 -0
- data/vendor/tesseract-2.04/classify/featdefs.cpp +244 -0
- data/vendor/tesseract-2.04/classify/featdefs.h +71 -0
- data/vendor/tesseract-2.04/classify/flexfx.cpp +87 -0
- data/vendor/tesseract-2.04/classify/flexfx.h +34 -0
- data/vendor/tesseract-2.04/classify/float2int.cpp +126 -0
- data/vendor/tesseract-2.04/classify/float2int.h +65 -0
- data/vendor/tesseract-2.04/classify/fpoint.cpp +73 -0
- data/vendor/tesseract-2.04/classify/fpoint.h +63 -0
- data/vendor/tesseract-2.04/classify/fxdefs.cpp +74 -0
- data/vendor/tesseract-2.04/classify/fxdefs.h +93 -0
- data/vendor/tesseract-2.04/classify/fxid.h +69 -0
- data/vendor/tesseract-2.04/classify/hideedge.cpp +35 -0
- data/vendor/tesseract-2.04/classify/hideedge.h +76 -0
- data/vendor/tesseract-2.04/classify/intfx.cpp +608 -0
- data/vendor/tesseract-2.04/classify/intfx.h +63 -0
- data/vendor/tesseract-2.04/classify/intmatcher.cpp +1524 -0
- data/vendor/tesseract-2.04/classify/intmatcher.h +199 -0
- data/vendor/tesseract-2.04/classify/intproto.cpp +1823 -0
- data/vendor/tesseract-2.04/classify/intproto.h +320 -0
- data/vendor/tesseract-2.04/classify/kdtree.cpp +884 -0
- data/vendor/tesseract-2.04/classify/kdtree.h +118 -0
- data/vendor/tesseract-2.04/classify/mf.cpp +106 -0
- data/vendor/tesseract-2.04/classify/mf.h +43 -0
- data/vendor/tesseract-2.04/classify/mfdefs.cpp +58 -0
- data/vendor/tesseract-2.04/classify/mfdefs.h +60 -0
- data/vendor/tesseract-2.04/classify/mfoutline.cpp +1087 -0
- data/vendor/tesseract-2.04/classify/mfoutline.h +277 -0
- data/vendor/tesseract-2.04/classify/mfx.cpp +436 -0
- data/vendor/tesseract-2.04/classify/mfx.h +52 -0
- data/vendor/tesseract-2.04/classify/normfeat.cpp +132 -0
- data/vendor/tesseract-2.04/classify/normfeat.h +63 -0
- data/vendor/tesseract-2.04/classify/normmatch.cpp +305 -0
- data/vendor/tesseract-2.04/classify/normmatch.h +38 -0
- data/vendor/tesseract-2.04/classify/ocrfeatures.cpp +310 -0
- data/vendor/tesseract-2.04/classify/ocrfeatures.h +148 -0
- data/vendor/tesseract-2.04/classify/outfeat.cpp +262 -0
- data/vendor/tesseract-2.04/classify/outfeat.h +76 -0
- data/vendor/tesseract-2.04/classify/picofeat.cpp +297 -0
- data/vendor/tesseract-2.04/classify/picofeat.h +65 -0
- data/vendor/tesseract-2.04/classify/protos.cpp +472 -0
- data/vendor/tesseract-2.04/classify/protos.h +258 -0
- data/vendor/tesseract-2.04/classify/sigmenu.cpp +225 -0
- data/vendor/tesseract-2.04/classify/sigmenu.h +39 -0
- data/vendor/tesseract-2.04/classify/speckle.cpp +127 -0
- data/vendor/tesseract-2.04/classify/speckle.h +69 -0
- data/vendor/tesseract-2.04/classify/xform2d.cpp +120 -0
- data/vendor/tesseract-2.04/classify/xform2d.h +60 -0
- data/vendor/tesseract-2.04/config/config.guess +1466 -0
- data/vendor/tesseract-2.04/config/config.h.in +188 -0
- data/vendor/tesseract-2.04/config/config.sub +1579 -0
- data/vendor/tesseract-2.04/config/depcomp +530 -0
- data/vendor/tesseract-2.04/config/install-sh +269 -0
- data/vendor/tesseract-2.04/config/missing +198 -0
- data/vendor/tesseract-2.04/config/mkinstalldirs +40 -0
- data/vendor/tesseract-2.04/config/stamp-h.in +0 -0
- data/vendor/tesseract-2.04/configure +10424 -0
- data/vendor/tesseract-2.04/cutil/Makefile.am +14 -0
- data/vendor/tesseract-2.04/cutil/Makefile.in +612 -0
- data/vendor/tesseract-2.04/cutil/bitvec.cpp +115 -0
- data/vendor/tesseract-2.04/cutil/bitvec.h +100 -0
- data/vendor/tesseract-2.04/cutil/callcpp.h +190 -0
- data/vendor/tesseract-2.04/cutil/const.h +108 -0
- data/vendor/tesseract-2.04/cutil/cutil.cpp +92 -0
- data/vendor/tesseract-2.04/cutil/cutil.h +159 -0
- data/vendor/tesseract-2.04/cutil/danerror.cpp +144 -0
- data/vendor/tesseract-2.04/cutil/danerror.h +41 -0
- data/vendor/tesseract-2.04/cutil/debug.cpp +97 -0
- data/vendor/tesseract-2.04/cutil/debug.h +348 -0
- data/vendor/tesseract-2.04/cutil/efio.cpp +62 -0
- data/vendor/tesseract-2.04/cutil/efio.h +32 -0
- data/vendor/tesseract-2.04/cutil/emalloc.cpp +91 -0
- data/vendor/tesseract-2.04/cutil/emalloc.h +44 -0
- data/vendor/tesseract-2.04/cutil/freelist.cpp +75 -0
- data/vendor/tesseract-2.04/cutil/freelist.h +45 -0
- data/vendor/tesseract-2.04/cutil/funcdefs.h +35 -0
- data/vendor/tesseract-2.04/cutil/general.h +33 -0
- data/vendor/tesseract-2.04/cutil/globals.cpp +69 -0
- data/vendor/tesseract-2.04/cutil/globals.h +70 -0
- data/vendor/tesseract-2.04/cutil/listio.cpp +68 -0
- data/vendor/tesseract-2.04/cutil/listio.h +43 -0
- data/vendor/tesseract-2.04/cutil/minmax.h +40 -0
- data/vendor/tesseract-2.04/cutil/oldheap.cpp +337 -0
- data/vendor/tesseract-2.04/cutil/oldheap.h +126 -0
- data/vendor/tesseract-2.04/cutil/oldlist.cpp +393 -0
- data/vendor/tesseract-2.04/cutil/oldlist.h +350 -0
- data/vendor/tesseract-2.04/cutil/structures.cpp +66 -0
- data/vendor/tesseract-2.04/cutil/structures.h +112 -0
- data/vendor/tesseract-2.04/cutil/tessarray.cpp +115 -0
- data/vendor/tesseract-2.04/cutil/tessarray.h +166 -0
- data/vendor/tesseract-2.04/cutil/tordvars.cpp +95 -0
- data/vendor/tesseract-2.04/cutil/tordvars.h +61 -0
- data/vendor/tesseract-2.04/cutil/variables.cpp +317 -0
- data/vendor/tesseract-2.04/cutil/variables.h +170 -0
- data/vendor/tesseract-2.04/dict/Makefile.am +13 -0
- data/vendor/tesseract-2.04/dict/Makefile.in +609 -0
- data/vendor/tesseract-2.04/dict/choicearr.h +96 -0
- data/vendor/tesseract-2.04/dict/choices.cpp +210 -0
- data/vendor/tesseract-2.04/dict/choices.h +241 -0
- data/vendor/tesseract-2.04/dict/context.cpp +270 -0
- data/vendor/tesseract-2.04/dict/context.h +82 -0
- data/vendor/tesseract-2.04/dict/dawg.cpp +363 -0
- data/vendor/tesseract-2.04/dict/dawg.h +394 -0
- data/vendor/tesseract-2.04/dict/hyphen.cpp +84 -0
- data/vendor/tesseract-2.04/dict/hyphen.h +125 -0
- data/vendor/tesseract-2.04/dict/lookdawg.cpp +228 -0
- data/vendor/tesseract-2.04/dict/lookdawg.h +76 -0
- data/vendor/tesseract-2.04/dict/makedawg.cpp +449 -0
- data/vendor/tesseract-2.04/dict/makedawg.h +83 -0
- data/vendor/tesseract-2.04/dict/matchdefs.h +145 -0
- data/vendor/tesseract-2.04/dict/permdawg.cpp +415 -0
- data/vendor/tesseract-2.04/dict/permdawg.h +98 -0
- data/vendor/tesseract-2.04/dict/permngram.cpp +358 -0
- data/vendor/tesseract-2.04/dict/permngram.h +33 -0
- data/vendor/tesseract-2.04/dict/permnum.cpp +522 -0
- data/vendor/tesseract-2.04/dict/permnum.h +83 -0
- data/vendor/tesseract-2.04/dict/permute.cpp +1704 -0
- data/vendor/tesseract-2.04/dict/permute.h +93 -0
- data/vendor/tesseract-2.04/dict/reduce.cpp +424 -0
- data/vendor/tesseract-2.04/dict/reduce.h +112 -0
- data/vendor/tesseract-2.04/dict/states.cpp +382 -0
- data/vendor/tesseract-2.04/dict/states.h +111 -0
- data/vendor/tesseract-2.04/dict/stopper.cpp +1458 -0
- data/vendor/tesseract-2.04/dict/stopper.h +103 -0
- data/vendor/tesseract-2.04/dict/trie.cpp +683 -0
- data/vendor/tesseract-2.04/dict/trie.h +190 -0
- data/vendor/tesseract-2.04/dlltest/Makefile.am +2 -0
- data/vendor/tesseract-2.04/dlltest/Makefile.in +388 -0
- data/vendor/tesseract-2.04/dlltest/dlltest.cpp +163 -0
- data/vendor/tesseract-2.04/dlltest/dlltest.dsp +186 -0
- data/vendor/tesseract-2.04/dlltest/dlltest.vcproj +637 -0
- data/vendor/tesseract-2.04/eurotext.tif +0 -0
- data/vendor/tesseract-2.04/image/Makefile.am +10 -0
- data/vendor/tesseract-2.04/image/Makefile.in +596 -0
- data/vendor/tesseract-2.04/image/bitstrm.cpp +157 -0
- data/vendor/tesseract-2.04/image/bitstrm.h +73 -0
- data/vendor/tesseract-2.04/image/img.h +336 -0
- data/vendor/tesseract-2.04/image/imgbmp.cpp +223 -0
- data/vendor/tesseract-2.04/image/imgbmp.h +50 -0
- data/vendor/tesseract-2.04/image/imgerrs.h +35 -0
- data/vendor/tesseract-2.04/image/imgio.cpp +321 -0
- data/vendor/tesseract-2.04/image/imgio.h +22 -0
- data/vendor/tesseract-2.04/image/imgs.cpp +1764 -0
- data/vendor/tesseract-2.04/image/imgs.h +102 -0
- data/vendor/tesseract-2.04/image/imgtiff.cpp +723 -0
- data/vendor/tesseract-2.04/image/imgtiff.h +89 -0
- data/vendor/tesseract-2.04/image/imgunpk.h +1377 -0
- data/vendor/tesseract-2.04/image/svshowim.cpp +40 -0
- data/vendor/tesseract-2.04/image/svshowim.h +25 -0
- data/vendor/tesseract-2.04/java/Makefile.am +4 -0
- data/vendor/tesseract-2.04/java/Makefile.in +473 -0
- data/vendor/tesseract-2.04/java/com/Makefile.am +1 -0
- data/vendor/tesseract-2.04/java/com/Makefile.in +470 -0
- data/vendor/tesseract-2.04/java/com/google/Makefile.am +1 -0
- data/vendor/tesseract-2.04/java/com/google/Makefile.in +470 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/Makefile.am +4 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/Makefile.in +473 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ScrollView.java +421 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/events/Makefile.am +5 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/events/Makefile.in +474 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/events/SVEvent.java +87 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/events/SVEventHandler.java +296 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/events/SVEventType.java +31 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/Makefile.am +7 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/Makefile.in +476 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVAbstractMenuItem.java +58 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVCheckboxMenuItem.java +60 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVEmptyMenuItem.java +48 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVImageHandler.java +228 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVMenuBar.java +130 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVMenuItem.java +61 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVPopupMenu.java +142 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVSubMenuItem.java +41 -0
- data/vendor/tesseract-2.04/java/com/google/scrollview/ui/SVWindow.java +643 -0
- data/vendor/tesseract-2.04/java/makefile +55 -0
- data/vendor/tesseract-2.04/pageseg/Makefile.am +13 -0
- data/vendor/tesseract-2.04/pageseg/Makefile.in +596 -0
- data/vendor/tesseract-2.04/pageseg/leptonica_pageseg.cpp +363 -0
- data/vendor/tesseract-2.04/pageseg/leptonica_pageseg.h +90 -0
- data/vendor/tesseract-2.04/pageseg/leptonica_pageseg_interface.cpp +82 -0
- data/vendor/tesseract-2.04/pageseg/leptonica_pageseg_interface.h +30 -0
- data/vendor/tesseract-2.04/pageseg/pageseg.cpp +170 -0
- data/vendor/tesseract-2.04/pageseg/pageseg.h +29 -0
- data/vendor/tesseract-2.04/phototest.tif +0 -0
- data/vendor/tesseract-2.04/tessdata/Makefile.am +31 -0
- data/vendor/tesseract-2.04/tessdata/Makefile.in +529 -0
- data/vendor/tesseract-2.04/tessdata/configs/Makefile.am +3 -0
- data/vendor/tesseract-2.04/tessdata/configs/Makefile.in +344 -0
- data/vendor/tesseract-2.04/tessdata/configs/api_config +1 -0
- data/vendor/tesseract-2.04/tessdata/configs/box.train +19 -0
- data/vendor/tesseract-2.04/tessdata/configs/box.train.stderr +18 -0
- data/vendor/tesseract-2.04/tessdata/configs/inter +4 -0
- data/vendor/tesseract-2.04/tessdata/configs/kannada +4 -0
- data/vendor/tesseract-2.04/tessdata/configs/makebox +1 -0
- data/vendor/tesseract-2.04/tessdata/configs/unlv +3 -0
- data/vendor/tesseract-2.04/tessdata/confsets +3 -0
- data/vendor/tesseract-2.04/tessdata/eng.DangAmbigs +39 -0
- data/vendor/tesseract-2.04/tessdata/eng.freq-dawg +0 -0
- data/vendor/tesseract-2.04/tessdata/eng.inttemp +0 -0
- data/vendor/tesseract-2.04/tessdata/eng.normproto +1247 -0
- data/vendor/tesseract-2.04/tessdata/eng.pffmtable +111 -0
- data/vendor/tesseract-2.04/tessdata/eng.unicharset +113 -0
- data/vendor/tesseract-2.04/tessdata/eng.user-words +921 -0
- data/vendor/tesseract-2.04/tessdata/eng.word-dawg +0 -0
- data/vendor/tesseract-2.04/tessdata/makedummies +8 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/Makefile.am +3 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/Makefile.in +344 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/batch +2 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/batch.nochop +2 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/matdemo +7 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/msdemo +13 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/nobatch +2 -0
- data/vendor/tesseract-2.04/tessdata/tessconfigs/segdemo +9 -0
- data/vendor/tesseract-2.04/tessdll.cpp +351 -0
- data/vendor/tesseract-2.04/tessdll.dsp +2050 -0
- data/vendor/tesseract-2.04/tessdll.h +143 -0
- data/vendor/tesseract-2.04/tessdll.vcproj +5495 -0
- data/vendor/tesseract-2.04/tesseract.dsp +2124 -0
- data/vendor/tesseract-2.04/tesseract.dsw +116 -0
- data/vendor/tesseract-2.04/tesseract.sln +59 -0
- data/vendor/tesseract-2.04/tesseract.spec +188 -0
- data/vendor/tesseract-2.04/tesseract.vcproj +5859 -0
- data/vendor/tesseract-2.04/testing/Makefile.am +2 -0
- data/vendor/tesseract-2.04/testing/Makefile.in +312 -0
- data/vendor/tesseract-2.04/testing/README +43 -0
- data/vendor/tesseract-2.04/testing/counttestset.sh +61 -0
- data/vendor/tesseract-2.04/testing/reorgdata.sh +44 -0
- data/vendor/tesseract-2.04/testing/reports/1995.bus.3B.sum +1 -0
- data/vendor/tesseract-2.04/testing/reports/1995.doe3.3B.sum +1 -0
- data/vendor/tesseract-2.04/testing/reports/1995.mag.3B.sum +1 -0
- data/vendor/tesseract-2.04/testing/reports/1995.news.3B.sum +1 -0
- data/vendor/tesseract-2.04/testing/reports/2.03.summary +9 -0
- data/vendor/tesseract-2.04/testing/reports/2.04.summary +9 -0
- data/vendor/tesseract-2.04/testing/runalltests.sh +110 -0
- data/vendor/tesseract-2.04/testing/runtestset.sh +61 -0
- data/vendor/tesseract-2.04/textord/Makefile.am +20 -0
- data/vendor/tesseract-2.04/textord/Makefile.in +624 -0
- data/vendor/tesseract-2.04/textord/blkocc.cpp +809 -0
- data/vendor/tesseract-2.04/textord/blkocc.h +327 -0
- data/vendor/tesseract-2.04/textord/blobcmpl.h +31 -0
- data/vendor/tesseract-2.04/textord/drawedg.cpp +77 -0
- data/vendor/tesseract-2.04/textord/drawedg.h +34 -0
- data/vendor/tesseract-2.04/textord/drawtord.cpp +469 -0
- data/vendor/tesseract-2.04/textord/drawtord.h +107 -0
- data/vendor/tesseract-2.04/textord/edgblob.cpp +412 -0
- data/vendor/tesseract-2.04/textord/edgblob.h +100 -0
- data/vendor/tesseract-2.04/textord/edgloop.cpp +211 -0
- data/vendor/tesseract-2.04/textord/edgloop.h +66 -0
- data/vendor/tesseract-2.04/textord/fpchop.cpp +1641 -0
- data/vendor/tesseract-2.04/textord/fpchop.h +238 -0
- data/vendor/tesseract-2.04/textord/gap_map.cpp +166 -0
- data/vendor/tesseract-2.04/textord/gap_map.h +40 -0
- data/vendor/tesseract-2.04/textord/makerow.cpp +2628 -0
- data/vendor/tesseract-2.04/textord/makerow.h +295 -0
- data/vendor/tesseract-2.04/textord/oldbasel.cpp +1761 -0
- data/vendor/tesseract-2.04/textord/oldbasel.h +195 -0
- data/vendor/tesseract-2.04/textord/pithsync.cpp +696 -0
- data/vendor/tesseract-2.04/textord/pithsync.h +134 -0
- data/vendor/tesseract-2.04/textord/pitsync1.cpp +425 -0
- data/vendor/tesseract-2.04/textord/pitsync1.h +135 -0
- data/vendor/tesseract-2.04/textord/scanedg.cpp +452 -0
- data/vendor/tesseract-2.04/textord/scanedg.h +74 -0
- data/vendor/tesseract-2.04/textord/sortflts.cpp +80 -0
- data/vendor/tesseract-2.04/textord/sortflts.h +64 -0
- data/vendor/tesseract-2.04/textord/tessout.h +76 -0
- data/vendor/tesseract-2.04/textord/topitch.cpp +2019 -0
- data/vendor/tesseract-2.04/textord/topitch.h +195 -0
- data/vendor/tesseract-2.04/textord/tordmain.cpp +907 -0
- data/vendor/tesseract-2.04/textord/tordmain.h +132 -0
- data/vendor/tesseract-2.04/textord/tospace.cpp +1939 -0
- data/vendor/tesseract-2.04/textord/tospace.h +193 -0
- data/vendor/tesseract-2.04/textord/tovars.cpp +87 -0
- data/vendor/tesseract-2.04/textord/tovars.h +94 -0
- data/vendor/tesseract-2.04/textord/underlin.cpp +312 -0
- data/vendor/tesseract-2.04/textord/underlin.h +53 -0
- data/vendor/tesseract-2.04/textord/wordseg.cpp +620 -0
- data/vendor/tesseract-2.04/textord/wordseg.h +70 -0
- data/vendor/tesseract-2.04/training/Makefile.am +54 -0
- data/vendor/tesseract-2.04/training/Makefile.in +720 -0
- data/vendor/tesseract-2.04/training/cnTraining.cpp +855 -0
- data/vendor/tesseract-2.04/training/cntraining.dsp +243 -0
- data/vendor/tesseract-2.04/training/cntraining.vcproj +950 -0
- data/vendor/tesseract-2.04/training/mergenf.cpp +451 -0
- data/vendor/tesseract-2.04/training/mergenf.h +106 -0
- data/vendor/tesseract-2.04/training/mfTraining.cpp +1341 -0
- data/vendor/tesseract-2.04/training/mftraining.dsp +285 -0
- data/vendor/tesseract-2.04/training/mftraining.vcproj +1055 -0
- data/vendor/tesseract-2.04/training/name2char.cpp +166 -0
- data/vendor/tesseract-2.04/training/name2char.h +38 -0
- data/vendor/tesseract-2.04/training/training.cpp +190 -0
- data/vendor/tesseract-2.04/training/training.h +130 -0
- data/vendor/tesseract-2.04/training/unicharset_extractor.cpp +140 -0
- data/vendor/tesseract-2.04/training/unicharset_extractor.dsp +335 -0
- data/vendor/tesseract-2.04/training/unicharset_extractor.vcproj +769 -0
- data/vendor/tesseract-2.04/training/wordlist2dawg.cpp +69 -0
- data/vendor/tesseract-2.04/training/wordlist2dawg.dsp +319 -0
- data/vendor/tesseract-2.04/training/wordlist2dawg.vcproj +1113 -0
- data/vendor/tesseract-2.04/viewer/Makefile.am +9 -0
- data/vendor/tesseract-2.04/viewer/Makefile.in +591 -0
- data/vendor/tesseract-2.04/viewer/scrollview.cpp +825 -0
- data/vendor/tesseract-2.04/viewer/scrollview.h +414 -0
- data/vendor/tesseract-2.04/viewer/svmnode.cpp +140 -0
- data/vendor/tesseract-2.04/viewer/svmnode.h +94 -0
- data/vendor/tesseract-2.04/viewer/svpaint.cpp +220 -0
- data/vendor/tesseract-2.04/viewer/svutil.cpp +347 -0
- data/vendor/tesseract-2.04/viewer/svutil.h +138 -0
- data/vendor/tesseract-2.04/wordrec/Makefile.am +23 -0
- data/vendor/tesseract-2.04/wordrec/Makefile.in +641 -0
- data/vendor/tesseract-2.04/wordrec/associate.cpp +62 -0
- data/vendor/tesseract-2.04/wordrec/associate.h +93 -0
- data/vendor/tesseract-2.04/wordrec/badwords.cpp +106 -0
- data/vendor/tesseract-2.04/wordrec/badwords.h +51 -0
- data/vendor/tesseract-2.04/wordrec/bestfirst.cpp +526 -0
- data/vendor/tesseract-2.04/wordrec/bestfirst.h +203 -0
- data/vendor/tesseract-2.04/wordrec/charsample.h +208 -0
- data/vendor/tesseract-2.04/wordrec/chop.cpp +458 -0
- data/vendor/tesseract-2.04/wordrec/chop.h +153 -0
- data/vendor/tesseract-2.04/wordrec/chopper.cpp +750 -0
- data/vendor/tesseract-2.04/wordrec/chopper.h +104 -0
- data/vendor/tesseract-2.04/wordrec/closed.cpp +136 -0
- data/vendor/tesseract-2.04/wordrec/closed.h +65 -0
- data/vendor/tesseract-2.04/wordrec/djmenus.cpp +118 -0
- data/vendor/tesseract-2.04/wordrec/djmenus.h +33 -0
- data/vendor/tesseract-2.04/wordrec/drawfx.cpp +92 -0
- data/vendor/tesseract-2.04/wordrec/drawfx.h +33 -0
- data/vendor/tesseract-2.04/wordrec/findseam.cpp +566 -0
- data/vendor/tesseract-2.04/wordrec/findseam.h +69 -0
- data/vendor/tesseract-2.04/wordrec/gradechop.cpp +226 -0
- data/vendor/tesseract-2.04/wordrec/gradechop.h +91 -0
- data/vendor/tesseract-2.04/wordrec/heuristic.cpp +194 -0
- data/vendor/tesseract-2.04/wordrec/heuristic.h +120 -0
- data/vendor/tesseract-2.04/wordrec/makechop.cpp +281 -0
- data/vendor/tesseract-2.04/wordrec/makechop.h +69 -0
- data/vendor/tesseract-2.04/wordrec/matchtab.cpp +191 -0
- data/vendor/tesseract-2.04/wordrec/matchtab.h +45 -0
- data/vendor/tesseract-2.04/wordrec/matrix.cpp +118 -0
- data/vendor/tesseract-2.04/wordrec/matrix.h +104 -0
- data/vendor/tesseract-2.04/wordrec/measure.h +135 -0
- data/vendor/tesseract-2.04/wordrec/metrics.cpp +363 -0
- data/vendor/tesseract-2.04/wordrec/metrics.h +130 -0
- data/vendor/tesseract-2.04/wordrec/mfvars.cpp +51 -0
- data/vendor/tesseract-2.04/wordrec/mfvars.h +27 -0
- data/vendor/tesseract-2.04/wordrec/msmenus.cpp +110 -0
- data/vendor/tesseract-2.04/wordrec/msmenus.h +45 -0
- data/vendor/tesseract-2.04/wordrec/olutil.cpp +153 -0
- data/vendor/tesseract-2.04/wordrec/olutil.h +128 -0
- data/vendor/tesseract-2.04/wordrec/outlines.cpp +172 -0
- data/vendor/tesseract-2.04/wordrec/outlines.h +148 -0
- data/vendor/tesseract-2.04/wordrec/pieces.cpp +410 -0
- data/vendor/tesseract-2.04/wordrec/pieces.h +154 -0
- data/vendor/tesseract-2.04/wordrec/plotedges.cpp +134 -0
- data/vendor/tesseract-2.04/wordrec/plotedges.h +71 -0
- data/vendor/tesseract-2.04/wordrec/plotseg.cpp +116 -0
- data/vendor/tesseract-2.04/wordrec/plotseg.h +73 -0
- data/vendor/tesseract-2.04/wordrec/render.cpp +152 -0
- data/vendor/tesseract-2.04/wordrec/render.h +58 -0
- data/vendor/tesseract-2.04/wordrec/seam.cpp +482 -0
- data/vendor/tesseract-2.04/wordrec/seam.h +136 -0
- data/vendor/tesseract-2.04/wordrec/split.cpp +182 -0
- data/vendor/tesseract-2.04/wordrec/split.h +115 -0
- data/vendor/tesseract-2.04/wordrec/tally.cpp +68 -0
- data/vendor/tesseract-2.04/wordrec/tally.h +94 -0
- data/vendor/tesseract-2.04/wordrec/tessinit.cpp +108 -0
- data/vendor/tesseract-2.04/wordrec/tessinit.h +46 -0
- data/vendor/tesseract-2.04/wordrec/tface.cpp +272 -0
- data/vendor/tesseract-2.04/wordrec/tface.h +35 -0
- data/vendor/tesseract-2.04/wordrec/wordclass.cpp +284 -0
- data/vendor/tesseract-2.04/wordrec/wordclass.h +64 -0
- metadata +708 -0
@@ -0,0 +1,1764 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
* File: imgs.c (Formerly images.c)
|
3
|
+
* Description: Main image manipulation functions.
|
4
|
+
* Author: Ray Smith
|
5
|
+
* Created: Thu Jun 07 16:25:02 BST 1990
|
6
|
+
*
|
7
|
+
* (C) Copyright 1990, Hewlett-Packard Ltd.
|
8
|
+
** Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
** you may not use this file except in compliance with the License.
|
10
|
+
** You may obtain a copy of the License at
|
11
|
+
** http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
** Unless required by applicable law or agreed to in writing, software
|
13
|
+
** distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
** See the License for the specific language governing permissions and
|
16
|
+
** limitations under the License.
|
17
|
+
*
|
18
|
+
**********************************************************************/
|
19
|
+
|
20
|
+
#include "mfcpch.h" //precompiled headers
|
21
|
+
#ifdef __MSW32__
|
22
|
+
#include <io.h>
|
23
|
+
#else
|
24
|
+
#include <unistd.h>
|
25
|
+
#endif
|
26
|
+
#include <string.h>
|
27
|
+
#ifdef __UNIX__
|
28
|
+
#include <assert.h>
|
29
|
+
#endif
|
30
|
+
|
31
|
+
// Include automatically generated configuration file if running autoconf.
|
32
|
+
#ifdef HAVE_CONFIG_H
|
33
|
+
#include "config_auto.h"
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifdef HAVE_LIBLEPT
|
37
|
+
// Include leptonica library only if autoconf (or makefile etc) tell us to.
|
38
|
+
#include "allheaders.h"
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#include "stderr.h"
|
42
|
+
#include "tprintf.h"
|
43
|
+
#include "imgerrs.h"
|
44
|
+
#include "memry.h"
|
45
|
+
#include "imgs.h"
|
46
|
+
#include "imgio.h"
|
47
|
+
#include "imgunpk.h"
|
48
|
+
|
49
|
+
#define FIXED_COLOURS 32 /*number of fixed colours */
|
50
|
+
#define MIN_4BIT 48 /*4bpp range */
|
51
|
+
#define MAX_4BIT 64
|
52
|
+
#define MIN_6BIT 64 /*6bpp range */
|
53
|
+
#define MAX_6BIT 128
|
54
|
+
#define BLACK_PIX 0
|
55
|
+
|
56
|
+
static uinT8 grey_scales[FIXED_COLOURS] = {
|
57
|
+
0, 255, 76, 227, 151, 179, 28, 104,
|
58
|
+
149, 72, 215, 67, 53, 44, 156, 137,
|
59
|
+
110, 153, 79, 181, 166, 218, 55, 81,
|
60
|
+
129, 105, 179, 149, 168, 69, 84, 126
|
61
|
+
};
|
62
|
+
|
63
|
+
#undef EXTERN
|
64
|
+
#define EXTERN
|
65
|
+
|
66
|
+
EXTERN INT_VAR (image_default_resolution, 300, "Image resolution dpi");
|
67
|
+
|
68
|
+
/**********************************************************************
|
69
|
+
* IMAGE
|
70
|
+
*
|
71
|
+
* Contructor for an IMAGE class. Makes the image definitely illegal.
|
72
|
+
**********************************************************************/
|
73
|
+
|
74
|
+
IMAGE::IMAGE() { //construct an image
|
75
|
+
bpp = 0; //all illegal
|
76
|
+
fd = -1;
|
77
|
+
image = NULL;
|
78
|
+
photo_interp = 1;
|
79
|
+
res = image_default_resolution;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
/**********************************************************************
|
84
|
+
* IMAGE::operator=
|
85
|
+
*
|
86
|
+
* Assign an IMAGE to another. The dest becomes the owner of the memory.
|
87
|
+
**********************************************************************/
|
88
|
+
|
89
|
+
IMAGE & IMAGE::operator= ( //assignment
|
90
|
+
IMAGE & source //source image
|
91
|
+
) {
|
92
|
+
destroy();
|
93
|
+
bpp = source.bpp;
|
94
|
+
photo_interp = source.photo_interp;
|
95
|
+
bps = source.bps;
|
96
|
+
bytespp = (bpp + 7) / 8;
|
97
|
+
lineskip = source.lineskip; //copy everything
|
98
|
+
captured = source.captured;
|
99
|
+
xsize = source.xsize;
|
100
|
+
ysize = source.ysize;
|
101
|
+
res = source.res;
|
102
|
+
image = source.image;
|
103
|
+
xdim = source.xdim;
|
104
|
+
bufheight = source.bufheight;
|
105
|
+
fd = source.fd;
|
106
|
+
reader = source.reader;
|
107
|
+
ymin = source.ymin;
|
108
|
+
ymax = source.ymax;
|
109
|
+
|
110
|
+
source.captured = TRUE; //source now captured
|
111
|
+
source.fd = -1;
|
112
|
+
|
113
|
+
return *this;
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
/**********************************************************************
|
118
|
+
* create
|
119
|
+
*
|
120
|
+
* Create an image (allocate memory) of a specific size and bpp.
|
121
|
+
**********************************************************************/
|
122
|
+
|
123
|
+
inT8 IMAGE::create( //get rest of image
|
124
|
+
inT32 x, //x size required
|
125
|
+
inT32 y, //ysize required
|
126
|
+
inT8 bits_per_pixel //bpp required
|
127
|
+
) {
|
128
|
+
uinT8 *pixels; //memory for image
|
129
|
+
|
130
|
+
xdim = check_legal_image_size (x, y, bits_per_pixel);
|
131
|
+
if (xdim < 0)
|
132
|
+
return -1;
|
133
|
+
pixels = (uinT8 *) alloc_big_zeros ((size_t) (xdim * y * sizeof (uinT8)));
|
134
|
+
if (pixels == NULL) {
|
135
|
+
MEMORY_OUT.error ("IMAGE::create", ABORT, "Size=(%d,%d)", xdim, y);
|
136
|
+
return -1;
|
137
|
+
}
|
138
|
+
//allocate to image
|
139
|
+
this->capture (pixels, x, y, bits_per_pixel);
|
140
|
+
captured = FALSE;
|
141
|
+
res = image_default_resolution;
|
142
|
+
return 0; //success
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
/**********************************************************************
|
147
|
+
* destroy
|
148
|
+
*
|
149
|
+
* Destroy an image, freeing memory and closing any open file.
|
150
|
+
**********************************************************************/
|
151
|
+
|
152
|
+
void IMAGE::destroy() { //get rid of image
|
153
|
+
if (image != NULL && !captured) {
|
154
|
+
free_big_mem(image);
|
155
|
+
}
|
156
|
+
image = NULL;
|
157
|
+
if (fd >= 0) {
|
158
|
+
close(fd);
|
159
|
+
fd = -1;
|
160
|
+
}
|
161
|
+
bpp = 0;
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
/**********************************************************************
|
166
|
+
* capture
|
167
|
+
*
|
168
|
+
* Assign a given memory area to an image to use as an image of
|
169
|
+
* given size and bpp.
|
170
|
+
**********************************************************************/
|
171
|
+
|
172
|
+
inT8 IMAGE::capture( //get rest of image
|
173
|
+
uinT8 *pixels, //image memory
|
174
|
+
inT32 x, //x size required
|
175
|
+
inT32 y, //ysize required
|
176
|
+
inT8 bits_per_pixel //bpp required
|
177
|
+
) {
|
178
|
+
destroy();
|
179
|
+
xdim = check_legal_image_size (x, y, bits_per_pixel);
|
180
|
+
if (xdim < 0)
|
181
|
+
return -1;
|
182
|
+
xsize = x;
|
183
|
+
ysize = y;
|
184
|
+
bufheight = y;
|
185
|
+
bpp = bits_per_pixel;
|
186
|
+
bps = bpp == 24 ? 8 : bpp;
|
187
|
+
photo_interp = 1;
|
188
|
+
bytespp = (bpp + 7) / 8;
|
189
|
+
image = pixels; //assign image area
|
190
|
+
ymin = 0;
|
191
|
+
ymax = bufheight; //read it all
|
192
|
+
captured = TRUE;
|
193
|
+
res = image_default_resolution;
|
194
|
+
return 0; //success
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
/**********************************************************************
|
199
|
+
* pixel
|
200
|
+
*
|
201
|
+
* Get a single pixel out of the image.
|
202
|
+
**********************************************************************/
|
203
|
+
|
204
|
+
uinT8 IMAGE::pixel( //get rest of image
|
205
|
+
inT32 x, //x coord
|
206
|
+
inT32 y //y coord
|
207
|
+
) {
|
208
|
+
if (x < 0)
|
209
|
+
x = 0; //silently clip
|
210
|
+
else if (x >= xsize)
|
211
|
+
x = xsize - 1;
|
212
|
+
if (y < 0)
|
213
|
+
y = 0;
|
214
|
+
else if (y >= ysize)
|
215
|
+
y = ysize - 1;
|
216
|
+
check_legal_access (x, y, 1);
|
217
|
+
switch (bpp) {
|
218
|
+
case 5:
|
219
|
+
case 6:
|
220
|
+
case 8:
|
221
|
+
return image[(ymax - 1 - y) * xdim + x];
|
222
|
+
case 4:
|
223
|
+
return bpp4table[image[(ymax - 1 - y) * xdim + x / 2]][x & 1];
|
224
|
+
case 2:
|
225
|
+
return bpp2table[image[(ymax - 1 - y) * xdim + x / 4]][x & 3];
|
226
|
+
case 1:
|
227
|
+
return bpp1table[image[(ymax - 1 - y) * xdim + x / 8]][x & 7];
|
228
|
+
default:
|
229
|
+
tprintf ("Unexpected bits per pixel %d\n", bpp);
|
230
|
+
return 0;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
|
235
|
+
/**********************************************************************
|
236
|
+
* check_legal_image_size
|
237
|
+
*
|
238
|
+
* Check that the supplied image sizes are legal. If they are,
|
239
|
+
* the xdim is returned, else -1.
|
240
|
+
**********************************************************************/
|
241
|
+
|
242
|
+
inT32 check_legal_image_size( //get rest of image
|
243
|
+
inT32 x, //x size required
|
244
|
+
inT32 y, //ysize required
|
245
|
+
inT8 bits_per_pixel //bpp required
|
246
|
+
) {
|
247
|
+
if (x <= 0 || y <= 0) {
|
248
|
+
BADIMAGESIZE.error ("check_legal_image_size", TESSLOG, "(%d,%d)", x, y);
|
249
|
+
return -1; //failed
|
250
|
+
}
|
251
|
+
if (bits_per_pixel != 1 && bits_per_pixel != 2
|
252
|
+
&& bits_per_pixel != 4 && bits_per_pixel != 5
|
253
|
+
&& bits_per_pixel != 6 && bits_per_pixel != 8 && bits_per_pixel != 24) {
|
254
|
+
BADBPP.error ("check_legal_image_size", TESSLOG, "%d", bits_per_pixel);
|
255
|
+
return -1;
|
256
|
+
}
|
257
|
+
//bytes per line
|
258
|
+
return COMPUTE_IMAGE_XDIM (x, bits_per_pixel);
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
/**********************************************************************
|
263
|
+
* copy_sub_image
|
264
|
+
*
|
265
|
+
* Copy a portion of one image to a portion of another image.
|
266
|
+
* If the bpps are different, the position of the most significant
|
267
|
+
* bit is preserved.
|
268
|
+
**********************************************************************/
|
269
|
+
|
270
|
+
DLLSYM void copy_sub_image( //copy rectangle
|
271
|
+
IMAGE *source, //source image
|
272
|
+
inT32 xstart, //start coords
|
273
|
+
inT32 ystart,
|
274
|
+
inT32 xext, //extent to copy
|
275
|
+
inT32 yext,
|
276
|
+
IMAGE *dest, //destination image
|
277
|
+
inT32 xdest, //destination coords
|
278
|
+
inT32 ydest,
|
279
|
+
BOOL8 adjust_grey //shift to new bpp
|
280
|
+
) {
|
281
|
+
IMAGELINE copyline; //copy of line
|
282
|
+
uinT8 *copy; //source pointer
|
283
|
+
inT8 shift; //shift factor
|
284
|
+
inT32 pixel; //pixel index
|
285
|
+
inT32 y; //line index
|
286
|
+
inT32 yoffset; //current adjusted offset
|
287
|
+
inT32 bytesize; //no of bytes to copy
|
288
|
+
inT32 srcppb; //pixels per byte
|
289
|
+
BOOL8 aligned;
|
290
|
+
|
291
|
+
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
|
292
|
+
return;
|
293
|
+
if (xext <= 0)
|
294
|
+
xext = source->xsize; //default to all
|
295
|
+
if (xext > source->xsize - xstart)
|
296
|
+
//clip to smallest
|
297
|
+
xext = source->xsize - xstart;
|
298
|
+
if (xext > dest->xsize - xdest)
|
299
|
+
xext = dest->xsize - xdest;
|
300
|
+
if (yext <= 0)
|
301
|
+
yext = source->ysize; //default to all
|
302
|
+
if (yext > source->ysize - ystart)
|
303
|
+
//clip to smallest
|
304
|
+
yext = source->ysize - ystart;
|
305
|
+
if (yext > dest->ysize - ydest)
|
306
|
+
yext = dest->ysize - ydest;
|
307
|
+
if (xext <= 0 || yext <= 0)
|
308
|
+
return; //nothing to do
|
309
|
+
|
310
|
+
srcppb = 8 / source->bpp; //pixels per byte
|
311
|
+
if (source->bpp == dest->bpp || !adjust_grey)
|
312
|
+
shift = 0; //no adjustment
|
313
|
+
else {
|
314
|
+
shift = source->bps - dest->bps;
|
315
|
+
if (shift < 0)
|
316
|
+
shift = -shift; //keep positive
|
317
|
+
}
|
318
|
+
aligned = source->bpp == dest->bpp;
|
319
|
+
if (aligned && srcppb != 0) {
|
320
|
+
aligned = xstart % srcppb == 0
|
321
|
+
&& xdest % srcppb == 0
|
322
|
+
&& (xext % srcppb == 0 || xdest + xext == dest->xsize);
|
323
|
+
}
|
324
|
+
for (y = 0; y < yext; y++) {
|
325
|
+
if (ystart >= ydest)
|
326
|
+
yoffset = y; //top down
|
327
|
+
else
|
328
|
+
yoffset = yext - y - 1; //bottom up
|
329
|
+
source->check_legal_access (xstart, ystart + yoffset, xext);
|
330
|
+
dest->check_legal_access (xdest, ydest + yoffset, xext);
|
331
|
+
if (aligned) {
|
332
|
+
bytesize = COMPUTE_IMAGE_XDIM (xext, source->bpp);
|
333
|
+
//get bytes per line
|
334
|
+
if (srcppb == 0)
|
335
|
+
//do cheap move
|
336
|
+
memmove (dest->image + (dest->ymax - 1 - ydest - yoffset) * dest->xdim + xdest * 3, source->image + (source->ymax - 1 - ystart - yoffset) * source->xdim + xstart * 3, (unsigned) bytesize);
|
337
|
+
else
|
338
|
+
//do cheap move
|
339
|
+
memmove (dest->image + (dest->ymax - 1 - ydest - yoffset) * dest->xdim + xdest / srcppb, source->image + (source->ymax - 1 - ystart - yoffset) * source->xdim + xstart / srcppb, (unsigned) bytesize);
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
if (shift == 0) {
|
343
|
+
source->fast_get_line (xstart, ystart + yoffset, xext,
|
344
|
+
©line);
|
345
|
+
}
|
346
|
+
else if (source->bpp < dest->bpp) {
|
347
|
+
source->get_line (xstart, ystart + yoffset, xext, ©line, 0);
|
348
|
+
if (source->bpp <= shift
|
349
|
+
&& (source->bpp == 1 || source->bpp == 4)) {
|
350
|
+
if (source->bpp == 1) {
|
351
|
+
for (pixel = 0, copy = copyline.pixels; pixel < xext;
|
352
|
+
pixel++, copy++)
|
353
|
+
if (*copy)
|
354
|
+
*copy = 0xff;
|
355
|
+
}
|
356
|
+
else {
|
357
|
+
for (pixel = 0, copy = copyline.pixels; pixel < xext;
|
358
|
+
pixel++, copy++)
|
359
|
+
//scale up
|
360
|
+
*copy = (*copy << shift) | *copy;
|
361
|
+
}
|
362
|
+
}
|
363
|
+
else {
|
364
|
+
for (pixel = 0, copy = copyline.pixels; pixel < xext;
|
365
|
+
pixel++)
|
366
|
+
*copy++ <<= shift; //scale up
|
367
|
+
}
|
368
|
+
}
|
369
|
+
else {
|
370
|
+
source->get_line (xstart, ystart + yoffset, xext, ©line, 0);
|
371
|
+
if (source->bpp == 24) {
|
372
|
+
for (pixel = 0, copy = copyline.pixels + 1; pixel < xext;
|
373
|
+
pixel++) {
|
374
|
+
*copy >>= shift;
|
375
|
+
copy += 3;
|
376
|
+
}
|
377
|
+
}
|
378
|
+
else {
|
379
|
+
for (pixel = 0, copy = copyline.pixels; pixel < xext;
|
380
|
+
pixel++)
|
381
|
+
*copy++ >>= shift; //scale down
|
382
|
+
}
|
383
|
+
}
|
384
|
+
dest->put_line (xdest, ydest + yoffset, xext, ©line, 0);
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
/**********************************************************************
|
391
|
+
* enlarge_sub_image
|
392
|
+
*
|
393
|
+
* Enlarge a portion of one image to a portion of another image.
|
394
|
+
* If the bpps are different, the position of the most significant
|
395
|
+
* bit is preserved.
|
396
|
+
**********************************************************************/
|
397
|
+
|
398
|
+
DLLSYM void enlarge_sub_image( //enlarge rectangle
|
399
|
+
IMAGE *source, //source image
|
400
|
+
inT32 xstart, //scaled start coords
|
401
|
+
inT32 ystart,
|
402
|
+
IMAGE *dest, //destination image
|
403
|
+
inT32 xdest, //dest coords
|
404
|
+
inT32 ydest,
|
405
|
+
inT32 xext, //destination extent
|
406
|
+
inT32 yext,
|
407
|
+
inT32 scale, //scale factor
|
408
|
+
BOOL8 adjust_grey //shift to new bpp
|
409
|
+
) {
|
410
|
+
inT8 shift; //shift factor
|
411
|
+
uinT8 pixel; //current pixel
|
412
|
+
inT32 srcext; //source extent
|
413
|
+
inT32 xoffset; //column index
|
414
|
+
inT32 yoffset; //line index
|
415
|
+
inT32 xindex, yindex; //index in super pixel
|
416
|
+
inT32 startxindex; //initial x index
|
417
|
+
inT32 xscale; //x scale factor
|
418
|
+
uinT8 *src; //source pixels
|
419
|
+
uinT8 *destpix; //dest pixels
|
420
|
+
IMAGELINE copyline; //copy of line
|
421
|
+
IMAGELINE bigline; //expanded line
|
422
|
+
|
423
|
+
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
|
424
|
+
return;
|
425
|
+
|
426
|
+
if (xext <= 0)
|
427
|
+
xext = dest->xsize; //default to all
|
428
|
+
if (xext > source->xsize * scale - xstart)
|
429
|
+
//clip to smallest
|
430
|
+
xext = source->xsize * scale - xstart;
|
431
|
+
if (xext > dest->xsize - xdest)
|
432
|
+
xext = dest->xsize - xdest;
|
433
|
+
if (yext <= 0)
|
434
|
+
yext = dest->ysize; //default to all
|
435
|
+
if (yext > source->ysize * scale - ystart)
|
436
|
+
yext = source->ysize * scale - ystart;
|
437
|
+
if (yext > dest->ysize - ydest)
|
438
|
+
yext = dest->ysize - ydest;
|
439
|
+
if (xext <= 0 || yext <= 0)
|
440
|
+
return; //nothing to do
|
441
|
+
|
442
|
+
xindex = xstart % scale; //offset in super pixel
|
443
|
+
startxindex = xindex;
|
444
|
+
yindex = ystart % scale;
|
445
|
+
//no of source pixels
|
446
|
+
srcext = (xext + xindex + scale - 1) / scale;
|
447
|
+
xstart /= scale; //actual start
|
448
|
+
ystart /= scale;
|
449
|
+
if (adjust_grey) {
|
450
|
+
shift = dest->bps - source->bps;
|
451
|
+
}
|
452
|
+
else
|
453
|
+
shift = 0; //no adjustment
|
454
|
+
bigline.init (xext * 3);
|
455
|
+
bigline.bpp = dest->bpp == 24 ? source->bpp : dest->bpp;
|
456
|
+
|
457
|
+
for (yoffset = 0; yoffset < yext; ystart++) {
|
458
|
+
source->check_legal_access (xstart, ystart, srcext);
|
459
|
+
dest->check_legal_access (xdest, ydest + yoffset, xext);
|
460
|
+
source->fast_get_line (xstart, ystart, srcext, ©line);
|
461
|
+
src = copyline.pixels;
|
462
|
+
destpix = bigline.pixels;
|
463
|
+
xscale = scale; //enlargement factor
|
464
|
+
if (source->bpp == 24 && dest->bpp == 24) {
|
465
|
+
for (xoffset = 0, xindex = startxindex; xoffset < xext;
|
466
|
+
src += source->bytespp) {
|
467
|
+
xoffset += xscale - xindex;
|
468
|
+
if (xoffset > xext)
|
469
|
+
xscale -= xoffset - xext;
|
470
|
+
for (; xindex < xscale; xindex++) {
|
471
|
+
*destpix++ = *src;
|
472
|
+
*destpix++ = *(src + 1);
|
473
|
+
*destpix++ = *(src + 2);
|
474
|
+
}
|
475
|
+
xindex = 0;
|
476
|
+
}
|
477
|
+
}
|
478
|
+
else {
|
479
|
+
if (source->bpp == 24)
|
480
|
+
src++;
|
481
|
+
for (xoffset = 0, xindex = startxindex; xoffset < xext;
|
482
|
+
src += source->bytespp) {
|
483
|
+
xoffset += xscale - xindex;
|
484
|
+
if (xoffset > xext)
|
485
|
+
//clip to dest limit
|
486
|
+
xscale -= xoffset - xext;
|
487
|
+
if (shift == 0)
|
488
|
+
pixel = *src;
|
489
|
+
else if (shift > 0)
|
490
|
+
pixel = *src << shift;
|
491
|
+
else
|
492
|
+
pixel = *src >> (-shift);
|
493
|
+
for (; xindex < xscale; xindex++)
|
494
|
+
*destpix++ = pixel; //duplicate pixel
|
495
|
+
xindex = 0;
|
496
|
+
}
|
497
|
+
}
|
498
|
+
for (; yoffset < yext && yindex < scale; yindex++, yoffset++) {
|
499
|
+
dest->put_line (xdest, ydest + yoffset, xext, &bigline, 0);
|
500
|
+
}
|
501
|
+
yindex = 0;
|
502
|
+
}
|
503
|
+
}
|
504
|
+
|
505
|
+
|
506
|
+
/**********************************************************************
|
507
|
+
* fast_reduce_sub_image
|
508
|
+
*
|
509
|
+
* Reduce a portion of one image to a portion of another image.
|
510
|
+
* If the bpps are different, the position of the most significant
|
511
|
+
* bit is preserved.
|
512
|
+
* This is a fast but dirty version, which simply sub-samples.
|
513
|
+
* It does not smooth as it reduces.
|
514
|
+
**********************************************************************/
|
515
|
+
|
516
|
+
DLLSYM void fast_reduce_sub_image( //reduce rectangle
|
517
|
+
IMAGE *source, //source image
|
518
|
+
inT32 xstart, //start coords
|
519
|
+
inT32 ystart,
|
520
|
+
inT32 xext, //extent to copy
|
521
|
+
inT32 yext,
|
522
|
+
IMAGE *dest, //destination image
|
523
|
+
inT32 xdest, //destination coords
|
524
|
+
inT32 ydest,
|
525
|
+
inT32 scale, //reduction factor
|
526
|
+
BOOL8 adjust_grey //shift to new bpp
|
527
|
+
) {
|
528
|
+
inT8 shift; //shift factor
|
529
|
+
inT32 xfactor; //run on x coord
|
530
|
+
inT32 divisor; //total cell area
|
531
|
+
inT32 xindex, yindex; //into averaging square
|
532
|
+
inT32 xcoord; //current x coord
|
533
|
+
inT32 destext; //destination size
|
534
|
+
inT32 yoffset; //current adjusted offset
|
535
|
+
uinT8 *pixel; //ptr to source pixels
|
536
|
+
inT32 *sums; //ptr to sums array
|
537
|
+
IMAGELINE copyline; //copy of line
|
538
|
+
inT32 *linesums; //averaging sums
|
539
|
+
|
540
|
+
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
|
541
|
+
return;
|
542
|
+
if (xext <= 0)
|
543
|
+
xext = source->xsize; //default to all
|
544
|
+
if (xext > source->xsize - xstart)
|
545
|
+
//clip to smallest
|
546
|
+
xext = source->xsize - xstart;
|
547
|
+
if (xext > (dest->xsize - xdest) * scale)
|
548
|
+
xext = (dest->xsize - xdest) * scale;
|
549
|
+
if (yext <= 0)
|
550
|
+
yext = source->ysize; //default to all
|
551
|
+
if (yext > source->ysize - ystart)
|
552
|
+
//clip to smallest
|
553
|
+
yext = source->ysize - ystart;
|
554
|
+
if (yext > (dest->ysize - ydest) * scale)
|
555
|
+
yext = (dest->ysize - ydest) * scale;
|
556
|
+
if (xext <= 0 || yext <= 0)
|
557
|
+
return; //nothing to do
|
558
|
+
|
559
|
+
xfactor = xext % scale; //left overs
|
560
|
+
if (xfactor == 0)
|
561
|
+
xfactor = scale;
|
562
|
+
//destination pixels
|
563
|
+
destext = (xext + scale - 1) / scale;
|
564
|
+
if (adjust_grey)
|
565
|
+
//shift factor
|
566
|
+
shift = dest->bps - source->bps;
|
567
|
+
else
|
568
|
+
shift = 0; //no adjustment
|
569
|
+
linesums = new inT32[destext * source->bytespp];
|
570
|
+
|
571
|
+
for (yoffset = 0; yoffset < yext; ydest++) {
|
572
|
+
source->check_legal_access (xstart, ystart + yoffset, xext);
|
573
|
+
dest->check_legal_access (xdest, ydest, destext);
|
574
|
+
for (xindex = destext * source->bytespp - 1; xindex >= 0; xindex--)
|
575
|
+
linesums[xindex] = 0; //zero sums
|
576
|
+
for (yindex = 0; yindex < scale
|
577
|
+
&& ystart + yoffset < source->ysize; yindex += 3) {
|
578
|
+
source->fast_get_line (xstart, ystart + yoffset, xext, ©line);
|
579
|
+
pixel = copyline.pixels; //start of line
|
580
|
+
if (source->bpp == 24) {
|
581
|
+
for (xcoord = 1, sums = linesums; xcoord < destext;
|
582
|
+
xcoord++, sums += 3) {
|
583
|
+
for (xindex = 0; xindex < scale; xindex += 2) {
|
584
|
+
*sums += *pixel++;
|
585
|
+
*(sums + 1) += *pixel++;
|
586
|
+
*(sums + 2) += *pixel++;
|
587
|
+
pixel += 3;
|
588
|
+
}
|
589
|
+
if (scale & 1)
|
590
|
+
pixel -= 3; //correct position
|
591
|
+
}
|
592
|
+
for (xindex = 0; xindex < xfactor; xindex += 2) {
|
593
|
+
*sums += *pixel++;
|
594
|
+
*(sums + 1) += *pixel++;
|
595
|
+
*(sums + 2) += *pixel++;
|
596
|
+
pixel += 3;
|
597
|
+
}
|
598
|
+
}
|
599
|
+
else {
|
600
|
+
for (xcoord = 1, sums = linesums; xcoord < destext;
|
601
|
+
xcoord++, sums++) {
|
602
|
+
for (xindex = 0; xindex < scale; xindex += 2) {
|
603
|
+
*sums += *pixel;
|
604
|
+
pixel += 2;
|
605
|
+
}
|
606
|
+
if (scale & 1)
|
607
|
+
pixel--; //correct position
|
608
|
+
}
|
609
|
+
for (xindex = 0; xindex < xfactor; xindex += 2) {
|
610
|
+
*sums += *pixel;
|
611
|
+
pixel += 2;
|
612
|
+
}
|
613
|
+
}
|
614
|
+
yoffset += 3; //every 3 lines
|
615
|
+
}
|
616
|
+
if (yindex > scale)
|
617
|
+
yoffset -= yindex - scale; //back on right scale
|
618
|
+
copyline.init (); //set pixels back to array
|
619
|
+
copyline.bpp = source->bpp;
|
620
|
+
pixel = copyline.pixels;
|
621
|
+
//pixels in block
|
622
|
+
divisor = ((yindex + 2) / 3) * ((scale + 1) / 2);
|
623
|
+
if (shift <= 0) {
|
624
|
+
divisor <<= (-shift); //do greyscale correction
|
625
|
+
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
|
626
|
+
xindex > 0; xindex--)
|
627
|
+
//turn to destination value
|
628
|
+
*pixel++ = (uinT8) (*sums++ / divisor);
|
629
|
+
for (xindex = source->bytespp; xindex > 0; xindex--)
|
630
|
+
*pixel++ = *sums++
|
631
|
+
/ (((yindex + 2) / 3) * ((xfactor + 1) / 2) << (-shift));
|
632
|
+
//lastone different
|
633
|
+
}
|
634
|
+
else {
|
635
|
+
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
|
636
|
+
xindex > 0; xindex--)
|
637
|
+
*pixel++ = (uinT8) ((*sums++ << shift) / divisor);
|
638
|
+
//destination value
|
639
|
+
for (xindex = source->bytespp; xindex > 0; xindex--)
|
640
|
+
//last one different
|
641
|
+
*pixel++ = (*(sums++) << shift) / (((yindex + 2) / 3) * ((xfactor + 1) / 2));
|
642
|
+
}
|
643
|
+
//put in destination
|
644
|
+
dest->put_line (xdest, ydest, destext, ©line, 0);
|
645
|
+
}
|
646
|
+
delete linesums;
|
647
|
+
}
|
648
|
+
|
649
|
+
|
650
|
+
/**********************************************************************
|
651
|
+
* reduce_sub_image
|
652
|
+
*
|
653
|
+
* Reduce a portion of one image to a portion of another image.
|
654
|
+
* If the bpps are different, the position of the most significant
|
655
|
+
* bit is preserved.
|
656
|
+
**********************************************************************/
|
657
|
+
|
658
|
+
DLLSYM void reduce_sub_image( //reduce rectangle
|
659
|
+
IMAGE *source, //source image
|
660
|
+
inT32 xstart, //start coords
|
661
|
+
inT32 ystart,
|
662
|
+
inT32 xext, //extent to copy
|
663
|
+
inT32 yext,
|
664
|
+
IMAGE *dest, //destination image
|
665
|
+
inT32 xdest, //destination coords
|
666
|
+
inT32 ydest,
|
667
|
+
inT32 scale, //reduction factor
|
668
|
+
BOOL8 adjust_grey //shift to new bpp
|
669
|
+
) {
|
670
|
+
inT8 shift; //shift factor
|
671
|
+
inT32 xfactor; //run on x coord
|
672
|
+
inT32 divisor; //total cell area
|
673
|
+
inT32 div2; //total cell area divided by 2
|
674
|
+
inT32 xindex, yindex; //into averaging square
|
675
|
+
inT32 xcoord; //current x coord
|
676
|
+
inT32 destext; //destination size
|
677
|
+
inT32 yoffset; //current adjusted offset
|
678
|
+
uinT8 *pixel; //ptr to source pixels
|
679
|
+
inT32 *sums; //ptr to sums array
|
680
|
+
IMAGELINE copyline; //copy of line
|
681
|
+
inT32 *linesums; //averaging sums
|
682
|
+
|
683
|
+
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
|
684
|
+
return;
|
685
|
+
if (xext <= 0)
|
686
|
+
xext = source->xsize; //default to all
|
687
|
+
if (xext > source->xsize - xstart)
|
688
|
+
//clip to smallest
|
689
|
+
xext = source->xsize - xstart;
|
690
|
+
if (xext > (dest->xsize - xdest) * scale)
|
691
|
+
xext = (dest->xsize - xdest) * scale;
|
692
|
+
if (yext <= 0)
|
693
|
+
yext = source->ysize; //default to all
|
694
|
+
if (yext > source->ysize - ystart)
|
695
|
+
//clip to smallest
|
696
|
+
yext = source->ysize - ystart;
|
697
|
+
if (yext > (dest->ysize - ydest) * scale)
|
698
|
+
yext = (dest->ysize - ydest) * scale;
|
699
|
+
if (xext <= 0 || yext <= 0)
|
700
|
+
return; //nothing to do
|
701
|
+
|
702
|
+
xfactor = xext % scale; //left overs
|
703
|
+
if (xfactor == 0)
|
704
|
+
xfactor = scale;
|
705
|
+
//destination pixels
|
706
|
+
destext = (xext + scale - 1) / scale;
|
707
|
+
if (adjust_grey)
|
708
|
+
//shift factor
|
709
|
+
shift = dest->bps - source->bps;
|
710
|
+
else
|
711
|
+
shift = 0; //no adjustment
|
712
|
+
linesums = new inT32[destext * source->bytespp];
|
713
|
+
|
714
|
+
for (yoffset = 0; yoffset < yext; ydest++) {
|
715
|
+
source->check_legal_access (xstart, ystart + yoffset, xext);
|
716
|
+
dest->check_legal_access (xdest, ydest, destext);
|
717
|
+
for (xindex = 0; xindex < (destext) * source->bytespp; xindex++)
|
718
|
+
linesums[xindex] = 0; //zero sums
|
719
|
+
for (yindex = 0; yindex < scale && ystart + yoffset < source->ysize;
|
720
|
+
yindex++) {
|
721
|
+
source->fast_get_line (xstart, ystart + yoffset, xext, ©line);
|
722
|
+
pixel = copyline.pixels; //start of line
|
723
|
+
if (source->bpp == 24) {
|
724
|
+
for (xcoord = 1, sums = linesums; xcoord < destext;
|
725
|
+
xcoord++, sums += 3) {
|
726
|
+
for (xindex = 0; xindex < scale; xindex++) {
|
727
|
+
*sums += *pixel++;
|
728
|
+
*(sums + 1) += *pixel++;
|
729
|
+
*(sums + 2) += *pixel++;
|
730
|
+
}
|
731
|
+
}
|
732
|
+
for (xindex = 0; xindex < xfactor; xindex++) {
|
733
|
+
*sums += *pixel++;
|
734
|
+
*(sums + 1) += *pixel++;
|
735
|
+
*(sums + 2) += *pixel++;
|
736
|
+
}
|
737
|
+
}
|
738
|
+
else {
|
739
|
+
for (xcoord = 1, sums = linesums; xcoord < destext;
|
740
|
+
xcoord++, sums++) {
|
741
|
+
for (xindex = 0; xindex < scale; xindex++)
|
742
|
+
*sums += *pixel++;
|
743
|
+
}
|
744
|
+
for (xindex = 0; xindex < xfactor; xindex++)
|
745
|
+
*sums += *pixel++;
|
746
|
+
}
|
747
|
+
yoffset++; //next line
|
748
|
+
}
|
749
|
+
copyline.init (); //set pixels back to array
|
750
|
+
copyline.set_bpp (source->bpp);
|
751
|
+
pixel = copyline.pixels;
|
752
|
+
divisor = yindex * scale;
|
753
|
+
if (divisor == 0) {
|
754
|
+
tprintf
|
755
|
+
("Impossible:divisor=0!, yindex=%d, scale=%d, yoffset=%d,yext=%d\n",
|
756
|
+
yindex, scale, yoffset, yext);
|
757
|
+
break;
|
758
|
+
}
|
759
|
+
if (shift <= 0) {
|
760
|
+
divisor <<= (-shift); //do greyscale correction
|
761
|
+
div2 = divisor / 2;
|
762
|
+
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
|
763
|
+
xindex > 0; xindex--)
|
764
|
+
*pixel++ = (uinT8) ((div2 + *sums++) / divisor);
|
765
|
+
//turn to destination value
|
766
|
+
div2 = (yindex * xfactor << (-shift)) / 2;
|
767
|
+
for (xindex = source->bytespp; xindex > 0; xindex--)
|
768
|
+
*pixel++ =
|
769
|
+
(uinT8) ((div2 + *sums++) / (yindex * xfactor << (-shift)));
|
770
|
+
//lastone different
|
771
|
+
}
|
772
|
+
else {
|
773
|
+
div2 = divisor / 2;
|
774
|
+
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
|
775
|
+
xindex > 0; xindex--)
|
776
|
+
*pixel++ = (uinT8) ((div2 + (*sums++ << shift)) / divisor);
|
777
|
+
//destination value
|
778
|
+
div2 = (yindex * xfactor) / 2;
|
779
|
+
for (xindex = source->bytespp; xindex > 0; xindex--)
|
780
|
+
*pixel++ =
|
781
|
+
(uinT8) ((div2 + (*sums++ << shift)) / (yindex * xfactor));
|
782
|
+
//last one different
|
783
|
+
}
|
784
|
+
//put in destination
|
785
|
+
dest->put_line (xdest, ydest, destext, ©line, 0);
|
786
|
+
}
|
787
|
+
delete linesums;
|
788
|
+
}
|
789
|
+
|
790
|
+
|
791
|
+
/**********************************************************************
|
792
|
+
* invert_image
|
793
|
+
*
|
794
|
+
* Invert the given image (the slow way.)
|
795
|
+
**********************************************************************/
|
796
|
+
|
797
|
+
DLLSYM void invert_image( /*invert the image */
|
798
|
+
IMAGE *image /*image ot invert */
|
799
|
+
) {
|
800
|
+
uinT8 mask; //bit mask
|
801
|
+
uinT8 bytespp; //bytes per pixel
|
802
|
+
inT32 xsize, ysize; /*size of image */
|
803
|
+
inT32 xindex, yindex; /*index into image */
|
804
|
+
uinT8 *pixel; /*current pixel */
|
805
|
+
IMAGELINE line; /*line of image */
|
806
|
+
|
807
|
+
bytespp = image->get_bpp () == 24 ? 3 : 1;
|
808
|
+
xsize = image->get_xsize (); /*find sizes */
|
809
|
+
ysize = image->get_ysize ();
|
810
|
+
//pixel mask
|
811
|
+
mask = (1 << image->get_bpp ()) - 1;
|
812
|
+
/*do each line */
|
813
|
+
for (yindex = ysize - 1; yindex >= 0; yindex--) {
|
814
|
+
image->fast_get_line (0, yindex, xsize, &line);
|
815
|
+
for (pixel = line.pixels, xindex = xsize * bytespp; xindex > 0;
|
816
|
+
xindex--) {
|
817
|
+
*pixel = (*pixel) ^ mask; //invert image only
|
818
|
+
++pixel;
|
819
|
+
}
|
820
|
+
/*put it back */
|
821
|
+
image->fast_put_line (0, yindex, xsize, &line);
|
822
|
+
}
|
823
|
+
}
|
824
|
+
|
825
|
+
|
826
|
+
/**********************************************************************
|
827
|
+
* bias_sub_image
|
828
|
+
*
|
829
|
+
* Add a constant to a portion of an image.
|
830
|
+
**********************************************************************/
|
831
|
+
|
832
|
+
DLLSYM void bias_sub_image( //bias rectangle
|
833
|
+
IMAGE *source, //source image
|
834
|
+
inT32 xstart, //start coords
|
835
|
+
inT32 ystart,
|
836
|
+
inT32 xext, //extent to copy
|
837
|
+
inT32 yext,
|
838
|
+
uinT8 bias //number to add
|
839
|
+
) {
|
840
|
+
IMAGELINE copyline; //copy of line
|
841
|
+
uinT8 *copy; //source pointer
|
842
|
+
inT32 pixel; //pixel index
|
843
|
+
inT32 y; //line index
|
844
|
+
uinT8 bytespp; //bytes per pixel
|
845
|
+
|
846
|
+
if (xstart < 0 || ystart < 0)
|
847
|
+
return;
|
848
|
+
if (xext <= 0)
|
849
|
+
xext = source->get_xsize (); //default to all
|
850
|
+
if (xext > source->get_xsize () - xstart)
|
851
|
+
//clip to smallest
|
852
|
+
xext = source->get_xsize () - xstart;
|
853
|
+
if (yext <= 0)
|
854
|
+
yext = source->get_ysize (); //default to all
|
855
|
+
if (yext > source->get_ysize () - ystart)
|
856
|
+
//clip to smallest
|
857
|
+
yext = source->get_ysize () - ystart;
|
858
|
+
if (xext <= 0 || yext <= 0)
|
859
|
+
return; //nothing to do
|
860
|
+
|
861
|
+
bytespp = source->get_bpp () == 24 ? 3 : 1;
|
862
|
+
for (y = 0; y < yext; y++) {
|
863
|
+
source->check_legal_access (xstart, ystart + y, xext);
|
864
|
+
source->fast_get_line (xstart, ystart + y, xext, ©line);
|
865
|
+
for (pixel = xext * bytespp, copy = copyline.pixels; pixel > 0;
|
866
|
+
pixel--, copy++)
|
867
|
+
*copy += bias; //add bias
|
868
|
+
|
869
|
+
source->fast_put_line (xstart, ystart + y, xext, ©line);
|
870
|
+
}
|
871
|
+
}
|
872
|
+
|
873
|
+
|
874
|
+
/**********************************************************************
|
875
|
+
* starbase_to_normal
|
876
|
+
*
|
877
|
+
* Copy a portion of one image to a portion of another image.
|
878
|
+
* This function maps the colour tables used on the screen to
|
879
|
+
* greyscale values in the way "normally" expected.
|
880
|
+
**********************************************************************/
|
881
|
+
|
882
|
+
DLLSYM void starbase_to_normal( //copy rectangle
|
883
|
+
IMAGE *source, //source image
|
884
|
+
inT32 xstart, //start coords
|
885
|
+
inT32 ystart,
|
886
|
+
inT32 xext, //extent to copy
|
887
|
+
inT32 yext,
|
888
|
+
IMAGE *dest, //destination image
|
889
|
+
inT32 xdest, //destination coords
|
890
|
+
inT32 ydest,
|
891
|
+
BOOL8 preserve_grey //shift to new bpp
|
892
|
+
) {
|
893
|
+
IMAGELINE copyline; //copy of line
|
894
|
+
uinT8 *copy; //source pointer
|
895
|
+
inT8 shift4; //shift factor
|
896
|
+
inT8 shift6; //shift factor
|
897
|
+
inT8 colour_shift; //shift of colours
|
898
|
+
uinT8 white_level; //dest white value
|
899
|
+
inT32 pixel; //pixel index
|
900
|
+
inT32 y; //line index
|
901
|
+
inT32 yoffset; //current adjusted offset
|
902
|
+
inT8 srcppb; //pixels per byte
|
903
|
+
|
904
|
+
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
|
905
|
+
return;
|
906
|
+
if (xext <= 0)
|
907
|
+
xext = source->get_xsize (); //default to all
|
908
|
+
if (xext > source->get_xsize () - xstart)
|
909
|
+
//clip to smallest
|
910
|
+
xext = source->get_xsize () - xstart;
|
911
|
+
if (xext > dest->get_xsize () - xdest)
|
912
|
+
xext = dest->get_xsize () - xdest;
|
913
|
+
if (yext <= 0)
|
914
|
+
yext = source->get_ysize (); //default to all
|
915
|
+
if (yext > source->get_ysize () - ystart)
|
916
|
+
//clip to smallest
|
917
|
+
yext = source->get_ysize () - ystart;
|
918
|
+
if (yext > dest->get_ysize () - ydest)
|
919
|
+
yext = dest->get_ysize () - ydest;
|
920
|
+
if (xext <= 0 || yext <= 0)
|
921
|
+
return; //nothing to do
|
922
|
+
|
923
|
+
//pixels per byte
|
924
|
+
srcppb = 8 / source->get_bpp ();
|
925
|
+
shift4 = 4 - dest->get_bpp (); //for different bpps
|
926
|
+
shift6 = 6 - dest->get_bpp ();
|
927
|
+
//for grey preserve
|
928
|
+
colour_shift = 8 - dest->get_bpp ();
|
929
|
+
white_level = dest->get_white_level ();
|
930
|
+
for (y = 0; y < yext; y++) {
|
931
|
+
if (ystart >= ydest)
|
932
|
+
yoffset = y; //top down
|
933
|
+
else
|
934
|
+
yoffset = yext - y - 1; //bottom up
|
935
|
+
source->check_legal_access (xstart, ystart + yoffset, xext);
|
936
|
+
dest->check_legal_access (xdest, ydest + yoffset, xext);
|
937
|
+
source->get_line (xstart, ystart + yoffset, xext, ©line, 0);
|
938
|
+
for (pixel = 0, copy = copyline.pixels; pixel < xext; pixel++) {
|
939
|
+
if (*copy < FIXED_COLOURS && preserve_grey)
|
940
|
+
*copy = grey_scales[*copy] >> colour_shift;
|
941
|
+
else if (*copy < FIXED_COLOURS) {
|
942
|
+
if (*copy == BLACK_PIX)
|
943
|
+
*copy = white_level; //black->white
|
944
|
+
else
|
945
|
+
*copy = 0; //others->black
|
946
|
+
}
|
947
|
+
else if (*copy >= MIN_4BIT && *copy < MAX_4BIT) {
|
948
|
+
if (shift4 < 0)
|
949
|
+
*copy = (*copy - MIN_4BIT) << (-shift4);
|
950
|
+
else
|
951
|
+
*copy = (*copy - MIN_4BIT) >> shift4;
|
952
|
+
}
|
953
|
+
else if (*copy >= MIN_6BIT && *copy < MAX_6BIT) {
|
954
|
+
if (shift6 < 0)
|
955
|
+
*copy = (*copy - MIN_6BIT) << (-shift6);
|
956
|
+
else
|
957
|
+
*copy = (*copy - MIN_6BIT) >> shift6;
|
958
|
+
}
|
959
|
+
else {
|
960
|
+
*copy = white_level; //white the rest
|
961
|
+
}
|
962
|
+
copy++;
|
963
|
+
}
|
964
|
+
dest->put_line (xdest, ydest + yoffset, xext, ©line, 0);
|
965
|
+
}
|
966
|
+
}
|
967
|
+
|
968
|
+
|
969
|
+
/**********************************************************************
|
970
|
+
* fast_get_line
|
971
|
+
*
|
972
|
+
* Get a line of image into the supplied image line buffer.
|
973
|
+
* The image is converted to 8bpp by simple assignment.
|
974
|
+
* If the image is aleady 8 or 6bpp, no copy is done and a pointer
|
975
|
+
* to the correct image section is put in the line buffer.
|
976
|
+
**********************************************************************/
|
977
|
+
|
978
|
+
void IMAGE::fast_get_line( //get image line
|
979
|
+
inT32 x, //coord to start at
|
980
|
+
inT32 y, //line to get
|
981
|
+
inT32 width, //no of pixels to get
|
982
|
+
IMAGELINE *linebuf //line to copy to
|
983
|
+
) {
|
984
|
+
if (width > 0 && bpp > 4) {
|
985
|
+
check_legal_access(x, y, width);
|
986
|
+
//get pointer only
|
987
|
+
linebuf->pixels = image + xdim * (ymax - 1 - y) + x * bytespp;
|
988
|
+
}
|
989
|
+
else
|
990
|
+
//just copy it
|
991
|
+
this->get_line (x, y, width, linebuf, 0);
|
992
|
+
linebuf->bpp = bpp;
|
993
|
+
}
|
994
|
+
|
995
|
+
|
996
|
+
/**********************************************************************
|
997
|
+
* get_line
|
998
|
+
*
|
999
|
+
* Get a line of image into the supplied image line buffer.
|
1000
|
+
* The image is converted to 8bpp by simple assignment.
|
1001
|
+
**********************************************************************/
|
1002
|
+
|
1003
|
+
void IMAGE::get_line( //get image line
|
1004
|
+
inT32 x, //coord to start at
|
1005
|
+
inT32 y, //line to get
|
1006
|
+
inT32 width, //no of pixels to get
|
1007
|
+
IMAGELINE *linebuf, //line to copy to
|
1008
|
+
inT32 margins //size of margins
|
1009
|
+
) {
|
1010
|
+
uinT8 *src; //source pointer
|
1011
|
+
uinT8 *dest; //destination pointer
|
1012
|
+
uinT8 *unpacksrc; //unpacking pointer
|
1013
|
+
inT8 bit; //bit index
|
1014
|
+
inT8 pixperbyte; //pixels per byte
|
1015
|
+
uinT8 white; //white colour
|
1016
|
+
inT32 pixel; //pixel index
|
1017
|
+
|
1018
|
+
//test coords
|
1019
|
+
this->check_legal_access (x, y, width);
|
1020
|
+
if (width > xsize - x)
|
1021
|
+
width = xsize - x; //clip to image
|
1022
|
+
width *= bytespp;
|
1023
|
+
linebuf->init (width + margins * bytespp * 2);
|
1024
|
+
linebuf->bpp = bpp;
|
1025
|
+
//start of line
|
1026
|
+
src = image + xdim * (ymax - 1 - y);
|
1027
|
+
dest = linebuf->line; //destination line
|
1028
|
+
linebuf->pixels = dest;
|
1029
|
+
white = (1 << bpp) - 1; //max value of pixel
|
1030
|
+
for (pixel = margins * bytespp; pixel > 0; pixel--) {
|
1031
|
+
*dest++ = white; //margins are white
|
1032
|
+
}
|
1033
|
+
if (width > 0) {
|
1034
|
+
if (bpp > 4) {
|
1035
|
+
src += x; //offset
|
1036
|
+
//easy way
|
1037
|
+
memmove (dest, src, (unsigned) width);
|
1038
|
+
}
|
1039
|
+
else if (bpp == 4) {
|
1040
|
+
src += x / 2; //offset on line
|
1041
|
+
if (x & 1) {
|
1042
|
+
//get coded nibble
|
1043
|
+
*dest++ = bpp4table[*src++][1];
|
1044
|
+
width--;
|
1045
|
+
}
|
1046
|
+
while (width >= 2) {
|
1047
|
+
//get coded bits
|
1048
|
+
unpacksrc = bpp4table[*src++];
|
1049
|
+
*dest++ = *unpacksrc++;
|
1050
|
+
*dest++ = *unpacksrc++; //copy nibbles
|
1051
|
+
width -= 2;
|
1052
|
+
}
|
1053
|
+
if (width) {
|
1054
|
+
//get coded nibble
|
1055
|
+
*dest++ = bpp4table[*src++][0];
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
else if (bpp == 2) {
|
1059
|
+
pixperbyte = 4;
|
1060
|
+
src += x / 4; //offset on line
|
1061
|
+
bit = (inT8) (x % 4); //offset in byte
|
1062
|
+
width += bit;
|
1063
|
+
while (width > 0) { //until all done
|
1064
|
+
if (width < pixperbyte)
|
1065
|
+
//less on last byte
|
1066
|
+
pixperbyte = (inT8) width;
|
1067
|
+
//get coded bits
|
1068
|
+
unpacksrc = &bpp2table[*src++][bit];
|
1069
|
+
for (; bit < pixperbyte; bit++)
|
1070
|
+
*dest++ = *unpacksrc++;//copy bytes
|
1071
|
+
width -= pixperbyte;
|
1072
|
+
bit = 0;
|
1073
|
+
}
|
1074
|
+
}
|
1075
|
+
else {
|
1076
|
+
pixperbyte = 8;
|
1077
|
+
src += x / 8; //offset on line
|
1078
|
+
bit = (inT8) (x % 8); //offset in byte
|
1079
|
+
width += bit;
|
1080
|
+
while (width > 0) { //until all done
|
1081
|
+
if (width < pixperbyte)
|
1082
|
+
//less on last byte
|
1083
|
+
pixperbyte = (inT8) width;
|
1084
|
+
//get coded bits
|
1085
|
+
unpacksrc = &bpp1table[*src++][bit];
|
1086
|
+
for (; bit < pixperbyte; bit++)
|
1087
|
+
*dest++ = *unpacksrc++;//copy bytes
|
1088
|
+
width -= pixperbyte;
|
1089
|
+
bit = 0;
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
for (pixel = margins * bytespp; pixel > 0; pixel--) {
|
1094
|
+
*dest++ = white; //margins are white
|
1095
|
+
}
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
|
1099
|
+
/**********************************************************************
|
1100
|
+
* get_column
|
1101
|
+
*
|
1102
|
+
* Get a column of image into the supplied image line buffer.
|
1103
|
+
* The image is converted to 8bpp by simple assignment.
|
1104
|
+
**********************************************************************/
|
1105
|
+
|
1106
|
+
void IMAGE::get_column( //get image column
|
1107
|
+
inT32 x, //coord to start at
|
1108
|
+
inT32 y, //line to get
|
1109
|
+
inT32 height, //no of pixels to get
|
1110
|
+
IMAGELINE *linebuf, //line to copy to
|
1111
|
+
inT32 margins //size of margins
|
1112
|
+
) {
|
1113
|
+
uinT8 *src; //source pointer
|
1114
|
+
uinT8 *dest; //destination pointer
|
1115
|
+
inT8 bit; //bit index
|
1116
|
+
inT8 pixperbyte; //pixels per byte
|
1117
|
+
uinT8 white; //white colour
|
1118
|
+
inT32 pixel; //pixel index
|
1119
|
+
|
1120
|
+
//test coords
|
1121
|
+
this->check_legal_access (x, y, 1);
|
1122
|
+
//test coords
|
1123
|
+
this->check_legal_access (x, y + height - 1, 1);
|
1124
|
+
if (height > ysize - y)
|
1125
|
+
height = ysize - y; //clip to image
|
1126
|
+
linebuf->init (height * bytespp + margins * bytespp * 2);
|
1127
|
+
//start of line
|
1128
|
+
src = image + xdim * (ymax - 1 - y);
|
1129
|
+
dest = linebuf->line; //destination line
|
1130
|
+
linebuf->pixels = dest;
|
1131
|
+
white = (1 << bpp) - 1; //max value of pixel
|
1132
|
+
for (pixel = margins * bytespp; pixel > 0; pixel--) {
|
1133
|
+
*dest++ = white; //margins are white
|
1134
|
+
}
|
1135
|
+
if (height > 0) {
|
1136
|
+
if (bpp == 24) {
|
1137
|
+
src += x * bytespp; //offset
|
1138
|
+
for (; height > 0; --height) {
|
1139
|
+
*dest++ = *src; //copy bytes
|
1140
|
+
*dest++ = *(src + 1);
|
1141
|
+
*dest++ = *(src + 2);
|
1142
|
+
src -= xdim;
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
else if (bpp > 4) {
|
1146
|
+
src += x;
|
1147
|
+
for (; height > 0; --height) {
|
1148
|
+
*dest++ = *src; //copy bytes
|
1149
|
+
src -= xdim;
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
else if (bpp == 4) {
|
1153
|
+
src += x / 2; //offset on line
|
1154
|
+
if (x & 1) {
|
1155
|
+
for (; height > 0; --height) {
|
1156
|
+
//get coded nibble
|
1157
|
+
*dest++ = bpp4table[*src][1];
|
1158
|
+
src -= xdim;
|
1159
|
+
}
|
1160
|
+
}
|
1161
|
+
else {
|
1162
|
+
for (; height > 0; --height) {
|
1163
|
+
//get coded nibble
|
1164
|
+
*dest++ = bpp4table[*src][0];
|
1165
|
+
src -= xdim;
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
else if (bpp == 2) {
|
1170
|
+
pixperbyte = 4;
|
1171
|
+
src += x / 4; //offset on line
|
1172
|
+
bit = (inT8) (x % 4); //offset in byte
|
1173
|
+
for (; height > 0; --height) {
|
1174
|
+
//get coded bits
|
1175
|
+
*dest++ = bpp2table[*src][bit];
|
1176
|
+
src -= xdim;
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
else {
|
1180
|
+
pixperbyte = 8;
|
1181
|
+
src += x / 8; //offset on line
|
1182
|
+
bit = (inT8) (x % 8); //offset in byte
|
1183
|
+
for (; height > 0; --height) {
|
1184
|
+
//get coded bits
|
1185
|
+
*dest++ = bpp1table[*src][bit];
|
1186
|
+
src -= xdim;
|
1187
|
+
}
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
for (pixel = margins * bytespp; pixel > 0; pixel--) {
|
1191
|
+
*dest++ = white; //margins are white
|
1192
|
+
}
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
|
1196
|
+
/**********************************************************************
|
1197
|
+
* fast_put_line
|
1198
|
+
*
|
1199
|
+
* Put a line buffer back into the image.
|
1200
|
+
* If the line buffer merely points back into the image, nothing is done.
|
1201
|
+
* Otherwise, put_line is used to copy the line back.
|
1202
|
+
**********************************************************************/
|
1203
|
+
|
1204
|
+
void IMAGE::fast_put_line( //put image line
|
1205
|
+
inT32 x, //coord to start at
|
1206
|
+
inT32 y, //line to get
|
1207
|
+
inT32 width, //no of pixels to put
|
1208
|
+
IMAGELINE *linebuf //line to copy to
|
1209
|
+
) {
|
1210
|
+
if (width > 0 && (bpp <= 4 || linebuf->pixels == linebuf->line))
|
1211
|
+
//just copy it
|
1212
|
+
put_line (x, y, width, linebuf, 0);
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
|
1216
|
+
/**********************************************************************
|
1217
|
+
* put_line
|
1218
|
+
*
|
1219
|
+
* Put the supplied line buffer into the image.
|
1220
|
+
* The image is converted from 8bpp by simple assignment.
|
1221
|
+
**********************************************************************/
|
1222
|
+
|
1223
|
+
void IMAGE::put_line( //put image line
|
1224
|
+
inT32 x, //coord to start at
|
1225
|
+
inT32 y, //line to get
|
1226
|
+
inT32 width, //no of pixels to get
|
1227
|
+
IMAGELINE *linebuf, //line to copy to
|
1228
|
+
inT32 margins //margins in buffer
|
1229
|
+
) {
|
1230
|
+
uinT8 *src; //source pointer
|
1231
|
+
uinT8 *dest; //destination pointer
|
1232
|
+
inT8 bit; //bit index
|
1233
|
+
uinT8 pixel; //collected bits
|
1234
|
+
inT8 pixperbyte; //pixels in a byte
|
1235
|
+
inT8 bytesperpix; //in source
|
1236
|
+
|
1237
|
+
this->check_legal_access (x, y, width);
|
1238
|
+
if (width > xsize - x)
|
1239
|
+
width = xsize - x; //clip to image
|
1240
|
+
if (width <= 0)
|
1241
|
+
return; //nothing to do
|
1242
|
+
//source line
|
1243
|
+
src = linebuf->pixels + margins;
|
1244
|
+
//start of line
|
1245
|
+
dest = image + xdim * (ymax - 1 - y);
|
1246
|
+
|
1247
|
+
if (linebuf->bpp == 24) {
|
1248
|
+
src++;
|
1249
|
+
bytesperpix = 3;
|
1250
|
+
}
|
1251
|
+
else
|
1252
|
+
bytesperpix = 1;
|
1253
|
+
if (bpp == 24 && linebuf->bpp == 24) {
|
1254
|
+
dest += x * bytespp;
|
1255
|
+
width *= bytespp;
|
1256
|
+
memmove (dest, src - 1, (unsigned) width);
|
1257
|
+
}
|
1258
|
+
else if (bpp == 24) {
|
1259
|
+
src--;
|
1260
|
+
dest += x * bytespp;
|
1261
|
+
while (width > 0) {
|
1262
|
+
pixel = *src++;
|
1263
|
+
*dest++ = pixel;
|
1264
|
+
*dest++ = pixel;
|
1265
|
+
*dest++ = pixel;
|
1266
|
+
width--;
|
1267
|
+
}
|
1268
|
+
}
|
1269
|
+
else if (bpp > 4) {
|
1270
|
+
dest += x; //offset
|
1271
|
+
if (linebuf->bpp == 24) {
|
1272
|
+
while (width > 0) {
|
1273
|
+
*dest++ = *src;
|
1274
|
+
src += 3;
|
1275
|
+
width--;
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
else
|
1279
|
+
//easy way
|
1280
|
+
memmove (dest, src, (unsigned) width);
|
1281
|
+
}
|
1282
|
+
else if (bpp == 4) {
|
1283
|
+
dest += x / 2; //offset on line
|
1284
|
+
if (x & 1) {
|
1285
|
+
*dest &= 0xf0; //clean odd byte
|
1286
|
+
*dest++ |= *src & 0x0f; //and copy it
|
1287
|
+
src += bytesperpix;
|
1288
|
+
width--;
|
1289
|
+
}
|
1290
|
+
while (width >= 2) {
|
1291
|
+
pixel = *src << 4; //left pixel
|
1292
|
+
src += bytesperpix;
|
1293
|
+
pixel |= *src & 0x0f; //right pixel
|
1294
|
+
src += bytesperpix;
|
1295
|
+
*dest++ = pixel;
|
1296
|
+
width -= 2;
|
1297
|
+
}
|
1298
|
+
if (width) {
|
1299
|
+
*dest &= 0x0f; //clean odd byte
|
1300
|
+
*dest |= *src << 4;
|
1301
|
+
}
|
1302
|
+
}
|
1303
|
+
else if (bpp == 2) {
|
1304
|
+
pixperbyte = 4;
|
1305
|
+
dest += x / 4; //offset on line
|
1306
|
+
bit = (inT8) (x % 4); //offset in byte
|
1307
|
+
width += bit;
|
1308
|
+
pixel = *dest >> (8 - bit - bit);
|
1309
|
+
while (width >= 4) { //until all done
|
1310
|
+
for (; bit < 4; bit++) {
|
1311
|
+
pixel <<= 2; //make space for new one
|
1312
|
+
pixel |= *src & 3;
|
1313
|
+
src += bytesperpix;
|
1314
|
+
}
|
1315
|
+
*dest++ = pixel; //new pixel
|
1316
|
+
width -= 4;
|
1317
|
+
bit = 0;
|
1318
|
+
}
|
1319
|
+
if (width > 0) { //until all done
|
1320
|
+
for (bit = 0; bit < width; bit++) {
|
1321
|
+
pixel <<= 2; //make space for new one
|
1322
|
+
pixel |= *src & 3;
|
1323
|
+
src += bytesperpix;
|
1324
|
+
}
|
1325
|
+
pixel <<= (8 - bit - bit); //shift rest
|
1326
|
+
//keep trainling bits
|
1327
|
+
pixel |= *dest & ((1 << (8 - bit - bit)) - 1);
|
1328
|
+
*dest++ = pixel; //new pixel
|
1329
|
+
}
|
1330
|
+
}
|
1331
|
+
else {
|
1332
|
+
pixperbyte = 8;
|
1333
|
+
dest += x / 8; //offset on line
|
1334
|
+
bit = (inT8) (x % 8); //offset in byte
|
1335
|
+
width += bit;
|
1336
|
+
pixel = *dest >> (8 - bit);
|
1337
|
+
while (width >= 8) { //until all done
|
1338
|
+
for (; bit < 8; bit++) {
|
1339
|
+
pixel <<= 1; //make space for new one
|
1340
|
+
pixel |= *src & 1;
|
1341
|
+
src += bytesperpix;
|
1342
|
+
}
|
1343
|
+
*dest++ = pixel; //new pixel
|
1344
|
+
width -= 8;
|
1345
|
+
bit = 0;
|
1346
|
+
}
|
1347
|
+
width -= bit;
|
1348
|
+
if (width > 0) { //until all done
|
1349
|
+
while (width > 0) {
|
1350
|
+
pixel <<= 1; //make space for new one
|
1351
|
+
pixel |= *src & 1;
|
1352
|
+
src += bytesperpix;
|
1353
|
+
bit++;
|
1354
|
+
width--;
|
1355
|
+
}
|
1356
|
+
pixel <<= (8 - bit); //shift rest
|
1357
|
+
//keep trainling bits
|
1358
|
+
pixel |= *dest & ((1 << (8 - bit)) - 1);
|
1359
|
+
*dest++ = pixel; //new pixel
|
1360
|
+
}
|
1361
|
+
}
|
1362
|
+
}
|
1363
|
+
|
1364
|
+
|
1365
|
+
/**********************************************************************
|
1366
|
+
* put_column
|
1367
|
+
*
|
1368
|
+
* Put the supplied column buffer into the image.
|
1369
|
+
* The image is converted from 8bpp by simple assignment.
|
1370
|
+
**********************************************************************/
|
1371
|
+
|
1372
|
+
void IMAGE::put_column( //put image column
|
1373
|
+
inT32 x, //coord to start at
|
1374
|
+
inT32 y, //line to get
|
1375
|
+
inT32 height, //no of pixels to get
|
1376
|
+
IMAGELINE *linebuf, //line to copy to
|
1377
|
+
inT32 margins //margins in buffer
|
1378
|
+
) {
|
1379
|
+
uinT8 *src; //source pointer
|
1380
|
+
uinT8 *dest; //destination pointer
|
1381
|
+
inT8 bit; //bit index
|
1382
|
+
uinT8 pixel; //collected bits
|
1383
|
+
inT8 bytesperpix; //in source
|
1384
|
+
|
1385
|
+
this->check_legal_access (x, y, 1);
|
1386
|
+
this->check_legal_access (x, y + height - 1, 1);
|
1387
|
+
if (height > ysize - y)
|
1388
|
+
height = ysize - y; //clip to image
|
1389
|
+
if (height <= 0)
|
1390
|
+
return; //nothing to do
|
1391
|
+
//source line
|
1392
|
+
src = linebuf->pixels + margins;
|
1393
|
+
//start of line
|
1394
|
+
dest = image + xdim * (ymax - 1 - y);
|
1395
|
+
|
1396
|
+
if (linebuf->bpp == 24) {
|
1397
|
+
src++;
|
1398
|
+
bytesperpix = 3;
|
1399
|
+
}
|
1400
|
+
else
|
1401
|
+
bytesperpix = 1;
|
1402
|
+
|
1403
|
+
if (bpp == 24 && linebuf->bpp == 24) {
|
1404
|
+
dest += x * bytesperpix;
|
1405
|
+
src--;
|
1406
|
+
for (; height > 0; --height) {
|
1407
|
+
*dest = *src++;
|
1408
|
+
*(dest + 1) = *src++;
|
1409
|
+
*(dest + 2) = *src++;
|
1410
|
+
dest -= xdim;
|
1411
|
+
}
|
1412
|
+
}
|
1413
|
+
else if (bpp == 24) {
|
1414
|
+
src--;
|
1415
|
+
dest += x * bytesperpix;
|
1416
|
+
for (; height > 0; --height) {
|
1417
|
+
pixel = *src++;
|
1418
|
+
*dest = pixel;
|
1419
|
+
*(dest + 1) = pixel;
|
1420
|
+
*(dest + 2) = pixel;
|
1421
|
+
dest -= xdim;
|
1422
|
+
}
|
1423
|
+
}
|
1424
|
+
else if (bpp > 4) {
|
1425
|
+
dest += x; //offset
|
1426
|
+
for (; height > 0; --height) {
|
1427
|
+
*dest = *src;
|
1428
|
+
src += bytesperpix;
|
1429
|
+
dest -= xdim;
|
1430
|
+
}
|
1431
|
+
}
|
1432
|
+
else if (bpp == 4) {
|
1433
|
+
dest += x / 2; //offset on line
|
1434
|
+
if (x & 1) {
|
1435
|
+
for (; height > 0; --height) {
|
1436
|
+
*dest &= 0xf0; //clean odd byte
|
1437
|
+
*dest |= *src & 0x0f; //and copy it
|
1438
|
+
src += bytesperpix;
|
1439
|
+
dest -= xdim;
|
1440
|
+
}
|
1441
|
+
}
|
1442
|
+
else {
|
1443
|
+
for (; height > 0; --height) {
|
1444
|
+
*dest &= 0x0f; //clean odd byte
|
1445
|
+
*dest |= *src << 4;
|
1446
|
+
src += bytesperpix;
|
1447
|
+
dest -= xdim;
|
1448
|
+
}
|
1449
|
+
}
|
1450
|
+
}
|
1451
|
+
else if (bpp == 2) {
|
1452
|
+
dest += x / 4; //offset on line
|
1453
|
+
bit = (inT8) (x % 4); //offset in byte
|
1454
|
+
bit = 6 - bit - bit; //bit shift
|
1455
|
+
pixel = ~(3 << bit); //mask
|
1456
|
+
for (; height > 0; --height) {
|
1457
|
+
//change 2 bits
|
1458
|
+
*dest = (*dest & pixel) | ((*src & 3) << bit);
|
1459
|
+
src += bytesperpix;
|
1460
|
+
dest -= xdim;
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
else {
|
1464
|
+
dest += x / 8; //offset on line
|
1465
|
+
bit = (inT8) (x % 8); //offset in byte
|
1466
|
+
bit = 7 - bit;
|
1467
|
+
pixel = ~(1 << bit);
|
1468
|
+
for (; height > 0; --height) {
|
1469
|
+
//change 1 bit
|
1470
|
+
*dest = (*dest & pixel) | ((*src & 1) << bit);
|
1471
|
+
src += bytesperpix;
|
1472
|
+
dest -= xdim;
|
1473
|
+
}
|
1474
|
+
}
|
1475
|
+
}
|
1476
|
+
|
1477
|
+
|
1478
|
+
/**********************************************************************
|
1479
|
+
* check_legal_access
|
1480
|
+
*
|
1481
|
+
* Check that x,y are within the bounds of the image.
|
1482
|
+
* Call bufread if necessary to get the image into memory.
|
1483
|
+
**********************************************************************/
|
1484
|
+
|
1485
|
+
void IMAGE::check_legal_access( //check coords are legal
|
1486
|
+
inT32 x, //coords to check
|
1487
|
+
inT32 y,
|
1488
|
+
inT32 xext //xextent
|
1489
|
+
) {
|
1490
|
+
if (x < 0 || x >= xsize || y < 0 || y >= ysize || x + xext > xsize)
|
1491
|
+
BADIMAGECOORDS.error ("IMAGE::check_legal_access",
|
1492
|
+
ABORT, "(%d+%d,%d)", x, xext, y);
|
1493
|
+
if (y >= ymax)
|
1494
|
+
BADIMAGESEEK.error ("IMAGE::check_legal_access", ABORT, "(%d,%d)", x, y);
|
1495
|
+
if (y < ymin)
|
1496
|
+
bufread(y); //read some more
|
1497
|
+
}
|
1498
|
+
|
1499
|
+
#ifdef HAVE_LIBLEPT
|
1500
|
+
// ONLY available if you have Leptonica installed.
|
1501
|
+
/**********************************************************************
|
1502
|
+
* ToPix
|
1503
|
+
*
|
1504
|
+
* Make a Pix from this image.
|
1505
|
+
**********************************************************************/
|
1506
|
+
Pix* IMAGE::ToPix() {
|
1507
|
+
int width = this->get_xsize();
|
1508
|
+
int height = this->get_ysize();
|
1509
|
+
int bpp = this->get_bpp();
|
1510
|
+
Pix* pix = pixCreate(width, height, bpp == 24 ? 32 : bpp);
|
1511
|
+
uint32* data = pixGetData(pix);
|
1512
|
+
IMAGELINE line;
|
1513
|
+
if (bpp == 24) {
|
1514
|
+
line.init(width * 3);
|
1515
|
+
line.set_bpp(24);
|
1516
|
+
} else {
|
1517
|
+
line.init(width);
|
1518
|
+
}
|
1519
|
+
switch (bpp) {
|
1520
|
+
case 1:
|
1521
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1522
|
+
this->get_line(0, y, width, &line, 0);
|
1523
|
+
for (int x = 0; x < width; ++x) {
|
1524
|
+
if (line.pixels[x])
|
1525
|
+
CLEAR_DATA_BIT(data, x);
|
1526
|
+
else
|
1527
|
+
SET_DATA_BIT(data, x);
|
1528
|
+
}
|
1529
|
+
data += pixGetWpl(pix);
|
1530
|
+
}
|
1531
|
+
break;
|
1532
|
+
|
1533
|
+
case 8:
|
1534
|
+
// Greyscale just copies the bytes in the right order.
|
1535
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1536
|
+
this->get_line(0, y, width, &line, 0);
|
1537
|
+
for (int x = 0; x < width; ++x)
|
1538
|
+
SET_DATA_BYTE(data, x, line.pixels[x]);
|
1539
|
+
data += pixGetWpl(pix);
|
1540
|
+
}
|
1541
|
+
break;
|
1542
|
+
|
1543
|
+
case 24:
|
1544
|
+
// Put the colors in the correct places in the line buffer.
|
1545
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1546
|
+
this->get_line(0, y, width, &line, 0);
|
1547
|
+
for (int x = 0; x < width; ++x, ++data) {
|
1548
|
+
SET_DATA_BYTE(data, COLOR_RED, line[x][RED_PIX]);
|
1549
|
+
SET_DATA_BYTE(data, COLOR_GREEN, line[x][GREEN_PIX]);
|
1550
|
+
SET_DATA_BYTE(data, COLOR_BLUE, line[x][BLUE_PIX]);
|
1551
|
+
}
|
1552
|
+
}
|
1553
|
+
break;
|
1554
|
+
|
1555
|
+
default:
|
1556
|
+
tprintf("Cannot convert image to Pix with bpp = %d\n", bpp);
|
1557
|
+
}
|
1558
|
+
return pix;
|
1559
|
+
}
|
1560
|
+
|
1561
|
+
/**********************************************************************
|
1562
|
+
* FromPix
|
1563
|
+
*
|
1564
|
+
* Copy from the given Pix into this image.
|
1565
|
+
**********************************************************************/
|
1566
|
+
void IMAGE::FromPix(const Pix* src_pix) {
|
1567
|
+
// Leptonica doesn't const its inputs, but we don't change the input.
|
1568
|
+
Pix* pix = const_cast<Pix*>(src_pix);
|
1569
|
+
Pix* destroy_this_pix = NULL;
|
1570
|
+
|
1571
|
+
int depth = pixGetDepth(pix);
|
1572
|
+
if (depth > 1 && depth < 8) {
|
1573
|
+
// Convert funny depths to 8 bit.
|
1574
|
+
destroy_this_pix = pixConvertTo8(pix, false);
|
1575
|
+
pix = destroy_this_pix;
|
1576
|
+
depth = pixGetDepth(pix);
|
1577
|
+
}
|
1578
|
+
int width = pixGetWidth(pix);
|
1579
|
+
int height = pixGetHeight(pix);
|
1580
|
+
const uint32* data = pixGetData(pix);
|
1581
|
+
this->create(width, height, depth == 32 ? 24 : depth);
|
1582
|
+
// For each line in the image, fill the IMAGELINE class and put it into the
|
1583
|
+
// destination image. Note that Tesseract stores images with the
|
1584
|
+
// bottom at y=0 and 0 is always black in grey and binary.
|
1585
|
+
IMAGELINE line;
|
1586
|
+
if (depth == 32) {
|
1587
|
+
line.init(width * 3);
|
1588
|
+
line.set_bpp(24);
|
1589
|
+
} else {
|
1590
|
+
line.init(width);
|
1591
|
+
}
|
1592
|
+
switch (depth) {
|
1593
|
+
case 1:
|
1594
|
+
// Binary images just flip the data bit.
|
1595
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1596
|
+
for (int x = 0; x < width; ++x)
|
1597
|
+
line.pixels[x] = GET_DATA_BIT(data, x) ^ 1;
|
1598
|
+
this->put_line(0, y, width, &line, 0);
|
1599
|
+
data += pixGetWpl(pix);
|
1600
|
+
}
|
1601
|
+
break;
|
1602
|
+
|
1603
|
+
case 8:
|
1604
|
+
// Greyscale just copies the bytes in the right order.
|
1605
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1606
|
+
for (int x = 0; x < width; ++x)
|
1607
|
+
line.pixels[x] = GET_DATA_BYTE(data, x);
|
1608
|
+
this->put_line(0, y, width, &line, 0);
|
1609
|
+
data += pixGetWpl(pix);
|
1610
|
+
}
|
1611
|
+
break;
|
1612
|
+
|
1613
|
+
case 32:
|
1614
|
+
// Put the colors in the correct places in the line buffer.
|
1615
|
+
for (int y = height - 1 ; y >= 0; --y) {
|
1616
|
+
for (int x = 0; x < width; ++x, ++data) {
|
1617
|
+
line[x][RED_PIX] = GET_DATA_BYTE(data, COLOR_RED);
|
1618
|
+
line[x][GREEN_PIX] = GET_DATA_BYTE(data, COLOR_GREEN);
|
1619
|
+
line[x][BLUE_PIX] = GET_DATA_BYTE(data, COLOR_BLUE);
|
1620
|
+
}
|
1621
|
+
this->put_line(0, y, width, &line, 0);
|
1622
|
+
}
|
1623
|
+
break;
|
1624
|
+
|
1625
|
+
default:
|
1626
|
+
tprintf("Cannot convert Pix to image with bpp = %d\n", depth);
|
1627
|
+
}
|
1628
|
+
if (destroy_this_pix != NULL)
|
1629
|
+
pixDestroy(&destroy_this_pix);
|
1630
|
+
}
|
1631
|
+
#endif // HAVE_LIBLEPT
|
1632
|
+
|
1633
|
+
/*************************************************************************
|
1634
|
+
* convolver()
|
1635
|
+
*
|
1636
|
+
* Calls the specified function for each pixel in the image, passing in an m x n
|
1637
|
+
* window of the image, centred on the pixel. The convolution function returns
|
1638
|
+
* a new value for the pixel, based on the window.
|
1639
|
+
*
|
1640
|
+
* At the edges of the image, the window is padded to white pixels.
|
1641
|
+
*************************************************************************/
|
1642
|
+
|
1643
|
+
void
|
1644
|
+
IMAGE::convolver ( //Map fn over window
|
1645
|
+
inT32 win_width, //Window width
|
1646
|
+
inT32 win_height, //Window height
|
1647
|
+
void (*convolve) ( //Conv Function
|
1648
|
+
uinT8 ** pixels, //Of window
|
1649
|
+
uinT8 bytespp, //1 or 3 for colour
|
1650
|
+
inT32 win_wd, //Window width
|
1651
|
+
inT32 win_ht, //Window height
|
1652
|
+
uinT8 ret_white_value, //White value to RETURN
|
1653
|
+
uinT8 * result) //Ptr to result pix
|
1654
|
+
) {
|
1655
|
+
IMAGELINE new_row; //Replacement pixels
|
1656
|
+
IMAGELINE *old_rows; //Rows being processed
|
1657
|
+
inT32 oldest_imline; //Next imline to replace
|
1658
|
+
uinT8 **window; //ptrs to pixel rows
|
1659
|
+
uinT8 **winmax; //ptrs to pixel rows
|
1660
|
+
uinT8 **win; //ptrs to pixel rows
|
1661
|
+
inT32 current_row; //Row being calculated
|
1662
|
+
inT32 current_col; //Col being calculated
|
1663
|
+
inT32 row = 0; //Next row to get
|
1664
|
+
|
1665
|
+
inT32 i, j;
|
1666
|
+
uinT8 *pix;
|
1667
|
+
uinT8 *max;
|
1668
|
+
inT32 xmargin = win_width / 2;
|
1669
|
+
inT32 ymargin = win_height / 2;
|
1670
|
+
uinT8 white = get_white_level ();
|
1671
|
+
const uinT8 max_white = 255;
|
1672
|
+
float white_scale = (float) 255 / get_white_level ();
|
1673
|
+
|
1674
|
+
if (((win_width % 2) == 0) ||
|
1675
|
+
((win_height % 2) == 0) ||
|
1676
|
+
(win_height < 3) ||
|
1677
|
+
(win_width < 3) || (win_height > ysize / 2) || (win_width > xsize / 2))
|
1678
|
+
BADWINDOW.error ("IMAGE::convolver",
|
1679
|
+
ABORT, "(%d x %d)", win_width, win_height);
|
1680
|
+
|
1681
|
+
new_row.init (xsize * bytespp);
|
1682
|
+
new_row.set_bpp (bpp);
|
1683
|
+
old_rows = new IMAGELINE[win_height];
|
1684
|
+
for (i = 0; i < win_height; i++) {
|
1685
|
+
old_rows[i].init ((xsize + 2 * xmargin) * bytespp);
|
1686
|
+
old_rows[i].set_bpp (bpp);
|
1687
|
+
}
|
1688
|
+
|
1689
|
+
window = (uinT8 **) alloc_mem (win_height * sizeof (uinT8 *));
|
1690
|
+
winmax = window + win_height;
|
1691
|
+
|
1692
|
+
/* Make bottom border */
|
1693
|
+
for (oldest_imline = 0; oldest_imline < ymargin; oldest_imline++) {
|
1694
|
+
pix = old_rows[oldest_imline].pixels;
|
1695
|
+
max = pix + (xsize + 2 * xmargin) * bytespp;
|
1696
|
+
while (pix < max)
|
1697
|
+
*pix++ = max_white;
|
1698
|
+
}
|
1699
|
+
/* Initialise remaining rows but one*/
|
1700
|
+
for (; oldest_imline < win_height - 1; oldest_imline++) {
|
1701
|
+
get_line (0, row++, xsize, &old_rows[oldest_imline], xmargin);
|
1702
|
+
if (max_white != white) {
|
1703
|
+
pix = old_rows[oldest_imline].pixels;
|
1704
|
+
max = pix + (xsize + 2 * xmargin) * bytespp;
|
1705
|
+
while (pix < max) {
|
1706
|
+
*pix = (uinT8) (*pix * white_scale);
|
1707
|
+
++pix;
|
1708
|
+
}
|
1709
|
+
}
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
/* Image Processing */
|
1713
|
+
|
1714
|
+
for (current_row = 0; current_row < ysize;) {
|
1715
|
+
/* Get next row and re-initialise window array */
|
1716
|
+
if (row < ysize) {
|
1717
|
+
get_line (0, row++, xsize, &old_rows[oldest_imline], xmargin);
|
1718
|
+
if (max_white != white) {
|
1719
|
+
pix = old_rows[oldest_imline].pixels;
|
1720
|
+
max = pix + (xsize + 2 * xmargin) * bytespp;
|
1721
|
+
while (pix < max) {
|
1722
|
+
*pix = (uinT8) (*pix * white_scale);
|
1723
|
+
++pix;
|
1724
|
+
}
|
1725
|
+
}
|
1726
|
+
}
|
1727
|
+
else {
|
1728
|
+
pix = old_rows[oldest_imline].pixels;
|
1729
|
+
max = pix + (xsize + 2 * xmargin) * bytespp;
|
1730
|
+
while (pix < max)
|
1731
|
+
*pix++ = max_white;
|
1732
|
+
}
|
1733
|
+
oldest_imline++;
|
1734
|
+
if (oldest_imline >= win_height)
|
1735
|
+
oldest_imline = 0;
|
1736
|
+
|
1737
|
+
/* Process line */
|
1738
|
+
pix = new_row.pixels;
|
1739
|
+
for (current_col = 0; current_col < xsize;) {
|
1740
|
+
/* Set up window ptrs */
|
1741
|
+
if (current_col == 0) {
|
1742
|
+
j = oldest_imline;
|
1743
|
+
for (i = 0; i < win_height; i++) {
|
1744
|
+
window[i] = old_rows[j++].pixels;
|
1745
|
+
if (j >= win_height)
|
1746
|
+
j = 0;
|
1747
|
+
}
|
1748
|
+
}
|
1749
|
+
else {
|
1750
|
+
for (win = window; win < winmax; (*win++) += bytespp);
|
1751
|
+
//Move along rows
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
convolve(window, bytespp, win_width, win_height, white, pix);
|
1755
|
+
pix += bytespp;
|
1756
|
+
current_col++;
|
1757
|
+
}
|
1758
|
+
|
1759
|
+
put_line (0, current_row, xsize, &new_row, 0);
|
1760
|
+
new_row.init ();
|
1761
|
+
new_row.set_bpp (bpp);
|
1762
|
+
current_row++;
|
1763
|
+
}
|
1764
|
+
}
|