Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
GESTION DE LA PALETTE ET AFFICHAGE D'UN .PCX EN 8BITS SOUS DJGPP EN C
Description
Bibliotheque qui gere l'affichage d'un fichier pcx (quelquesoit sa taille), sous 8bits avec gestion de la palette graphique avec DJGPP ! On peut modifier la position de l'image, les couleurs de la palette ...
Source
-
-
- void taille_pcx(char * fichier, unsigned * largeur, unsigned * hauteur)
- {
- FILE * flot;
- unsigned width = 0, height = 0;
-
- flot = fopen(fichier,"rb");
- fseek(flot,8,SEEK_SET);
- fread(&width,2,1,flot);
- fread(&height,2,1,flot);
- width++;
- height++;
-
- *largeur = width;
- *hauteur = height;
-
- fclose(flot);
- }
-
- void charge_palette_pcx(char * fichier)
- { unsigned char pal[256][3];
- int i,j;
- FILE * flot;
-
- if(!(sauve_palette("palette.dat")))
- {
- printf("Erreur dans la sauvegarde de la palette.\n");
- exit(1);
- }
-
- flot = fopen(fichier,"rb");
- fseek(flot,-768L,SEEK_END);
- for(i = 0; i <256 ; i ++)
- {
- pal_rouge[i] = fgetc(flot)>>2;
- pal_vert[i] = fgetc(flot)>>2;
- pal_bleu[i] = fgetc(flot)>>2;
- }
- fclose(flot);
- applique_palette();
- }
-
- void charge_pcx(char * fichier, unsigned char * buffer, unsigned taille)
- {
- FILE * flot;
-
- unsigned long position;
- unsigned num;
- unsigned char ch;
-
- flot = fopen(fichier,"rb");
- fseek(flot,128,SEEK_SET);
-
- position=0;
- do
- {
- ch = fgetc(flot);
- if ((ch & 0xC0) == 0xC0)
- {
- num = ch & 0x3F;
- ch = fgetc(flot);
- while(num--)
- buffer[position++]=ch;
- }
- else
- buffer[position++]=ch;
- }
- while(position < (taille));
- fclose(flot);
- }
-
- void affiche_pcx_transparent(unsigned char * buffersource, unsigned char * bufferdest, unsigned width, unsigned height, unsigned X, unsigned Y)
- {
- int u, z;
- for (u=0; u<=height-1; u++)
- for (z=0; z<=width-1; z++)
- {
- if((int)buffersource[u*width+z] && ((table_mode.resolution_horizontale*(Y+u)+X+z) < (table_mode.resolution_horizontale*table_mode.resolution_verticale)) && ((X+z) < table_mode.resolution_horizontale))
- (unsigned char *)bufferdest[table_mode.resolution_horizontale*(Y+u)+X+z] = buffersource[u*width+z];
- }
- }
-
- void affiche_pcx(unsigned char * buffersource, unsigned char * bufferdest, unsigned width, unsigned height, unsigned X, unsigned Y)
- { int u, z;
- for (u=0; u<=height-1; u++)
- for (z=0; z<=width-1; z++)
- {
- if(((table_mode.resolution_horizontale*(Y+u)+X+z) < (table_mode.resolution_horizontale*table_mode.resolution_verticale)) && ((X+z) < table_mode.resolution_horizontale))
- (unsigned char *)bufferdest[table_mode.resolution_horizontale*(Y+u)+X+z] = buffersource[u*width+z];
- }
- }
void taille_pcx(char * fichier, unsigned * largeur, unsigned * hauteur)
{
FILE * flot;
unsigned width = 0, height = 0;
flot = fopen(fichier,"rb");
fseek(flot,8,SEEK_SET);
fread(&width,2,1,flot);
fread(&height,2,1,flot);
width++;
height++;
*largeur = width;
*hauteur = height;
fclose(flot);
}
void charge_palette_pcx(char * fichier)
{ unsigned char pal[256][3];
int i,j;
FILE * flot;
if(!(sauve_palette("palette.dat")))
{
printf("Erreur dans la sauvegarde de la palette.\n");
exit(1);
}
flot = fopen(fichier,"rb");
fseek(flot,-768L,SEEK_END);
for(i = 0; i <256 ; i ++)
{
pal_rouge[i] = fgetc(flot)>>2;
pal_vert[i] = fgetc(flot)>>2;
pal_bleu[i] = fgetc(flot)>>2;
}
fclose(flot);
applique_palette();
}
void charge_pcx(char * fichier, unsigned char * buffer, unsigned taille)
{
FILE * flot;
unsigned long position;
unsigned num;
unsigned char ch;
flot = fopen(fichier,"rb");
fseek(flot,128,SEEK_SET);
position=0;
do
{
ch = fgetc(flot);
if ((ch & 0xC0) == 0xC0)
{
num = ch & 0x3F;
ch = fgetc(flot);
while(num--)
buffer[position++]=ch;
}
else
buffer[position++]=ch;
}
while(position < (taille));
fclose(flot);
}
void affiche_pcx_transparent(unsigned char * buffersource, unsigned char * bufferdest, unsigned width, unsigned height, unsigned X, unsigned Y)
{
int u, z;
for (u=0; u<=height-1; u++)
for (z=0; z<=width-1; z++)
{
if((int)buffersource[u*width+z] && ((table_mode.resolution_horizontale*(Y+u)+X+z) < (table_mode.resolution_horizontale*table_mode.resolution_verticale)) && ((X+z) < table_mode.resolution_horizontale))
(unsigned char *)bufferdest[table_mode.resolution_horizontale*(Y+u)+X+z] = buffersource[u*width+z];
}
}
void affiche_pcx(unsigned char * buffersource, unsigned char * bufferdest, unsigned width, unsigned height, unsigned X, unsigned Y)
{ int u, z;
for (u=0; u<=height-1; u++)
for (z=0; z<=width-1; z++)
{
if(((table_mode.resolution_horizontale*(Y+u)+X+z) < (table_mode.resolution_horizontale*table_mode.resolution_verticale)) && ((X+z) < table_mode.resolution_horizontale))
(unsigned char *)bufferdest[table_mode.resolution_horizontale*(Y+u)+X+z] = buffersource[u*width+z];
}
}
Conclusion
Cette source ne me convient pas car elle gere l'affichage sur 8bits et je voudrais travailler en 16, si vous modifiez le code... j'espere que vous m'enverrez la nouvelle version. (j'ai ajouté au zip la bibliotheque pour un affichage 16 bits). Trillian
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Sources de la même categorie
Commentaires
|
|