Saving a picture and loading it back works, but there are struct misalignment problems, asved file will NOT be compatible with other tools

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@91 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2008-08-02 15:38:00 +00:00
parent aaf7bc09fa
commit 3bf7246855
5 changed files with 51 additions and 24 deletions

View File

@ -612,7 +612,13 @@ byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne)
void Palette_256_to_64(T_Palette Palette) void Palette_256_to_64(T_Palette Palette)
{ {
UNIMPLEMENTED int i;
for(i=0;i<256;i++)
{
Palette[i].R = Palette[i].B >> 2;
Palette[i].V = Palette[i].V >> 2;
Palette[i].B = Palette[i].R >> 2;
}
} }
void Palette_64_to_256(T_Palette Palette) void Palette_64_to_256(T_Palette Palette)

View File

@ -71,10 +71,10 @@ int Fichier_existe(char * Fichier)
// Dtermine si un fichier pass en paramŠtre existe ou non dans le // Dtermine si un fichier pass en paramŠtre existe ou non dans le
// rpertoire courant. // rpertoire courant.
{ {
struct stat* buf = NULL; struct stat buf;
int Resultat; int Resultat;
Resultat=stat(Fichier,buf); Resultat=stat(Fichier,&buf);
if (Resultat!=0) if (Resultat!=0)
return(errno!=ENOENT); return(errno!=ENOENT);
else else

BIN
gfx2.cfg

Binary file not shown.

View File

@ -1,5 +1,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h>
void _splitpath(char* Buffer, char* Chemin, char* Nom_Fichier) void _splitpath(char* Buffer, char* Chemin, char* Nom_Fichier)
{ {
@ -19,8 +20,9 @@ void _splitpath(char* Buffer, char* Chemin, char* Nom_Fichier)
int filelength(int fichier) int filelength(int fichier)
{ {
printf("filelenght non implémenté!\n"); struct stat infos_fichier;
return 0; fstat(fichier,&infos_fichier);
return infos_fichier.st_size;
} }
void itoa(int source,char* dest, int longueur) void itoa(int source,char* dest, int longueur)

View File

@ -19,7 +19,16 @@
#include "erreurs.h" #include "erreurs.h"
#ifdef __linux__ #ifdef __linux__
#include <endian.h>
#include <byteswap.h>
#include "linux.h" #include "linux.h"
#if __BYTE_ORDER == __BIG_ENDIAN
#define endian_magic(x) bswap_16(x)
#else
#define endian_magic(x) bswap_16(x)
#endif
#elif __WATCOMC__
#define endian_magic(x) (x)
#endif #endif
// Chargement des pixels dans l'écran principal // Chargement des pixels dans l'écran principal
@ -962,7 +971,7 @@ void Load_PKM(void)
dword Taille_image; dword Taille_image;
dword Taille_pack; dword Taille_pack;
long Taille_du_fichier; long Taille_du_fichier;
struct stat* Informations_Fichier=NULL; struct stat Informations_Fichier;
Nom_fichier_complet(Nom_du_fichier,0); Nom_fichier_complet(Nom_du_fichier,0);
@ -971,8 +980,8 @@ void Load_PKM(void)
if ((Fichier=open(Nom_du_fichier,O_RDONLY))!=-1) if ((Fichier=open(Nom_du_fichier,O_RDONLY))!=-1)
{ {
stat(Nom_du_fichier,Informations_Fichier); stat(Nom_du_fichier,&Informations_Fichier);
Taille_du_fichier=Informations_Fichier->st_size; Taille_du_fichier=Informations_Fichier.st_size;
if (read(Fichier,&Head,sizeof(struct Header))==sizeof(struct Header)) if (read(Fichier,&Head,sizeof(struct Header))==sizeof(struct Header))
{ {
@ -1082,7 +1091,7 @@ void Load_PKM(void)
Compteur_de_donnees_packees=0; Compteur_de_donnees_packees=0;
Compteur_de_pixels=0; Compteur_de_pixels=0;
Taille_pack=(Informations_Fichier->st_size)-sizeof(struct Header)-Head.Jump; Taille_pack=(Informations_Fichier.st_size)-sizeof(struct Header)-Head.Jump;
// Boucle de décompression: // Boucle de décompression:
while ( (Compteur_de_pixels<Taille_image) && (Compteur_de_donnees_packees<Taille_pack) && (!Erreur_fichier) ) while ( (Compteur_de_pixels<Taille_image) && (Compteur_de_donnees_packees<Taille_pack) && (!Erreur_fichier) )
@ -2670,12 +2679,12 @@ void Load_GIF(void)
char Nom_du_fichier[256]; char Nom_du_fichier[256];
char Signature[6]; char Signature[6];
word * Alphabet_Pile; // Pile de décodage d'une chaŒne word * Alphabet_Pile; // Pile de décodage d'une chaîne
word * Alphabet_Prefixe; // Table des préfixes des codes word * Alphabet_Prefixe; // Table des préfixes des codes
word * Alphabet_Suffixe; // Table des suffixes des codes word * Alphabet_Suffixe; // Table des suffixes des codes
word Alphabet_Free; // Position libre dans l'alphabet word Alphabet_Free; // Position libre dans l'alphabet
word Alphabet_Max; // Nombre d'entrées possibles dans l'alphabet word Alphabet_Max; // Nombre d'entrées possibles dans l'alphabet
word Alphabet_Pos_pile; // Position dans la pile de décodage d'un chaŒne word Alphabet_Pos_pile; // Position dans la pile de décodage d'un chaîne
struct Type_LSDB struct Type_LSDB
{ {
@ -2688,8 +2697,8 @@ void Load_GIF(void)
struct Type_IDB struct Type_IDB
{ {
word Pos_X; // Abscisse o— devrait ˆtre affichée l'image word Pos_X; // Abscisse où devrait être affichée l'image
word Pos_Y; // Ordonnée o— devrait ˆtre affichée l'image word Pos_Y; // Ordonnée où devrait être affichée l'image
word Largeur_image; // Largeur de l'image word Largeur_image; // Largeur de l'image
word Hauteur_image; // Hauteur de l'image word Hauteur_image; // Hauteur de l'image
byte Indicateur; // Informations diverses sur l'image byte Indicateur; // Informations diverses sur l'image
@ -2736,12 +2745,17 @@ void Load_GIF(void)
Alphabet_Prefixe=(word *)malloc(4096*sizeof(word)); Alphabet_Prefixe=(word *)malloc(4096*sizeof(word));
Alphabet_Suffixe=(word *)malloc(4096*sizeof(word)); Alphabet_Suffixe=(word *)malloc(4096*sizeof(word));
if (read(GIF_Fichier,&LSDB,sizeof(struct Type_LSDB))==sizeof(struct Type_LSDB)) if (read(GIF_Fichier,&(LSDB.Largeur),sizeof(word))==sizeof(word)
&& read(GIF_Fichier,&(LSDB.Hauteur),sizeof(word))==sizeof(word)
&& read(GIF_Fichier,&(LSDB.Resol),sizeof(byte))==sizeof(byte)
&& read(GIF_Fichier,&(LSDB.Backcol),sizeof(byte))==sizeof(byte)
&& read(GIF_Fichier,&(LSDB.Aspect),sizeof(byte))==sizeof(byte)
)
{ {
// Lecture du Logical Screen Descriptor Block réussie: // Lecture du Logical Screen Descriptor Block réussie:
Ecran_original_X=LSDB.Largeur; Ecran_original_X=endian_magic(LSDB.Largeur);
Ecran_original_Y=LSDB.Hauteur; Ecran_original_Y=endian_magic(LSDB.Hauteur);
// Palette globale dispo = (LSDB.Resol and $80) // Palette globale dispo = (LSDB.Resol and $80)
// Profondeur de couleur =((LSDB.Resol and $70) shr 4)+1 // Profondeur de couleur =((LSDB.Resol and $70) shr 4)+1
@ -2760,7 +2774,7 @@ void Load_GIF(void)
{ {
// Palette globale dispo: // Palette globale dispo:
// On commence par passer la palette en 256 comme a, si la // On commence par passer la palette en 256 comme ça, si la
// nouvelle palette a moins de 256 coul, la précédente ne souffrira // nouvelle palette a moins de 256 coul, la précédente ne souffrira
// pas d'un assombrissement préjudiciable. // pas d'un assombrissement préjudiciable.
if (Config.Clear_palette) if (Config.Clear_palette)
@ -2787,7 +2801,7 @@ void Load_GIF(void)
Set_palette(Principal_Palette); Set_palette(Principal_Palette);
} }
// On s'apprˆte à sauter tous les blocks d'extension: // On s'apprête à sauter tous les blocks d'extension:
// On lit un indicateur de block // On lit un indicateur de block
read(GIF_Fichier,&Block_indicateur,1); read(GIF_Fichier,&Block_indicateur,1);
@ -2797,8 +2811,8 @@ void Load_GIF(void)
// Lecture du code de fonction: // Lecture du code de fonction:
read(GIF_Fichier,&Block_indicateur,1); read(GIF_Fichier,&Block_indicateur,1);
// On exploitera peut-ˆtre un jour ce code indicateur pour stocker // On exploitera peut-être un jour ce code indicateur pour stocker
// des remarques dans le fichier. En attendant d'en connaŒtre plus // des remarques dans le fichier. En attendant d'en connaître plus
// on se contente de sauter tous les blocs d'extension: // on se contente de sauter tous les blocs d'extension:
// Lecture de la taille du bloc: // Lecture de la taille du bloc:
@ -2821,13 +2835,18 @@ void Load_GIF(void)
// Présence d'un Image Separator Header // Présence d'un Image Separator Header
// lecture de 10 derniers octets // lecture de 10 derniers octets
if ( (read(GIF_Fichier,&IDB,sizeof(struct Type_IDB))==sizeof(struct Type_IDB)) if ( (read(GIF_Fichier,&(IDB.Pos_X),sizeof(word))==sizeof(word))
&& (read(GIF_Fichier,&(IDB.Pos_Y),sizeof(word))==sizeof(word))
&& (read(GIF_Fichier,&(IDB.Largeur_image),sizeof(word))==sizeof(word))
&& (read(GIF_Fichier,&(IDB.Hauteur_image),sizeof(word))==sizeof(word))
&& (read(GIF_Fichier,&(IDB.Indicateur),sizeof(byte))==sizeof(byte))
&& (read(GIF_Fichier,&(IDB.Nb_bits_pixel),sizeof(byte))==sizeof(byte))
&& IDB.Largeur_image && IDB.Hauteur_image) && IDB.Largeur_image && IDB.Hauteur_image)
{ {
Principal_Largeur_image=IDB.Largeur_image; Principal_Largeur_image=endian_magic(IDB.Largeur_image);
Principal_Hauteur_image=IDB.Hauteur_image; Principal_Hauteur_image=endian_magic(IDB.Hauteur_image);
Initialiser_preview(IDB.Largeur_image,IDB.Hauteur_image,Taille_du_fichier,FORMAT_GIF); Initialiser_preview(endian_magic(IDB.Largeur_image),endian_magic(IDB.Hauteur_image),Taille_du_fichier,FORMAT_GIF);
// Palette locale dispo = (IDB.Indicateur and $80) // Palette locale dispo = (IDB.Indicateur and $80)
// Image entrelacée = (IDB.Indicateur and $40) // Image entrelacée = (IDB.Indicateur and $40)