2

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))

Glenn Randers-Pehrson
  • 11,940
  • 3
  • 37
  • 61
  • https://www.google.fr/search?q=convert+a+BMP+from+24+bit+to+16+bit+Mode+in+ImageMagick.&ie=utf-8&oe=utf-8&gws_rd=cr&ei=nHFwVuWfBcOxad-RqKAC –  Dec 15 '15 at 20:01
  • `ppmtobmp` man-page agrees that 16-bit BMPs are not possible... http://manpages.ubuntu.com/manpages/hardy/man1/ppmtobmp.1.html – Mark Setchell Dec 15 '15 at 21:47
  • 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... https://en.m.wikipedia.org/wiki/Netpbm_format – Mark Setchell Dec 15 '15 at 22:06
  • 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... –  Dec 16 '15 at 17:43
  • Please don't mistake people who are trying to help you for people who are telling you to change your mind. – Mark Setchell Dec 21 '15 at 09:41
  • BTW, on Linux you can use GIMP to save RGB565 BMPs, if that helps? That can also be scripted for bulk conversion. – KevinJWalters Jun 19 '20 at 10:48

2 Answers2

2

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.

Glenn Randers-Pehrson
  • 11,940
  • 3
  • 37
  • 61
  • Thanks Glenn for mentioning the color depth definition - I was searching for similar information and just to conclude that the depth represents per color and not total (as you mentioned) took me hours of searching. However, I am still looking for (a) the 'official' location of setImageDepth() manpage on ImageMagick.org. I am using php Imagick, whose manpage on this is very brief (b) I want to set the depth of an image to 2 (i.e., per RGB color) and eventually write it as a PNG. It seems there is no effect of setting depth - it ultimately comes out as 8 bit. Can someone help? – sm535 Apr 28 '16 at 14:39
  • 1
    The PNG format does not support RGB222 or 6-bit indexed, so it'll get written as RGB888 or 8-bit indexed, the latter with a 64-entry palette. – Glenn Randers-Pehrson Apr 28 '16 at 16:36
  • Glenn, thanks very much again. Is the PNG format not supporting RGB222 a limitation of Imagick/IM? I ask this because I see this here: https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_size_factors "Color depth can range from 1 to 64 bits per pixel." If so, is there a pointer regarding support of various depths for each file format in PHP Imagick/IM? I do not necessarily need to use PNG as an output format. – sm535 Apr 29 '16 at 13:17
  • The defined depths and color types in PNG are defined here:https://www.w3.org/TR/PNG/#11IHDR and for other formats, ImageMagick generally supports whatever depths are allowed by the respective formats. I don't think there is table of these within the ImageMagick documentation. – Glenn Randers-Pehrson Apr 29 '16 at 13:27
  • ok. ImageMagick can not do what I wanted to to. I close the Question as answered. –  Jul 18 '17 at 10:03
0

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?

KevinJWalters
  • 193
  • 1
  • 7
  • Thank you for an advice. My goal was to store graphical images without any compression. PNG format uses compression. BMP format seemed more applicable for that purpose. I will try get more information about that 565 format. –  Nov 21 '21 at 14:05