-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|632|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Variables


 
mike_g
Created : 13 October 2007
 
Language : Basic

C++ Unfinished Image Class



An unfinised class for dealing with images. So far it only loads and saves 24bit bitmaps, but I am planning to add support for PNG, JPG, and TGA. It is not dependent on any non-standard external libraries. The image data is loaded directly to RAM, which avoids overheads when dealing with drawing surfaces. I plan on this being a part of an image filtering prog I am working on.

 

Comments


Saturday, 13 October 2007, 17:23
JL235
I've only skimmed your code quickly, but from the looks of it you are checking the end of the file extension to see what type of image it is. You shouldn't actually do this. Instead you should open the file up and check the data inside.

If I renamed my .bmp to .png then your code wouldn't work anymore becaue it would think it's a .png and not a .bmp. If you check inside instead it'll still work, like how it does with Paint, Blitz Basic and various media players with films and sound. Rename your .avi to .mpeg and Windows Media Player will give you a warning, but still play it.
Saturday, 13 October 2007, 17:30
mike_g
Yes I could add some extra sanity checking. It would only involve reading the first 2 bytes of the file. I'll probably do that along with a couple of other things, but tbh how many people are going to rename a bitmap as .png?
Saturday, 13 October 2007, 19:45
JL235
Mike_G how many people are going to rename a bitmap as .png?


Idiots will, and there was a tutorial on the Blitz site that pointed out that Blitz Basic doesn't check the extension. So you can convert your images to a different format, rename it to the format used in your code and Blitz will still read and use it.

Plus if you do that your code will be more robust and harder to break.
Sunday, 14 October 2007, 00:37
Agent
Mike, why don't you just use type casting instead of all those type conversion methods?
e.g.


Sunday, 14 October 2007, 06:39
mike_g
Wow thats cool. I had to use type casting in order to get a few things to work so far, but I never would have thought of using it like that.

At first it didn't seem as if it would sort out the big endian thing you get with BMP files, but I tried it and it does. Cheers. That will make my code shorter and faster