[luv-main] Imagemagick - convert to same format as another image

Hi all, I have an little microcontroller and LCD that can display windows bmp files, but it only seems to work with the ones provided. When I create a bmp file with the same basic resolution, colour depth etc, it fails to display. Does anyone know of a way to convert an image to bmp format having the same characteristics as a reference image? I'm sure I could work it out for this specific case, but it would be handy thing to be able to do in general. anyone? cory

On 24/10/11 20:57, cory seligman wrote:
Hi all,
I have an little microcontroller and LCD that can display windows bmp files, but it only seems to work with the ones provided.
When I create a bmp file with the same basic resolution, colour depth etc, it fails to display.
Does anyone know of a way to convert an image to bmp format having the same characteristics as a reference image?
I'm sure I could work it out for this specific case, but it would be handy thing to be able to do in general.
anyone?
Do the images that work still work if you do bmptoppm <orig.file | ppmtobmp >new.file? Note that you may need to alter the bits per pixel to suit the microcontroller. Use pnmquant or ppmdither to reduce the number of colors in the image.

On Mon, 24 Oct 2011 20:57:38 +1100, cory seligman <coryms.luv@gmail.com> wrote:
When I create a bmp file with the same basic resolution, colour depth etc, it fails to display.
Does anyone know of a way to convert an image to bmp format having the same characteristics as a reference image?
It would be worth using the ImageMagick identify command so you know more about the format. If you just need to copy resolution and depth, something like this can be used: convert in.jpg $(identify -format '-resize %wx%h -depth %z' ref.bmp) out.bmp Another aspect is whether the bmp should have a color table ('pseudocolor'). You can force an 8-bit color table using the ImageMagick flag '-colors 256' (at least for certain filetypes such as bmp). If forcing a color table works but the colors come out wrong, the device might already have a built in color table, in which case you would have to remap using a reference color table with all the default colors: convert in.jpg $(identify -format '-resize %wx%h -depth %z' ref.bmp) -remap colortable.bmp out.bmp Glenn

On Mon, Oct 24, 2011 at 9:55 PM, Glenn McIntosh <neonsignal@memepress.org>wrote:
On Mon, 24 Oct 2011 20:57:38 +1100, cory seligman <coryms.luv@gmail.com> wrote:
When I create a bmp file with the same basic resolution, colour depth etc, it fails to display.
Does anyone know of a way to convert an image to bmp format having the same characteristics as a reference image?
It would be worth using the ImageMagick identify command so you know more about the format.
If you just need to copy resolution and depth, something like this can be used:
convert in.jpg $(identify -format '-resize %wx%h -depth %z' ref.bmp) out.bmp
Another aspect is whether the bmp should have a color table ('pseudocolor'). You can force an 8-bit color table using the ImageMagick flag '-colors 256' (at least for certain filetypes such as bmp).
If forcing a color table works but the colors come out wrong, the device might already have a built in color table, in which case you would have to remap using a reference color table with all the default colors:
convert in.jpg $(identify -format '-resize %wx%h -depth %z' ref.bmp) -remap colortable.bmp out.bmp
Thanks for the replies. I used identify to work out that I needed to remove the alpha channel and make it uncompressed, but now the image is all offset. I suspect that the code in the microcontroller is very stupid and uses fixed byte offsets into the image. However, the bmptoppm trick worked a treat, with the following message: bmptoppm: Windows BMP, 240x320x24 bmptoppm: warning: the BMP header says the raster starts at offset 138 bytes into the file (offbits), but that there are 54 bytes of information before the raster. This inconsistency probably means the input file is not a legal BMP file and is unusable. bmptoppm: warning: read 230538 bytes, expected to read 230454 bytes bmptoppm: warning: some image data remains unread. bmptoppm: WRITING PPM IMAGE ppmtobmp: analyzing colors... ppmtobmp: More than 256 colors found ppmtobmp: Writing 24 bits per pixel truecolor (no palette) in any case, it's not a big deal to fix for this specific case. i was actually more interested in the more general question of whether there's a way to copy the formatting of a reference image. actually, that would be a neat trick for video files too.
participants (3)
-
Allan Duncan
-
cory seligman
-
Glenn McIntosh