Witam
Czy ktoś mógłby mi podpowiedzieć jak wyświetlić obrazek bmp, gif albo jpg w c lub c++ (kompilatory dosowe)
Z góry THX
proponuje ci zająć się biblioteką allegro bardzo prosto można wyświetlać bitmapy :)
Wygrzebałem w sieci :-) Wyświetla pliki BMP ale tylko 320x200 i 256 kolorów
#include <dos.h>
#include <stdio.h>
void VgaScreen ()
/This sets the display to VGA 320x200 in 256 colours/
{
asm {
mov ax, 0x13
int 0x10
}
}
void TextScreen ()
/This resets the display to text mode/
{
asm {
mov ax, 0x3
int 0x10
}
}
void SetDAC (unsigned char DAC, unsigned char R, unsigned char G,
unsigned char B)
{
/This sets a DAC register to a specific Red Green Blue-value/
outportb (0x3c8, DAC);
outportb (0x3c9, R);
outportb (0x3c9, G);
outportb (0x3c9, B);
}
void LoadBMP (char FileName)
/
This loads in the actual BMP-file and displays it.
*/
{
/BMP Header structure/
struct BMPHeader {
unsigned int bfType;
long bfSize,
bfReserved,
bfOffBits,
biSize,
biWidth,
biHeight;
unsigned int biPlanes,
biBitCount;
long biCompression,
biSizeImage,
biXPelsPerMeter,
biYPelsPerMeter,
biClrUsed,
biClrImportant;
} Header;
/File handle/
FILE *BMPFile;
/Required for palette/
unsigned char c, Palette[256][4];
/USed for loading into video memory/
unsigned int offset, lines;
/Set up a pointer to the vga memory at A000:0000/
char far *screen; screen = MK_FP (0xA000,0);
/Check to see whether the file exists and can be opened/
BMPFile = fopen (FileName, "rb");
if (BMPFile == NULL) {
strcat (FileName,".BMP");
BMPFile = fopen (FileName, "rb");
if (BMPFile == NULL) {
printf ("Couldn't open file.");
return;
}
}
/Read in header information/
fread (&Header, 54, 1, BMPFile);
/Check to see whether we can display it/
if (Header.bfType != 19778 || Header.bfReserved != 0 ||
Header.biPlanes !=1) {
/Not a valid bitmap file - don't display/
fclose (BMPFile);
return;
}
if (Header.biCompression != 0) {
/Compressed file - don't display/
fclose (BMPFile);
return;
}
if (Header.biBitCount != 8) {
/Other than 8-bit colour - don't display/
fclose (BMPFile);
return;
}
if (Header.biWidth > 320 || Header.biHeight > 200) {
/Too large - don't display/
fclose (BMPFile);
return;
}
/Load in the palette/
fread (&Palette, 1024, 1, BMPFile);
for (c = 0; c < 255; c++) {
SetDAC (c, Palette[c][2] >> 2, Palette[c][1] >> 2, Palette[c][0]
2);
}
/Set appropriate position to display graphics data/
offset = (100 + (Header.biHeight >> 1)) * 320 + 160 -
(Header.biWidth >> 1);
/We've read no lines so far/
lines = 0;
/Decode and display graphics/
while (lines < Header.biHeight) {
/Read next line/
fread (&screen [offset], Header.biWidth, 1, BMPFile);
/Move up one line on the screen/
offset -= 320;
/increase amount of lines read/
lines++;
} fclose (BMPFile);
}
void main (int argcount, char *argvalue[])
{
char FileName[80];
if (argcount>1) {
strcpy (FileName,argvalue[1]);
} else { printf ("Enter filename:"); gets (FileName);
}
VgaScreen ();
LoadBMP (FileName);
getch ();
TextScreen ();
}
To samo tylko że pliki PCX:
#include <dos.h>
#include <stdio.h>
void VgaScreen ()
/This sets the display to VGA 320x200 in 256 colours/
{
asm {
mov ax, 0x13
int 0x10
}
}
void TextScreen ()
/This resets the display to text mode/
{
asm {
mov ax, 0x3
int 0x10
}
}
void SetDAC (unsigned char DAC, unsigned char R, unsigned char G,
unsigned char B)
{
/This sets a DAC register to a specific Red Green Blue-value/
outportb (0x3c8, DAC);
outportb (0x3c9, R);
outportb (0x3c9, G);
outportb (0x3c9, B);
}
void LoadPCX (char FileName)
/
This loads in the actual PCX-file and displays it.
*/
{
/PCX Header structure/
struct PCXHeader {
char Manufacturer, Version, Encoding, BitsPerPixel;
int xMin, yMin, xMax, yMax;
char Other[116];
} Header;
/File handle/
FILE *PCXFile;
/Required for decoding and palette/
unsigned char DataByte, HowMany, Palette[256][3];
int x, y, c;
/Set up a pointer to the vga memory at A000:0000/
char far *screen; screen = MK_FP (0xA000,0);
/Check to see whether the file exists and can be opened/
PCXFile = fopen (FileName, "rb");
if (PCXFile == NULL) {
strcat (FileName,".PCX");
PCXFile = fopen (FileName, "rb");
if (PCXFile == NULL) {
printf ("Couldn't open file.");
return;
}
}
/Read in header information/
fread (&Header, 128, 1, PCXFile);
/Check to see whether we can display it/
if (Header.Version != 5) {
/If other version than 5 don't display/
fclose (PCXFile);
return;
}
if (Header.xMax>319 || Header.xMin<0 || Header.yMax>200 ||
Header.yMin<0) {
/If it doesn't fit on-screen, don't display/
fclose (PCXFile);
return;
}
/Load in the palette/
fseek (PCXFile, -769, SEEK_END);
/Read in identifier/
fread (&DataByte, 1, 1, PCXFile);
if (DataByte!=12) {
/If there is no palette, don't display/
}
fread (&Palette, 768, 1, PCXFile);
for (c=0; c<255; c++) {
SetDAC (c,Palette[c][0] >> 2, Palette[c][1] >> 2, Palette[c][2]
2);
}
/Go back to start of graphic data/
fseek (PCXFile, 128, SEEK_SET);
y=Header.yMin;
x=Header.xMin;
Header.xMax++;
Header.yMax++;
/Decode and display graphics/
while (y<Header.yMax) {
/Read next byte/
fread (&DataByte, 1, 1, PCXFile);
/*Reset counter*/
HowMany=1;
/*If it is encoded, extract the count information and read in
the colour byte*/
if ((DataByte & 0xC0)==0xC0) {
HowMany = (DataByte & 0x3F);
fread (&DataByte, 1, 1, PCXFile);
}
/*Display it*/
for (c=1; c<=HowMany; c++) {
/Calculate on-screen offset, display Pixel and go to next
pixel/
screen[(((y << 2) + y) << 6) + x++] = DataByte;
/If End of Line reached, next line/
if (x>=Header.xMax) {
y++; x=Header.xMin;
} }
} fclose (PCXFile);
}
void main (int argcount, char *argvalue[]) {
char FileName[80];
if (argcount>1) {
strcpy (FileName,argvalue[1]);
} else { printf ("Enter filename:"); gets (FileName);
}
VgaScreen ();
LoadPCX (FileName);
getch ();
TextScreen ();
}