Sign in to follow this  
BlueChip

32bit .BMP -- only a legend?

Recommended Posts

hi folk.. I must build a 32bit texture, where each single channel (r,g,b,a) has an alpha map... I've thought at 32bit .bmp format, but I've discovered nothing... I've coded an editor on 24bit bitmap, working on this
//////////////////////////////////////////////////////////////////////
// bitmap.h          by Tobias Franke (webmaster@cyberhead.de) 2001 //
//////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <math.h>
#include <windows.h>

#ifndef BITMAP_H
#define BITMAP_H

class bitmap
{
	typedef struct
    {
		unsigned short bfType;           
		unsigned int   bfSize;           
		unsigned short bfReserved1;      
		unsigned short bfReserved2;      
		unsigned int   bfOffBits;        
	} bmpFHEAD;


	typedef struct bmpIHEAD
    {
		unsigned int   biSize;           
		int            biWidth;          
		int            biHeight;         
		unsigned short biPlanes;         
		unsigned short biBitCount;       
		unsigned int   biCompression;    
		unsigned int   biSizeImage;      
		int            biXPelsPerMeter;  
		int            biYPelsPerMeter;  
		unsigned int   biClrUsed;        
		unsigned int   biClrImportant;   
	} bmpIHEAD;


	typedef struct bmpPAL
	{
		unsigned char r;
		unsigned char g;
		unsigned char b;
	} PAL;



	int width, height;
	
public:
	unsigned char *data;

	bitmap(void);

	bool create(int x, int y);
	bool load(char *filename);
	bool save(char *filename);

	int getwidth(void)	{ if (data) return width; else return -1;  };
	int getheight(void) { if (data) return height; else return -1; };

	void getcolor(int x, int y, BYTE &r, BYTE &g, BYTE &b);
	void setcolor(int x, int y, BYTE  r, BYTE  g, BYTE  b);

	~bitmap(void);
};

#endif BITMAP_H
maybe, is necessary to make these changes ?? void setcolor(int x, int y, BYTE r, BYTE g, BYTE b, Byte a); and
	typedef struct bmpPAL
	{
		unsigned char r;
		unsigned char g;
		unsigned char b;
                unsigned char a;
	} PAL;
or there is another way? can you help me?? or can you give me some advises? thank very much

Share this post


Link to post
Share on other sites
I have not followed T1oracole advises, because PNG format, is too much complex for my uses...

I've seen all T1oracole's sites, and W3C web site also (http://www.w3.org/TR/PNG/), and I've noticed that PNG has too many flags and attributes...

I don't must manage PNG files... I must only to build a 32bit texture...and then load it in my project, and give it at my pixel shader function... stop.

If there is an easy way to do it, it's welcome...
otherwise, I must search different ways...

I can't work 1 week for a tool that can do 100000000 things that don't serve me.


But thanks for your aids!!
always they are welcome!

Share this post


Link to post
Share on other sites
TGA is the easy way - they're very standard (moreso than PNG if anything), very easy to load and save, and work with most any half decent graphics or modelling package.

Share this post


Link to post
Share on other sites
BlueChip,
Here is my BMP reader/writer C++ class: imageBmp.zip

It reads 8/24/32-bit uncompressed and 8-bit RLE compressed formats. The basic usage of this class is:

Image::Bmp bmp;
bmp.read("myImage.bmp");
int width = bmp.getWidth();
int height = bmp.getHeight();
int channelCount = bmp.getBitCount() / 8;
const char* data = bmp.getData(); // BGR order, or
data = bmp.getDataRGB(); // RGB order



In my opinion, TGA format is easier to implement than BMP.
imageTga.zip

Share this post


Link to post
Share on other sites
yeahhhhhhhhhhhhhhh!!!

yatta yatta!! as it would say Hero Nakamura >__<
:) :)

ok... my experiment works fine...

32 bit bitmap is a reality... and Dx manages it very well...


X songho
Thanks... I'll see your implementation, in order to improve my one...
and then I'll study TGA format...



Only a last question...
When I speak of BMP, people seem scared...
why? Is it a cursed format?

In my case, where I don't need of the alpha channel, but I simply need of a channel, is real better to use a TAG format? the size is the same...


Bye friends

Share this post


Link to post
Share on other sites
Quote:

typedef struct bmpPAL
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
} PAL;


you really should use


typedef struct bmpPAL
{
unsigned char b;
unsigned char g;
unsigned char r;
unsigned char a;
} PAL;


since the BMP format is backwards. bmp format is ok for windows. but if you are using windows and dx i would switch to dds.

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueChip
Only a last question...
When I speak of BMP, people seem scared...
why? Is it a cursed format?

Because BMP is a container format that is very versatile, and consequently potentially difficult to use properly.

For example:
  • It handles lots of bit depths (1, 4, 8, 15, 16, 24, 32, and 64) yet many libraries only handle a few of those.
  • It supports multiple bit planes (although support for them in Windows GDI is deprecated.) I know I'm not the only one here old enough to remember keeping data in sync between bit planes, and the shouts of joy when VGA had a chained mode (with fewer features) that managed the bit planes for you.
  • It supports (and sometimes requires) scanline lengths that are different than the length of the data being stored.
  • It handles top-down images that most libraries support, but also bottom-up images that are often not handled correctly.
  • It can use big-endian and little-endian numbers, but most Windows programmers have only lived on little-endian systems.
  • The latest editions support (at least) seven different compression types, which precludes naive implementations from taking advantage of the full range of compression.
  • It supports dimensionless and physically-sized image formats.
  • It supports gamma correction, color profiles, and colormetric information.


That's an awful lot for programmers to handle properly unless they really understand it.

So rather than understand it, they take the simple approach of only using 24BPP uncompressed, un-color-corrected, fixed dimension regular images. So naturally these images are quite large, and so considered unfit for regular use.

People often don't realize that BMP (remember it is a container) can contain both JPG and PNG images -- including the lossless variety -- and has supported both of them since Win98.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this