Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1384 connectés 

  FORUM HardWare.fr
  Programmation
  C

  Impossible de lancer une fonction ...

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Impossible de lancer une fonction ...

n°1943553
Ydalb
In Crêpes n' Cidre I Trust!
Posté le 23-11-2009 à 15:35:27  profilanswer
 

Bonjour à tous!
 
J'ai besoin de créer un programme qui va lire les pixels d'une image png 1 par 1 (pour plus tard y reconnaitre des lettres dedans).
 
Voici mon header :

Code :
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #define PNG_DEBUG 3
  6. #include <png.h>
  7. void read_png_file(char* file_name);
  8. void process_file(void);
  9. void abort_(const char * s, ...);


 
 
Et voici mon .c :

Code :
  1. /*
  2. * Copyright 2002-2008 Guillaume Cottenceau.
  3. *
  4. * This software may be freely redistributed under the terms
  5. * of the X11 license.
  6. *
  7. */
  8. #include "open_png.h"
  9. /*
  10. * Ne pas mettre en variables globales
  11. */
  12. int x, y;
  13. int width, height;
  14. png_byte color_type;
  15. png_byte bit_depth;
  16. png_structp png_ptr;
  17. png_infop info_ptr;
  18. int number_of_passes;
  19. png_bytep * row_pointers;
  20. void read_png_file(char* file_name)
  21. {
  22.   printf("Entering read_png_file" );
  23. char header[8]; // 8 is the maximum size that can be checked
  24. /* open file and test for it being a png */
  25. FILE *fp = fopen(file_name, "rb" );
  26. if (!fp)
  27.  abort_("[read_png_file] File %s could not be opened for reading", file_name);
  28. fread(header, 1, 8, fp);
  29. if (png_sig_cmp(header, 0, 8))
  30.  abort_("[read_png_file] File %s is not recognized as a PNG file", file_name);
  31. /* initialize stuff */
  32. png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  33. if (!png_ptr)
  34.  abort_("[read_png_file] png_create_read_struct failed" );
  35. info_ptr = png_create_info_struct(png_ptr);
  36. if (!info_ptr)
  37.  abort_("[read_png_file] png_create_info_struct failed" );
  38. if (setjmp(png_jmpbuf(png_ptr)))
  39.  abort_("[read_png_file] Error during init_io" );
  40. png_init_io(png_ptr, fp);
  41. png_set_sig_bytes(png_ptr, 8);
  42. png_read_info(png_ptr, info_ptr);
  43. width = info_ptr->width;
  44. height = info_ptr->height;
  45. color_type = info_ptr->color_type;
  46. bit_depth = info_ptr->bit_depth;
  47. number_of_passes = png_set_interlace_handling(png_ptr);
  48. png_read_update_info(png_ptr, info_ptr);
  49. /* read file */
  50. if (setjmp(png_jmpbuf(png_ptr)))
  51.  abort_("[read_png_file] Error during read_image" );
  52. row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
  53. for (y=0; y<height; y++)
  54.  row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes);
  55. png_read_image(png_ptr, row_pointers);
  56.         fclose(fp);
  57. }
  58. /*
  59. * Voir pour creer un tableau autre que ptr pour se creer unn tableau perso, genre monochromatique en prenant une couleur
  60. * de fond unique et une couleur de lettre unique.  
  61. */
  62. void process_file(void)
  63. {
  64.   if (info_ptr->color_type != PNG_COLOR_TYPE_RGBA)
  65.     abort_("[process_file] color_type of input file must be PNG_COLOR_TYPE_RGBA (is %d)", info_ptr->color_type);
  66.   for (y=0; y<height; y++) {
  67.     png_byte* row = row_pointers[y];
  68.     for (x=0; x<width; x++) {
  69.       /* png_byte* ptr = &(row[x*4]); */
  70.       png_uint_16* ptr = (png_uint_16*)&(row[x*6]);
  71.       printf("Pixel at position [ %d - %d ] has the following RGBA values: %d - %d - %d - %d\n",
  72.      x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
  73.      
  74.       /* set red value to 0 and green value to the blue one */
  75.       ptr[0] = 0;
  76.       ptr[1] = ptr[2];
  77.     }
  78.   }
  79.  
  80. }
  81. void abort_(const char * s, ...)
  82. {
  83.   printf("moo" );
  84.   va_list args;
  85.   va_start(args, s);
  86.   vfprintf(stderr, s, args);
  87.   fprintf(stderr, "\n" );
  88.   va_end(args);
  89.   abort();
  90. }
  91. int main(int argc, char **argv)
  92. {
  93.   if (argc < 2)
  94.     {
  95.       printf("Usage: program_name <file_in>" );
  96.       exit(1);
  97.     }
  98.   printf("Opening %s ...\n", argv[1]);
  99.   read_png_file(argv[1]);
  100.   printf("Proccessing %s ...\n", argv[1]);
  101.   process_file();
  102.   return 0;
  103. }


 
Lors de la compilation du programme, j'obtiens un warning :

Citation :


[ledolequ@fujiw120-l projet]$ gcc -Wall -g -lpng open_png.c
open_png.c: In function 'read_png_file':
open_png.c:43: attention : pointer targets in passing argument 1 of 'png_sig_cmp' differ in signedness
 
La ligne 43 correspond à :
if (png_sig_cmp(header, 0, 8))


 
Et lorsque j'essaie de lancer le programme avec une image en paramètre, voici ce qui se passe :

Citation :


[ledolequ@fujiw120-l projet]$ ./png ref.png  
Opening ref.png ...
[ledolequ@fujiw120-l projet]$  


 
Autrement dit, il a l'air de bloqué entre  

Code :
  1. printf("Opening %s ...\n", argv[1]);
  2.   read_png_file(argv[1]);


 
 
Des idées ? :(


Message édité par Ydalb le 23-11-2009 à 15:36:29

---------------
:o
mood
Publicité
Posté le 23-11-2009 à 15:35:27  profilanswer
 

n°1943555
theshockwa​ve
I work at a firm named Koslow
Posté le 23-11-2009 à 15:37:52  profilanswer
 

quel environnement as-tu pour développer ? Tu dois bien avoir un débugger sous le coude, ce sereait le bon moment pour apprendre à t'en servir, parce que tracer à coups de printf va vite devenir un calvaire


---------------
last.fm
n°1943559
Ydalb
In Crêpes n' Cidre I Trust!
Posté le 23-11-2009 à 15:41:23  profilanswer
 

Je développe sous CentOS en utilisant emacs. Je vais voir si mon école met à notre disposition des débuggers :)


---------------
:o
n°1943560
Ydalb
In Crêpes n' Cidre I Trust!
Posté le 23-11-2009 à 15:43:49  profilanswer
 

Avec gdb :

 
Code :
  1. [ledolequ@fujiw120-l projet]$ gdb png
  2. GNU gdb Fedora (6.8-37.el5)
  3. Copyright (C) 2008 Free Software Foundation, Inc.
  4. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  5. This is free software: you are free to change and redistribute it.
  6. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  7. and "show warranty" for details.
  8. This GDB was configured as "i386-redhat-linux-gnu"...
  9. (no debugging symbols found)
  10. (gdb) run ref.png
  11. Starting program: /home2/ledolequ/c/redoublage/projet/png ref.png
  12. (no debugging symbols found)
  13. (no debugging symbols found)
  14. (no debugging symbols found)
  15. (no debugging symbols found)
  16. (no debugging symbols found)
  17. (no debugging symbols found)
  18. Opening ref.png ...
  19. Program exited normally.
  20. (gdb)


Message édité par Ydalb le 23-11-2009 à 15:43:59

---------------
:o
n°1943584
theshockwa​ve
I work at a firm named Koslow
Posté le 23-11-2009 à 16:12:58  profilanswer
 

tente de mettre un breakpoint dans la fonction où tu remplis tes globales.
 
ta fonction png_read_info ne peut pas échouer ? J'ai comme l'impression que les infos que cette fonction te retourne sont nulles. Avoir soit la width soit la height à 0 expliquerait le comportement que tu obtiens


---------------
last.fm
n°1943588
Ydalb
In Crêpes n' Cidre I Trust!
Posté le 23-11-2009 à 16:20:46  profilanswer
 

Alors j'ai abandonné emacs pour passer sur eclipse, après quelques minutes à voir comment configurer le bouzin, et utiliser son débugger, le test qui me fait aborder le programme est :
 
Fonction process_file :

Code :
  1. if (info_ptr->color_type != PNG_COLOR_TYPE_RGBA)
  2.      abort_("[process_file] color_type of input file must be PNG_COLOR_TYPE_RGBA (is %d)", info_ptr->color_type);


 
Je l'ai commenté et ça tourne nickel. J'vais me pencher sur ce test pour voir ce qui ne va pas.
 
Merci pour ton aide theshockwave :jap:


---------------
:o

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  Impossible de lancer une fonction ...

 

Sujets relatifs
J'ai besoin d'une petite mise à jour de syntaxe : fonction eregiProblème avec la fonction Unlink
vba excell variable texte dans cellule active impossibleappel d'une fonction dans une boucle ne se réalise qu'une fois
arbre binaire/fonction recursif/lecture fichierlecture d'un .flv (fonction random)
lecteur video + fonction randomConditions en fonction de l'heure en PHP
[SOAP]Appel d'une fonction depuis un client de web serviceImpossible de suprimer un fichier .htacces en double
Plus de sujets relatifs à : Impossible de lancer une fonction ...


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR