FromToImage - Program to convert any file to bmp image

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
ricardo_sdl
Enthusiast
Enthusiast
Posts: 109
Joined: Sat Sep 21, 2019 4:24 pm

FromToImage - Program to convert any file to bmp image

Post 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!
You can check my games at:
https://ricardo-sdl.itch.io/
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

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

Post by mpz »

Hi,

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

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

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

Post 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.
ricardo_sdl
Enthusiast
Enthusiast
Posts: 109
Joined: Sat Sep 21, 2019 4:24 pm

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

Post 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.
You can check my games at:
https://ricardo-sdl.itch.io/
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

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

Post 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).
ricardo_sdl
Enthusiast
Enthusiast
Posts: 109
Joined: Sat Sep 21, 2019 4:24 pm

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

Post 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.
You can check my games at:
https://ricardo-sdl.itch.io/
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

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

Post 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 ???
ricardo_sdl
Enthusiast
Enthusiast
Posts: 109
Joined: Sat Sep 21, 2019 4:24 pm

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

Post 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.
You can check my games at:
https://ricardo-sdl.itch.io/
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

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

Post 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
Post Reply