296 lines
10 KiB
C++
296 lines
10 KiB
C++
|
||
#include <stdio.h>
|
||
#include <conio.h>
|
||
#include <graphics.h>
|
||
|
||
#define OK 0
|
||
#define ERROR 1
|
||
|
||
//#define RES_X 320
|
||
//#define RES_Y 200
|
||
#define RES_X 273+1
|
||
#define RES_Y 411
|
||
|
||
typedef unsigned char DacPalette256[256][3];
|
||
DacPalette256 Palette256;
|
||
|
||
int CargaPaleta(char *file );
|
||
|
||
unsigned char Movs[73][71][3];
|
||
|
||
int MuestraImagen( char *file );
|
||
void ProcesaPunto( int x, int y, char byte );
|
||
void Mem2CPP(void);
|
||
FILE *out1,*out2,*out3,*out4;
|
||
|
||
void main( int argc, char *argv[] )
|
||
{
|
||
int gd=DETECT, gm, errorcode;
|
||
int i, j, k;
|
||
|
||
// initgraph( &gd, &gm, "c:\\program\\borlandc\\bgi" );
|
||
errorcode = graphresult();
|
||
|
||
if (errorcode != grOk) /* an error occurred */
|
||
{
|
||
printf("Graphics error: %s\n", grapherrormsg(errorcode));
|
||
printf("Press any key to halt:");
|
||
getch();
|
||
return;
|
||
}
|
||
if ( (out1=fopen("foto1.txt", "wt" ) ) != NULL )
|
||
if ( (out2=fopen("foto2.txt", "wt" ) ) != NULL )
|
||
if ( (out3=fopen("foto3.txt", "wt" ) ) != NULL )
|
||
if ( (out4=fopen("foto4.txt", "wt" ) ) != NULL )
|
||
{
|
||
|
||
MuestraImagen( "D:\\JD2bin.pcx"/*argv[1]*/ );
|
||
// CargaPaleta( argv[1] );
|
||
fclose(out1);
|
||
fclose(out2);
|
||
fclose(out3);
|
||
fclose(out4);
|
||
// getch();
|
||
}
|
||
// Mem2CPP();
|
||
|
||
// closegraph();
|
||
}
|
||
|
||
void Mem2CPP(void)
|
||
{
|
||
FILE *out;
|
||
int i, j, k;
|
||
|
||
if ( (out=fopen("foto.txt", "wt" ) ) != NULL )
|
||
{
|
||
for ( i = 0; i < 411; i ++ )
|
||
{
|
||
for ( j = 0; j < 273; j ++ )
|
||
{
|
||
fprintf( out, "%d", (int)Movs[j][i][0] );
|
||
}
|
||
fprintf( out, "\n" );
|
||
}
|
||
/*
|
||
fprintf( out, "unsigned char Movs[23][23][3] = { \n");
|
||
for ( k = 0; k < 3; k ++ )
|
||
{
|
||
fprintf( out, " {\n");
|
||
for ( i = 0; i < 22; i++ )
|
||
{
|
||
fprintf( out, " { ");
|
||
for ( j = 0; j < 23; j++ )
|
||
fprintf( out, "%03d, ", (int)Movs[j][i][k] );
|
||
fprintf( out, " }, \n");
|
||
}
|
||
i = 22;
|
||
fprintf( out, " { ");
|
||
for ( j = 0; j < 23; j++ )
|
||
fprintf( out, "%03d, ", (int)Movs[j][i][k] );
|
||
fprintf( out, " } \n");
|
||
fprintf( out, " },\n");
|
||
}
|
||
fprintf( out, " };");
|
||
|
||
fprintf( out, "\n\n\n");
|
||
for ( i = 0; i < 256; i++ )
|
||
fprintf ( out, "{ %03d, %03d, %03d }, \n", Palette256[i][0], Palette256[i][1], Palette256[i][2] );
|
||
*/
|
||
fclose(out);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* MuestraImagen *|
|
||
|* *|
|
||
|* Descripci<63>n: *|
|
||
|* Descomprime y copia a la pagina indicada un PCX *|
|
||
|* *|
|
||
|* Entradas: nombre de la imagen *|
|
||
|* *|
|
||
|* *|
|
||
|* Salidas: OK Todo ha ido bien *|
|
||
|* ERROR Algo va mal *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
int MuestraImagen( char *file )
|
||
{
|
||
int alto, ancho, contador;
|
||
unsigned char byte;
|
||
FILE *fp;
|
||
|
||
if ( (fp = fopen( file,"rb")) != NULL )
|
||
{
|
||
// Saltamos la cabecera
|
||
fseek( fp, 128, SEEK_SET );
|
||
|
||
for(alto=0; alto<RES_Y; alto++)
|
||
{
|
||
for(ancho=0; ancho<RES_X; )
|
||
{
|
||
|
||
|
||
byte=getc(fp);
|
||
if(byte<=0xC0)
|
||
{
|
||
// set_point (ancho, alto, byte);
|
||
// ProcesaPunto( ancho, alto, byte );
|
||
// fprintf( out, "%d", (int)byte == 0 ? 0: 1 );
|
||
if ( alto <= RES_Y/2 )
|
||
{
|
||
if ( ancho < RES_X/2 )
|
||
{
|
||
fprintf( out1, "%d", (int)byte == 0 ? 0: 1 );
|
||
gotoxy( 1,1 );cprintf( " " );
|
||
} else {
|
||
fprintf( out2, "%d", (int)byte == 0 ? 0: 1 );
|
||
gotoxy( 1,1 );cprintf( "*" );
|
||
}
|
||
} else {
|
||
if ( ancho < RES_X/2 )
|
||
{
|
||
fprintf( out3, "%d", (int)byte == 0 ? 0: 1 );
|
||
gotoxy( 1,1 );cprintf( " " );
|
||
|
||
} else {
|
||
fprintf( out4, "%d", (int)byte == 0 ? 0: 1 );
|
||
gotoxy( 1,1 );cprintf( "*" );
|
||
|
||
}
|
||
}
|
||
|
||
if ( alto <= RES_Y/2 )
|
||
{
|
||
if ( ancho == RES_X/2 )
|
||
{
|
||
fprintf( out1, "\n" );
|
||
} else {
|
||
if ( ancho == RES_X - 1 )
|
||
fprintf( out2, "\n" );
|
||
}
|
||
} else {
|
||
if ( ancho == RES_X/2 )
|
||
{
|
||
fprintf( out3, "\n" );
|
||
} else {
|
||
if ( ancho == RES_X-1 )
|
||
fprintf( out4, "\n" );
|
||
}
|
||
}
|
||
ancho++;
|
||
} else {
|
||
contador=byte&0x3F; byte=getc(fp);
|
||
for(; contador>0; contador--)
|
||
{
|
||
// set_point (ancho, alto, byte);
|
||
// ProcesaPunto( ancho, alto, byte );
|
||
// fprintf( out, "%d", (int)byte );
|
||
// fprintf( out, "%d", (int)byte == 0 ? 0: 1 );
|
||
if ( alto <= RES_Y/2 )
|
||
{
|
||
if ( ancho < RES_X/2 )
|
||
{
|
||
gotoxy( 1,1 );cprintf( " " );
|
||
|
||
fprintf( out1, "%d", (int)byte == 0 ? 0: 1 );
|
||
} else {
|
||
gotoxy( 1,1 );cprintf( "*" );
|
||
|
||
fprintf( out2, "%d", (int)byte == 0 ? 0: 1 );
|
||
}
|
||
} else {
|
||
if ( ancho < RES_X/2 )
|
||
{
|
||
gotoxy( 1,1 );cprintf( " " );
|
||
|
||
fprintf( out3, "%d", (int)byte == 0 ? 0: 1 );
|
||
}else{
|
||
gotoxy( 1,1 );cprintf( "*" );
|
||
|
||
fprintf( out4, "%d", (int)byte == 0 ? 0: 1 );
|
||
}
|
||
}
|
||
|
||
if ( alto <= RES_Y/2 )
|
||
{
|
||
if ( ancho == RES_X/2 )
|
||
fprintf( out1, "\n" );
|
||
else if ( ancho == RES_X - 1 )
|
||
fprintf( out2, "\n" );
|
||
} else {
|
||
if ( ancho == RES_X/2 )
|
||
fprintf( out3, "\n" );
|
||
else if ( ancho == RES_X-1 )
|
||
fprintf( out4, "\n" );
|
||
}
|
||
ancho++;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
fclose(fp);
|
||
} else return ERROR;
|
||
|
||
return OK;
|
||
}
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* CargaPaleta *|
|
||
|* *|
|
||
|* Descripci<63>n: *|
|
||
|* Carga la paleta con los colores por defecto *|
|
||
|* *|
|
||
|* *|
|
||
|* Entradas: achivo PCX de donde cargar la paleta *|
|
||
|* *|
|
||
|* Salidas: OK Todo ha ido bien *|
|
||
|* ERROR Algo va mal *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
int CargaPaleta(char *file )
|
||
{
|
||
int index;
|
||
FILE *fp;
|
||
|
||
if ( (fp=fopen( file, "rb" ) ) == NULL )
|
||
return ERROR;
|
||
|
||
if ( fseek( fp, -768L, SEEK_END ) == 0 )
|
||
{
|
||
for (index=0; index<256; index++)
|
||
{
|
||
// get the red component
|
||
// get the green component
|
||
// get the blue component
|
||
// set components
|
||
Palette256[index][0] = getc(fp) >> 2;
|
||
Palette256[index][1] = getc(fp) >> 2;
|
||
Palette256[index][2] = getc(fp) >> 2;
|
||
} // end for index
|
||
|
||
}
|
||
|
||
|
||
fclose( fp );
|
||
return OK;
|
||
}
|
||
|
||
void ProcesaPunto( int x, int y, char byte )
|
||
{
|
||
/*
|
||
if ( x > 0 && x < 23 && y > 0 && y < 23 )
|
||
Movs[x][y][0] = byte;
|
||
if ( x > 0 + 23 && x < 23 + 23 && y > 0 && y < 23 )
|
||
Movs[x-23][y][1] = byte;
|
||
if ( x > 0 + 23*2 && x < 23 + 23*2 && y > 0 && y < 23 )
|
||
Movs[x-23*2][y][2] = byte;
|
||
*/
|
||
putpixel( x /*+ x*2*/, y /*+ y*2*/, byte );
|
||
}
|