Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing 24bpp (depth=24, spp=3) PIX to BMP produces b0rked files #684

Closed
GerHobbelt opened this issue Mar 21, 2023 · 1 comment
Closed

Comments

@GerHobbelt
Copy link
Contributor

See also comment at #675 for code extract as sample code zip.

Relevant code sequence extract shown here (knowing pixReadWithHint is same as pixRead or BMP, but this was coded while looking at #675, where pixReadWithHint was initially used) :

	pix[5] = pixReadWithHint(DEMOPATH("test-rgba.bmp"), IFF_BMP);
	// identical to: pix[5] = pixRead(DEMOPATH("test-rgba.bmp"));

	d = pixGetDepth(pix[5]);
	assert(d == 32);
	spp = pixGetSpp(pix[5]);
	assert(spp == 4);
	pix[11] = pixConvert32To24(pix[5]);  // <<-- required to reproduce this issue: only happens for 24bpp PIX
	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);

Note that the expected output BMP filesize is around 15K (4 planes source is 20K; we dropped the A plane, so 25% size reduction estimate), but instead is a wild, quite large size.

Turns out d=24 will drive the bmp writer to use a cmapped / b<=8 code path, rather than the d=32/d=16 'full color' code path.

A pullreq with a patch is forthcoming.

(I need to extract/cherrypick that from my fork, so expect a ~30 mins delay on that.)

@GerHobbelt
Copy link
Contributor Author

Closed & fixed as per #685.

DanBloomberg added a commit that referenced this issue Mar 22, 2023
…sions.

* split out extension table lookup (getFormatFromExtension()) from
  getImpliedFileFormat()
* add prog/scaleimages.c, for filtered scaling of images in a directory.
* add JPG to extension table
* fix incorrect use of lept_free() in pdfio2.c.  Use LEPT_FREE in the library.
* in case there is a request to write a 24 bit pix in bmp format,
  add converter from 24 to 32 bits in bmpio, as suggested by Ger Hobbelt
  in PR #684 and #685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant