Conversion to 8-bit Bitmap Requires 130 MB of Ram
Posted: 2013-06-21T05:53:12-07:00
I am having an issue converting images from png to an 8-bit bitmap with only 256 colors.
I need to do this conversion on an embedded device with a very small amount of RAM, only about 24MB free, and every command I try to do this results in an out of memory error:
I have tried to do this in the simplest way I could find:
Valgrind on my desktop computer indicates that this command uses 136.8MB of ram:
I have also tried simply extracting the unique colors from the input image, then providing that as a map to the conversion. This worked for a few bitmaps, but still often consumes over 130MB of RAM:
The first command only uses around 2MB of ram and is no problem. The second command has a similar RAM usage to the all-in-one command I tried above:
If anybody has any ideas for a command to do this using a resonable amount of RAM for the conversion would be greatly appreciated.
The file I am trying to convert is only around 8.6KB as a PNG and 301KB as a 24-bit bitmap.
On my device (Embedded Linux), I have ImageMagick 6.4.4 2013-06-20 Q16, an old version I know.
On my desktop (Up-to-date Arch Linux), I have ImageMagick 6.8.5-10 2013-06-07 Q16, which should be pretty close to the latest version.
I have tried running these commands through ImageMagick Q8 with no improvements to memory usage. I do not care about losing any color information, so if it were possible to tell ImageMagick to do all its work in an 8-bit format instead of a 24-bit format would be fine. The image I used to generate the valgrind output above can be found here: http://i.imgur.com/i8pnMX6.png.
Thank you for the help!
I need to do this conversion on an embedded device with a very small amount of RAM, only about 24MB free, and every command I try to do this results in an out of memory error:
Code: Select all
convert: Memory allocation failed `out.bmp'.
Code: Select all
convert in.png -channel RGB -depth 8 -colors 256 -compress none +matte out.bmp
Code: Select all
==16095== Memcheck, a memory error detector
==16095== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==16095== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==16095== Command: convert in.png -channel RGB -depth 8 -colors 256 -compress none +matte out.bmp
==16095==
==16095==
==16095== HEAP SUMMARY:
==16095== in use at exit: 328 bytes in 9 blocks
==16095== total heap usage: 3,250 allocs, 3,241 frees, 137,563,383 bytes allocated
==16095==
==16095== LEAK SUMMARY:
==16095== definitely lost: 0 bytes in 0 blocks
==16095== indirectly lost: 0 bytes in 0 blocks
==16095== possibly lost: 0 bytes in 0 blocks
==16095== still reachable: 328 bytes in 9 blocks
==16095== suppressed: 0 bytes in 0 blocks
==16095== Rerun with --leak-check=full to see details of leaked memory
==16095==
==16095== For counts of detected and suppressed errors, rerun with: -v
==16095== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Code: Select all
convert in.png -unique-colors in.colors.bmp
convert in.png -channel RGB -depth 8 -compress none +matte -map in.colors.bmp out.bmp
Code: Select all
==16109== Memcheck, a memory error detector
==16109== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==16109== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==16109== Command: convert in.png -channel RGB -depth 8 -compress none +matte -map in.colors.bmp out.bmp
==16109==
==16109==
==16109== HEAP SUMMARY:
==16109== in use at exit: 392 bytes in 10 blocks
==16109== total heap usage: 3,451 allocs, 3,441 frees, 137,687,938 bytes allocated
==16109==
==16109== LEAK SUMMARY:
==16109== definitely lost: 0 bytes in 0 blocks
==16109== indirectly lost: 0 bytes in 0 blocks
==16109== possibly lost: 0 bytes in 0 blocks
==16109== still reachable: 392 bytes in 10 blocks
==16109== suppressed: 0 bytes in 0 blocks
==16109== Rerun with --leak-check=full to see details of leaked memory
==16109==
==16109== For counts of detected and suppressed errors, rerun with: -v
==16109== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
The file I am trying to convert is only around 8.6KB as a PNG and 301KB as a 24-bit bitmap.
On my device (Embedded Linux), I have ImageMagick 6.4.4 2013-06-20 Q16, an old version I know.
On my desktop (Up-to-date Arch Linux), I have ImageMagick 6.8.5-10 2013-06-07 Q16, which should be pretty close to the latest version.
I have tried running these commands through ImageMagick Q8 with no improvements to memory usage. I do not care about losing any color information, so if it were possible to tell ImageMagick to do all its work in an 8-bit format instead of a 24-bit format would be fine. The image I used to generate the valgrind output above can be found here: http://i.imgur.com/i8pnMX6.png.
Thank you for the help!