Moved two loading functions from op_c.c to loadsave.c and converted to fopen/read_bytes.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@151 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
a3f2b7c2f8
commit
ca9115aba6
104
loadsave.c
104
loadsave.c
@ -5214,3 +5214,107 @@ void Save_PC1(void)
|
||||
Erreur_fichier=1;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************
|
||||
Functions from op_c.c : load raw 24B (for testing) and load_tga (broken ? incomplete ?)
|
||||
Saving would be nice as well.
|
||||
******************************************************************************************/
|
||||
void Load_RAW_24B(int Largeur,int Hauteur,Bitmap24B Source)
|
||||
{
|
||||
FILE* Fichier;
|
||||
|
||||
Fichier=fopen("TEST.RAW","rb");
|
||||
if (read_bytes(Fichier,Source,Largeur*Hauteur*sizeof(struct Composantes))!=Largeur*Hauteur*sizeof(struct Composantes))
|
||||
exit(3);
|
||||
fclose(Fichier);
|
||||
}
|
||||
|
||||
void Load_TGA(char * nom,Bitmap24B * dest,int * larg,int * haut)
|
||||
{
|
||||
FILE* fichier;
|
||||
struct
|
||||
{
|
||||
byte Id_field_size; // Taille des donn‚es sp‚cifiques plac‚es aprŠs le header
|
||||
byte Color_map_type; // Pr‚sence d'une palette
|
||||
byte Image_type_code; // Type d'image
|
||||
word Color_map_origin; // Indice de d‚part de la palette
|
||||
word Color_map_length; // Taille de la palette
|
||||
byte Color_map_entry_size; // Palette sur 16, 24 ou 32 bits
|
||||
word X_origin; // Coordonn‚es de d‚part
|
||||
word Y_origin;
|
||||
word Width; // Largeur de l'image
|
||||
word Height; // Hauteur de l'image
|
||||
byte Pixel_size; // Pixels sur 16, 24 ou 32 bits
|
||||
byte Descriptor; // ParamŠtres divers
|
||||
} TGA_Header;
|
||||
int x,y,py,skip,t;
|
||||
byte * buffer;
|
||||
|
||||
fichier=fopen(nom,"rb");
|
||||
read_bytes(fichier,&TGA_Header,sizeof(TGA_Header));
|
||||
if (TGA_Header.Image_type_code==2)
|
||||
{
|
||||
*larg=TGA_Header.Width;
|
||||
*haut=TGA_Header.Height;
|
||||
*dest=(Bitmap24B)malloc((*larg)*(*haut)*3);
|
||||
|
||||
// On saute l'ID field
|
||||
fseek(fichier,TGA_Header.Id_field_size,SEEK_CUR);
|
||||
|
||||
// On saute la palette
|
||||
if (TGA_Header.Color_map_type==0)
|
||||
skip=0;
|
||||
else
|
||||
{
|
||||
skip=TGA_Header.Color_map_length;
|
||||
if (TGA_Header.Color_map_entry_size==16)
|
||||
skip*=2;
|
||||
else
|
||||
if (TGA_Header.Color_map_entry_size==24)
|
||||
skip*=3;
|
||||
else
|
||||
if (TGA_Header.Color_map_entry_size==32)
|
||||
skip*=4;
|
||||
}
|
||||
fseek(fichier,skip,SEEK_CUR);
|
||||
|
||||
// Lecture des pixels
|
||||
skip=(*larg);
|
||||
if (TGA_Header.Pixel_size==16)
|
||||
skip*=2;
|
||||
else
|
||||
if (TGA_Header.Pixel_size==24)
|
||||
skip*=3;
|
||||
else
|
||||
if (TGA_Header.Pixel_size==32)
|
||||
skip*=4;
|
||||
|
||||
buffer=(byte *)malloc(skip);
|
||||
for (y=0;y<(*haut);y++)
|
||||
{
|
||||
read_bytes(fichier,buffer,skip);
|
||||
|
||||
// Inversion du rouge et du bleu
|
||||
for (x=0;x<(*larg);x++)
|
||||
{
|
||||
t=buffer[(x*3)+0];
|
||||
buffer[(x*3)+0]=buffer[(x*3)+2];
|
||||
buffer[(x*3)+2]=t;
|
||||
}
|
||||
|
||||
// Prise en compte du sens d'‚criture verticale
|
||||
if (TGA_Header.Descriptor & 0x20)
|
||||
py=y;
|
||||
else
|
||||
py=(*haut)-y-1;
|
||||
|
||||
// Prise en compte de l'interleave verticale
|
||||
if (TGA_Header.Descriptor & 0xC0)
|
||||
py=((py % (*haut))*2)+(py/(*haut));
|
||||
|
||||
memcpy((*dest)+(py*(*larg)),buffer,skip);
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
fclose(fichier);
|
||||
}
|
||||
|
||||
99
op_c.c
99
op_c.c
@ -1203,102 +1203,3 @@ int Convert_bitmap_24B_to_256(Bitmap256 Dest,Bitmap24B Source,int largeur,int ha
|
||||
|
||||
|
||||
|
||||
void Load_RAW_24B(int Largeur,int Hauteur,Bitmap24B Source)
|
||||
{
|
||||
int Fichier;
|
||||
|
||||
Fichier=open("TEST.RAW",O_RDONLY|O_BINARY);
|
||||
if (read(Fichier,Source,Largeur*Hauteur*sizeof(struct Composantes))!=Largeur*Hauteur*sizeof(struct Composantes))
|
||||
exit(3);
|
||||
close(Fichier);
|
||||
}
|
||||
|
||||
void Load_TGA(char * nom,Bitmap24B * dest,int * larg,int * haut)
|
||||
{
|
||||
int fichier;
|
||||
struct
|
||||
{
|
||||
byte Id_field_size; // Taille des donn‚es sp‚cifiques plac‚es aprŠs le header
|
||||
byte Color_map_type; // Pr‚sence d'une palette
|
||||
byte Image_type_code; // Type d'image
|
||||
word Color_map_origin; // Indice de d‚part de la palette
|
||||
word Color_map_length; // Taille de la palette
|
||||
byte Color_map_entry_size; // Palette sur 16, 24 ou 32 bits
|
||||
word X_origin; // Coordonn‚es de d‚part
|
||||
word Y_origin;
|
||||
word Width; // Largeur de l'image
|
||||
word Height; // Hauteur de l'image
|
||||
byte Pixel_size; // Pixels sur 16, 24 ou 32 bits
|
||||
byte Descriptor; // ParamŠtres divers
|
||||
} TGA_Header;
|
||||
int x,y,py,skip,t;
|
||||
byte * buffer;
|
||||
|
||||
fichier=open(nom,O_RDONLY|O_BINARY);
|
||||
read(fichier,&TGA_Header,sizeof(TGA_Header));
|
||||
if (TGA_Header.Image_type_code==2)
|
||||
{
|
||||
*larg=TGA_Header.Width;
|
||||
*haut=TGA_Header.Height;
|
||||
*dest=(Bitmap24B)malloc((*larg)*(*haut)*3);
|
||||
|
||||
// On saute l'ID field
|
||||
lseek(fichier,TGA_Header.Id_field_size,SEEK_CUR);
|
||||
|
||||
// On saute la palette
|
||||
if (TGA_Header.Color_map_type==0)
|
||||
skip=0;
|
||||
else
|
||||
{
|
||||
skip=TGA_Header.Color_map_length;
|
||||
if (TGA_Header.Color_map_entry_size==16)
|
||||
skip*=2;
|
||||
else
|
||||
if (TGA_Header.Color_map_entry_size==24)
|
||||
skip*=3;
|
||||
else
|
||||
if (TGA_Header.Color_map_entry_size==32)
|
||||
skip*=4;
|
||||
}
|
||||
lseek(fichier,skip,SEEK_CUR);
|
||||
|
||||
// Lecture des pixels
|
||||
skip=(*larg);
|
||||
if (TGA_Header.Pixel_size==16)
|
||||
skip*=2;
|
||||
else
|
||||
if (TGA_Header.Pixel_size==24)
|
||||
skip*=3;
|
||||
else
|
||||
if (TGA_Header.Pixel_size==32)
|
||||
skip*=4;
|
||||
|
||||
buffer=(byte *)malloc(skip);
|
||||
for (y=0;y<(*haut);y++)
|
||||
{
|
||||
read(fichier,buffer,skip);
|
||||
|
||||
// Inversion du rouge et du bleu
|
||||
for (x=0;x<(*larg);x++)
|
||||
{
|
||||
t=buffer[(x*3)+0];
|
||||
buffer[(x*3)+0]=buffer[(x*3)+2];
|
||||
buffer[(x*3)+2]=t;
|
||||
}
|
||||
|
||||
// Prise en compte du sens d'‚criture verticale
|
||||
if (TGA_Header.Descriptor & 0x20)
|
||||
py=y;
|
||||
else
|
||||
py=(*haut)-y-1;
|
||||
|
||||
// Prise en compte de l'interleave verticale
|
||||
if (TGA_Header.Descriptor & 0xC0)
|
||||
py=((py % (*haut))*2)+(py/(*haut));
|
||||
|
||||
memcpy((*dest)+(py*(*larg)),buffer,skip);
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
close(fichier);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user