Reading/Writing File formats

BlitzMax Forums/BlitzMax Programming/Reading/Writing File formats

gellyware(Posted 2006) [#1]
Does anyone have example(s) of how to read/write bmp, jpg, png files?

I'm looking at the wotsit.org site and although intrigued at all of the usefull file formats, I am not sure what to do with them.

Any help of reading/writing byte by byte information would be great.

Thanks.


ImaginaryHuman(Posted 2006) [#2]
See in the manual,..

LoadPixmap
LoadImage
SavePixmapPNG

Max automatically can load jpeg png and bmp and can save png


ImaginaryHuman(Posted 2006) [#3]
As to reading and writing files that's a different matter. See streams.


gellyware(Posted 2006) [#4]
I believe there is a miscommunication.

I am not talking about the normal blitz way of loading images... I am talking about reading and writing raw (bytes) in the jpg,png (etc) format.


N(Posted 2006) [#5]
http://www.wotsit.org/

Have fun.


Robert Cummings(Posted 2006) [#6]
File : TStream commands in the manual. ReadFile, readbyte etc.


gellyware(Posted 2006) [#7]
I am looking for code that reads in byte by byte information. I know of the blitz commands and the wotsit site.... what I am asking for is if anyone has written a png, jpg, bmp, reading/writing program(using bytes). I would like to see examples of what someone has done with info found at the wotsit site.

Examples Examples Examples.

Thanks.


Scott Shaver(Posted 2006) [#8]
here is some java code to read a bmp file



here is a little snippet of blitz code reading a binary tilemap file.



together they should give you an idea of how to go about it.


gellyware(Posted 2006) [#9]
Thanks Scott :) I'm going to go through these now.

Any other examples anyone? I like a lot of examples.


N(Posted 2006) [#10]
The file format references are all you should need to read these formats like those.


Beaker(Posted 2006) [#11]
You might want to take a look at the bmax source code for loading images:
C:\Program Files\BlitzMax\mod\brl.mod\pngloader.mod\pngloader.bmx
C:\Program Files\BlitzMax\mod\brl.mod\bmploader.mod\bmploader.bmx
etc


ImaginaryHuman(Posted 2006) [#12]
Probably you'll have to write it yourself. As far as I know the jpeg and png loaders are based on external C code. I'd be surprised if anyone has yet written a jpeg or png loader/saver in purely blitzmax code. I'm going to try doing it at some point for my project but not right now. It can be pretty complicated depending on the file format.


xlsior(Posted 2006) [#13]
JPG and GIF are hideously complex formats, mostly thanks to the bizarre compression routines & hash tables.

I did make a 256 color PCX writer for PowerBASIC 3.x (DOS) 8 years ago, based on the fileformat description from Wotsit. But PCX compression is much easier than JPG, since all it uses is a basic RLE (Run-Length encoding) algorithm, similar to BMP.

Probably won't be of much use in today's true-color world, but just in case:



Anyway, if you're looking for some source material that you could possibly adapt, I suggest searching around a bit for the old ABC releases ("All Basic Code"). If I recall correctly, it had a bunch of image file readers & writers over the years, mostly written in QuickBASIC. It might be easier to adapt to Blitz than some of the Java/C code?


ImaginaryHuman(Posted 2006) [#14]
An IFF/ILBM loader/saver is fairly easy to do, if you want something to practice on.

I agree that some of these formats are hideously complex, I don't think I would even be able to understand all the math involved in jpeg, for example, or to even `get` what all the articles about it are trying to say. Also PNG and GIF are pretty complicated and highly detailed. I still don't understand their compression either.

That's why people sometimes opt for simple ones like PCX, BMP, IFF, etc

Or do a direct raw graphics dump ;-D


xlsior(Posted 2006) [#15]
That's why people sometimes opt for simple ones like PCX, BMP, IFF, etc


Yup - When I last looked into it, PCX and BMP were the only 'mainstream' formats that looked easy enough to understand for me to tackle...
Just looking at the JPG file format description made my head hurt.


N(Posted 2006) [#16]
I prefer custom formats. Keeps most people from messing with my stuff.


xlsior(Posted 2006) [#17]
Custom formats are great when you want to keep your info locked up, (like game graphics, etc.) but they won't do you a whole lot of good when you are creating a paint program for example, where you need to be able to read/write other common file formats to interface with the outside world. Not being able to do so would severely limit the usefulness of such an application.


N(Posted 2006) [#18]
Custom formats are great when you want to keep your info locked up, (like game graphics, etc.) but they won't do you a whole lot of good when you are creating a paint program for example


Well, this is a game programming language, so it's a fair assumption that one is making a game using it. As for me, I like to make random modules that're neat (mostly so I'm not bored) and then share them.

Anyhow, that's a different subject.


ImaginaryHuman(Posted 2006) [#19]
A custom file format can be a good idea if your application has features which you want to store that wouldn't be supported by any other formats, such as photoshop saving a file that preserves all the layers and information etc. Also if your application intends to be successful and widely used, a custom format is a good idea as it will then be adopted by other people to support files of that kind. After all, before photoshop there were no photoshop files.

I don't think Blitz is necessarily just a game programming language, I think that's just what it is geared towards and is mostly used for. If it were impossible to write anything other than games in it, I would call it a game language. But it's not exclusive. I am also working on something along the lines of a paint program in BlitzMax.

You could maybe look into using the existing C code of those file loaders and savers, but change them in some way to get access to the data in the way that you want to. Also maybe look around for existing libraries of file-format support that you could translate.


Dreamora(Posted 2006) [#20]
BM in its core or GUI working is for 3D at least and not 2D because all drawing etc is in 3D. And have requirements with XXMB 3D cards aren't that good for 2D programs normally ;-)
You would need to implement own drivers for GDI+ / WinFX and the Linux / OSX parts to make it really 2D ...

I would call Blitz (not only BM) a multifunctional media language ... there is more in 3D than just games after all and the best commercial showcase apps for b3d for example weren't games at all ...


Hotcakes(Posted 2006) [#21]
An IFF/ILBM loader/saver is fairly easy to do, if you want something to practice on.

Yeh but that would be reinventing the wheel, now =]

@lucid: Check out the brl.bmploader module. That's the best basic example of byte-reading a picture file in that there could possibly be.