2014-05-10 10:13:06 +00:00
# include <math.h>
# define PI 3.14159265359
2014-05-13 20:23:45 +00:00
# define MAXCOMPOSANTEDEFAUT 255
2014-05-10 10:13:06 +00:00
2014-05-08 17:44:09 +00:00
// Gestion de fichiers
2014-05-13 20:23:45 +00:00
int creer ( Image & sortie , unsigned int dimensionX , unsigned int dimensionY , unsigned int maxComposante , PILG_Comp typeComposantes ) { // Créer une image de dimensions X et Y
2014-05-10 10:13:06 +00:00
sortie = * new Image ( dimensionX , dimensionY , maxComposante , typeComposantes ) ;
2014-05-13 20:23:45 +00:00
return 0 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int ouvrir ( Image & sortie , string nomFichier ) { // Ouvrir une image existante à partir du nom du fichier ***Geoffrey
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int sauver ( Image entree , string nomFichier , bool ASCII , string commentaire ) { // Sauvegarder l'image obtenue dans un nouveau fichier
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int importer ( Image entree , Image & sortie , string nomFichier , int x , int y ) {
2014-05-05 09:29:04 +00:00
// Image fichierImporte;
// sortie = entree
// ouvrir(fichierImporte, nomFichier)
// Pour x1 = 0 to x1 = fichierImporte.g_dimensionX
2014-05-05 19:00:08 +00:00
// Pour y1 = 0 to y1 = fichierImporte.g_dimensionY
// sortie.s_pixel(x1 + x, y1 + y, fichierImporte.g_pixel(x1, x2));
// FinPour
2014-05-08 17:44:09 +00:00
// FinPour
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-03-27 18:03:14 +00:00
// Couleur
2014-05-19 09:40:08 +00:00
int rvbVersTsl ( Pixel entree , Pixel & sortie ) {
TSLcouleur tslcouleur ;
float r = ( float ) entree . r / entree . maxComposante ;
float v = ( float ) entree . v / entree . maxComposante ;
float b = ( float ) entree . b / entree . maxComposante ;
float min = ( r < v < b ? | | ( v < r & & v < b ? b b | | v ) ) ;
float max = ( r > v > b ? | | ( v > r & & v > b ? b b | | v ) ) ;
float s , h , l ;
if max = = min
s = 0
h = Number . NaN
else
s = if l < 0.5 then ( max - min ) / ( max + min ) else ( max - min ) / ( 2 - max - min )
if r = = max then h = ( g - b ) / ( max - min )
else if ( g = = max ) then h = 2 + ( b - r ) / ( max - min )
else if ( b = = max ) then h = 4 + ( r - g ) / ( max - min )
h * = 60 ;
h + = 360 if h < 0
[ h , s , l ]
}
2014-05-13 20:23:45 +00:00
int teinte ( Image entree , Image & sortie , float teinte ) { // Change la teinte de l'image
2014-05-19 09:40:08 +00:00
for ( int x = 0 , x = image . g_DimensionX ( ) , x + + ) {
for ( int y = 0 , y = image . g_DimensionY ( ) , y + + ) {
rvbVersTsl ( ) ;
g_pixel ( x , y ) ;
}
}
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-13 20:23:45 +00:00
int saturation ( Image entree , Image & sortie , float saturation ) { // Sature l'image
2014-05-05 09:29:04 +00:00
// Pour x = image.g_DimensionX()
2014-05-05 19:00:08 +00:00
// Pour y = image.g_DimensionY()
// Ajouter la variable saturation à chaque valeur de chaque pixel
// Ne pas dépasser le seuil limite MaxComposante !!!
// Fin Pour
2014-04-28 13:01:14 +00:00
// Fin Pour
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int luminosite ( Image entree , Image & sortie , float luminosite ) { // Augmente la luminosité de l'image
2014-04-28 13:01:14 +00:00
// Pour x=0 à x=image.g_DimensionX()
2014-05-05 19:00:08 +00:00
// Pour y=0 à y=image.g_DimensionY()
// si image.g_typeComposante=1
2014-05-08 17:44:09 +00:00
// pixel = image.g_pixel(x,y);
2014-05-05 19:00:08 +00:00
// pixel.g = luminosite*10+pixel.g;
2014-05-08 17:44:09 +00:00
// image.s_pixel(x, y, pixel);
2014-05-05 19:00:08 +00:00
// sinon si image.g_typeComposante=2
2014-05-08 17:44:09 +00:00
// pixel = image.g_pixel(x,y);
2014-05-05 19:00:08 +00:00
// pixel.r = luminosite*10+pixel.r;
// pixel.v = luminosite*10+pixel.v;
// pixel.b = luminosite*10+pixel.b;
2014-05-08 17:44:09 +00:00
// image.s_pixel(x, y, pixel);
2014-05-05 19:00:08 +00:00
// Fin si
// Fin Pour
2014-04-28 13:01:14 +00:00
// Fin Pour
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int contraste ( Image entree , Image & sortie , float contraste ) { // Accentue les contrastes de l'image
2014-04-28 13:01:14 +00:00
// pour x=0 à x=image.g_dimensionX()
2014-05-05 19:00:08 +00:00
// pour y=0 à y=image.g_DimensionY()
// si image.g_typeComposante=1
2014-05-08 17:44:09 +00:00
// pixel = image.g_pixel(x,y);
2014-05-05 19:00:08 +00:00
// pixel.g = contraste*pixel.g;
// if pixel.g > Image.g_maxComposante
// pixel.g = Image.g_maxComposante
// end if
2014-05-12 09:33:32 +00:00
// End If
// Fin Pour
// Fin Pour
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-03-27 18:03:14 +00:00
// Dessin
2014-05-19 09:40:08 +00:00
int trait ( Image entree , Image & sortie , int x1 , int y1 , int x2 , int y2 , Pixel couleur ) { // Dessine un trait d'un point (x1,y1) à un point (x2,y2)
int x , y , dx , dy ;
float e , e ( 1 , 0 ) , e ( 0 , 1 ) ; // valeur d’ erreur et incréments
dy = y2 - y1 ;
dx = x2 - x1 ;
y = y1 ; // rangée initiale
e = 0 , 0 ; // valeur d’ erreur initiale
e ( 1 , 0 ) = dy / dx ;
e ( 0 , 1 ) = - 1.0 ;
for ( x = x1 , x = x2 , x + + ) {
sortie . s_pixel ( x , y , couleur ) ;
if ( ( e = e + e ( 1 , 0 ) ) > = 0 , 5 ) { // erreur pour le pixel suivant de même rangée
y = y + 1 ; // choisir plutôt le pixel suivant dans la rangée supérieure
e = e + e ( 0 , 1 ) ; // ajuste l’ erreur commise dans cette nouvelle rangée
}
}
2014-05-05 09:29:04 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-05-05 09:29:04 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int rectangle ( Image entree , Image & sortie , int x1 , int y1 , int x2 , int y2 , Pixel couleur ) {
2014-05-08 17:44:09 +00:00
sortie = entree ;
for ( int x = x1 ; x < = x2 ; x + + ) {
for ( int y = y1 ; y < = y2 ; y + + ) {
sortie . s_pixel ( x , y , couleur ) ;
}
}
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 0 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int cercle ( Image entree , Image & sortie , int x0 , int y0 , int r , Pixel couleur ) {
2014-05-19 09:40:08 +00:00
sortie = entree ;
for ( int x = 0 , x = image . g_dimensionX ( ) , x + + ) {
for ( int y = 0 , y = image . g_dimensionY ( ) , y + + ) {
if ( sqrt ( pow ( x - x0 , 2 ) + pow ( y - y0 , 2 ) ) = = r ) {
sortie . s_pixel ( x , y , couleur ) ;
}
}
}
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int disque ( Image entree , Image & sortie , int x , int y , int r , Pixel couleur ) {
2014-05-19 09:40:08 +00:00
sortie = entree ;
for ( int x = 0 , x = image . g_dimensionX ( ) , x + + ) {
for ( int y = 0 , y = image . g_dimensionY ( ) , y + + ) {
if ( sqrt ( pow ( x - x0 , 2 ) + pow ( y - y0 , 2 ) ) < = r ) {
sortie . s_pixel ( x , y , couleur ) ;
}
}
}
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-03-27 18:03:14 +00:00
// Geométrie
2014-05-13 20:23:45 +00:00
int zoom ( Image entree , Image & sortie ) {
2014-04-14 10:02:13 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int pivoter ( Image entree , Image & sortie , int x0 , int y0 , float angle ) {
2014-05-10 10:13:06 +00:00
sortie = entree . g_vide ( ) ;
float xF , yF , angleF , xI , yI , angleI , h ;
Pixel pixel = entree . g_pixelVide ( ) ;
for ( xF = 0 ; xF < entree . g_dimensionX ( ) ; xF + + ) {
for ( yF = 0 ; yF < entree . g_dimensionY ( ) ; yF + + ) {
if ( xF = = x0 & & yF = = y0 ) {
xI = x0 ;
yI = y0 ;
} else {
2014-05-13 20:23:45 +00:00
angleF = atan ( ( yF - y0 ) / ( xF - x0 ) ) ;
angleF = ( xF - x0 < 0 ? angleF + PI : angleF ) ;
2014-05-10 10:13:06 +00:00
angleI = angleF - angle ;
2014-05-13 20:23:45 +00:00
h = sqrt ( pow ( xF - x0 , 2 ) + pow ( yF - y0 , 2 ) ) ;
xI = cos ( angleI ) * h + x0 ;
yI = sin ( angleI ) * h + y0 ;
2014-05-10 10:13:06 +00:00
}
entree . g_pixel ( ( int ) xI , ( int ) yI , pixel ) ;
sortie . s_pixel ( ( int ) xF , ( int ) yF , pixel ) ;
}
}
2014-05-13 20:23:45 +00:00
return 0 ;
2014-05-05 09:29:04 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int retourner ( Image entree , Image & sortie , int rotation ) {
2014-05-05 09:29:04 +00:00
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int redimensionner ( Image entree , Image & sortie , int x1 , int x2 , int y1 , int y2 ) {
2014-05-19 09:40:08 +00:00
sortie = * new Image ( x2 - x1 , y2 - y1 , entree . g_maxComposante ( ) , entree . g_typeComposantes ( ) ) ;
Pixel pixel = entree . g_pixelVide ( ) ;
for ( int x = x1 , x < = x2 , x + + ) {
for ( int y = y1 , y < = y2 , y + + ) {
entree . g_pixel ( x + x1 , y + y1 , pixel ) ;
sortie . s_pixel ( x , y , pixel ) ;
}
}
2014-05-13 20:23:45 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-03-27 18:03:14 +00:00
// Modification couleur
2014-05-13 20:23:45 +00:00
int convBIN ( Image entree , Image & sortie ) {
if ( entree . g_typeComposantes ( ) = = PILG_BIN ) {
sortie = entree ;
} else {
sortie = * new Image ( entree . g_dimensionX ( ) , entree . g_dimensionY ( ) , 0 , PILG_BIN ) ;
Pixel pixelI , pixelF ;
pixelF = sortie . g_pixelVide ( ) ;
for ( int x = 0 ; x < = entree . g_dimensionX ( ) ; x + + ) {
for ( int y = 0 ; y < = entree . g_dimensionY ( ) ; y + + ) {
entree . g_pixel ( x , y , pixelI ) ;
switch ( entree . g_typeComposantes ( ) ) {
case PILG_NIV :
pixelF . n = ( pixelI . g > entree . g_maxComposante ( ) / 2 ) ;
break ;
case PILG_RVB :
pixelF . n = ( ( pixelI . r + pixelI . v + pixelI . b ) / 3 > entree . g_maxComposante ( ) / 2 ) ;
break ;
default :
return 2 ;
2014-05-12 09:33:32 +00:00
}
2014-05-13 20:23:45 +00:00
sortie . s_pixel ( x , y , pixelF ) ;
2014-05-12 09:33:32 +00:00
}
2014-05-13 20:23:45 +00:00
}
2014-05-12 09:33:32 +00:00
}
2014-05-13 20:23:45 +00:00
return 0 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int convNIV ( Image entree , Image & sortie ) {
if ( entree . g_typeComposantes ( ) = = PILG_NIV ) {
sortie = entree ;
} else {
sortie = * new Image ( entree . g_dimensionX ( ) , entree . g_dimensionY ( ) , MAXCOMPOSANTEDEFAUT , PILG_NIV ) ;
Pixel pixelI , pixelF ;
pixelF = sortie . g_pixelVide ( ) ;
for ( int x = 0 ; x < = entree . g_dimensionX ( ) ; x + + ) {
for ( int y = 0 ; y < = entree . g_dimensionY ( ) ; y + + ) {
entree . g_pixel ( x , y , pixelI ) ;
switch ( entree . g_typeComposantes ( ) ) {
case PILG_BIN :
2014-05-12 09:33:32 +00:00
pixelF . g = ( pixelI . n ? sortie . g_maxComposante ( ) : 0 ) ;
2014-05-13 20:23:45 +00:00
break ;
case PILG_RVB :
pixelF . g = ( pixelI . r + pixelI . v + pixelI . b ) / 3.0 / entree . g_maxComposante ( ) * sortie . g_maxComposante ( ) ;
break ;
default :
return 1 ;
2014-05-12 09:33:32 +00:00
}
2014-05-13 20:23:45 +00:00
sortie . s_pixel ( x , y , pixelF ) ;
2014-05-12 09:33:32 +00:00
}
2014-05-13 20:23:45 +00:00
}
}
return 0 ;
2014-04-14 10:02:13 +00:00
}
2014-05-05 19:00:08 +00:00
2014-05-13 20:23:45 +00:00
int convRVB ( Image entree , Image & sortie ) {
2014-05-19 09:41:42 +00:00
return 1 ;
2014-04-14 10:02:13 +00:00
}
2014-03-27 18:03:14 +00:00
//Help
2014-05-13 20:23:45 +00:00
int aide ( ) {
2014-05-05 09:29:04 +00:00
//Afficher le texte suivant :
2014-05-13 20:23:45 +00:00
return 1 ;
2014-05-05 09:29:04 +00:00
}