Comments (6)
pixReadWithHint() ignores the second arg if the input image format is not jpeg. So there's no issue there.
I wrote the following test code, run on linux, and there are no issues with component order. Try it, and let me know the results on Windows.
pix1 = pixRead("source.bmp");
// pix1 = pixReadWithHint("source.bmp", IFF_BMP); // ignores 2nd arg
pixWrite("/tmp/junk1.bmp", pix1, IFF_BMP);
pixWrite("/tmp/junk1.png", pix1, IFF_PNG);
pix2 = pixRead("/tmp/junk1.bmp");
pix3 = pixRead("/tmp/junk1.png");
pixEqual(pix2, pix1, &same);
lept_stderr("same: %d\n", same);
pixEqual(pix3, pix1, &same);
lept_stderr("same: %d\n", same);
pixDisplay(pix2, 300, 100);
pixDisplay(pix3, 500, 100);
pixWrite("/tmp/junk2.bmp", pix2, IFF_BMP);
writeImageFileInfo("/tmp/junk1.bmp", stderr, 0);
writeImageFileInfo("/tmp/junk2.bmp", stderr, 0);
from leptonica.
pixReadWithHint() ignores the second arg if the input image format is not jpeg. So there's no issue there.
I wrote the following test code, run on linux, and there are no issues with component order. Try it, and let me know the results on Windows.
pix1 = pixRead("source.bmp"); // pix1 = pixReadWithHint("source.bmp", IFF_BMP); // ignores 2nd arg pixWrite("/tmp/junk1.bmp", pix1, IFF_BMP); pixWrite("/tmp/junk1.png", pix1, IFF_PNG); pix2 = pixRead("/tmp/junk1.bmp"); pix3 = pixRead("/tmp/junk1.png"); pixEqual(pix2, pix1, &same); lept_stderr("same: %d\n", same); pixEqual(pix3, pix1, &same); lept_stderr("same: %d\n", same); pixDisplay(pix2, 300, 100); pixDisplay(pix3, 500, 100); pixWrite("/tmp/junk2.bmp", pix2, IFF_BMP); writeImageFileInfo("/tmp/junk1.bmp", stderr, 0); writeImageFileInfo("/tmp/junk2.bmp", stderr, 0);
auto pix = pixRead("source.bmp");
auto ret = pixWrite("target.bmp", pix, IFF_BMP);
The same as previous, not working!
from leptonica.
Please send all output from that test code, both to stderr and files written.
from leptonica.
Interestingly, when inspecting both BMP files with a hex inspection tool, it turns out source.bmp
(here called test-rgba.bmp
) and target.bmp
differ quite a bit:
- source.bmp has a 32 bits (BGRA) per pixel setting in its (Windows format) BMP header,
- target.bmp has a 24 bits (BGR) per pixel setting in its (Windows format) BMP header.
See also this hex comparison (using Beyond Compare in Hex Compare mode):
note the 20 00
vs. 18 00
little endian 32 vs. 24 bpp values at offset 0x1C (bits per pixel)
Another interesting thing to note is that the source BGRA values are rotated to RGB in the target. That's not possibly an endian swap mistake or suchlike, as then the alpha channel of the source (first value: 31
) should have ended up front instead, instead of the observed 33
value (target, offset 0x36)
Ran the C++ code
auto pix = pixRead("source.bmp");
auto ret = pixWrite("target.bmp", pix, IFF_BMP);
on Win10/64 with latest leptonica (+ irrelevant patches) and was not able to produce target.bmp
from source.bmp
.
Other interesting things to note:
-
leptonica
pixRead
+pixWrite
keep the 32bits per pixel setting intact, so getting an actual 24 bits per pixeltarget.bmp
from a 32 bppsource.bmp
is done 🤔 somewhere else? -
also note that the original
source.bmp
has a 0(zero)-almost-everywhere A alpha channel which had me thwarted for a while as my image viewers (ImageGlass, ACDSee) showed the source BMP as all-grey (while their preview wasn't) which had me wonder for a bit ifsource.bmp
was triggering bugs in those viewers. (Verdict for ImageGlass: apparently the preview bar doesn't do transparency, intentionally or otherwise. Off topic.)
When you look at the A alpha channel insource.bmp
, you'll see it's 0x00 (fully transparant) everywhere, except the first pixel, which has alpha = 0x31.target.bmp
has dropped this alpha channel completely. -
in an attempt to see if I could reproduce
target.bmp
(goal: use only one or two leptonica calls, max, to change pix), I added code to create a 24bpp PIX from the 32bpp source:pix[5] = pixReadWithHint(DEMOPATH("source.bmp"), IFF_BMP); ret |= pixWrite("/tmp/lept/bmp-test/target-rgba1.bmp", pix[5], IFF_BMP); d = pixGetDepth(pix[5]); assert(d == 32); spp = pixGetSpp(pix[5]); assert(spp == 4); pix[11] = pixConvert32To24(pix[5]); // <<--- attempt to create 24bpp BMP/header d = pixGetDepth(pix[11]); assert(d == 24); spp = pixGetSpp(pix[11]); assert(spp == 3); ret |= pixWrite("/tmp/lept/bmp-test/target-rgba24.bmp", pix[11], IFF_BMP); ret |= pixWrite("/tmp/lept/bmp-test/target-rgba24.png", pix[11], IFF_PNG);
This uncovered something else (to be filed as issue), but after fixing that, did not produce the provided
target.bmp
: in fact, the size and header were now identical to the providedtarget.bmp
, but leptonica correctly output BGR.BGR.BGR pixel byte sequences, instead oftarget.bmp
s RGB.RGB.RGB.Haven't been able to produce an exact byte-for-byte match of
target.bmp
;, though the abovepixConvert32To24()
plus a R-vs-B color channel plane exchange SHOULD produce the giventarget.bmp
. My goal was to see if some simple one/two-line code/calls would produce this issue.
@sinall: So are you running an old version of leptonica -- I haven't run a git blame
analysis to see if there ever was a bug in BMP I/O code that could trigger this -- or a patched/augmented system?
Code used to test: (test-rgba.bmp
in there is identical to original source.bmp
; DEMOPATH
and a few other bits in there are specific to my patched copy of leptonica, so you'll have to adjust/remove those lines to make them work with regular leptonica)
from leptonica.
We are unable to find a problem on linux or Windows.
Will leave this open for a while in case @sinall has more information to share.
from leptonica.
This problem is fixed on linux and Windows.
from leptonica.
Related Issues (20)
- My. net6 program uses the Tesseract library, which works fine under Windows, but fails under Linux HOT 1
- Security binary scan reports XZ Utils library but unable to detect the version HOT 2
- Build fails under Windows HOT 27
- 1.83.1: test suite fails in `ioformats_reg` unit HOT 7
- JPEG decompression is not unique, which can cause colorcontent_reg to fail on the number of colors in wyom.jpg HOT 1
- Suggest noting that libtiff must have been compiled with JPEG compression support for tests to run correctly HOT 4
- Leptonica 1.84 release schedule HOT 28
- How to detect the four corners of paper or ID card HOT 8
- 1.84.0 fails to build in FreeBSD 14.0 due missing reference to libm using CMake HOT 24
- CMake build in 1.84.0 adds include to non-existant path
- 1.84.1: compile time warnings HOT 3
- pixWriteJp2k: unexpected strong color artifacts on featureless image HOT 7
- pixOrientDetect with .bmp file HOT 6
- Logic error in pixcmapIsValid() HOT 5
- Regression: file not found on MacOS when opening /tmp file HOT 2
- Identifying and removing asterisks HOT 8
- pixDeskewGeneral(...) failing to detect a 45 degree skew? HOT 2
- Application crashing while disposing Pix.Create object HOT 5
- get minarea-rotated box of a skew area HOT 2
- pixRead() can't read png images HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptonica.