3

I need to update a logo bitmap to an updated logo. The existing code uses a C header which is loaded via XChangeProperty.

I have looked into imagemagick and the Gimp in order to convert the updated png I have into a suitable header. Gimp even said 'export a C header' (or something like it) but the result did not resemble the existing format.

How do I go (preferably on the command-line) from a png to a suitable header file?

Edit: Expanding the question a little, the (now out of date) logo I would like to replace is in this file and gets used here.

  • Which property is this? Can you guess the format of the old file or post the beginning? From your earlier comment, it looks like there's a size followed by some bitmap data, is there other meta-information besides the size? How many colors? – Gilles 'SO- stop being evil' Jul 31 '15 at 14:11
  • I can point you to the code. I once received this as a patch for package I maintain for Debian and then guided it upstream -- but I am a little ignorant as to how it got created. And the gentleman who created it hasn't replied to a recent email question I sent ... – Dirk Eddelbuettel Jul 31 '15 at 14:16
2

Using ImageMagick, based on rlogo_icon.h.

#!/bin/sh
echo 'unsigned long rlogo_icon[] = {'
identify -format '%w, %h,' $1
convert $1 -color-matrix '0 0 1 0, 0 1 0 0, 1 0 0 0, 0 0 0 1' RGBA:- | hexdump -v -e '1/4 "0x%08x,\n"'
echo '};'

Usage:

./script.sh rlogo_icon.png > rlogo_icon.h

I'm not sure this -color-matrix is always correct. I placed bytes in the order of BGRA because my computer is little endian.

  • That worked! You are my hero! Thanks so much! (I also had to edit the code to account for the 200x155 size which I failed last time around when trying the first suggestion (by @Gilles, IIRC). – Dirk Eddelbuettel Jul 31 '15 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.