First commit 16/09/1994
This commit is contained in:
146
BGI/QUA.C
Normal file
146
BGI/QUA.C
Normal file
@ -0,0 +1,146 @@
|
||||
/* Ejemplo de displayado de TGA tipo 2 en SVGA 640*480*256
|
||||
Autor: Juan Ramon Lehmann
|
||||
14-09-1994 (c)
|
||||
No olvidar compilar en modo large
|
||||
y a<>adir libreria de graficos */
|
||||
|
||||
#include "graphics.h"
|
||||
#include "stdlib.h"
|
||||
#include "alloc.h"
|
||||
#include "math.h"
|
||||
#include "dos.h"
|
||||
#include "conio.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "search.h"
|
||||
#include "math.h"
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned int WORD;
|
||||
|
||||
void InitGrafico(void);
|
||||
int huge DetectSVGA(void);
|
||||
|
||||
struct Triplete {
|
||||
BYTE Red;
|
||||
BYTE Green;
|
||||
BYTE Blue;
|
||||
} *MiTriplete;
|
||||
|
||||
struct {
|
||||
BYTE bIDFieldSize;
|
||||
BYTE bColorMapType;
|
||||
BYTE bImageType;
|
||||
BYTE ClrMapSpec[5];
|
||||
WORD wXOrigin;
|
||||
WORD wYOrigin;
|
||||
WORD wWidth;
|
||||
WORD wHeight;
|
||||
BYTE bBitsPerPixel;
|
||||
BYTE bImageDesc;
|
||||
} stTarga24Header = {
|
||||
0,0,2,
|
||||
0,0,0,0,0,
|
||||
0,0,0,0,
|
||||
24,
|
||||
0
|
||||
};
|
||||
|
||||
int pal_index(unsigned char *p);
|
||||
void lee(FILE *uno,double gam); /* funci<63>n que leer<65> la 1<> vez el TGA */
|
||||
|
||||
// Para las llamadas a las interrupciones
|
||||
union REGS regset;
|
||||
struct SREGS sregset;
|
||||
FILE *in;
|
||||
|
||||
int main(int argv,char *argc[])
|
||||
{
|
||||
register n;
|
||||
static BYTE RGBLineBuffer[1024*3];
|
||||
int wLineCount,i,x,y;
|
||||
static double gamma;
|
||||
static BYTE pixel;
|
||||
char *name,*endptr;
|
||||
WORD wHeight,wWidth;
|
||||
|
||||
if (argv<2)
|
||||
{
|
||||
printf("Error, la sintaxis es demo.exe <filename> <gamma factor>\n");
|
||||
printf("filename= TGA tipo 2\n");
|
||||
printf("gamma factor= Factor de correcci<63>n, se aconseja 0.2\n\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
name=argc[1]; // nombre del fichero
|
||||
gamma=strtod(argc[2],&endptr);
|
||||
|
||||
InitGrafico();
|
||||
|
||||
if ((in=fopen(name,"rb"))==NULL)
|
||||
{
|
||||
perror("Error al abrir el fichero TGA");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fread(&stTarga24Header, sizeof(stTarga24Header),1, in); // leo cabecera
|
||||
lee(in,gamma); /* Lee TGA la primera vez */
|
||||
|
||||
// aqui ya est<73> la quantizaci<63>n
|
||||
|
||||
fseek(in, 0L, SEEK_SET); // dejo el fichero al principio
|
||||
fread(&stTarga24Header, sizeof(stTarga24Header),1, in); // leo cabecera
|
||||
|
||||
wHeight=stTarga24Header.wHeight;
|
||||
wWidth=stTarga24Header.wWidth; // longitud grafico
|
||||
|
||||
y=320;
|
||||
x=0;
|
||||
|
||||
for(wLineCount=0;wLineCount<=wHeight-1;wLineCount++)
|
||||
{
|
||||
fread(&RGBLineBuffer,wWidth*3,1,in); //wWidth*3 ---> 320
|
||||
|
||||
i=0;
|
||||
while (i<=wWidth*3)
|
||||
{
|
||||
/* como los valores est<73>n a la inversa....:-) */
|
||||
|
||||
MiTriplete->Blue=RGBLineBuffer[i++];
|
||||
MiTriplete->Green=RGBLineBuffer[i++];
|
||||
MiTriplete->Red=RGBLineBuffer[i++];
|
||||
|
||||
pixel=pal_index(MiTriplete);
|
||||
putpixel(x++,y,pixel);
|
||||
}
|
||||
x=0;
|
||||
y--;
|
||||
}
|
||||
getch();
|
||||
closegraph(); /* desactiva modo grafico */
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void InitGrafico(void)
|
||||
{
|
||||
int gdriver = DETECT, gmode=0, errorcode;
|
||||
installuserdriver("Svga256",DetectSVGA);
|
||||
initgraph(&gdriver,&gmode, "");
|
||||
errorcode = graphresult();
|
||||
if (errorcode != grOk)
|
||||
{
|
||||
printf("Error de gr<67>ficos: %s\n", grapherrormsg(errorcode));
|
||||
printf("Pulse una tecla para salir:");
|
||||
getch();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int huge DetectSVGA(void)
|
||||
{
|
||||
return(2); /* 2=SVGA 640*480*256 0=320*200*256*/
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user