how to display 256 color bmp files in trubo c++ 3.0??? i ve already displayed a 16 color bitmap in turbo c++...
i came across this code but it doesnt work...pls tell me whts the error...
#include<iostream.h>
#include<graphics.h>
#include<fstream.h>
#include<conio.h>
struct A{
char type[2]; /* Magic identifier */
unsigned long size; /* File size in bytes */
unsigned short int reserved1, reserved2;
unsigned long offset; /* Offset to image data, bytes */
}HEADER,HEADER1;
struct B{
unsigned long size; /* Header size in bytes */
unsigned long width,height; /* Width and height of image */
unsigned short int planes; /* Number of colour planes */
unsigned short int bits; /* Bits per pixel */
unsigned long compression; /* Compression type */
unsigned long imagesize; /* Image size in bytes */
unsigned long xresolution,yresolution; /* Pixels per meter */
unsigned long ncolours; /* Number of colours */
unsigned long importantcolours; /* Important colours */
}INFOHEADER,INFOHEADER1;
huge DetectSvga()
{
return 2;
}
void Show()
{
fstream File;
File.open("c:\\tc\\bin\\tet.bmp",ios::in);
char Ch;
File.read((char*)&HEADER,14); //This is the header part of the Bitmap.
File.read((char*)&INFOHEADER,40); //This is another part of the bitmap
unsigned int i;
char ColorBytes[4];
char*PaletteData;
PaletteData=new char[256*3];
if(PaletteData)//if memory allocated successfully
{
//read color data
for(i=0;i<256;i++)
{
//pls xplain wht this part does..i don understand it fully
File.read(ColorBytes,4);
PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2;
PaletteData[(int)(i*3+1)]=ColorBytes[1]>>2;
PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2;
}
outp(0x03c8,0); //tell DAC that data is coming
for(i=0;i<256*3;i++) //send data to SVGA DAC
{
outp(0x03c9,PaletteData[i]);
}
delete[]PaletteData;
}
for(i=0;i<INFOHEADER.height;i++) //This for loop is used to display the bitmap.
{
for(int j=0;j<INFOHEADER.width;)
{
File.read(&Ch,1); // Here Ch reads the color of your bitmap.
putpixel(0+(j++),0+INFOHEADER.height-i-1,Ch);
}
}
File.close();
}
void Show1()
{
char Ch;
fstream File;
File.open("c:\\tc\\bin\\ab.bmp",ios::in);
File.seekg(54,ios::beg);
File.seekg(256*4,ios::cur);
for(int i=0;i<214;i++)
{
for(int j=0;j<356;j++)
{
File.read(&Ch,1); //Here Ch is the character which reads the color of your bitmap.
putpixel(10+j,10+39+i,Ch);
}
}
}
void main()
{
clrscr();
int gd = DETECT, md, a;
initgraph(&gd,&md,"c:\\tc\\bgi"); //Path may be different in your computer.
installuserdriver("svga256",&DetectSvga);
Show();
getch();
setcolor(BLACK);
setfillstyle(1,0);
bar(0,0,640,480);//clears the screen..cant use clrscr() as den myscreen turns grey
Show1();
getch();
}
PS-
1. i have svga256.bgi in c:\\tc\\bgi...do i need sum other files??
2. this is to be used in my skool project...n i asked my teacher n she said u cant use allegero,fastgraph or ne other compiler...i HAVE to use turbo c++ onli<sigh>
3."ab.bmp"(file i m trying to open) is attached with this msg
4.when i try to run the code...if i use show(),i get a completely destroyed form of the pic...its worse thn wht i get by displaying 16 colors... if i use show1(),i get the same output but this tym its inverted also...pls help!!!!!!!!!