Header file to image

With Wonderbrush i can export a image to header file, but how can i do this on the other way?

I wish to create my own decorator for Haiku, but i need the garphics to make my work, i does not can do this in code way.

Blep Blop. The provided information is incomplete.

Asuming you mean that Wonderbrush exported a RGB-A (4 bytes per pixel) image, with transparency, you may end with a C header file containing an array with this values.
You may check this with the length value, as the array size/length would be WIDTHxHEIGHTx3 (RGB) or WIDTHxHEIGHTx4 (RGB-A).

Unfortunately, you cannot do the opposite operation without using an image manipulation library (or at least in many of the common programming languages).

For C , there are the STB imaging libraries which are inneficient yet portable as requiring one file only to do the work, without further install of dependencies.

This has 5 functions to write a image file from the header data, depending on the desired output format.

Of course, this involves creating a simple C program (10 lines?), and may require more info about the header file contents to guide you, like uploading to a pastebin or so.

In particular because Wonderbrush is a vector format, so if you exported a raw bitmap, there is no way back.

1 Like

Yeah i tried to meant you cannot just throw a bunch of commands with the STL of the languages.
Even python requires PIL to do so.

it was not a 10lineer but here it is.
@lelldorin you can use the following source code to convert your headers to BMP

https://0x0.st/zzYy.c

  • instructions inside
  • if you are on haiku gcc2h use setarch x86 before compiling (got undefined reference to _main)
  • compile with gcc zzYy.c no extra options required
  • run a.out

Yeah. Beating code simplicity of using STB is hard in c++. If all they werent orders of magnitude slower than libpng/libjpeg, and weren’t slow at compilation times, we would live in a happy header only world.

Your program does not compile?

`zzYy.c:95:18: error: use of undeclared identifier 'kBitmapWidth`

`zzYy.c:96:20: error: use of undeclared identifier 'kBitmapHeight'`

you need to #include the header generated by WonderBrush. Remember: instructions inside

Oh yeah, it compiles only with wonderbrush generated .h files, i was trying with another one which looks to have a different format, but even then, after a succesfull compilation, it generated the out.bmp file and a “a.out” file(why both?) but i was unable to open the out.bmp by any app i have including wonderbrush.
This could be a neat little app if you can improve it to do this sort of conversions with any header file, and not only the ones wonderbrush generates?.

out of scope.

yeah, i hit that too, but you can convert with imagemagick convert out.bmp out.png or open directly with WebPositive. It looks like there is no Translator for these BMP files.

There is definitely a BMPTranslator. Did we miss one of the variants of the format? If so, a bugreport with a sample file would be appreciated.

1 Like

according to wikipedia.org there are several variants and they are differentiated by its header size.

in BMPTranslator.h you have defined structs for 12 and 40 byte sized-headers. The one I use in my script is the 108 bytes variant called BitmapV4Header which supports custom ARGB bitmask.

You can look at the detailed wikipedia’s Example #2 which uses this format. Or inspect my script and generated files. Imagemagick can generate these files too (stackoverflow answer, imagemagick docs)

FWTW, i was unable to open the generated BMP’s in windows using diffrent tools , and i was unable to convert them with imagemagick’s convert cmd either, some error: file size and length size don't match?.

must be endianness related, it works in Haiku. Managing endian things is tricky and didn’t bother with it.