1
0
mirror of https://github.com/DanBloomberg/leptonica.git synced 2026-10-23 15:28:56 +03:00

187 Commits

Author SHA1 Message Date
danblooomberg
e75c16b3f1 Small cleanups
* Change documentation of cleanpdf.c and rotateorthpdf.c
  * Fix alphabetization of source file listings in Makefile.am (webp, webpanim)
2026-09-01 10:59:16 -06:00
Stefan Weil
af9f993e9b Require tiff version number in findFileFormatBuffer()
findFileFormatBuffer() classified any buffer starting with the
two-byte tiff byte-order markers "II" or "MM" as a tiff file,
without checking the version number (42) that follows them.
This caused text files - e.g. tesseract file lists whose first
filename starts with "MM" or "II" - to be misdetected as tiff
files (tesseract-ocr/tesseract#4619).

Require the version number 42 in the correct byte order for
"II" (42, 0) and "MM" (0, 42) before reporting IFF_TIFF.
All callers of findFileFormatBuffer() provide buffers of at
least 12 bytes, so this check is safe.

Add regression tests to ioformats_reg.c and update
version-notes.html.

Assisted-by: OpenCode / qwen3.8-27b-thinking (Alibaba Cloud)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2026-08-29 10:28:14 +02:00
danblooomberg
86e7c416f3 Use adaptive thresholding before skew detection
* This uses a new function pixFindSkewAdaptAndDeskew() in pixCleanImage().
* Using a fixed threshold (typ. 160) will not properly binaries for
  skew detection if the background is dark.
* This makes in prog/cleanpdf robust to dark background.
2026-06-05 15:52:39 -07:00
danblooomberg
19e4d64c62 Added casts & fixed typo in dpixReadStream(), from PR #793
* 3 other merges from 7 years ago ignored
2026-06-03 11:10:44 -07:00
danblooomberg
d14a5d538d Add checks on sizes for reading FPix and DPix from file.
* Also add more FPix and DPix tests to fpix2_reg.
2026-05-18 22:02:51 -07:00
danblooomberg
948d9aab1e Fix rotateorthpdf to preserve image quality, using pdfimages.
* New image from pdf rendering functions using pdfimages.
* Clarify interaction between imres and scalefactor in compresspdf.
2026-05-10 15:25:07 -07:00
danblooomberg
bb244a3176 New program for selective orthogonal rotation of images in a pdf.
* Give 3 modes for specifying rotations
* Allow scaling of the images
2026-04-18 16:52:20 -07:00
danblooomberg
bab20e1368 Investigate issue #785, a crash when tesseract apparenty calls bmfCreate()
* Only happens on aarch64 hardward with latest compilers
* Tesseract is building the fonts from a memory string representing the imges.
* No failures observed in leptonica
* Cleaned up a test program for the bmf font generation.
* The issue is not yet resolved.
2026-01-30 16:43:52 -08:00
danblooomberg
6b06357741 Fixed several heap buffer overflows when converting sarrays to strings
* The vulnerability types were CWE-190 (integer overflow)
   and CWE-122 (heap overflow).
* Lei Dongzheng found the problems, identified the origin and provided
  proof-of-concept programs that demonstrated them.
2026-01-29 11:54:51 -08:00
danblooomberg
13275a278e Change README and version-notes for release 1.87.0 2025-12-24 15:07:35 -08:00
danblooomberg
2d889876a6 Update version numbers to prepare for release 1.87.0 2025-10-23 16:42:37 -07:00
danblooomberg
3b4d7f7909 Update README.html and version-notes.html for release 1.86.0 2025-09-18 12:56:27 -06:00
danblooomberg
737f969e7c Fix indexing error in pixFillMapHoles()
* This caused an innocuous error message attempting to access invalid index
* Clean up notes in pixFillMapHoles() and in pixGetBackgroundGrayMap()
* Improve documentation in prog/croppdf.c and prog/compresspdf.c
2025-03-02 16:14:11 -08:00
danblooomberg
64a2ad31b9 In pixFindBaselines(), remove baseline if no textbox is found for it
* This is in relation to Issue #766.
* If no textbox is found, we do not know the end points of the baseline.
  It is almost certainly very short, so it is removed from output.
* Change order of operation: for each baseline, save all textboxes that
  describe text at that y-location.  There can be multiple textboxes
  for each baseline if the line of text has large horizontal breaks.
* As a result of this change, all reported baselines have x-value
  endpoints of text that can optionally be returned.
2025-01-14 16:17:07 -08:00
danblooomberg
f9ef244e69 Better filter for bogus textboxes in pixFindBaselines()
* Remove bogus textblocks that are really just part of a real textblock
  but have very small height and are above or below the actual textblock.
* Continue to allow more than one textbox for each baseline.
  This is because large gaps between textblocks in a line make it
  difficult to join safely.
* Could also add a minimal vertical closing (c1.2) to filter in order to
  join bogus textboxes; not done yet because it may not be necessary.
2025-01-14 12:32:20 -08:00
danblooomberg
9a22f967d5 Crop to foreground when cropping from a page with a black border
* All pageseg cropping options in pixCropImage() should crop to foreground.
2024-11-24 22:07:04 -08:00
danblooomberg
833afd1700 Fix compressFilesToPdf() to allow upscale interpolation for low res pdfs
* It is useful to have the option of doing a 2x linear interpolation
  upscaleing before thresholding, to improve readability.
2024-11-02 20:40:43 -07:00
danblooomberg
eb54f8b315 Updated version numbers (etc) for Release 1.85.0 2024-10-16 11:45:50 -07:00
danblooomberg
c35a72ed7e Added option to pixCropImage() to extract a page embedded in black image
* When there is an oversized media box, the pdftoppm renderer can get
  confused about the image size and generate a larger image that
  is embedded in a black background.
* Added a test to misctest2.c for this functionality.
2024-10-07 22:51:50 -07:00
danblooomberg
a60bd16e2c Clean up prog/jbrankhaus.c and prog/jbcorrelation.c 2024-09-23 15:05:28 -06:00
danblooomberg
1a4ba7eebe Return error instead of first image plus warning if given animated gif input
* this follows Amit's suggestion
* also added a blending test to blend4_reg
2024-08-26 16:23:32 -06:00
danblooomberg
0cadcdfd46 Addressed new coverity-scan results 2024-07-12 23:55:05 -06:00
danblooomberg
913550c707 Add renderpdf.c to library
* This implements a function used in several programs, that takes a
  set of input pdf files that are assumed to be page images,
  and renders every page in a temp directory at a requested resolution.
* Modified prog/cleanpdf to use this function; checked with previous
  implementation; used valgrind.
* The new implementation is better because it writes the output files
  in a temp directory that is cleaned out with each invocation of
  the function.  In the previous implementation, it was necessary to
  remove previously rendered files by hand.
* The new implementation allows output images to be rendered at
  resolutions between 50 and 300 ppi, independent of the actual
  resolution of the input images wrapped in the pdf files.  This is
  done by assuming the input pages are 612 x 792 printer points.
* pdf files generated by applications like cleanpdf, that use this
  function, will print normally on 8.5 x 11 inch paper.
2024-07-08 12:44:47 -06:00
danblooomberg
fb88cabc42 Add 'printwiden' arg to pixCropImage(), cropFilesToPdf() and prog/croppdf
* This allows filling to the full width of 8.5 x 11 or A4 paper when
  the h/w ratio is too large to do this without extra horizontal stretching.
* This is not needed for displaying the pdf, because the viewers display
  the image as it is, without consideration of printing.
2024-07-03 17:56:08 -06:00
danblooomberg
1e7c3a9e68 Add pixCropImage() option to aggressively remove side noise
* This is from the left and right sides, and is invoked in prog/croppdf
  by using a negative input paramater for edgeclean.
* New prog/misctest2.c to have page cropping and cleaning examples,
  with two sample music notation images.  Existing cropping and cleaning
  examples have been removed from prog/misctest1.c.
2024-05-24 00:12:04 -07:00
Amit D
a7da35cab4 version-notes.html: Fix a typo 2024-05-15 09:12:52 +03:00
danblooomberg
ca6260676f New findpattern2_reg.c demonstrates generation of sels and their use.
* also rename findpattern_reg.c ==> findpattern1_reg.c
2024-03-26 23:02:07 -07:00
danblooomberg
2d73d85f75 Fixed various coverity scan issues 2024-03-05 14:30:12 -08:00
danblooomberg
5e4f9a6dba Resolve Issue #734: invalid colormap made in jbcorrelation and jbrankhaus.
* Clarified comments in pixcmapIsValid()
* Bad colormap indices were generated in jbDataRender() by doing bit-or
  between colormap indices.
* Also clean up libversions.c
2024-02-17 17:30:46 -08:00
danblooomberg
e09c1f283a Remove lept_fopen() and lept_fclose() functions from use in library.
* They should only be used in programs; use fopenReadStream(),
  fopenWriteStream() and fclose() instead.
* Do the opposite in prog: replace calls to fopenReadStream() and
  fopenWriteStream() by lept_fopen(); replace calls to fclose()
  by lept_fclose().
* Also add documentation clarifying when to use the functions lept_open,
    lept_close, lept_calloc and lept_free.
2024-02-08 22:03:32 -08:00
danblooomberg
ac2d07127c Small documentation clean up of the opj stream jp2k I/O implementation
* In the improved implemtation, compression to and from memory is enabled
  by callbacks in the openjpeg library, and file stream operations
  are wrappers around the memory stream functions.
2024-02-05 18:47:51 -08:00
danblooomberg
ad5206391c Fix Issue 730: artifacts and bad compression with pixWriteJp2k()
* Anton Tykhyy reported problems with jp2k compression.
* Comparing convert with quality=42 in ImageMagick 7.1.1, one gets a smaller
  and more accurate color image from a "featureless" input 1.6Mpixel
  image than with leptonica's pixWriteJp2k() interface.
* In addition, leptonica was not robust to input of small images with
  a requested large number of resolution levels.
* Following the lead of the ImageMagick encoder, the requested number of
  levels of resolution, nlevels, is now limited to 6 or 7.
* For images with a min dimension smaller than 31, nlevels is reduced to 5
  or less; for those between 32 and 63, nlevels is reduced to 6 if necessary.
* The number of channels (1 for gray or 3 for rgb) is now set as an input
  parameter, to avoid false colors.
* Also changed version to non-release 1.84.2.
2024-02-03 20:44:10 -08:00
danblooomberg
0d44776536 Use system wrapper callSystemDebug() in programs
* also have callSystemDebug() return an int (success or failure)
2024-01-23 16:00:39 -08:00
danblooomberg
96061155d2 Use 4-arg error messages for a few I/O functions
* This returns the name of the file that failed to open
2024-01-23 14:39:33 -08:00
danblooomberg
699b2a10bd Fix two bugs, found in Issue #726
* use after free in gplot.c in code only invoked if error has occurred)
* extra ';' in partify.c
2024-01-05 10:34:06 -08:00
danblooomberg
7e803e7351 Remove support for openjpeg 2.0.
* This cleans up the jp2kio.c code and fixes a new bug with 2.5.0,
  where for reasons not yet understood the fragile code set up for 2.0
  causes 2.5.0 to select the 2.0 path.
* Improve error handling for stringLength() and stringCat(), and
  add tests to prog/string_reg.
* Fix warnings of uninitialized or unused variables.
* Prepare for release of 1.84.1
2024-01-02 16:03:10 -08:00
danblooomberg
9a08040789 Prepare for release of 1.84 2023-12-24 00:24:30 -08:00
danblooomberg
1fc4fc8dbe Add function pixCropImage() for cropping images
* Also add function cropFilesToPdf() and prog/croppdf
* Add static function  pixAdaptTo1bppAndDarken()
* Also remove 'thresh' parameter from cleanTo1bppFilesToPdf() and
  from prog/cleanpdf.  We're using adaptive thresholding so varying
  this parameter from 180 within its allowed range has little effect.
* Add tel3.tif for testing of cropping in prog/misctest1
2023-08-28 13:24:27 -07:00
danblooomberg
6c15bd5863 New pdfapp.c and pdfappstub.c.
* These have functions compressFilesToPdf() and cleanTo1bppFilesToPdf(),
  which hold the image processing functionality that was previously in
  prog/cleanpdf and prog/compresspdf.  These no longer write intermediate
  image files; they store everything in either a pixa (n <= 100 images)
  or a pixac (n > 100 images).
* Input to these functions is an SArray of image file paths.
* The programs pull images out of a set of input pdfs, and put them
  uncompressed in a set of files.  The new functions do some image
  processing and wrap the results up in a single output pdf.
* Also, rename concatpdf --> compresspdf, because all these functions,
  and others to be written, will do concatenation of input pdf files.
* Also, minor documentation fix in gplot.c.
2023-08-12 19:32:23 -07:00
danblooomberg
a7b5bc2e69 Use getPdfRendererResolution() in concatpdf.c
* As with cleanpdf.c, this prevents the pdftoppm renderer from
  making very large ppm files.
* Also improve comments in environ.h.
2023-05-26 23:38:56 -07:00
danblooomberg
8339bbaa49 New getPdfMediaBoxSizes().
* Most pdf files have an unencrypted MediaBox variable, which is used
  by image renderers for scaling the raster output.  Some pdf files
  have this set incorrectly.  If it is too big (e.g., by confusing
  printer points with pixels, thus assuming the resolution is 72 ppi),
  the renderer will make very large images.  This can be prevented
  by finding the median mediabox sizes and modifying the resolution
  in the renderer accordingly.
* Modify prog/cleanpdf.c to avoid making large intermediate ppm files.
2023-05-25 18:24:16 -07:00
danblooomberg
1b1d7ade6d Modify concatpdf.c to handle very large inputs and do better compression
* For many image files (> 100), store them compressed with pixacomp.
* By default, all images will be encoded as rgb using jpeg's DCT.
* For efficient encoding of monochrome images, call with the one_bit
  input parameter set to 1.  This will encode all images with tiffg4.
* For mixed encoding, where images with color are encoded with DCT
  and those without color are encoded with tiffg4, set both one_bit
  and save_color input parameters to 1.
* For determining color content, we are only using the colorfract
  output from pixColorFract(), so make both outputs optional.
2023-04-18 18:44:02 -07:00
danblooomberg
6c68e008a1 New pixDisplayDiff() function to display difference between images; issue #682
* The display function is tested in misctest1.c
* It is used in ioformats_reg.c to investigate a bug found by Ger Hobbelt.
  This is a problem with png writing 24 bpp: the rightmost column of pixels
  is wrong.  (bmp writing and reading 24 bpp rgb files is correct.)
  The problem was uncovered when Hobbelt investigated issue #675, which
  claimed that components were switched when reading RGBA bmp files, but
  this was determined not to be reproducible on linux or Windows.
* Also in ioformats_reg.c, test the 32->24 bit and 24->32 bit conversions.
2023-04-02 12:31:40 -07:00
danblooomberg
71023ae0bd New regression test for white-space rectangle allocation (partition_reg.c)
* Also improved output for prog/partitiontest.
2023-02-09 00:02:20 -08:00
danblooomberg
0215271f25 Support read/write of 4 sample/pixel rgba images in bmp format
* Vlad Astakhov submitted a fix to allow reading rgba (ignoring the alpha).
  Windows screengrabs apparently produce these.
* Save the alpha component when reading rgba in bmp format.
* For spp == 4 pix, save the alpha component when writing bmp.
* Added a test section in ioformats_reg for miscellaneous tests.
  In there, test write/read of rgba, including alpha, for both png and bmp.
2023-02-04 20:56:13 -08:00
danblooomberg
d44c591d63 Implement function for determining number of pages in a pdf.
* Use this in a new program: prog/splitpdf.  This requires the
  use of mutool for splitting out a set of pages from a pdf.
* Also fix numaGetUniformBinSizes() to handle situation where the
  input number of bins is larger than the count of the numa.
2023-01-07 22:34:38 -08:00
danblooomberg
97b82b09ea Final changes for release 1.83.0 2022-12-20 13:54:49 -08:00
danblooomberg
c1ee126afa Coverity scan found we didn't check return for inflateInit() in zlib 2022-11-21 17:47:09 -08:00
danblooomberg
ef49111e03 Change input args to cleanpdf
* allow for more flexibility when cleaning light images; now there are
  4 levels that can be used for the 'darken' parameter.
* change the order of the parameters, to put the output filename last
* require all 7 arguments to be given
* require valid values for the 'darken' and 'rotation' parameters; don't
  use defaults if invalid values are given.
2022-05-18 23:13:12 -07:00
danblooomberg
a14036fa5f Remove 'static char mainName' and replace mainName by __func__ in all prog. 2022-05-08 16:10:16 -07:00