Page 1 of 1

FromToImage - Program to convert any file to bmp image

Posted: Mon Nov 29, 2021 7:57 pm
by ricardo_sdl
Hi!
Inspired by a post I've seen on reddit I created this program to convert any file to a bmp image file.
Here is a small game (in a zipped file) viewed as bmp image:
Image

And here is the fromtoimage.exe in a bmp file:
Image

The encoding is simple, each pixel in the image encodes 3 bytes (red, green, blue) from the input file. The first 3 pixels store the file size. The program is a command line one, to see the usage just execute it without any parameters.
Thanks!

Re: FromToImage - Program to convert any file to bmp image

Posted: Mon Nov 29, 2021 10:31 pm
by mpz
Hi,

Thanks it is a nice idea to store this as image file...

Greetings Michael

Re: FromToImage - Program to convert any file to bmp image

Posted: Tue Nov 30, 2021 5:26 am
by kenmo
Nice job! I recommend saving to PNG instead of BMP, it should be a smaller file size and still preserve every pixel value.

Re: FromToImage - Program to convert any file to bmp image

Posted: Tue Nov 30, 2021 1:02 pm
by ricardo_sdl
Thanks @mpz and @kenmo!
I didn't think about png's :shock:
It might actually create images smaller than the original file.

Re: FromToImage - Program to convert any file to bmp image

Posted: Wed Dec 01, 2021 4:52 pm
by ebs
Thank you - that's very simple and very cool!

I changed the image format to PNG and it reduces the image size for fromtoimage.exe from 74 KB (BMP) to 38 KB (PNG).

Re: FromToImage - Program to convert any file to bmp image

Posted: Wed Dec 01, 2021 8:26 pm
by ricardo_sdl
ebs wrote: Wed Dec 01, 2021 4:52 pm Thank you - that's very simple and very cool!

I changed the image format to PNG and it reduces the image size for fromtoimage.exe from 74 KB (BMP) to 38 KB (PNG).
Nice! The thing with png's is that we can use less pixels also to store the input file, because of transparency we can store 4 bytes per pixel.

Re: FromToImage - Program to convert any file to bmp image

Posted: Thu Dec 02, 2021 3:50 pm
by ebs
Hi Ricardo,
Nice! The thing with png's is that we can use less pixels also to store the input file, because of transparency we can store 4 bytes per pixel.
I'm trying to do exactly that - using 32-bit images, replacing RGB with RGBA, changing all references from 3 bytes to 4 bytes, etc., but so far I haven't been able to make it work. I think I'm creating the image correctly, but I can't decode it back to the original file. Can you tell me if 32-bit images store pixels as RGBA or ARGB or ???

Re: FromToImage - Program to convert any file to bmp image

Posted: Thu Dec 02, 2021 8:22 pm
by ricardo_sdl
I created a branch where the images are saved and read as png. It also uses the alpha channel to store 4 bytes per pixel.
The fromtoimage.exe now looks like this:
Image

Not as striking as before because of the lots of transparent pixels :lol:

This is the branch with the updated code:
https://github.com/ricardosdl/FromToIma ... /saveAsPNG

Not much was changed, but I had to use "DrawingMode(#PB_2DDrawing_AllChannels)" after the calls to StartDrawing, so when we read a pixel or plot one the alpha channel was actually used.

Re: FromToImage - Program to convert any file to bmp image

Posted: Fri Dec 03, 2021 2:50 pm
by ebs
Hi Ricardo,

Thanks for the updated version.

The interesting thing (to me) is that a version I made that just used the PNG format instead of BMP, with no use of the alpha bytes to store data, produces a PNG image that is almost exactly the same size as your 4-byte version (37.2 KB vs. 37.1 KB) from the same input file.

In any case, this has been a very interesting learning exercise - thanks again!

Regards,
Eric