I got a unlogical compile error to the following piece of code to save .bmp's in RGBA format:
typedef struct tagBITMAPFILEHEADER {
Uint16 bfType;
Uint32 bfSize;
Uint16 bfReserved1;
Uint16 bfReserved2;
Uint32 bfOffBits;
} BITMAPFILEHEADER;
typedef long FXPT2DOT30;
typedef struct tagCIEXYZ {
FXPT2DOT30 ciexyzX;
FXPT2DOT30 ciexyzY;
FXPT2DOT30 ciexyzZ;
} CIEXYZ;
typedef struct tagCIEXYZTRIPLE {
CIEXYZ ciexyzRed;
CIEXYZ ciexyzGreen;
CIEXYZ ciexyzBlue;
} CIEXYZTRIPLE;
typedef struct tagBITMAPV4HEADER {
Uint32 bV4Size;
Sint32 bV4Width;
Sint32 bV4Height;
Uint16 bV4Planes;
Uint16 bV4BitCount;
Uint32 bV4V4Compression;
Uint32 bV4SizeImage;
Sint32 bV4XPelsPerMeter;
Sint32 bV4YPelsPerMeter;
Uint32 bV4ClrUsed;
Uint32 bV4ClrImportant;
Uint32 bV4RedMask;
Uint32 bV4GreenMask;
Uint32 bV4BlueMask;
Uint32 bV4AlphaMask;
Uint32 bV4CSType;
CIEXYZTRIPLE bV4Endpoints;
Uint32 bV4GammaRed;
Uint32 bV4GammaGreen;
Uint32 bV4GammaBlue;
} BITMAPV4HEADER;
BITMAPFILEHEADER bmpFileHeader;
BITMAPV4HEADER bmpV4Header;
bool SaveRGBA32BMP_RW(SDL_Surface *surf, SDL_RWops *dst, bool freedst)
{
if (!surf || !dst || surf->format->BitsPerPixel != 32)
{
if (dst && freedst)
SDL_RWclose(dst);
return false;
}
long fp_start = SDL_RWtell(dst);
// Fill the BITMAPFILEHEADER:
bmpFileHeader.bfType = 0x4D42;
// bmpFileHeader.bfMagic[0] = 'B';
// bmpFileHeader.bfMagic[1] = 'M';
bmpFileHeader.bfSize = 0;
bmpFileHeader.bfReserved1 = 0;
bmpFileHeader.bfReserved2 = 0;
bmpFileHeader.bfOffBits = 0;
// Write it:
SDL_RWwrite(dst,&bmpFileHeader,sizeof(bmpFileHeader),1);
// Fill the BITMAPV4HEADER:
bmpV4Header.bV4Size = 108; //sizeof BITMAPV4HEADER;
bmpV4Header.bV4Width = surf->w;
bmpV4Header.bV4Height = surf->h;
bmpV4Header.bV4Planes = 1;
bmpV4Header.bV4BitCount = 32;
bmpV4Header.bV4V4Compression = BI_RGB;
bmpV4Header.bV4SizeImage = surf->pitch * surf->h;
bmpV4Header.bV4XPelsPerMeter = 0;
bmpV4Header.bV4YPelsPerMeter = 0;
bmpV4Header.bV4ClrUsed = 0;
bmpV4Header.bV4ClrImportant = 0;
bmpV4Header.bV4RedMask = surf->format->Rmask; // line 198
bmpV4Header.bV4GreenMask = surf->format->Gmask;
bmpV4Header.bV4BlueMask = surf->format->Bmask;
bmpV4Header.bV4AlphaMask = surf->format->Amask;
bmpV4Header.bV4CSType = 0;
bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzX = 0;
bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzY = 0;
bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzZ = 0;
bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzX = 0;
bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzY = 0;
bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzZ = 0;
bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzX = 0;
bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzY = 0;
bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzZ = 0;
bmpV4Header.bV4GammaRed = 0;
bmpV4Header.bV4GammaGreen = 0;
bmpV4Header.bV4GammaBlue = 0;
// Write it:
SDL_RWwrite(dst,&bmpV4Header,sizeof(bmpV4Header),1);
// Get the offset:
bmpFileHeader.bfOffBits = SDL_RWtell(dst);
// Write the pixels:
SDL_RWwrite(dst,surf->pixels,bmpV4Header.bV4SizeImage,1);
// Get the file size:
bmpFileHeader.bfSize = SDL_RWtell(dst);
// Re-Write the BITMAPFILEHEADER with the new info:
SDL_RWseek(dst,fp_start,RW_SEEK_SET); // Set the file pointer back.
SDL_RWwrite(dst,&bmpFileHeader,sizeof(bmpFileHeader),1); // Write it.
SDL_RWseek(dst,fp_start+bmpFileHeader.bfSize,RW_SEEK_SET); // Set the file pointer back.
if (freedst)
SDL_RWclose(dst);
return true;
}
The error prompt:
Compiling...
rgba.cpp
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(198) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2039: 'bV4GreenMask' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2039: 'bV4BlueMask' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2039: 'bV4AlphaMask' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(202) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(202) : error C2039: 'bV4CSType' : is not a member of 'SDL_PixelFormat'
c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(212) : error C2228: left of '.bV4GammaRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(213) : error C2228: left of '.bV4GammaGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(214) : error C2228: left of '.bV4GammaBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(222) : error C2228: left of '.bV4SizeImage' must have class/struct/union type
Error executing cl.exe.
RGBA.exe - 43 error(s), 0 warning(s)
This code causes the strange compile errors:
bmpV4Header.bV4RedMask = surf->format->Rmask;
bmpV4Header.bV4GreenMask = surf->format->Gmask;
bmpV4Header.bV4BlueMask = surf->format->Bmask;
bmpV4Header.bV4AlphaMask = surf->format->Amask;
I don't get it; It says that bmpV4Header, bV4RedMask, bV4GreenMask, bV4BlueMask and bV4AlphaMask is not a member of 'SDL_PixelFormat' when I assign the bV4XXXMask members of bmpV4Header with surf->format->Xmask. When I remove the "surf->format->" before the errors disappears.
How can this be?