First commit 09/12/1994
This commit is contained in:
166
LEE_PCX.CPP
Normal file
166
LEE_PCX.CPP
Normal file
@ -0,0 +1,166 @@
|
||||
#include <dos.h> /* cabeceras que hacen que se incluyan */
|
||||
#include <alloc.h>
|
||||
#include <conio.h> /* durante el proceso de compilado */
|
||||
#include <stdio.h> /* las funciones que el programa utilize */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int leepcx(char dibujo[80]);
|
||||
int asigna_memoria_pcx(void); /* se usar<61>n en el programa. Se indica el */
|
||||
void libera_memoria_pcx(void); /* tipo de dato que devuelven y el tipo */
|
||||
int lee_dibujo_pcx(void); /* de dato/s que necesitan que se les */
|
||||
int comprueba_dibujo(void); /* pase para funcionar. */
|
||||
void descomprime_dibujo(void);
|
||||
void asigna_rgb(void);
|
||||
|
||||
extern "C" void VUELCA_PANTALLA(unsigned char *);
|
||||
|
||||
/*************************** VARIABLES GLOBALES ****************************/
|
||||
|
||||
unsigned char *dir_planos;
|
||||
unsigned char *dir_dibujo;
|
||||
char dibujo[80];
|
||||
char bits_pixel;
|
||||
char num_planos;
|
||||
int colores[16] = { 0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63 };
|
||||
int ancho;
|
||||
int alto;
|
||||
int tecla;
|
||||
FILE *handle_dibujo;
|
||||
|
||||
|
||||
/************************** COMIENZO DEL LISTADO ***************************/
|
||||
|
||||
int leepcx(char diu[80])
|
||||
{
|
||||
strcpy(dibujo, diu);
|
||||
if(asigna_memoria_pcx()==1){ /* reserva memoria al dibujo */
|
||||
if(lee_dibujo_pcx()==1) { /* lee el dibujo del disco */
|
||||
if(comprueba_dibujo()==1){ /* ve si formato es adecuado */
|
||||
descomprime_dibujo(); /* descomprime el dibujo */
|
||||
VUELCA_PANTALLA(dir_planos); /* visualiza el dibujo */
|
||||
} else {
|
||||
libera_memoria_pcx();
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
libera_memoria_pcx();
|
||||
return 0;
|
||||
}
|
||||
libera_memoria_pcx(); /* devuelve la memoria al prg*/
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
} /* vuelve al Programa */
|
||||
|
||||
int asigna_memoria_pcx(void) /* reserva memoria para cargar el dibujo */
|
||||
{
|
||||
if((dir_dibujo=(unsigned char *)farmalloc(153600))==NULL) {
|
||||
return 0;
|
||||
}
|
||||
if((dir_planos=(unsigned char *)farmalloc(153600))==NULL) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void libera_memoria_pcx(void) /* libera la memoria asignada al DOS */
|
||||
{
|
||||
farfree(dir_dibujo);
|
||||
farfree(dir_planos);
|
||||
}
|
||||
|
||||
int lee_dibujo_pcx(void)
|
||||
{
|
||||
int *dir_dibu;
|
||||
char huge *dir;
|
||||
|
||||
if((handle_dibujo=fopen(dibujo, "rb"))==NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir=(char huge *)dir_dibujo;
|
||||
while(!feof(handle_dibujo)) { *dir++=getc(handle_dibujo); }
|
||||
|
||||
if(fclose(handle_dibujo)!=NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir_dibu=(int *)dir_dibujo;
|
||||
bits_pixel=*(dir_dibujo+3);
|
||||
num_planos=*(dir_dibujo+65);
|
||||
ancho=1+(*(dir_dibu+4));
|
||||
alto =1+(*(dir_dibu+5));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int comprueba_dibujo(void)
|
||||
{
|
||||
if(*dir_dibujo!=10) {
|
||||
return 0;
|
||||
}
|
||||
if(bits_pixel!=1 || num_planos!=4) { /* comprueba que el */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(ancho>640 || alto>480) { /* comp. el tama<6D>o */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void descomprime_dibujo(void)
|
||||
{
|
||||
unsigned char huge *dir_lectura;
|
||||
unsigned char huge *dir_escritura;
|
||||
unsigned char byte;
|
||||
int columnas, filas, contador;
|
||||
|
||||
dir_lectura =dir_dibujo+128; /* inicio del dibujo comprimido */
|
||||
dir_escritura=dir_planos;
|
||||
|
||||
for(filas=alto; filas>0; filas--) {
|
||||
columnas=ancho/2;
|
||||
while(columnas>0) {
|
||||
byte=*dir_lectura++;
|
||||
if(byte<=192) { *dir_escritura++=byte; columnas--; }
|
||||
else {
|
||||
contador=byte&0x3F; byte=*dir_lectura++;
|
||||
for(; contador>0; contador--) {
|
||||
*dir_escritura++=byte; columnas--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
asigna_rgb();
|
||||
}
|
||||
|
||||
void asigna_rgb(void)
|
||||
{
|
||||
struct SREGS seg;
|
||||
union REGS ent, sal;
|
||||
int num_color, n;
|
||||
long int dir;
|
||||
unsigned char *dir_col;
|
||||
|
||||
dir_col=dir_dibujo+16; /* divide entre 4 */
|
||||
for(n=16*3; n>0; n--) { /* los colores */
|
||||
*dir_col=(*dir_col) >> 2; dir_col++;
|
||||
}
|
||||
|
||||
dir =(long)(dir_dibujo+16); /* obtiene el segmento */
|
||||
seg.es=(int) (dir >> 16); /* donde estan los colores */
|
||||
|
||||
for(n=0; n<16; n++) {
|
||||
num_color=colores[n];
|
||||
ent.h.al = 18;
|
||||
ent.h.ah = 16;
|
||||
ent.x.bx = num_color;
|
||||
ent.x.cx = 1;
|
||||
ent.x.dx = (int)dir; /* offset de los colores */
|
||||
int86x(0x10, &ent, &sal, &seg); /* funci<63>n para asignar los colores */
|
||||
dir+=3;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user