begin process at 2012 02 13 02:37:32
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > GESTION DE LA PALETTE ET AFFICHAGE D'UN .PCX EN 8BITS SOUS DJGPP EN C

GESTION DE LA PALETTE ET AFFICHAGE D'UN .PCX EN 8BITS SOUS DJGPP EN C


 Information sur la source

Note :
Aucune note
Catégorie :Graphique Niveau :Débutant Date de création :12/02/2003 Date de mise à jour :12/02/2003 23:11:15 Vu / téléchargé :3 236 / 140

Auteur : Trillian

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip BIBLIOTHEQUE GRAPHIQUE MODE VESA SOUS DJGPP (VERSION 2.0)
Source avec Zip MODE GRAPHIQUE VESA AVEC DJGPP EN C

 Sources de la même categorie

Source avec Zip APPLICATION DE DESSIN DE QUELQUES FIGURES par laguchori
Source avec Zip Source avec une capture HDR EXPOSURE FUSION par mecrosoft
Source avec Zip Source avec une capture IRC CLIENT MULTISERVEUR EN MFC (TXIRC) par TeniX
Source avec Zip ENTETE DU FICHIER BMP (BIPMAP) par k.Lutchi
Source avec Zip Source avec une capture XCOUPE : COUPE 2D par pop70

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,562 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales