2
votes

I am trying to convert a BMP from 24 bits/pixel to 16 bit/pixel Mode in ImageMagick.

convert /tmp/a/new/37.bmp -depth 5 -define bmp:format=bmp2 /tmp/a/new/37_v2_16bit.bmp
convert /tmp/a/new/37.bmp -depth 5 -define bmp:format=bmp3 /tmp/a/new/37_v3_16bit.bmp

The result has the same 8 bit per R., per G. and per B., according to output of: identify -verbose

What am I doing wrong? How to get 16-bit color in BMP ?

Thank you!

P. S.

-depth value

depth of the image. This is the number of bits in a pixel. The only acceptable values are 8 or 16. http://linux.math.tifr.res.in/manuals/html/convert.html

=(

Official Documentation says (no restrictions mentioned):

-depth value

depth of the image.

This the number of bits in a color sample within a pixel. Use this option to specify the depth of raw images whose depth is unknown such as GRAY, RGB, or CMYK, or to change the depth of any image after it has been read.


convert /tmp/a/new/37.bmp -colors 256 /tmp/a/new/37_256.bmp

makes the file smaller, but visually it is the same! wth?! )))))


convert /tmp/a/new/37.bmp -colors 65536 /tmp/a/new/37_64k.bmp

same size, same visual picture.


convert /tmp/a/new/37.bmp -dither None -colors 256 /tmp/a/new/37_256_nd.bmp

a bit smaller again, but it does not look like 256-colored! bug? 256 colored 800x600 BMP is ~ 800x600x1 Bytes (without headers) ~ 480 000 Bytes. But it says ~650 000 Bytes)))) funny program))

2
google.fr/…user3131905
ppmtobmp man-page agrees that 16-bit BMPs are not possible... manpages.ubuntu.com/manpages/hardy/man1/ppmtobmp.1.htmlMark Setchell
What do you actually want to do with the 16-bpp BMP? Maybe you can use PNG or NetPBM's PNM format which is very simple to process... en.m.wikipedia.org/wiki/Netpbm_formatMark Setchell
I always liked when instead of answering people try to make me change my opinion :) What I want to do with BMP? I need 16 bit BMPs to store ScreenShots of old games that used 16-bit graphics without compression and in a lossless way and in a format that is easy to open. Photoshop helped me. But on Linux it does not work...Chelovek
Please don't mistake people who are trying to help you for people who are telling you to change your mind.Mark Setchell

2 Answers

1
votes

The documentation you quoted from linux.math... is pretty old (2001) and is incorrect about -depth. The "-depth 16" option does not mean 16-bit pixels (like R5G6R5 or R5G5R5A1); -depth 16 means 48-bit/pixel R16, G16, B16 or 64-bit/pixel R16, G16, B16, A16 pixels. The "Official documentation" that you quoted (2015) is correct.

ImageMagick doesn't support that kind of 16 bit/pixel formats, so you'll need to store them in an 8 bit/channel format and live with the larger filesize.

It also appears that for images with 256 or fewer colors, it will write a colormapped image with 1, 4, or 8-bit indices. You don't have to make any special request, it'll do that automatically. Use "-compress none" for uncompressed BMP's. The current ImageMagick (version 6.9.2-8) gives me the expected 480kbyte file if I start with an 800x600 image with more than 256 colors and use

convert im.bmp -colors 256 -compress none out.bmp

ImageMagick does support a 16-bit "bitfields" BMP format while reading but I don't see any indication that it can write them, and haven't tried either reading or writing such images.

0
votes

It's not ImageMagick but ffmpeg, more associated with video, can create a 16bit bmp image if you are referring to the 565 format?

ffmpeg -i ffmpeg-logo.png -sws_flags neighbor -sws_dither none -pix_fmt rgb565 -y ffmpeg-logo-16bit-nodither.bmp

That intentionally disables dithering but if you want that just omit the sws parts, e.g.

ffmpeg -i ffmpeg-logo.png -pix_fmt rgb565 -y ffmpeg-logo-16bit-dithered.bmp

If your images are inherently from an rgb565 source then it should not dither them but I'd always be cautious and inspect a few closely before doing any batch conversions.

Based on the discussion in the comments it sounds like PNG would be a good format for preserving old screenshots verbatim as it uses lossless compression but maybe that's not applicable due to use with vintage software?