IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

ecriture avec libpng


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de trax44
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    300
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 300
    Par défaut ecriture avec libpng
    Bonjour les gens,

    le problème est simple, j'arrive à lire mon image png (et à l'afficher en ascii), mais quand je veux l'écrire dans un nouveau fichier, ça plante.

    Quand je ferme l'écriture (ligne 170) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
        png_write_image (pngP, img_read->img);
        png_write_end (pngP, infoP);
    il me renvoie comme erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    libpng error: No IDATs written into file
    make: *** [ALL] Abandon
    Code complet : (http://clubnix.esiee.fr/~trax/libpng.tar.bz2)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #include "main.h"
     
    int main (void) {
    	img_s img_read_s;
    	img_r img_read;	
    	img_read = & img_read_s; 
    	read_img(img_read);
    	write_img(img_read);
    	return 0;
    }
     
    void read_img(img_r img_read){
    	int def,color;
    	int tailpix;
     
    	png_structp pngP;
    	png_infop infoP;
     
    	FILE *file;
    	png_byte magic[8];
     
    	file = fopen ("plop.png", "rb");
    	if (!file){
    		printf("Erreur fichier inconnu\n");
    		return ;
    	}
     
    	fread (magic, sizeof(magic[0]), sizeof(magic), file);
     
    	if (!png_check_sig(magic, sizeof(magic))){
    		printf("Erreur dans l'entete du fichier\n");
    		fclose(file);
    		return ;
    	}
     
    	pngP = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
     
    	if(!pngP){
    		fclose(file);
    		printf("Erreur lors de la création du pointeur de structure\n");
    		return ;
    	}
     
    	infoP = png_create_info_struct (pngP);
     
    	if(!infoP){
    		fclose(file);
    		png_destroy_read_struct (&pngP, NULL, NULL); /*deuxieme argument infoP ???*/
    		printf("Erreur lors de la création du pointeur d'info\n");
    		return ;
    	}
     
    	png_init_io (pngP, file);
    	png_set_sig_bytes (pngP, sizeof (magic));
    	png_read_info (pngP, infoP);
     
     
    	def = png_get_bit_depth (pngP, infoP);
    	color = png_get_color_type (pngP, infoP);
     
    	printf("Profondeur : %d\nType de couleur : %d\n", def, color);
     
    	img_read->img_prop = &img_read->img_prop_s;
    	img_read->img_prop->largeur = &img_read->img_prop->png_uint_32_largeur;
    	img_read->img_prop->hauteur = &img_read->img_prop->png_uint_32_hauteur;
    	img_read->img_prop->profondeur = &img_read->img_prop->int_profondeur;
    	img_read->img_prop->couleur = &img_read->img_prop->int_couleur;
    	img_read->img_prop->entrelacement = &img_read->img_prop->int_entrelacement;
    	img_read->img_prop->compression = &img_read->img_prop->int_compression;
    	img_read->img_prop->filtre = &img_read->img_prop->int_filtre;
     
    	png_get_IHDR (pngP, infoP,
    	  img_read->img_prop->largeur,
    	  img_read->img_prop->hauteur,
    	  img_read->img_prop->profondeur,
    	  img_read->img_prop->couleur,
    	  img_read->img_prop->entrelacement, 
    	  img_read->img_prop->compression,
    	  img_read->img_prop->filtre);	
     
    	printf("\nimg_prop->largeur : %d\t\timg_prop->hauteur : %d \nimg_prop->profondeur : %d\t\timg_prop->couleur : %d\nimg_prop->entrelacement : %d\timg_prop->compression : %d\nimg_prop->filtre : %d\n",
    		(int)*img_read->img_prop->largeur,
    		(int)*img_read->img_prop->hauteur,
    		*img_read->img_prop->profondeur,
    		*img_read->img_prop->couleur,
    		*img_read->img_prop->entrelacement,
    		*img_read->img_prop->compression,
    		*img_read->img_prop->filtre);
     
    	tailpix = 	(int)(img_read->img_prop->png_uint_32_largeur)*
    				(int)(img_read->img_prop->png_uint_32_hauteur)*
    				(img_read->img_prop->int_profondeur);
    	int i;
     
    	printf("Taille des pixels de l'image : %d\n", tailpix );
              img_read->img = (png_bytep)malloc(img_read->img_prop->png_uint_32_hauteur*sizeof(png_bytep));
              for (i = 0 ; i < (img_read->img_prop->png_uint_32_hauteur) ; i++){
                 img_read->img[i]=(png_bytep)malloc(img_read->img_prop->png_uint_32_largeur*png_sizeof(png_bytep)*3);
    		  }    
     
    	png_read_image(pngP, img_read->img);
     
    	printf("ping\n");
    /*	int ii ;
    	for (ii = 0 ; ii < (int)img_read->img_prop->png_uint_32_hauteur ; ii++){
    		for (i = 0 ; i < (int)img_read->img_prop->png_uint_32_largeur ; i++){
    			if (img_read->img[ii][i] > 201){printf(".");}else{printf(" ");}
    		}
    		printf("\n");
    	}
    */	printf("\n");
     
    	png_read_end (pngP, infoP);
    	png_destroy_read_struct (&pngP, &infoP, NULL);
     
    	fclose (file);
     
    }
     
    /*=====================================================================================*/
    void write_img(img_r img_read){
     
        printf("%d %d %d %d %d %d %d\n",
          (int)*img_read->img_prop->largeur,
          (int)*img_read->img_prop->hauteur,
          *img_read->img_prop->profondeur,
          *img_read->img_prop->couleur,
          *img_read->img_prop->entrelacement,
          *img_read->img_prop->compression,
          *img_read->img_prop->filtre);
     
    	FILE *file;
    	png_structp pngP;
    	png_infop infoP;
    	if((file = fopen("plop2.png", "wb"))== NULL){
    		printf("Impossible d'ouvrir le fichier\n");
    		return;
    	}
     
    	if((pngP = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) == NULL) {
    		printf("Impossible de créer le pointeur de structure\n");
    		return;
    	}
     
    	if ((infoP = png_create_info_struct(pngP)) == NULL){
    		printf("Impossible de créer le pointeur de structure d'info\n");
    	}
     
    	printf("ping1\n");
    	png_init_io(pngP, file);
    	printf("ping2\n");
     
        png_set_IHDR (pngP, infoP,
          *img_read->img_prop->largeur,
          *img_read->img_prop->hauteur,
          *img_read->img_prop->profondeur,
          *img_read->img_prop->couleur,
    	  *img_read->img_prop->entrelacement, 
          *img_read->img_prop->compression,
          *img_read->img_prop->filtre);
    	printf("ping3\n");
     
    	int i, ii ;
        for (ii = 0 ; ii < (int)img_read->img_prop->png_uint_32_hauteur ; ii++){
            for (i = 0 ; i < (int)img_read->img_prop->png_uint_32_largeur ; i++){
                if (img_read->img[ii][i] > 201){printf(".");}else{printf(" ");}
            }
            printf("\n");
        }
    	png_write_image (pngP, img_read->img);
    	printf("ping4\n");
    	png_write_end (pngP, infoP); /*<= ça plante la */ 
    	printf("ping5\n");
    	png_destroy_write_struct (&pngP, &infoP);
    	printf("ping6\n");
    	fclose(file);
     
    return;
    }
    Cordialement

    trax
    Fichiers attachés Fichiers attachés

  2. #2
    Membre éclairé Avatar de trax44
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    300
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 300
    Par défaut
    J'ai édité en hexa une image png et j'ai vu qu'il fallait mettre en plus le PLTE
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur E/S 105 lors d'ecriture avec un fichier text
    Par Andry dans le forum Langage
    Réponses: 5
    Dernier message: 20/02/2009, 11h29
  2. Probleme d'ecriture avec JExcel
    Par LawSter dans le forum Documents
    Réponses: 1
    Dernier message: 31/05/2007, 16h51
  3. Ecriture avec FileStream
    Par Bob Groove dans le forum Windows Forms
    Réponses: 3
    Dernier message: 20/02/2007, 17h25
  4. [debutant] ecriture avec FileWriter
    Par newgeek91 dans le forum Langage
    Réponses: 1
    Dernier message: 09/11/2006, 23h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo