begin process at 2008 08 21 21:11:42
1 229 636 membres
448 nouveaux aujourd'hui
14 264 membres club

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


Information sur la source

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é: 1 718 / 116

Note :
Aucune note

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
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

    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

Boutique

Boutique de goodies CodeS-SourceS