1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <windows.h>
void pause();
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
Uint32 obtenirPixel(SDL_Surface *surface, int x, int y);
void affichage()
{
int c;
FILE * fichier;
int tempo,i=0,j;
char chaine[10] = "";
int image[7656],k;
int matriceimage[116][66];
char filename[30];
int facteur=1;
SDL_Surface *ecran = NULL; // Le pointeur qui va stocker la surface de l'écran
//SDL_Init(SDL_INIT_VIDEO);
if( SDL_Init( SDL_INIT_VIDEO ) == -1 )
{
printf( "Can't init SDL: %s\n", SDL_GetError( ) );
//return EXIT_FAILURE;
}
ecran=SDL_SetVideoMode(116*facteur, 60*facteur, 32, SDL_HWSURFACE |SDL_RESIZABLE);
if( ecran == NULL )
{
printf( "Can't set video mode: %s\n", SDL_GetError( ) );
//return EXIT_FAILURE;
}
while(1)
{
for(c=0;c<399;c+=2)
{
sprintf(filename,"%d.txt", c);
fichier=fopen(filename,"r"); //Ouverture des fichiers
if (fichier != NULL)
{
while (fgets(chaine, 10, fichier) != NULL) // On lit le fichier tant qu'on ne reçoit pas d'erreur (NULL)
{
tempo=atoi(chaine); //Conversion chaine->entier
image[i]=tempo; //Remplissage image
i++; //Incrémentation de i
}
k=0; //Creation de la matrice
for(i=65;i>=0;i--) //
{ //
for(j=0;j<116;j++) //
{ //
matriceimage[j][i]=image[k]; //
k++; //
} //
} //
SDL_LockSurface(ecran); /*On bloque la surface*/
for(i=0;i<(116*facteur);i++)
{
for(j=0;j<(60*facteur);j++)
{
Uint32 pixel;
Uint8 r,v,b,a;
int couleur=matriceimage[(int)(i/facteur)][(int)(j/facteur)];
pixel=obtenirPixel(ecran,i,j);
SDL_GetRGBA(pixel, ecran->format, &r, &v, &b, &a);
r=couleur;
v=couleur;
b=couleur;
a=255;
pixel=SDL_MapRGBA(ecran->format, r, v, b, a);
definirPixel(ecran,i,j,pixel);
}
}
SDL_Flip(ecran);
SDL_UnlockSurface(ecran); /*On libère la surface, elle peut être utilisée pour une autre tâche*/
_sleep(55);
}
}
}
/*
for(c=0;c<399;c+=2)
{
printf("essai");
sprintf(filename,"%d.txt", c);
remove(filename);
}
*/
pause();
SDL_Quit();
}
int main(int argc, char *argv[]) //Main
{
affichage();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
void pause() //fonction pause
{ //
int continuer = 1; //
SDL_Event event; //
//
while (continuer) //
{ //
SDL_WaitEvent(&event); //
switch(event.type) //
{ //
case SDL_QUIT: //
continuer = 0; //
} //
} //
} //
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
/*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel.
En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur
de l'image : 8, 16, 24 ou 32 bits.*/
int nbOctetsParPixel = surface->format->BytesPerPixel;
/*Ici p est l'adresse du pixel que l'on veut modifier*/
/*surface->pixels contient l'adresse du premier pixel de l'image*/
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
/*Gestion différente suivant le nombre d'octets par pixel de l'image*/
switch(nbOctetsParPixel)
{
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
/*Suivant l'architecture de la machine*/
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}
/* ********************************************************************* */
/*obtenirPixel : permet de récupérer la couleur d'un pixel
Paramètres d'entrée/sortie :
SDL_Surface *surface : la surface sur laquelle on va récupérer la couleur d'un pixel
int x : la coordonnée en x du pixel à récupérer
int y : la coordonnée en y du pixel à récupérer
Uint32 resultat : la fonction renvoie le pixel aux coordonnées (x,y) dans la surface
*/
Uint32 obtenirPixel(SDL_Surface *surface, int x, int y)
{
/*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel.
En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur
de l'image : 8, 16, 24 ou 32 bits.*/
int nbOctetsParPixel = surface->format->BytesPerPixel;
/* Ici p est l'adresse du pixel que l'on veut connaitre */
/*surface->pixels contient l'adresse du premier pixel de l'image*/
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
/*Gestion différente suivant le nombre d'octets par pixel de l'image*/
switch(nbOctetsParPixel)
{
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
/*Suivant l'architecture de la machine*/
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
/*Ne devrait pas arriver, mais évite les erreurs*/
default:
return 0;
}
}
//////////////////////////////////////////////////////////////////////////////// |
Partager