Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "../LIBS/pile.h"
- // A. G.
- //
- // 2017/2018
- typedef struct IMAGE_NB_E{
- char * nom;
- int nbligne;
- int nbcolonne;
- unsigned char ** matrice;
- }IMAGE_NB;
- typedef struct IMAGE_RGB_E{
- char * nom;
- int nbligne;
- int nbcolonne;
- unsigned char ** matrice_R;
- unsigned char ** matrice_G;
- unsigned char ** matrice_B;
- unsigned int ** matrice_Enc;
- }IMAGE_RGB;
- typedef struct HISTOGRAMME_E{
- int ** valeurs;
- int nbcolonne;
- int nbligne;
- char type;
- }HISTOGRAMME;
- #define PARAM_BITS_NB 3
- #define PARAM_BITS_RGB 3
- #define FICHIER_DESCRIPTEUR "base_descripteur_image.txt"
- #define FICHIER_BASE "liste_base_image.txt"
- #define CHECK_FICHIER_BASE "wc -l liste_base_image.txt"
- /*
- *
- *
- * Lancer l'indexation via la fonction "indexImage()"
- *
- *
- */
- //==================================================================================
- //= Commun =
- //==================================================================================
- int lectureFichier(char * s, FILE ** f, int * nbligne, int * nbcolonne, int * type){
- //printf("\n\nOuverture du fichier image");
- if((*f=fopen(s,"r")) == NULL)
- {
- printf("\n\nErreur Fatale a l'ouverture du fichier \n");
- return 0;
- }
- //Lecture colonne / ligne
- //Enlever les printf pour les débugs
- fscanf(*f,"%i ", nbligne);
- //printf("\n\nNombre de lignes: %i", nbligne);
- fscanf(*f,"%i ", nbcolonne);
- //printf("\n\nNombre de colonnes: %i", nbcolonne);
- fscanf(*f,"%i ", type);
- //printf("\n\nNiveau lu: %i", type);
- return 1;
- }
- void creationLien(char * nom, char * type){
- FILE * base = fopen(FICHIER_BASE,"a+");
- int ID;
- FILE* check = popen(CHECK_FICHIER_BASE, "r");
- fscanf(check, "%d", &ID);
- fclose(check);
- fprintf(base, "<id> %d </id> <fichier> %s </fichier> <type> %s </type>\n", ID, nom, type);
- fclose(base);
- }
- /*Lis descripteur d'entiers */
- int lireBase(char * fichier) {
- int check = 0 ;
- FILE* read ;
- read = fopen(FICHIER_BASE, "r");
- char* val = malloc(sizeof(char));
- if(read != NULL){
- while (fscanf(read,"%s",val) == 1) {
- if(strcmp(val, fichier) == 0){
- check = 1;
- }
- if((strcmp(val, "NB") == 0) && check == 1)
- {
- free(val);
- fclose(read);
- return 1;
- }
- if((strcmp(val, "RGB") == 0) && check == 1)
- {
- free(val);
- fclose(read);
- return 3;
- }
- }
- }
- return 0;
- }
- //==================================================================================
- //= IMAGE N & B =
- //==================================================================================
- IMAGE_NB * initImageNB(char * nom_e, int nbligne_e, int nbcolonne_e){
- //Malloc structure
- IMAGE_NB * retour = malloc(sizeof(*retour));
- //Affectation des differentes valeurs de l'image
- retour->nbligne = nbligne_e;
- retour->nbcolonne = nbcolonne_e;
- retour->nom = nom_e;
- //Creation de la matrice image et affectation du pointeur dans la matrice
- int i;
- unsigned char ** matrice = malloc(sizeof(unsigned char *) * nbligne_e);
- for(i=0;i<retour->nbligne;i++){
- matrice[i] = malloc(sizeof(unsigned char) * nbcolonne_e);
- }
- retour->matrice = matrice;
- return retour;
- }
- void freeImageNB(IMAGE_NB * image){
- //free((*image).nom);
- int i;
- for(i=0;i<image->nbligne;i++){
- free(image->matrice[i]);
- }
- free(image->matrice);
- free(image);
- }
- void afficherImageNB(IMAGE_NB image){
- int i, j;
- printf("\n\nAffichage de la matrice :\n");
- printf("nbColonne:%d, nbLigne:%d\n", image.nbcolonne, image.nbligne);
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- printf("%i ", image.matrice[i][j]);
- }
- printf("\n");
- }
- printf("\nFin Affichage matrice");
- }
- int lectureImgageNB(IMAGE_NB image, FILE *f){
- int tempo, i, j, retour;
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- retour = fscanf(f,"%i ",&tempo);
- if(retour == EOF)
- {
- printf("\nErreur fatale : Pas assez de valeurs dans l'image");
- return 0;
- }
- if((tempo > 255) || (tempo < 0))
- {
- printf("\nErreur fatale : Valeur incorrecte dans l'image");
- return 0;
- }
- image.matrice[i][j] = tempo;
- }
- }
- return 1;
- }
- int quantificationImageNB(IMAGE_NB image){
- int i, j;
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- image.matrice[i][j] = image.matrice[i][j] >> (8-PARAM_BITS_NB);
- image.matrice[i][j] = image.matrice[i][j] << (8-PARAM_BITS_NB);
- }
- }
- return 1;
- }
- int creationDescripteurNB(IMAGE_NB image){
- FILE * descripteur = fopen(FICHIER_DESCRIPTEUR,"a+");
- //Cretion id
- int ID = 0;
- FILE* check = popen(CHECK_FICHIER_BASE, "r");
- fscanf(check, "%d", &ID);
- fclose(check);
- fputs("<id> ", descripteur);
- fprintf(descripteur, "%d", ID);
- fputs(" </id>\n", descripteur);
- fprintf(descripteur, "<type> NB </type>\n<nbcolonne> %d </nbcolonne>\n<nbligne> %d </nbligne>\n", image.nbcolonne,image.nbligne);
- /*
- Creation de l'histogramme de valeurs:
- 1. On alloue un espace mémoire d'une matrice 2dim x (nbcol * nbligne)
- => On considére qu'il peut y avoir maximum de (nbcol * nbligne) valeurs différentes
- dans la matrice image
- (en vérité, on pourrait diminuer l'espace mémoire en vérifiant le nb de bits de quantification,
- et en disant que si (nbcol * nbligne) > 2^nbit de quantification, on a alloue 2^nbit de quantification,
- mais c'est "inutile" car on traite ici toujours le pire cas).
- 2. On parcours la matrice.
- => La premiere colonne de "histogramme" corresponds aux valeurs
- => La seconde colonne corresponds au nb d'occurences
- => Si on trouve une occurence, on incrémente la seconde variable
- 3. Dès qu'on a traiter tous le tableau, on arrête.
- */
- int max = image.nbligne * image.nbcolonne;
- int ** histogramme = malloc(sizeof(int*)*2);
- histogramme[0] = malloc(sizeof(int)* max);
- histogramme[1] = malloc(sizeof(int)* max);
- int i, j, k;
- int nbvaleur = 0;
- unsigned char valeur;
- //Init
- for(i=0;i<2;i++)
- {
- for(j=0;j<max;j++)
- {
- histogramme[i][j] = -1;
- }
- }
- //Parcourir matrice
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- valeur = image.matrice[i][j];
- //printf("\nvaleur :%d",valeur);
- for(k=0;k<max;k++){
- //On regarde d'abord si on voit valeur, puis ensuite si on voit 0
- if(histogramme[0][k] == valeur)
- {
- histogramme[1][k] += 1;
- //printf("\nhistogramme:%d:%d, valeur: %d",histogramme[0][k],histogramme[0][k],valeur);
- break;
- }
- if(histogramme[0][k] == -1)
- {
- histogramme[0][k] = valeur;
- histogramme[1][k] = 1;
- nbvaleur += 1;
- //printf("\nhistogralmme init :%d",histogramme[1][k]);
- break;
- }
- }
- }
- }
- //Mise en forme des valeurs
- fputs("<valeurs>\n", descripteur);
- int valmin = 0x7FFFFFFF;
- int indicemin = 0;
- int valprec = -1;
- for(i=0;i<nbvaleur;i++)
- {
- valmin = 0x7FFFFFFF;
- for(j=0;j<nbvaleur;j++)
- {
- // On check si
- // 1. Val min (censé être la val min de la plage) est bien minimum
- // 2. On est bien supérieur à la val précédente
- if((valmin>histogramme[0][j]) && (valprec < histogramme[0][j]))
- {
- valmin = histogramme[0][j];
- indicemin = j;
- }
- }
- valprec = valmin;
- if(histogramme[0][indicemin]<16)
- fprintf(descripteur, "0x0%1x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- else
- fprintf(descripteur, "0x%2x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- }
- fputs("</valeurs>\n\n", descripteur);
- free(histogramme[0]);
- free(histogramme[1]);
- free(histogramme);
- fclose(descripteur);
- return 1;
- }
- //==================================================================================
- //= IMAGE RGB =
- //==================================================================================
- IMAGE_RGB * initImageRGB(char * nom_e, int nbligne_e, int nbcolonne_e){
- //Malloc structure
- IMAGE_RGB * retour = malloc(sizeof(*retour));
- //Affectation des differentes valeurs de l'image
- retour->nbligne = nbligne_e;
- retour->nbcolonne = nbcolonne_e;
- retour->nom = nom_e;
- //Creation des matrices image et affectation du pointeur dans la matrice
- int i;
- unsigned char ** matriceR = malloc(sizeof(unsigned char*) * nbligne_e);
- for(i=0;i<retour->nbligne;i++){
- matriceR[i] = malloc(sizeof(unsigned char) * nbcolonne_e);
- }
- retour->matrice_R = matriceR;
- unsigned char ** matriceB = malloc(sizeof(unsigned char*) * nbligne_e);
- for(i=0;i<retour->nbligne;i++){
- matriceB[i] = malloc(sizeof(unsigned char) * nbcolonne_e);
- }
- retour->matrice_B = matriceB;
- unsigned char ** matriceG = malloc(sizeof(unsigned char*) * nbligne_e);
- for(i=0;i<retour->nbligne;i++){
- matriceG[i] = malloc(sizeof(unsigned char) * nbcolonne_e);
- }
- retour->matrice_G = matriceG;
- unsigned int ** matriceEnc = malloc(sizeof(unsigned int*) * nbligne_e);
- for(i=0;i<retour->nbligne;i++){
- matriceEnc[i] = malloc(sizeof(unsigned int) * nbcolonne_e);
- }
- retour->matrice_Enc = matriceEnc;
- return retour;
- }
- void freeImageRGB(IMAGE_RGB * image){
- int i;
- for(i=0;i<image->nbligne;i++){
- free(image->matrice_R[i]);
- }
- for(i=0;i<image->nbligne;i++){
- free(image->matrice_G[i]);
- }
- for(i=0;i<image->nbligne;i++){
- free(image->matrice_B[i]);
- }
- for(i=0;i<image->nbligne;i++){
- free(image->matrice_Enc[i]);
- }
- free(image->matrice_R);
- free(image->matrice_G);
- free(image->matrice_B);
- free(image);
- }
- void afficherImageRGBEnc(IMAGE_RGB image){
- int i, j;
- printf("nbColonne:%d, nbLigne:%d\n", image.nbcolonne, image.nbligne);
- printf("\n\nAffichage de la matrice R :\n");
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- printf("%x ", image.matrice_Enc[i][j]);
- }
- printf("\n");
- }
- }
- void afficherImageRGB(IMAGE_RGB image){
- int i, j;
- printf("nbColonne:%d, nbLigne:%d\n", image.nbcolonne, image.nbligne);
- printf("\n\nAffichage de la matrice R :\n");
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- printf("%i ", image.matrice_R[i][j]);
- }
- printf("\n");
- }
- printf("\n\nAffichage de la matrice G :\n");
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- printf("%i ", image.matrice_G[i][j]);
- }
- printf("\n");
- }
- printf("\n\nAffichage de la matrice B :\n");
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- printf("%i ", image.matrice_B[i][j]);
- }
- printf("\n");
- }
- printf("\nFin Affichage matrice");
- }
- int lectureImgageRGB(IMAGE_RGB image, FILE *f){
- int tempo, i, j, retour;
- // Lecture image rouge,
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- retour = fscanf(f,"%i ",&tempo);
- if(retour == EOF)
- {
- printf("\nErreur fatale : Pas assez de valeurs dans l'image");
- return 0;
- }
- if((tempo > 255) || (tempo < 0))
- {
- printf("\nErreur fatale : Valeur incorrecte dans l'image");
- return 0;
- }
- image.matrice_R[i][j] = tempo;
- }
- }
- //Lecture image verte
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- retour = fscanf(f,"%i ",&tempo);
- if(retour == EOF)
- {
- printf("\nErreur fatale : Pas assez de valeurs dans l'image");
- return 0;
- }
- if((tempo > 255) || (tempo < 0))
- {
- printf("\nErreur fatale : Valeur incorrecte dans l'image");
- return 0;
- }
- image.matrice_G[i][j] = tempo;
- }
- }
- //lecture image bleue
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- retour = fscanf(f,"%i ",&tempo);
- if(retour == EOF)
- {
- printf("\nErreur fatale : Pas assez de valeurs dans l'image");
- return 0;
- }
- if((tempo > 255) || (tempo < 0))
- {
- printf("\nErreur fatale : Valeur incorrecte dans l'image");
- return 0;
- }
- image.matrice_B[i][j] = tempo;
- }
- }
- return 1;
- }
- int quantificationImageRGB(IMAGE_RGB image){
- int i, j;
- for(i=0;i<image.nbligne;i++){
- for(j=0;j<image.nbcolonne;j++){
- image.matrice_R[i][j] = image.matrice_R[i][j] >> (8-PARAM_BITS_RGB);
- image.matrice_R[i][j] = image.matrice_R[i][j] << (8-PARAM_BITS_RGB);
- image.matrice_G[i][j] = image.matrice_G[i][j] >> (8-PARAM_BITS_RGB);
- image.matrice_G[i][j] = image.matrice_G[i][j] << (8-PARAM_BITS_RGB);
- image.matrice_B[i][j] = image.matrice_B[i][j] >> (8-PARAM_BITS_RGB);
- image.matrice_B[i][j] = image.matrice_B[i][j] << (8-PARAM_BITS_RGB);
- //Mise dans la bonne matrice
- // R, puis G, puis B
- image.matrice_Enc[i][j] = (image.matrice_R[i][j]<<PARAM_BITS_RGB*2) + (image.matrice_G[i][j]<<PARAM_BITS_RGB*1) + image.matrice_B[i][j];
- }
- }
- return 1;
- }
- int creationDescripteurRGB(IMAGE_RGB image){
- FILE * descripteur = fopen(FICHIER_DESCRIPTEUR,"a+");
- //Cretion id
- int ID = 0;
- FILE* check = popen(CHECK_FICHIER_BASE, "r");
- fscanf(check, "%d", &ID);
- fclose(check);
- fputs("<id> ", descripteur);
- fprintf(descripteur, "%d", ID);
- fputs(" </id>\n", descripteur);
- fprintf(descripteur, "<type> RGB </type>\n<nbcolonne> %d </nbcolonne>\n<nbligne> %d </nbligne>\n", image.nbcolonne,image.nbligne);
- /*
- Creation de l'histogramme de valeurs:
- 1. On alloue un espace mémoire d'une matrice 2dim x (nbcol * nbligne)
- => On considére qu'il peut y avoir maximum de (nbcol * nbligne) valeurs différentes
- dans la matrice image
- (en vérité, on pourrait diminuer l'espace mémoire en vérifiant le nb de bits de quantification,
- et en disant que si (nbcol * nbligne) > 2^nbit de quantification, on a alloue 2^nbit de quantification,
- mais c'est "inutile" car on traite ici toujours le pire cas).
- 2. On parcours la matrice.
- => La premiere colonne de "histogramme" corresponds aux valeurs
- => La seconde colonne corresponds au nb d'occurences
- => Si on trouve une occurence, on incrémente la seconde variable
- 3. Dès qu'on a traiter tous le tableau, on arrête.
- */
- int max = image.nbligne * image.nbcolonne;
- int ** histogramme = malloc(sizeof(int*)*2);
- histogramme[0] = malloc(sizeof(int)* max);
- histogramme[1] = malloc(sizeof(int)* max);
- int i, j, k;
- int nbvaleur = 0;
- unsigned int valeur;
- //Init
- for(i=0;i<2;i++)
- {
- for(j=0;j<max;j++)
- {
- histogramme[i][j] = -1;
- }
- }
- //Parcourir matrice
- for(i=0;i<image.nbligne;i++)
- {
- for(j=0;j<image.nbcolonne;j++)
- {
- valeur = image.matrice_Enc[i][j];
- //printf("\nvaleur :%d",valeur);
- for(k=0;k<max;k++){
- //On regarde d'abord si on voit valeur, puis ensuite si on voit 0
- if(histogramme[0][k] == valeur)
- {
- histogramme[1][k] += 1;
- //printf("\nhistogramme:%d:%d, valeur: %d",histogramme[0][k],histogramme[0][k],valeur);
- break;
- }
- if(histogramme[0][k] == -1)
- {
- histogramme[0][k] = valeur;
- histogramme[1][k] = 1;
- nbvaleur += 1;
- //printf("\nhistogralmme init :%d",histogramme[1][k]);
- break;
- }
- }
- }
- }
- //Mise en forme des valeurs
- fputs("<valeurs>\n", descripteur);
- int valmin = 0x7FFFFFFF;
- int indicemin = 0;
- int valprec = -1;
- for(i=0;i<nbvaleur;i++)
- {
- valmin = 0x7FFFFFFF;
- for(j=0;j<nbvaleur;j++)
- {
- // On check si
- // 1. Val min (censé être la val min de la plage) est bien minimum
- // 2. On est bien supérieur à la val précédente
- if((valmin>histogramme[0][j]) && (valprec < histogramme[0][j]))
- {
- valmin = histogramme[0][j];
- indicemin = j;
- }
- }
- valprec = valmin;
- if(histogramme[0][indicemin]<0x10)
- fprintf(descripteur, "0x000%1x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- else
- {
- if(histogramme[0][indicemin]<0X100)
- fprintf(descripteur, "0x00%2x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- else
- {
- if(histogramme[0][indicemin]<0X1000)
- fprintf(descripteur, "0x0%3x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- else
- fprintf(descripteur, "0x%4x: %i;\n", histogramme[0][indicemin], histogramme[1][indicemin]);
- }
- }
- }
- fputs("</valeurs>\n\n", descripteur);
- free(histogramme[0]);
- free(histogramme[1]);
- free(histogramme);
- fclose(descripteur);
- return 1;
- }
- //==================================================================================
- //= index Image =
- //==================================================================================
- int indexImageNB(FILE * f, char * adresse, int nbligne, int nbcolonne){
- IMAGE_NB * image;
- image = initImageNB(adresse,nbligne,nbcolonne);
- if(!(lectureImgageNB(*image,f)))
- return 0;
- if(!(quantificationImageNB(*image)))
- return 0;
- creationDescripteurNB(*image);
- fclose(f);
- freeImageNB(image);
- return 1;
- }
- int indexImageRGB(FILE * f, char * adresse, int nbligne, int nbcolonne){
- IMAGE_RGB * image;
- image = initImageRGB(adresse,nbligne,nbcolonne);
- if(!lectureImgageRGB(*image,f))
- return 0;
- if(!quantificationImageRGB(*image))
- return 0;
- //afficherImageRGB(*image);
- //afficherImageRGBEnc(*image);
- creationDescripteurRGB(*image);
- fclose(f);
- freeImageRGB(image);
- return 1;
- }
- int indexImage()
- {
- //remove(FICHIER_DESCRIPTEUR);
- //remove(FICHIER_BASE);
- FILE * p;
- FILE * f = NULL;
- char * res = malloc(sizeof(char));
- int nbligne, nbcolonne, type;
- int id = 1;
- //Test RGB
- p = popen("ls TEST_RGB/ | grep .txt ", "r");
- while (fscanf(p,"%s",res) == 1) {
- char fileToRead[100]="TEST_RGB/";
- strcat(fileToRead, res);
- //printf("%s\n",fileToRead );
- lectureFichier(fileToRead,&f,&nbligne,&nbcolonne,&type);
- if(lireBase(res) != type)
- {
- if((type != 3 ) && (type != 1)){
- printf("\nType de l'image inconnu !\nArret de l'indexation");
- return 0;}
- if(type == 1){
- if(indexImageNB(f, fileToRead, nbligne, nbcolonne))
- creationLien(res,"NB");
- }
- if(type == 3){
- if(indexImageRGB(f, fileToRead, nbligne, nbcolonne))
- creationLien(res,"RGB");
- }
- }
- id += 1;
- fclose(f);
- }
- fclose(p);
- //Test NB
- p = popen("ls TEST_NB/ | grep .txt ", "r");
- while (fscanf(p,"%s",res) == 1) {
- char fileToRead[100]="TEST_NB/";
- strcat(fileToRead, res);
- //Descripteur non présent
- lectureFichier(fileToRead,&f,&nbligne,&nbcolonne,&type);
- if(lireBase(res) != type)
- {
- //printf("%s\n",fileToRead );
- if((type != 3 ) && (type != 1)){
- printf("\nType de l'image inconnu !\nArret de l'indexation");
- return 0;}
- if(type == 1){
- if(indexImageNB(f, fileToRead, nbligne, nbcolonne))
- creationLien(res,"NB");
- }
- if(type == 3){
- if(indexImageRGB(f, fileToRead, nbligne, nbcolonne))
- creationLien(res,"RGB");
- }
- }
- id += 1;
- fclose(f);
- }
- fclose(p);
- return 1;
- }
- //==================================================================================
- //= Comparaison =
- //==================================================================================
- HISTOGRAMME * lireDescripteur(FILE * read){
- HISTOGRAMME * retour = malloc(sizeof(HISTOGRAMME));
- int etat = 0;
- int id, type, nbligne, nbcolonne;
- unsigned int max;
- unsigned int cpt = 0;
- int i;
- char canswitch = 1;
- char* val = malloc(sizeof(char));
- int ** histoTempo;
- while (fscanf(read,"%s",val) == 1) {
- // Fonctionnement en MAE
- // Actions
- if(etat == 1){
- id = atoi(val);
- etat = 0;
- }
- if(etat == 2){
- if(strcmp(val, "RGB"))
- type = 3;
- else
- type = 1;
- etat = 0;
- }
- if(etat == 3){
- nbcolonne = atoi(val);
- etat = 0;
- }
- if(etat == 4){
- nbligne = atoi(val);
- etat = 0;
- }
- // Valeurs
- if(etat == 5){
- max = nbligne * nbcolonne;
- histoTempo = malloc(sizeof(int*)*2);
- histoTempo[0] = malloc(sizeof(int)*max);
- histoTempo[1] = malloc(sizeof(int)*max);
- cpt = 0;
- canswitch = 0;
- histoTempo[0][0] = (int)strtol(val, NULL, 0);
- etat = 52;
- }
- if(etat == 51 && canswitch){
- histoTempo[0][cpt] = (int)strtol(val, NULL, 0);
- etat = 52;
- canswitch = 0;
- }
- if(etat == 52 && canswitch){
- histoTempo[1][cpt] = atoi(val);
- etat = 51;
- canswitch = 0;
- cpt += 1;
- }
- // Changement d'états
- if(strcmp(val, "<id>") == 0 && (etat == 0))
- etat = 1;
- if(strcmp(val, "<type>") == 0 && (etat == 0))
- etat = 2;
- if(strcmp(val, "<nbcolonne>") == 0 && (etat == 0))
- etat = 3;
- if(strcmp(val, "<nbligne>") == 0 && (etat == 0))
- etat = 4;
- if(strcmp(val, "<valeurs>") == 0 && (etat == 0))
- etat = 5;
- //if(strcmp(val, "</valeurs>") == 0 && ((etat==51) || (etat == 52)))
- if(strcmp(val, "</valeurs>") == 0)
- {
- //affichage debug
- printf("id:%u, type:%u, nbcolonne:%u, nbligne:%u\n", id, type, nbcolonne,nbligne);
- /*for(i=0;i<cpt;i++){
- printf("%x : %u \n", histoTempo[0][i], histoTempo[1][i]);
- }*/
- int ** histogramme = malloc(sizeof(int*)*2);
- histogramme[0] = malloc(sizeof(int)*cpt);
- histogramme[1] = malloc(sizeof(int)*cpt);
- for(i=0;i<cpt;i++){
- histogramme[0][cpt] = histoTempo[0][cpt];
- histogramme[1][cpt] = histoTempo[1][cpt];
- }
- cpt = 0;
- etat = 0;
- retour->valeurs = histogramme;
- retour->nbcolonne = nbcolonne;
- retour->nbligne = nbligne;
- retour->type = type;
- nbligne = 0;
- nbcolonne = 0;
- type = 0;
- free(histoTempo[0]);
- free(histoTempo[1]);
- free(histoTempo);
- free(val);
- return retour;
- }
- canswitch =1;
- }
- return retour;
- }
- void test()
- {
- FILE * read = fopen(FICHIER_DESCRIPTEUR,"r");
- HISTOGRAMME * test;
- int i = 0;
- test = lireDescripteur(read);
- //printf("%i\n\n\n", test->valeurs[1][1]);
- fclose(read);
- free(test);
- }
- //==================================================================================
- //= Main =
- //==================================================================================
- int main(){
- //indexImage();
- test();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement