-
Programming help
ok before you flame me please understand I know nothing about C++ so bare with me. I have a program that converts bitmaps into .map files for the use in game textures. I need to create a program that does the exact same thing but backwards. I need it to convert the .maps back into bmps. I have this program code but I don't know what changes need to be made to it to make it work with the types of .maps the game uses. How do you find out the specs of the .map file without asking the game creator, which I have received no responses from them. Here is the code.
//Program for reading Battlezone .map and converting it to a bitmap
//include libraries
#include <stdio.h> //standered input/output
#include <alloc.h> //memory functions
#include <string.h> //string functions
#include <stdlib.h> //exit function
#include "map2bmp.h"
//define variables used in program
DIVMAPHEADER header;
RGBTRIP palette[256];
RANGE range[16];
short int no_points;
CPOINTS *points = NULL;
char *graphic = NULL;
BITMAPFILEHEADER bitHeader;
BITMAPINFOHEADER bitInfo;
RGBQUAD bitPalette[256];
BYTE end; //a blank variable used to pad out scanlines
short int EndofLine = 0;
short int EndofFile = 1;
int temp_ctr;
void main( int argc, char *argv[] )
{
FILE *map_file; //pointer to a file
if(argc<3)
{
fprintf( stdout, "\nUsage is map2bmp <mapname.map> <bitmapname.bmp>.\n");
exit(0);
};
//open map_name for binary reading
if( (map_file = fopen(argv[1], "rb")) == 0 )
{
//if map_file is zero file wasn't opened
fprintf( stdout, "\nERROR: Could not open file\n");
exit(0);
}
//file is open now read into the header
fread( &header, sizeof( DIVMAPHEADER ), 1, map_file);
//check if map is valid
if( strcmp( header.head, "map\x1a\x0d\x0a" ) != 0)
{
//not a valid map
fprintf( stdout,"\nERROR: File is not a valid map");
fclose( map_file ); //close the file
exit(0); //exit program
}
//otherwise read in palette and range
fread( palette, sizeof(RGBTRIP), 256, map_file );
fread( range, sizeof(RANGE), 16, map_file);
//read in the number of control points
fread( &no_points, sizeof(short int), 1, map_file);
if(no_points!=0)
{
// if there are control points allocate memory and read them in
points = (CPOINTS *) malloc( no_points * sizeof(CPOINTS) );
if(points == NULL) //then no memory was assigned
{
fprintf( stdout, "\nERROR: Could not assign memory.");
fclose( map_file );
exit(0);
};
//otherwise read in the points from file
fread( points, sizeof( CPOINTS ), no_points, map_file );
};
//now to read the graphic
//first allocate memory to read the graphic into
graphic = (char *) malloc( header.height*header.width );
if(graphic == NULL)
{
//no memory assigned
fprintf(stdout, "\nERROR: Could not assign memory.");
if( points != NULL)
{
free( points );
};
fclose( map_file );
exit(0);
};
fread( graphic, sizeof( char ), header.height*header.width, map_file );
//and thats the map file read
//file is no longer needed so close it
fclose( map_file );
/*
//Display some information about the map that was read
printf( "\nDESCRIPTION:\t %s", header.description );
printf( "\nDIMENSI0N:\t %dx%d",header.width, header.height );
printf( "\nGRAPHIC CODE:\t %d", header.code);
printf( "\nNO. POINTS:\t %d", no_points);
printf( "\nPress ENTER");
fflush( stdin );
getchar();
*/
//fill in the BITMAPFILEHEADER
bitHeader.bfType = 19778; //BM
bitHeader.bfSize = 256 + 65536 + 256 + header.height*header.width;
bitHeader.bfReserved1 = 0;
bitHeader.bfReserved2 = 0;
bitHeader.bfOffBits = 256 + 65536 + 256;
//fill in the BITMAPIFOHEADER
bitInfo.biSize = sizeof( BITMAPINFOHEADER );
bitInfo.biWidth = header.width;
bitInfo.biHeight = header.height;
bitInfo.biPlanes = 1;
bitInfo.biBitCount = 8;
bitInfo.biCompression = BI_RGB;
bitInfo.biXPelsPerMeter = 0;
bitInfo.biYPelsPerMeter = 0;
bitInfo.biClrUsed = 256;
bitInfo.biClrImportant = 0;
//create the palette
for( temp_ctr=0; temp_ctr<256; temp_ctr++)
{
bitPalette[temp_ctr].rgbBlue = palette[temp_ctr].b*4;
bitPalette[temp_ctr].rgbGreen = palette[temp_ctr].g*4;
bitPalette[temp_ctr].rgbRed = palette[temp_ctr].r*4;
bitPalette[temp_ctr].rgbReserved = 0;
};
//open myfirst.bmp for binary writing
if( (map_file = fopen(argv[2], "wb")) == 0 )
{
//if map_file is zero file wasn't opened
fprintf( stdout, "\nERROR: Could not open file\n");
if( points!=NULL)
free( points );
if( graphic!=NULL)
free( graphic );
exit(0);
}
//now write the bitmap to the file
fwrite( &bitHeader, sizeof(BITMAPFILEHEADER), 1, map_file );
fwrite( &bitInfo, sizeof(BITMAPINFOHEADER), 1, map_file );
fwrite( bitPalette, sizeof(RGBQUAD), 256, map_file);
//write the graphic line by line starting at the bottom
for( temp_ctr=0; temp_ctr<header.height; temp_ctr++)
{
//write a scanline
fwrite( (graphic + ((header.height-1-temp_ctr)*header.width) ), sizeof( char), bitInfo.biWidth, map_file);
if( (bitInfo.biWidth%2)!=0)
{
fwrite( &end, sizeof(char), 1, map_file); //make sure scanline is word aligned
};
};
fclose( map_file );
//tidy up program and exit
if( points!=NULL)
free( points );
if( graphic!=NULL)
free( graphic );
fprintf( stdout, "\nMap2bmp successful\n");
};
and this is the 2nd part of the code
#ifndef DIVMAPTOBITMAP
#define DIVMAPTOBITMAP
#define BI_RGB 0
#define BI_RLE8 2
//typedef unsigned int UINT;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned char BYTE;
//define structures needed in the program
//definition of bitmap structures
typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType; //specifies the file type must be BM or 19778
DWORD bfSize; //size of file in bytes
WORD bfReserved1; //reserved must be zero
WORD bfReserved2; //reserved must be zero
DWORD bfOffBits; //offset from this struct to the graphic/bitmap data
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize; //size of this structure in bytes
int biWidth; //width of the bitmap
int biHeight; //height of the bitmap
WORD biPlanes; //Number of planes for target device. set to 1.
WORD biBitCount; //number of bits per pixel 8 for 256 colours
DWORD biCompression; //compression type BI_RGB==uncompressed
DWORD biSizeImage; //size of image, set to 0 if image is uncompressed
int biXPelsPerMeter;
int biYPelsPerMeter;
DWORD biClrUsed; //colours used
DWORD biClrImportant; //important colours
} BITMAPINFOHEADER;
typedef struct tagRGBQUAD { // rgbq
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
//definition of div map header
typedef struct _DIVMAPHEADER
{
char head[8] ; //used to identify the map "fpg\x1a\x0d\x0a"
short int width; //the width of the map
short int height; //the hieght of the map
int code; //the code of the graphic used for fpg
char description[32];//A description of the map
}DIVMAPHEADER;
typedef struct _RGBTRIP
{
BYTE r;
BYTE g;
BYTE b;
}RGBTRIP;
typedef struct _RANGE
{
char num_colours; //number of colours in range 8,16 or 32
char type; //type fo rnage i.e editable every n colours
char fixed; //0=no 1=yes is range fixed
char black; //the black colour
char colours[32]; //the colours in the range
}RANGE;
typedef struct _CPOINTS
{
short int x;
short int y;
}CPOINTS;
#endif
here is the link to the original bmp2map proggie if anyone wants to help me ... Thanks for any assistance you can give me
bmp2map
Scott
-
Just because
A couple of points:- Don't use void main() to start off your program.
- If no-one's willing to tell you the specs for a MAP file, it's pretty much up to trial and error.
- Use code tags. A message about them is located on top of the forum.
-
Hey thanks. What C++ program is the best out there to work with. I have an old version of Borland C++ 4.52 but it not very good.
-
-
Originally posted by 7stud
MS Visual C++ 6
not necessarily. I haven't used it personally, but I hear that it is not that great of a compiler when it comes to standards.
I would recommend you upgrade your compiler to a newer compiler. mingw 3.2 and borland 5.5 are two fairly popular free compilers.
As for your IDE, Dev-C++ is liked by many. A lot of people will recommend v4, instead of the 5 beta. I don't really use either, I use Quincy
But you should upgrade from 4.52.
Popular pages
Recent additions