From acfe5836ced31b4cce4e38fbf4104903b1909be9 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Mon, 29 Sep 2008 23:15:08 +0000 Subject: [PATCH] Grafx2 can now read and convert gfx2.cfg from the original DOS (96.5%) format. Older .cfg files in svn were saved incorrectly: the wrong size of chunk #5 (0x0101 instead of 0xE1) made it impossible to re-read the file in gfxcfg. gfxcfg can read and save gfx2.cfg. Upward compatibility is provided: - If new chunk types are added to the format, it only needs a re-compile. Older files can be read and saved. - If new keyboard shortcuts are added (134 currently), the older files can be read and the default shortcut will be used for missing keys. Fixed many endianness cases, hopefully Fixed LBM loading : bug in ASM->C conversion of Couleur_ILBM_line() Broke PCX loading : argh! git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@176 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- Makefile | 2 +- Makefile.dep | 5 +- cfg_new/Makefile | 7 +- cfg_new/gfxcfg.c | 287 ++++++++++++++++-------- clavier.c | 12 +- const.h | 19 +- divers.c | 4 +- divers.h | 2 +- gfx2.cfg | Bin 10351 -> 10351 bytes gfx2_fra.cfg | Bin 10286 -> 10351 bytes init.c | 8 +- io.c | 118 ++++++++++ io.h | 16 ++ loadsave.c | 564 ++++++++++++++++++++++------------------------- loadsave.h | 2 +- struct.h | 10 +- 16 files changed, 635 insertions(+), 421 deletions(-) create mode 100644 io.c create mode 100644 io.h diff --git a/Makefile b/Makefile index 3c14dd1d..9030a604 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ endif .PHONY : all debug release clean depend zip CC = gcc -OBJ = main.o init.o graph.o sdlscreen.o divers.o special.o boutons.o palette.o aide.o operatio.o pages.o loadsave.o readline.o moteur.o files.o op_c.o linux.o op_asm.o readini.o saveini.o shade.o clavier.o +OBJ = main.o init.o graph.o sdlscreen.o divers.o special.o boutons.o palette.o aide.o operatio.o pages.o loadsave.o readline.o moteur.o files.o op_c.o linux.o op_asm.o readini.o saveini.o shade.o clavier.o io.o SCREEN = -D WINDOWED OBJDIR = obj/ diff --git a/Makefile.dep b/Makefile.dep index d92fe1ed..cc0506d1 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1,7 +1,7 @@ main.o: main.c const.h struct.h global.h loadsave.h graph.h divers.h \ init.h boutons.h moteur.h pages.h files.h sdlscreen.h erreurs.h \ readini.h saveini.h linux.h -init.o: init.c const.h struct.h global.h loadsave.h graph.h \ +init.o: init.c const.h struct.h global.h loadsave.h modesvdo.h graph.h \ boutons.h palette.h aide.h operatio.h divers.h erreurs.h clavier.h graph.o: graph.c sdlscreen.h struct.h const.h graph.h divers.h moteur.h \ boutons.h pages.h global.h loadsave.h erreurs.h @@ -23,7 +23,7 @@ operatio.o: operatio.c const.h struct.h global.h loadsave.h divers.h \ pages.o: pages.c global.h struct.h const.h loadsave.h pages.h graph.h \ erreurs.h linux.h loadsave.o: loadsave.c const.h struct.h global.h loadsave.h graph.h \ - divers.h pages.h op_c.h boutons.h erreurs.h linux.h + divers.h pages.h op_c.h boutons.h erreurs.h linux.h io.h readline.o: readline.c const.h struct.h global.h loadsave.h graph.h \ divers.h erreurs.h linux.h moteur.o: moteur.c const.h struct.h global.h loadsave.h graph.h divers.h \ @@ -39,3 +39,4 @@ saveini.o: saveini.c const.h global.h struct.h loadsave.h readini.h \ shade.o: shade.c global.h struct.h const.h loadsave.h graph.h moteur.h \ divers.h readline.h clavier.o: clavier.c global.h struct.h const.h loadsave.h +io.o: io.c struct.h const.h diff --git a/cfg_new/Makefile b/cfg_new/Makefile index 47450e21..315e541d 100644 --- a/cfg_new/Makefile +++ b/cfg_new/Makefile @@ -6,14 +6,17 @@ COPT = -c `sdl-config --cflags` -Wall -g LOPT = `sdl-config --libs` -lSDL_image -lSDL_gfx -g endif -gfxcfg: gfxcfg.o SFont.o ../clavier.o - gcc gfxcfg.o ../clavier.o SFont.o -o gfxcfg $(LOPT) +gfxcfg: gfxcfg.o SFont.o ../clavier.o ../io.o + gcc gfxcfg.o ../clavier.o ../io.o SFont.o -o gfxcfg $(LOPT) gfxcfg.o: gfxcfg.c SFont.h gcc -c gfxcfg.c -o gfxcfg.o $(COPT) ../clavier.o: ../clavier.c gcc -c ../clavier.c -o ../clavier.o $(COPT) + +../io.o: ../io.c + gcc -c ../io.c -o ../io.o $(COPT) SFont.o: SFont.h SFont.c gcc -c SFont.c -o SFont.o $(COPT) diff --git a/cfg_new/gfxcfg.c b/cfg_new/gfxcfg.c index 32269c8c..c17aa8aa 100644 --- a/cfg_new/gfxcfg.c +++ b/cfg_new/gfxcfg.c @@ -15,20 +15,23 @@ //mine #include "SFont.h" -typedef uint8_t byte; -typedef uint16_t word; -typedef uint32_t dword; // Modificateurs pour Touche #define MOD_SHIFT 0x1000 #define MOD_CTRL 0x2000 #define MOD_ALT 0x4000 +#include "../struct.h" #include "../clavier.h" +#include "../const.h" +#include "../io.h" + /*** Constants ***/ #define NB_MAX_OPTIONS 134 #define HAUTEUR_DEBUT_SETUP 7 #define HAUTEUR_FIN_SETUP 44 +#define Header_size sizeof(struct Config_Header) +#define Chunk_size sizeof(struct Config_Chunk) /* Colors */ #define COULEUR_SETUP 1 @@ -47,23 +50,6 @@ typedef struct{ bool Suppr; } __attribute__((__packed__)) Options; -typedef struct{ - char Signature[3]; - uint8_t Version1; - uint8_t Version2; - uint8_t Beta1; - uint8_t Beta2; -} __attribute__((__packed__)) Type_header; - -#define Header_size 7 - -typedef struct{ - uint8_t Numero; - uint16_t Taille; -} __attribute__((__packed__)) Type_chunk; - -#define Chunk_size 3 - /*** Global variables ***/ SFont_Font* MyFont; SDL_Surface* Ecran; @@ -74,6 +60,14 @@ uint16_t NB_OPTIONS; uint16_t Decalage_curseur=0; uint16_t Position_curseur=0; +byte * FichierConfig = NULL; +byte * ChunkData[CHUNK_MAX]; +struct Config_Chunk Chunk[CHUNK_MAX]; + + +uint8_t Fenetre_choix(int Largeur, int Hauteur, const char* Titre, const char* Choix, uint8_t Choix_debut, + uint8_t Couleur,uint8_t Couleur_choix); + /*** Fonctions de gestion des évènements SDL ***/ /* Attend qu'une touche soit pressée. Retourne le code touche. */ @@ -168,17 +162,104 @@ void Tout_ecrire() /*** Configuration handling functions ***/ -/* Generate the INI file from the CFG */ -bool Recreer_INI() -{ - puts("RECREER INI"); - return false; -} /* Reads the config file */ -void Interpretation_du_fichier_config() +/* returns an error message, or NULL if everything OK */ +char * Interpretation_du_fichier_config() { - puts("INTERPRETATION FICHIER CONFIG"); + + FILE* Fichier; + long int Taille_fichier; + byte Numero_chunk; + word Taille_chunk; + byte * Ptr; + int i; + + Fichier = fopen("gfx2.cfg","rb"); + if (!Fichier) + { + return "gfx2.cfg is missing! Please run the\nmain program to generate it."; + } + fseek(Fichier,0,SEEK_END); // Positionnement à la fin + Taille_fichier = ftell(Fichier); + if (!Taille_fichier) + { + fclose(Fichier); + return "gfx2.cfg is empty. Please run the main\nprogram to generate it."; + } + FichierConfig = malloc(Taille_fichier); + if (!Fichier) + { + fclose(Fichier); + return "Out of memory when reading gfx2.cfg."; + } + fseek(Fichier,0,SEEK_SET); // Positionnement au début + if (! read_bytes(Fichier, FichierConfig, Taille_fichier)) + { + fclose(Fichier); + return "Error while reading gfx2.cfg."; + } + fclose(Fichier); + + // Initialisation des "index" + for (i=0; i= CHUNK_MAX) + return "File gfx2.cfg invalid."; + + ChunkData[Numero_chunk] = Ptr; + Chunk[Numero_chunk].Taille = Taille_chunk; + printf("%d %6X %d\n", Numero_chunk, Ptr - FichierConfig, Taille_chunk); + Ptr+=Taille_chunk; + } + // Si la config contenait des touches, on les initialise: + if (Chunk[CHUNK_TOUCHES].Taille) + { + int Indice_config; + Ptr = ChunkData[CHUNK_TOUCHES]; + for (Indice_config=0; Indice_config< Chunk[CHUNK_TOUCHES].Taille / sizeof(struct Config_Infos_touche) ; Indice_config++) + { + word Numero; + word Touche; + word Touche2; + int Indice_touche; + + Numero = endian_magic16(*((word *)Ptr)); + Ptr+=2; + Touche = endian_magic16(*((word *)Ptr)); + Ptr+=2; + Touche2 = endian_magic16(*((word *)Ptr)); + Ptr+=2; + //printf("%4d %4X %4X\t", Numero, Touche, Touche2); + // Recherche de la touche qui porte ce numéro + for (Indice_touche=0; Indice_touche <= NB_OPTIONS; Indice_touche ++) + { + if (Config[Indice_touche].Numero == Numero) + { + Config[Indice_touche].Touche = Touche; + Config[Indice_touche].Touche2 = Touche2; + //printf("%4d %s\n", Indice_touche, Nom_touche(Touche)); + break; + } + } + + } + } + return NULL; } /* Defines an option */ @@ -199,8 +280,7 @@ void Definir_option(uint16_t Numero, char* Libelle, char* Explic1, char* Explic2 /* Initialize configuration */ bool Initialiser_config() { - bool Erreur = false; - FILE* Fichier_INI; + char * MessageErreur = NULL; Numero_definition_option = 0; @@ -332,12 +412,12 @@ bool Initialiser_config() "Allows you to replace all the pixels of the color pointed by the mouse with", "the fore-color or the back-color.", true,SDLK_f|MOD_SHIFT); /*Shift + F*/ - Definir_option(31,"Bézier""s curves", - "Allows you to draw Bézier""s curves.", + Definir_option(31,"Bezier""s curves", + "Allows you to draw Bezier""s curves.", "", true,SDLK_i); /*I*/ - Definir_option(32,"Bézier""s curve with 3 or 4 points", - "Allows you to choose whether you want to draw Bézier""s curves with 3 or 4", + Definir_option(32,"Bezier""s curve with 3 or 4 points", + "Allows you to choose whether you want to draw Bezier""s curves with 3 or 4", "points.", true,SDLK_i|MOD_SHIFT); /*Shift + I*/ Definir_option(33,"Empty rectangle", @@ -744,15 +824,14 @@ bool Initialiser_config() NB_OPTIONS = Numero_definition_option - 1; - Fichier_INI = fopen("gfx2.ini","r"); - if(Fichier_INI == NULL) - Erreur=Recreer_INI(); - else - fclose(Fichier_INI); + MessageErreur = Interpretation_du_fichier_config(); - if(Erreur==0) Interpretation_du_fichier_config(); - - return Erreur; + if (MessageErreur) + { + Fenetre_choix(30,10,MessageErreur,"Ok",0,0x2A,0x6F); + return 1; + } + return 0; } uint8_t Fenetre_choix(int Largeur, int Hauteur, const char* Titre, const char* Choix, uint8_t Choix_debut, @@ -842,13 +921,13 @@ void Test_duplic() uint16_t i,j; bool Pas_encore_erreur; - for(i=0;i 0) + if (Sym.sym != 0) Retour = Sym.sym; - else if (Sym.unicode > 0) - Retour = (Sym.unicode & 0x07FF) | 0x0800; + else if (Sym.scancode != 0) + { + Retour = (Sym.scancode & 0x07FF) | 0x0800; + } if (Sym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) Retour |= MOD_SHIFT; @@ -309,7 +311,7 @@ word Conversion_Touche(SDL_keysym Sym) Retour |= MOD_CTRL; if (Sym.mod & (KMOD_LALT | KMOD_RALT | KMOD_MODE)) Retour |= MOD_ALT; - return Retour; + return Retour; } const char * Nom_touche(word Touche) @@ -434,7 +436,7 @@ const char * Nom_touche(word Touche) } } // Autres touches inconnues - sprintf(Buffer+strlen(Buffer), "(%d)", Touche); + sprintf(Buffer+strlen(Buffer), "0x%X", Touche & 0x7FF); return Buffer; } diff --git a/const.h b/const.h index 4f2640c4..c556e07a 100644 --- a/const.h +++ b/const.h @@ -265,15 +265,16 @@ enum MODES_DE_SHADE enum CHUNKS_CFG { - CHUNK_TOUCHES, - CHUNK_MODES_VIDEO, - CHUNK_SHADE, - CHUNK_MASQUE, - CHUNK_STENCIL, - CHUNK_DEGRADES, - CHUNK_SMOOTH, - CHUNK_EXCLUDE_COLORS, - CHUNK_QUICK_SHADE + CHUNK_TOUCHES = 0, + CHUNK_MODES_VIDEO = 1, + CHUNK_SHADE = 2, + CHUNK_MASQUE = 3, + CHUNK_STENCIL = 4, + CHUNK_DEGRADES = 5, + CHUNK_SMOOTH = 6, + CHUNK_EXCLUDE_COLORS = 7, + CHUNK_QUICK_SHADE = 8, + CHUNK_MAX }; // Les différents types de lecteurs: diff --git a/divers.c b/divers.c index 57da6bc6..a0078117 100644 --- a/divers.c +++ b/divers.c @@ -611,14 +611,14 @@ long Freespace(byte Numero_de_lecteur) // Les images ILBM sont stockés en bitplanes donc on doit trifouiller les bits pour // en faire du chunky -byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne) +byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne, byte HBPm1) { // CL sera le rang auquel on extrait les bits de la couleur byte cl = 7 - (Pos_X & 7); int ax,bh,dx; byte bl=0; - for(dx = HBPm1;dx>0;dx--); + for(dx=HBPm1;dx>=0;dx--) { //CIL_Loop ax = (Vraie_taille_ligne * dx + Pos_X) >> 3; diff --git a/divers.h b/divers.h index 4489b502..a987fc06 100644 --- a/divers.h +++ b/divers.h @@ -107,7 +107,7 @@ byte Pixel_dans_cercle(void); byte Bit(byte Octet, byte Rang); // Extrait un bit d'un certain rang à partir d'un octet. -byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne); +byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne, byte HBPm1); // Renvoie la couleur du pixel (ILBM) en Pos_X. // Gestion du chrono dans les fileselects diff --git a/gfx2.cfg b/gfx2.cfg index 4cee6ffa739a7f6e81237a2a6f6efb49f009737f..67f5eb9b162f84837fe5d5d429663188ba40572b 100644 GIT binary patch delta 79 zcmaDK@IGKe63gZyg}=<3vlZA_Hs>oa;UYv>CO4?Rn!G@TotcG!adM&hPY|1l_2J}+ MDvvfttBWuK07L;AOaK4? delta 138 zcmaDK@IGKe5{n!IBLfoyGXo0)D+3z?I|By;Cj%D)HvLE6KVMuxxt8Gv97hya4jOrXSt&C%*2i~!zL8j%11 diff --git a/gfx2_fra.cfg b/gfx2_fra.cfg index d14370a561cbdc644c36ec830194a2b18c872a2d..7b425b84fde61a7e42a6d14db227927db57b87e3 100644 GIT binary patch literal 10351 zcmeI2>3S4J7)DQb5=hiUCW(+eJtVji1jQARi72=Wt|)?GCS)4L$wma+Xt)1;N&fUQ z@D99#@|2h1ROZQfzUQ5)Gu2v?tIQQSRQ~z7RVTvIg@gL2{}lk5g1}z?qgE! zXF?9sSPhIYE+1f0KFEZ8h(jgHfe`LdYksH{iNSRZD`dWnwpGMyrD zgpSFhbdCoeqi6m&J@Y5%nLkO-{3&)?funTg3LSZj&V|6!47tMN47tJ+Tqp1h3ntI9 zVDcLa&A{(0oCus`(fm0U&7Ws+HShw97XvTSb=FIC{j8Vi7J*ZA{lr)3t_4n0IO|mk zXPu#G{R2(w7EKMSv|EAKXuFcLwDr7BTf-Z)wVmUR$$9R|H@Pj};{`FWuJyZY zTEEAp_4_RA|9~U%0^gfoWKDj^n(uz(x&j|_%K8(=9P=ro@-y0NflJ)--Ot_Oz!!`< z<}x$B`z153_KGJWaFr4Bub4GoW7hl{bJlI^bWX?#a^g z72MHb>#v<1_=YX{6I&*~vQ-4n#FWl&nU+1K^lUOMw;0mA%|W@tl-%Wzyv4NKbB%%T zTy?NhSG3*Xvi#W{2%g0iS#jFr7gpq5&qA}SGqpFN5CuKra8C7Lem6>T7Rb^B;I6_q!Rb^C_QB_A( z9aVKyIX)Ar>Zq!ts*b8Us_Lk6aD=Kls_Lk!qpHfaRJoQa*HYzLs$4;pUyX21l`C*u zgn}wpP~{4$TtP7)yf+5&MuCR(N*zcY=+h2l=?3W2olp0E>Oky3x&hKTNFC_s4x}5P zpLah!d+I>C0n!;r9q8u{q#K~0cRxLQ>Oi^y(iun{=;sck8=#+eKRtWuK<1B%yaoFE eZ!ooB=T1jx8giNg99om4j_Uk&gFnOfzt*e)SY3uGr};! zPtl#9fjgJ}!SlS|u(F9hapP6yt<3wfb4B0r6R{?wKe5y=Q=~x{>om;i46IUrWUAI6 ztkG$>Kxg1WeW^0l>N{MduW+%x!6o__o0jS`tkZK?uNSaE`*Ca3e&#OIQFN2~;BsAr zD|7@l>oQMUlt;HJk6x)fbKBHGWtBRpwBux2tp@ZOtwXP6hB2pw$~s(41vR19tBBs9 zA`Tl>q|%{c&a_Eo>YG)jzC~r~TUDmMO--!7Qw6wPMOaj^+O$Ihj4x?`k!99y+No~1 zOCwae)PvrwE9gC%WY%6yGHV~JF!o%aen17@bx;M~a!7?5(_vM3dPJiZeG;=-gWL0QnjHYek>cd-OSd zfP?JMbe?^iE@%r+FOrApk~X1-7;75F$#hvI);U6dOjk(VG^%#SjIj^XRb4`l(_7Ou z)uXSoGvg=?p>ME1(@hPdZ|OQKzpV*)N8?oP(r42>HKP;Gi0QuS&=2UR=^;HgJz`I$ zNmgoltdl&Q(s}qqpYVCAm++b1!RMNWFEj(EIU}YS&Wq`#Rx$pS+Td$?WqL!eIN_a< zdZJ&d^hEQHzYay9&e7)RbR>?{@xw9iPz>4~U5=5slDJjkR*73BZk4!I;#P@UB@tGM zTP1GAUxN z{yG$aI!CADS~NEsr>=guns+6i(eCJSjKp*K9N@Q~iyQOeRtSF~fsjB(6NthMkkQVE zdp{)L34|LUoP&@+mJ5N?1hcR%bsBoJ +#include "struct.h" + +word endian_magic16(word x) +{ + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + return x; + #else + return SDL_Swap16(x); + #endif +} +word endian_magic32(word x) +{ + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + return x; + #else + return SDL_Swap32(x); + #endif +} + +// Lit des octets +// Renvoie -1 si OK, 0 en cas d'erreur +int read_bytes(FILE *Fichier, void *Dest, size_t Taille) +{ + return fread(Dest, 1, Taille, Fichier) == Taille; +} +// Ecrit des octets +// Renvoie -1 si OK, 0 en cas d'erreur +int write_bytes(FILE *Fichier, void *Src, size_t Taille) +{ + return fwrite(Src, 1, Taille, Fichier) == Taille; +} + +// Lit un word (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_word_le(FILE *Fichier, word *Dest) +{ + if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) + return 0; + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + *Dest = SDL_Swap16(*Dest); + #endif + return -1; +} +// Ecrit un word (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_word_le(FILE *Fichier, word Mot) +{ + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + Mot = SDL_Swap16(Mot); + #endif + return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); +} +// Lit un word (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_word_be(FILE *Fichier, word *Dest) +{ + if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) + return 0; + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + *Dest = SDL_Swap16(*Dest); + #endif + return -1; +} +// Ecrit un word (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_word_be(FILE *Fichier, word Mot) +{ + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + Mot = SDL_Swap16(Mot); + #endif + return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); +} +// Lit un dword (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_dword_le(FILE *Fichier, dword *Dest) +{ + if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) + return 0; + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + *Dest = SDL_Swap32(*Dest); + #endif + return -1; +} +// Ecrit un dword (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_dword_le(FILE *Fichier, dword Mot) +{ + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + Mot = SDL_Swap32(Mot); + #endif + return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); +} + +// Lit un dword (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_dword_be(FILE *Fichier, dword *Dest) +{ + if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) + return 0; + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + *Dest = SDL_Swap32(*Dest); + #endif + return -1; +} +// Ecrit un dword (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_dword_be(FILE *Fichier, dword Mot) +{ + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + Mot = SDL_Swap32(Mot); + #endif + return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); +} diff --git a/io.h b/io.h new file mode 100644 index 00000000..e821c1f3 --- /dev/null +++ b/io.h @@ -0,0 +1,16 @@ + +word endian_magic16(word x); +dword endian_magic32(dword x); + +int read_bytes(FILE *Fichier, void *Dest, size_t Taille); +int write_bytes(FILE *Fichier, void *Dest, size_t Taille); + +int read_word_le(FILE *Fichier, word *Dest); +int write_word_le(FILE *Fichier, word Mot); +int read_dword_le(FILE *Fichier, dword *Dest); +int write_dword_le(FILE *Fichier, dword Mot); + +int read_word_be(FILE *Fichier, word *Dest); +int write_word_be(FILE *Fichier, word Mot); +int read_dword_be(FILE *Fichier, dword *Dest); +int write_dword_be(FILE *Fichier, dword Mot); diff --git a/loadsave.c b/loadsave.c index c690e083..6355ecfd 100644 --- a/loadsave.c +++ b/loadsave.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "const.h" #include "struct.h" @@ -19,53 +18,10 @@ #include "boutons.h" #include "erreurs.h" #include "linux.h" - -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - #define endian_magic(x) (x) -#else - #define endian_magic(x) (SDL_Swap16(x)) -#endif +#include "io.h" #define FILENAMESPACE 16 -// Conversion des words d'une structure, si necessaire sur cette plate-forme -void Retraite_Word_LittleEndian(word ** Adresse) -{ - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - while (*Adresse != NULL) - { - word ValeurConvertie = SDL_Swap16(**Adresse); - **Adresse = ValeurConvertie; - Adresse++; - } - #endif -} -void Retraite_DWord_LittleEndian(dword * Adresse[]) -{ - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - while (*Adresse != NULL) - { - dword ValeurConvertie = SDL_Swap32(**Adresse); - **Adresse = ValeurConvertie; - Adresse++; - } - #endif -} - -// Lit des octets -// Renvoie -1 si OK, 0 en cas d'erreur -int read_bytes(FILE *Fichier, void *Dest, size_t Taille) -{ - return fread(Dest, 1, Taille, Fichier) == Taille; -} -// Ecrit des octets -// Renvoie -1 si OK, 0 en cas d'erreur -int write_bytes(FILE *Fichier, void *Dest, size_t Taille) -{ - return fwrite(Dest, 1, Taille, Fichier) == Taille; -} - - // Chargement des pixels dans l'écran principal void Pixel_Chargement_dans_ecran_courant(word Pos_X,word Pos_Y,byte Couleur) { @@ -89,6 +45,8 @@ short Preview_Facteur_Y; short Preview_Pos_X; short Preview_Pos_Y; +byte HBPm1; // Header.BitPlanes-1 + // Chargement des pixels dans la preview void Pixel_Chargement_dans_preview(word Pos_X,word Pos_Y,byte Couleur) @@ -353,9 +311,9 @@ void Dessiner_preview_palette(void) 5*Menu_Facteur_X,5*Menu_Facteur_Y,Indice); SDL_UpdateRect(Ecran_SDL, - Preview_Pos_X*Menu_Facteur_X, - Preview_Pos_Y*Menu_Facteur_Y, - 5*Menu_Facteur_X*256,5*Menu_Facteur_Y*256); + Preview_Pos_X*Menu_Facteur_X, + Preview_Pos_Y*Menu_Facteur_Y, + 5*Menu_Facteur_X*256,5*Menu_Facteur_Y*256); } @@ -408,29 +366,11 @@ void Nom_fichier_complet(char * Nom_du_fichier, byte Sauve_Colorix) // Gestion des lectures et écritures // ///////////////////////////////////////////////////////////////////////////// -byte * Tampon_lecture; -word Index_lecture; - -void Init_lecture(void) +void Lire_octet(FILE * Fichier, byte *Octet) { - Tampon_lecture=(byte *)malloc(64000); - Index_lecture=64000; -} - -byte Lire_octet(FILE *Fichier) -{ - if (++Index_lecture>=64000) - { - if (read_bytes(Fichier,Tampon_lecture,64000)) - Erreur_fichier=2; - Index_lecture=0; - } - return Tampon_lecture[Index_lecture]; -} - -void Close_lecture(void) -{ - free(Tampon_lecture); + // FIXME : Remplacer les appelants par read_bytes(), et gérer les retours d'erreur. + if (!read_bytes(Fichier, Octet, 1)) + ;// Erreur_fichier = 2; } // -------------------------------------------------------------------------- @@ -1035,8 +975,8 @@ void Load_PKM(void) if (Octet==4) { Indice+=4; - if ( ! read_bytes(Fichier,&Ecran_original_X,2) - || !read_bytes(Fichier,&Ecran_original_Y,2) ) + if ( ! read_word_le(Fichier,&Ecran_original_X) + || !read_word_le(Fichier,&Ecran_original_Y) ) Erreur_fichier=2; } else @@ -1080,7 +1020,7 @@ void Load_PKM(void) Erreur_fichier=2; } - Init_lecture(); + /*Init_lecture();*/ if (!Erreur_fichier) { @@ -1102,7 +1042,7 @@ void Load_PKM(void) // Boucle de décompression: while ( (Compteur_de_pixels>16)+(Temp<<16)); - } - - void Test_LBM(void) { char Nom_du_fichier[TAILLE_CHEMIN_FICHIER]; char Format[4]; char Section[4]; - + dword Dummy; Nom_fichier_complet(Nom_du_fichier,0); @@ -1396,7 +1323,8 @@ void Test_LBM(void) Erreur_fichier=1; else { - Lire_long(); // On aurait pu vérifier que ce long est égal à la taille + read_dword_be(LBM_Fichier, &Dummy); + // On aurait pu vérifier que ce long est égal à la taille // du fichier - 8, mais ça aurait interdit de charger des // fichiers tronqués (et déjà que c'est chiant de perdre // une partie du fichier il faut quand même pouvoir en @@ -1533,8 +1461,7 @@ void Test_LBM(void) return 0; while (memcmp(Section_lue,Section_attendue,4)) // Sect. pas encore trouvée { - Taille_section=Lire_long(); - if (Erreur_fichier) + if (!read_dword_be(LBM_Fichier,&Taille_section)) return 0; if (Taille_section&1) Taille_section++; @@ -1558,7 +1485,7 @@ void Test_LBM(void) { for (Pos_X=0; Pos_X 127 alors il faut répéter 256-'Octet' fois la couleur de l'octet suivant - // Si Octet <= 127 alors il faut afficher directement les 'Octet' octets suivants + Lire_octet(LBM_Fichier, &Octet); + // Si Octet > 127 alors il faut répéter 256-'Octet' fois la couleur de l'octet suivant + // Si Octet <= 127 alors il faut afficher directement les 'Octet' octets suivants if (Octet>127) { - Couleur=Lire_octet(LBM_Fichier); + Lire_octet(LBM_Fichier, &Couleur); B256=(short)(256-Octet); for (Compteur=0; Compteur<=B256; Compteur++) if (Pos_X127) { - Couleur=Lire_octet(LBM_Fichier); + Lire_octet(LBM_Fichier, &Couleur); B256=256-Octet; for (Compteur=0; Compteur<=B256; Compteur++) Pixel_de_chargement(Pos_X++,Pos_Y,Couleur); } else for (Compteur=0; Compteur<=Octet; Compteur++) - Pixel_de_chargement(Pos_X++,Pos_Y,Lire_octet(LBM_Fichier)); + { + byte Lu=0; + Lire_octet(LBM_Fichier, &Lu); + Pixel_de_chargement(Pos_X++,Pos_Y,Lu); + } } } - Close_lecture(); + /*Close_lecture();*/ } } } @@ -1883,17 +1815,6 @@ void Load_LBM(void) word LBM_Taille_de_file; byte LBM_Mode_repetition; - // ----------- Traduire et écrire une valeur au format Motorola ----------- - void Ecrire_long(dword Valeur) - { - dword Temp; - - swab((char *)&Valeur,(char *)&Temp,4); - Valeur=(Temp>>16)+(Temp<<16); - if (! write_bytes(LBM_Fichier,&Valeur,4)) - Erreur_fichier=1; - } - // ------------- Ecrire les couleurs que l'on vient de traiter ------------ void Transferer_couleurs(void) { @@ -1996,10 +1917,10 @@ void Save_LBM(void) if ((LBM_Fichier=fopen(Nom_du_fichier,"wb"))) { write_bytes(LBM_Fichier,"FORM",4); - Ecrire_long(0); // On mettra la taille à jour à la fin + write_dword_be(LBM_Fichier,0); // On mettra la taille à jour à la fin write_bytes(LBM_Fichier,"PBM BMHD",8); - Ecrire_long(20); + write_dword_be(LBM_Fichier,20); // On corrige la largeur de l'image pour qu'elle soit multiple de 2 Vraie_largeur=Principal_Largeur_image+(Principal_Largeur_image&1); @@ -2007,6 +1928,9 @@ void Save_LBM(void) //swab((byte *)&Vraie_largeur,(byte *)&Header.Width,2); swab((byte *)&Principal_Largeur_image,(byte *)&Header.Width,2); swab((byte *)&Principal_Hauteur_image,(byte *)&Header.Height,2); + //Header.Width=Principal_Largeur_image; + //Header.Height=Principal_Hauteur_image; + Header.Xorg=0; Header.Yorg=0; Header.BitPlanes=8; @@ -2018,18 +1942,20 @@ void Save_LBM(void) Header.Yaspect=1; swab((byte *)&Largeur_ecran,(byte *)&Header.Xscreen,2); swab((byte *)&Hauteur_ecran,(byte *)&Header.Yscreen,2); + //Header.Xscreen = Largeur_ecran; + //Header.Yscreen = Hauteur_ecran; write_bytes(LBM_Fichier,&Header,sizeof(T_Header_LBM)); write_bytes(LBM_Fichier,"CMAP",4); - Ecrire_long(sizeof(T_Palette)); + write_dword_be(LBM_Fichier,sizeof(T_Palette)); Palette_64_to_256(Principal_Palette); write_bytes(LBM_Fichier,Principal_Palette,sizeof(T_Palette)); Palette_256_to_64(Principal_Palette); write_bytes(LBM_Fichier,"BODY",4); - Ecrire_long(0); // On mettra la taille à jour à la fin + write_dword_be(LBM_Fichier,0); // On mettra la taille à jour à la fin Init_ecriture(); @@ -2053,7 +1979,7 @@ void Save_LBM(void) fseek(LBM_Fichier,820,SEEK_SET); stat(Nom_du_fichier,Informations_Fichier); - Ecrire_long((Informations_Fichier->st_size)-824); + write_dword_be(LBM_Fichier,Informations_Fichier->st_size-824); if (!Erreur_fichier) { @@ -2063,14 +1989,14 @@ void Save_LBM(void) // impaire, on rajoute un 0 (Padding) à la fin. if ((Informations_Fichier->st_size) & 1) { - Ecrire_long((Informations_Fichier->st_size)-7); + write_dword_be(LBM_Fichier,Informations_Fichier->st_size-7); fseek(LBM_Fichier,0,SEEK_END); Octet=0; if (! write_bytes(LBM_Fichier,&Octet,1)) Erreur_fichier=1; } else - Ecrire_long((Informations_Fichier->st_size)-8); + write_dword_be(LBM_Fichier,Informations_Fichier->st_size-8); fclose(LBM_Fichier); @@ -2132,23 +2058,23 @@ void Test_BMP(void) if ((Fichier=fopen(Nom_du_fichier, "rb"))) { - if (read_bytes(Fichier,&(Header.Signature),sizeof(word)) - && read_bytes(Fichier,&(Header.Taille_1),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Reserv_1),sizeof(word)) - && read_bytes(Fichier,&(Header.Reserv_2),sizeof(word)) - && read_bytes(Fichier,&(Header.Decalage),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Taille_2),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Largeur),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Hauteur),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Plans),sizeof(word)) - && read_bytes(Fichier,&(Header.Nb_bits),sizeof(word)) - && read_bytes(Fichier,&(Header.Compression),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Taille_3),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.XPM),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.YPM),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Nb_Clr),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Clr_Imprt),sizeof(uint32_t)) - ) + if (read_bytes(Fichier,&(Header.Signature),2) // "BM" + && read_dword_le(Fichier,&(Header.Taille_1)) + && read_word_le(Fichier,&(Header.Reserv_1)) + && read_word_le(Fichier,&(Header.Reserv_2)) + && read_dword_le(Fichier,&(Header.Decalage)) + && read_dword_le(Fichier,&(Header.Taille_2)) + && read_dword_le(Fichier,&(Header.Largeur)) + && read_dword_le(Fichier,&(Header.Hauteur)) + && read_word_le(Fichier,&(Header.Plans)) + && read_word_le(Fichier,&(Header.Nb_bits)) + && read_dword_le(Fichier,&(Header.Compression)) + && read_dword_le(Fichier,&(Header.Taille_3)) + && read_dword_le(Fichier,&(Header.XPM)) + && read_dword_le(Fichier,&(Header.YPM)) + && read_dword_le(Fichier,&(Header.Nb_Clr)) + && read_dword_le(Fichier,&(Header.Clr_Imprt)) + ) { if ( (Header.Signature==0x4D42) && (Header.Taille_2==40) && Header.Largeur && Header.Hauteur ) @@ -2186,22 +2112,22 @@ void Load_BMP(void) stat(Nom_du_fichier,&Informations_Fichier); Taille_du_fichier=Informations_Fichier.st_size; - if (read_bytes(Fichier,&(Header.Signature),sizeof(word)) - && read_bytes(Fichier,&(Header.Taille_1),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Reserv_1),sizeof(word)) - && read_bytes(Fichier,&(Header.Reserv_2),sizeof(word)) - && read_bytes(Fichier,&(Header.Decalage),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Taille_2),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Largeur),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Hauteur),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Plans),sizeof(word)) - && read_bytes(Fichier,&(Header.Nb_bits),sizeof(word)) - && read_bytes(Fichier,&(Header.Compression),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Taille_3),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.XPM),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.YPM),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Nb_Clr),sizeof(uint32_t)) - && read_bytes(Fichier,&(Header.Clr_Imprt),sizeof(uint32_t)) + if (read_word_le(Fichier,&(Header.Signature)) + && read_dword_le(Fichier,&(Header.Taille_1)) + && read_word_le(Fichier,&(Header.Reserv_1)) + && read_word_le(Fichier,&(Header.Reserv_2)) + && read_dword_le(Fichier,&(Header.Decalage)) + && read_dword_le(Fichier,&(Header.Taille_2)) + && read_dword_le(Fichier,&(Header.Largeur)) + && read_dword_le(Fichier,&(Header.Hauteur)) + && read_word_le(Fichier,&(Header.Plans)) + && read_word_le(Fichier,&(Header.Nb_bits)) + && read_dword_le(Fichier,&(Header.Compression)) + && read_dword_le(Fichier,&(Header.Taille_3)) + && read_dword_le(Fichier,&(Header.XPM)) + && read_dword_le(Fichier,&(Header.YPM)) + && read_dword_le(Fichier,&(Header.Nb_Clr)) + && read_dword_le(Fichier,&(Header.Clr_Imprt)) ) { switch (Header.Nb_bits) @@ -2287,9 +2213,9 @@ void Load_BMP(void) Pos_X=0; Pos_Y=Principal_Hauteur_image-1; - Init_lecture(); - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + /*Init_lecture();*/ + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); while ( (!Erreur_fichier) && ((A)||(B!=1)) ) { if (A) // Encoded mode @@ -2305,16 +2231,16 @@ void Load_BMP(void) case 1 : // End of bitmap break; case 2 : // Delta - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); Pos_X+=A; Pos_Y-=B; break; default: // Nouvelle série while (B) { - A=Lire_octet(Fichier); - C=Lire_octet(Fichier); + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &C); Pixel_de_chargement(Pos_X++,Pos_Y,A); if (--B) { @@ -2323,19 +2249,19 @@ void Load_BMP(void) } } } - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); } - Close_lecture(); + /*Close_lecture();*/ break; case 2 : // Compression RLE 4 bits Pos_X=0; Pos_Y=Principal_Hauteur_image-1; - Init_lecture(); - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + /*Init_lecture();*/ + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); while ( (!Erreur_fichier) && ((A)||(B!=1)) ) { if (A) // Encoded mode (A fois les 1/2 pixels de B) @@ -2357,8 +2283,8 @@ void Load_BMP(void) case 1 : // End of bitmap break; case 2 : // Delta - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); Pos_X+=A; Pos_Y-=B; break; @@ -2367,7 +2293,7 @@ void Load_BMP(void) { if (Indice&1) { - C=Lire_octet(Fichier); + Lire_octet(Fichier, &C); Pixel_de_chargement(Pos_X,Pos_Y,C>>4); } else @@ -2376,12 +2302,15 @@ void Load_BMP(void) // On lit l'octet rendant le nombre d'octets pair, si // nécessaire. Encore un truc de crétin "made in MS". if ( ((B&3)==1) || ((B&3)==2) ) - Lire_octet(Fichier); + { + byte Dummy; + Lire_octet(Fichier, &Dummy); + } } - A=Lire_octet(Fichier); - B=Lire_octet(Fichier); + Lire_octet(Fichier, &A); + Lire_octet(Fichier, &B); } - Close_lecture(); + /*Close_lecture();*/ } fclose(Fichier); } @@ -2587,9 +2516,9 @@ void Test_GIF(void) // Définition de quelques variables globales au chargement du GIF87a word GIF_Nb_bits; // Nb de bits composants un code complet word GIF_Rest_bits; // Nb de bits encore dispos dans GIF_Last_byte - word GIF_Rest_byte; // Nb d'octets avant le prochain bloc de Raster Data + byte GIF_Rest_byte; // Nb d'octets avant le prochain bloc de Raster Data word GIF_Code_actuel; // Code traité (qui vient d'être lu en général) - word GIF_Last_byte; // Octet de lecture des bits + byte GIF_Last_byte; // Octet de lecture des bits word GIF_Pos_X; // Coordonnées d'affichage de l'image word GIF_Pos_Y; word GIF_Entrelacee; // L'image est entrelacée @@ -2616,8 +2545,8 @@ void Test_GIF(void) // Si on a atteint la fin du bloc de Raster Data if (GIF_Rest_byte==0) // Lire l'octet nous donnant la taille du bloc de Raster Data suivant - GIF_Rest_byte=Lire_octet(GIF_Fichier); - GIF_Last_byte=Lire_octet(GIF_Fichier); + Lire_octet(GIF_Fichier, &GIF_Rest_byte); + Lire_octet(GIF_Fichier,&GIF_Last_byte); GIF_Rest_byte--; GIF_Rest_bits=8; } @@ -2734,17 +2663,17 @@ void Load_GIF(void) Alphabet_Prefixe=(word *)malloc(4096*sizeof(word)); Alphabet_Suffixe=(word *)malloc(4096*sizeof(word)); - if (read_bytes(GIF_Fichier,&(LSDB.Largeur),sizeof(word)) - && read_bytes(GIF_Fichier,&(LSDB.Hauteur),sizeof(word)) - && read_bytes(GIF_Fichier,&(LSDB.Resol),sizeof(byte)) - && read_bytes(GIF_Fichier,&(LSDB.Backcol),sizeof(byte)) - && read_bytes(GIF_Fichier,&(LSDB.Aspect),sizeof(byte)) - ) + if (read_word_le(GIF_Fichier,&(LSDB.Largeur)) + && read_word_le(GIF_Fichier,&(LSDB.Hauteur)) + && read_bytes(GIF_Fichier,&(LSDB.Resol),1) + && read_bytes(GIF_Fichier,&(LSDB.Backcol),1) + && read_bytes(GIF_Fichier,&(LSDB.Aspect),1) + ) { // Lecture du Logical Screen Descriptor Block réussie: - Ecran_original_X=endian_magic(LSDB.Largeur); - Ecran_original_Y=endian_magic(LSDB.Hauteur); + Ecran_original_X=endian_magic16(LSDB.Largeur); + Ecran_original_Y=endian_magic16(LSDB.Hauteur); // Palette globale dispo = (LSDB.Resol and $80) // Profondeur de couleur =((LSDB.Resol and $70) shr 4)+1 @@ -2774,12 +2703,12 @@ void Load_GIF(void) // On peut maintenant charger la nouvelle palette: if (!(LSDB.Aspect & 0x80)) // Palette dans l'ordre: - for(Indice_de_couleur=0;Indice_de_couleur=0) if ( /* (GIF_Pos_X!=0) || */ @@ -3362,20 +3291,6 @@ typedef struct T_PCX_Header PCX_Header; -word * PCX_words[] = { - &PCX_Header.X_min, - &PCX_Header.Y_min, - &PCX_Header.X_max, - &PCX_Header.Y_max, - &PCX_Header.X_dpi, - &PCX_Header.Y_dpi, - &PCX_Header.Bytes_per_plane_line, - &PCX_Header.Palette_info, - &PCX_Header.Screen_X, - &PCX_Header.Screen_Y, - NULL - }; - // -- Tester si un fichier est au format PCX -------------------------------- void Test_PCX(void) @@ -3388,9 +3303,25 @@ void Test_PCX(void) if ((Fichier=fopen(Nom_du_fichier, "rb"))) { - if (read_bytes(Fichier,&PCX_Header,sizeof(T_PCX_Header))) + if (read_bytes(Fichier,&(PCX_Header.Manufacturer),1) && + read_bytes(Fichier,&(PCX_Header.Version),1) && + read_bytes(Fichier,&(PCX_Header.Compression),1) && + read_bytes(Fichier,&(PCX_Header.Depth),1) && + read_word_le(Fichier,&(PCX_Header.X_min)) && + read_word_le(Fichier,&(PCX_Header.Y_min)) && + read_word_le(Fichier,&(PCX_Header.X_max)) && + read_word_le(Fichier,&(PCX_Header.Y_max)) && + read_word_le(Fichier,&(PCX_Header.X_dpi)) && + read_word_le(Fichier,&(PCX_Header.Y_dpi)) && + read_bytes(Fichier,&(PCX_Header.Palette_16c),48) && + read_bytes(Fichier,&(PCX_Header.Reserved),1) && + read_bytes(Fichier,&(PCX_Header.Plane),1) && + read_word_le(Fichier,&(PCX_Header.Bytes_per_plane_line)) && + read_word_le(Fichier,&(PCX_Header.Palette_info)) && + read_word_le(Fichier,&(PCX_Header.Screen_X)) && + read_word_le(Fichier,&(PCX_Header.Screen_Y)) && + read_bytes(Fichier,&(PCX_Header.Filler),54) ) { - Retraite_Word_LittleEndian(PCX_words); // Vu que ce header a une signature de merde et peu significative, il // va falloir que je teste différentes petites valeurs dont je connais @@ -3452,7 +3383,6 @@ void Load_PCX(void) byte * Buffer; struct stat Informations_Fichier; - Nom_fichier_complet(Nom_du_fichier,0); Erreur_fichier=0; @@ -3461,11 +3391,29 @@ void Load_PCX(void) { stat(Nom_du_fichier,&Informations_Fichier); Taille_du_fichier=Informations_Fichier.st_size; - + /* if (read_bytes(Fichier,&PCX_Header,sizeof(T_PCX_Header))) + {*/ + + if (read_bytes(Fichier,&(PCX_Header.Manufacturer),1) && + read_bytes(Fichier,&(PCX_Header.Version),1) && + read_bytes(Fichier,&(PCX_Header.Compression),1) && + read_bytes(Fichier,&(PCX_Header.Depth),1) && + read_word_le(Fichier,&(PCX_Header.X_min)) && + read_word_le(Fichier,&(PCX_Header.Y_min)) && + read_word_le(Fichier,&(PCX_Header.X_max)) && + read_word_le(Fichier,&(PCX_Header.Y_max)) && + read_word_le(Fichier,&(PCX_Header.X_dpi)) && + read_word_le(Fichier,&(PCX_Header.Y_dpi)) && + read_bytes(Fichier,&(PCX_Header.Palette_16c),48) && + read_bytes(Fichier,&(PCX_Header.Reserved),1) && + read_bytes(Fichier,&(PCX_Header.Plane),1) && + read_word_le(Fichier,&(PCX_Header.Bytes_per_plane_line)) && + read_word_le(Fichier,&(PCX_Header.Palette_info)) && + read_word_le(Fichier,&(PCX_Header.Screen_X)) && + read_word_le(Fichier,&(PCX_Header.Screen_Y)) && + read_bytes(Fichier,&(PCX_Header.Filler),54) ) { - // Ce format est Little-Endian - Retraite_Word_LittleEndian(PCX_words); Principal_Largeur_image=PCX_Header.X_max-PCX_Header.X_min+1; Principal_Hauteur_image=PCX_Header.Y_max-PCX_Header.Y_min+1; @@ -3520,17 +3468,17 @@ void Load_PCX(void) if (read_bytes(Fichier,&Octet1,1)) if (Octet1==12) // Lire la palette si c'est une image en 256 couleurs { - int indice; + int indice; // On lit la palette 256c que ces crétins ont foutue à la fin du fichier - for(indice=0;indice<256;indice++) - if ( ! read_bytes(Fichier,&Principal_Palette[indice].R,1) - || ! read_bytes(Fichier,&Principal_Palette[indice].V,1) - || ! read_bytes(Fichier,&Principal_Palette[indice].B,1) ) - { - Erreur_fichier=2; - DEBUG("ERROR READING PCX PALETTE !",indice); - break; - } + for(indice=0;indice<256;indice++) + if ( ! read_bytes(Fichier,&Principal_Palette[indice].R,1) + || ! read_bytes(Fichier,&Principal_Palette[indice].V,1) + || ! read_bytes(Fichier,&Principal_Palette[indice].B,1) ) + { + Erreur_fichier=2; + DEBUG("ERROR READING PCX PALETTE !",indice); + break; + } } } Palette_256_to_64(Principal_Palette); @@ -3540,7 +3488,6 @@ void Load_PCX(void) // Maintenant qu'on a lu la palette que ces crétins sont allés foutre // à la fin, on retourne juste après le header pour lire l'image. fseek(Fichier,128,SEEK_SET); - if (!Erreur_fichier) { Taille_ligne=PCX_Header.Bytes_per_plane_line*PCX_Header.Plane; @@ -3554,8 +3501,8 @@ void Load_PCX(void) // Chargement de l'image if (PCX_Header.Compression) // Image compressée { - Init_lecture(); - + /*Init_lecture();*/ + Taille_image=(long)PCX_Header.Bytes_per_plane_line*Principal_Hauteur_image; if (PCX_Header.Depth==8) // 256 couleurs (1 plan) @@ -3563,13 +3510,13 @@ void Load_PCX(void) for (Position=0; ((Position>1)*Header1.Height)!=Taille ) ) { @@ -3956,17 +3917,17 @@ void Load_CEL(void) if (Erreur_fichier==0) { // Chargement de l'image - Init_lecture(); + /*Init_lecture();*/ for (Pos_Y=0;((Pos_Y> 4)); } else Pixel_de_chargement(Pos_X,Pos_Y,(Dernier_octet & 15)); - Close_lecture(); + /*Close_lecture();*/ } } else @@ -3986,7 +3947,7 @@ void Load_CEL(void) if (Erreur_fichier==0) { // Chargement de l'image - Init_lecture(); + /*Init_lecture();*/ if (!Erreur_fichier) { @@ -4005,7 +3966,7 @@ void Load_CEL(void) for (Pos_X=0;((Pos_X> 4)); } else @@ -4015,14 +3976,18 @@ void Load_CEL(void) case 8: for (Pos_Y=0;((Pos_Y