Page 1 of 1

Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-04-11T11:52:13-07:00
by serrated_flange_nut
Hi!

I'm trying to convert a PNG to BMP, with the explicit requirement, that the file must be a palette type BMP3.

You see, the u-boot bootloader can only display palette BMP's, but imagemagick keeps turning the output into a grayscale type image. I think there might be some automatic conversion done to save space, but the result is that the image can't be displayed.

Does anyone know how to force the output to be a palette format?

Command used was:

Code: Select all

$ convert -verbose boot_logo.png -type palette BMP3:boot.bmp
boot_logo.png PNG 320x240 320x240+0+0 8-bit sRGB 22.3KB 0.000u 0:00.000
boot_logo.png=>boot.bmp PNG 320x240 320x240+0+0 8-bit Palette sRGB 238c 19.8KB 0.070u 0:00.059

Code: Select all

$ identify -verbose boot.bmp 
Image: boot.bmp
  Format: BMP3 (Microsoft Windows bitmap image (V3))
  Class: PseudoClass
  Geometry: 320x240+0+0
  Units: PixelsPerCentimeter
  Type: Grayscale
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    gray: 8-bit
  Channel statistics:
    Pixels: 76800
    Gray:
      min: 0 (0)
      max: 237 (0.929412)
      mean: 24.8867 (0.097595)
      standard deviation: 67.5699 (0.26498)
      kurtosis: 4.44979
      skewness: 2.49846
      entropy: 0.174434
  Colors: 238
  Histogram:
     65964: (  0,  0,  0) #000000 gray(0)
        40: (  1,  1,  1) #010101 gray(1)
        ...
        
  Colormap entries: 256
  Colormap:
         0: (  0,  0,  0) #000000 gray(0)
         1: (  1,  1,  1) #010101 gray(1)
         ...

  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 320x240+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: RLE
  Orientation: Undefined
  Properties:
    date:create: 2018-04-11T20:52:40+02:00
    date:modify: 2018-04-11T20:52:40+02:00
    signature: 05cdd6fa8c6ff1bee79a6e96819d16233726fb537b384a0b212055737088318c
  Artifacts:
    filename: boot.bmp
    verbose: true
  Tainted: False
  Filesize: 19.8KB
  Number pixels: 76.8K
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
This is a file that u-boot can display:

Code: Select all

$ identify -verbose boot-backup.bmp 
Image: boot-backup.bmp
  Format: BMP3 (Microsoft Windows bitmap image (V3))
  Class: DirectClass
  Geometry: 320x240+0+0
  Units: PixelsPerCentimeter
  Type: Palette
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Pixels: 76800
    Red:
      min: 0 (0)
      max: 247 (0.968627)
      mean: 10.7822 (0.042283)
      standard deviation: 47.954 (0.188055)
      kurtosis: 18.3298
      skewness: 4.4539
      entropy: 0.121676
    Green:
      min: 0 (0)
      max: 247 (0.968627)
      mean: 3.19845 (0.0125429)
      standard deviation: 23.4586 (0.0919945)
      kurtosis: 87.1343
      skewness: 9.20918
      entropy: 0.115328
    Blue:
      min: 0 (0)
      max: 249 (0.976471)
      mean: 2.70246 (0.0105979)
      standard deviation: 23.5542 (0.0923692)
      kurtosis: 89.5192
      skewness: 9.39096
      entropy: 0.0532598
  Image statistics:
    Overall:
      min: 0 (0)
      max: 249 (0.976471)
      mean: 5.56103 (0.021808)
      standard deviation: 33.6882 (0.132111)
      kurtosis: 42.7356
      skewness: 6.62803
      entropy: 0.0967545
  Colors: 16
  Histogram:
     72588: (  0,  0,  0) #000000 black
       161: ( 26, 18, 18) #1A1212 srgb(26,18,18)
       212: ( 59,  3,  0) #3B0300 srgb(59,3,0)
       200: ( 59, 59, 59) #3B3B3B grey23
        66: ( 85, 85, 86) #555556 srgb(85,85,86)
        85: ( 86,  5,  0) #560500 srgb(86,5,0)
       159: (121,  7,  0) #790700 srgb(121,7,0)
       110: (121,121,122) #79797A srgb(121,121,122)
        54: (146,147,148) #929394 srgb(146,147,148)
        94: (152,  9,  0) #980900 srgb(152,9,0)
       157: (187,188,190) #BBBCBE srgb(187,188,190)
       218: (188, 12,  0) #BC0C00 srgb(188,12,0)
        91: (225, 14,  0) #E10E00 srgb(225,14,0)
        84: (225,226,228) #E1E2E4 srgb(225,226,228)
       469: (246,247,249) #F6F7F9 srgb(246,247,249)
      2052: (247, 16,  0) #F71000 srgb(247,16,0)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 320x240+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: Undefined
  Properties:
    date:create: 2018-04-11T17:21:06+02:00
    date:modify: 2018-04-11T17:21:06+02:00
    signature: 19cdc82c1e831800ec578ceff8a086ded5e35b2a1c6f09486f0595bbc91b147d
  Artifacts:
    filename: boot-backup.bmp
    verbose: true
  Tainted: False
  Filesize: 230KB
  Number pixels: 76.8K
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org


Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-04-12T06:38:05-07:00
by 246246
I think your boot.bmp is palette format because identify -verbose shows colormap entry.

Create file just the same way you've done:

Code: Select all

% convert logo: -type Palette -colorspace Gray PNG8:logo.png
% convert logo.png -type Palette BMP3:logo.bmp
Then checking it.

Code: Select all

% identify -verbose logo.bmp | grep -A 10 -i colormap:
  Colormap:
         0: (255,255,255) #FFFFFF gray(255)
         1: (235,235,235) #EBEBEB gray(235)
         2: (229,229,229) #E5E5E5 gray(229)
         3: (213,213,213) #D5D5D5 gray(213)
         4: (201,201,201) #C9C9C9 gray(201)
         5: (245,245,245) #F5F5F5 gray(245)
         6: (250,250,250) #FAFAFA gray(250)
         7: (241,241,241) #F1F1F1 gray(241)
         8: (223,223,223) #DFDFDF gray(223)
         9: (204,204,204) #CCCCCC gray(204)

% dd bs=1 if=logo.bmp skip=54 | od -cx | head
0000000  377 377 377  \0 353 353 353  \0 345 345 345  \0 325 325 325  \0
             ffff    00ff    ebeb    00eb    e5e5    00e5    d5d5    00d5
0000020  311 311 311  \0 365 365 365  \0 372 372 372  \0 361 361 361  \0
             c9c9    00c9    f5f5    00f5    fafa    00fa    f1f1    00f1
0000040  337 337 337  \0 314 314 314  \0 330 330 330  \0 356 356 356  \0
             dfdf    00df    cccc    00cc    d8d8    00d8    eeee    00ee
0000060  360 360 360  \0 223 223 223  \0 240 240 240  \0 006 006 006  \0
             f0f0    00f0    9393    0093    a0a0    00a0    0606    0006
0000100  317 317 317  \0 370 370 370  \0   5   5   5  \0   F   F   F  \0
             cfcf    00cf    f8f8    00f8    3535    0035    4646    0046
As you see, there are same colormap entry in binary as is shown in identify -verbose, all RGB and reserved bit is extant.
So I guess there is other reason the file is not displayed in your boot loader.

At quick look, your boot.bmp is RLE compressed, whereas boot-backup.bmp is not compressed. Isn't it the reason?

Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-04-13T14:26:16-07:00
by Jason S
BMP does not have a grayscale image type. boot.bmp is an 8-bits/pixel RLE-compressed color paletted image, which (I guess) ImageMagick pretends is grayscale, since all its colors are gray. Note the Class is "PseudoClass", which is IM's term for paletted.

boot-backup.bmp is a 24-bits/pixel uncompressed RGB file, which (I guess) ImageMagick pretends is paletted, since it only has 16 colors. Note the class is "DirectClass", which means non-paletted. Note the file size is 230KB, which is about 3 bytes/pixel.

Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-04-13T19:23:48-07:00
by 246246
Jason S wrote: 2018-04-13T14:26:16-07:00 boot-backup.bmp is a 24-bits/pixel uncompressed RGB file, which (I guess) ImageMagick pretends is paletted, since it only has 16 colors. Note the class is "DirectClass", which means non-paletted. Note the file size is 230KB, which is about 3 bytes/pixel.
Indeed. Also, 'identify -verbose boot-backup.bmp' dose not show colormap entry.

So the OPs requirement would be to create 24-bits/pixel uncompressed RGB bmp3 from png, even if all the colors used are gray. Try

Code: Select all

convert boot_logo.png -type TrueColor -compress none BMP3:boot.bmp

Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-04-16T07:07:23-07:00
by serrated_flange_nut
Looks like there's conflicting information on the web on the proper format to use. For the record, and since this forum post is already number 2 for the related search terms, this is for use with the Armbian system. It works flawless when I use the command #246246 typed out (

Code: Select all

convert boot_logo.png -type TrueColor -compress none BMP3:boot.bmp
)
Jason S wrote: 2018-04-13T14:26:16-07:00Note the Class is "PseudoClass", which is IM's term for paletted.
That's good to know! Even weirder then, that the original working image is a "DirectClass", but the type is "Palette".

Thank you guys for being so helpful, you rock!

Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-10-12T08:04:43-07:00
by xiao
just reviving the old thread because my problem is very very similar experts please see my thread also

http://www.imagemagick.org/discourse-se ... =1&t=34857

Re: Saving image as a palette type bmp, even if it is greyscale?

Posted: 2018-10-12T13:10:43-07:00
by fmw42
Please do not revive old threads. Start a new one and be specific about the problem, provide your IM version and platform, your example images and the code you have tried.


See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli