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>
* 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.
* 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.
* 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.
* 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
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* Clarified comments in pixcmapIsValid()
* Bad colormap indices were generated in jbDataRender() by doing bit-or
between colormap indices.
* Also clean up libversions.c
* 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.
* 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.
* 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.
* 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
* 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
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.