bonjour,

j'ai réussio a faire un petit bout de code qui utilise la libjpeg, et qui compresse et décompresse une image en JPEG.
par contre, je travail avec beaucoup de descripteur de fichier, ou de fichier.
et j'aimerai en faite, travailler avec des buffer ou les information serai dedans.
et pour avoir l'image, il me suffirai de "fwrite" le buffer.

je m'explique :
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
 
 
void convjpeg(char * image_buffer,int image_height,int image_width,int quality,char*filename)
{
 
struct jpeg_compress_struct cinfo;
 struct jpeg_error_mgr jerr;
  FILE * outfile;               /* target file */
  JSAMPROW row_pointer[1];      /* pointer to JSAMPLE row[s] */
  int row_stride;  
 
  cinfo.err = jpeg_std_error(&jerr);
 jpeg_create_compress(&cinfo);
 
  if ((outfile = fopen(filename, "wb")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    exit(1);
  }
  jpeg_stdio_dest(&cinfo, outfile);
 
  cinfo.image_width = image_width;      /* image width and height, in pixels */
  cinfo.image_height = image_height;
  cinfo.input_components = 3;           /* # of color components per pixel */
  cinfo.in_color_space = JCS_RGB;  
  jpeg_set_defaults(&cinfo);
 
  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
 
 jpeg_start_compress(&cinfo, TRUE);
 
   row_stride = image_width * 3;
 
 
  while (cinfo.next_scanline < cinfo.image_height) {
    /* jpeg_write_scanlines expects an array of pointers to scanlines.
     * Here the array is only one element long, but you could pass
     * more than one scanline at a time if that's more convenient.
     */
    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
    (void) jpeg_write_scanlines(&cinfo, row_pointer,1);
  }
 
    jpeg_finish_compress(&cinfo);
 
   fclose(outfile);    
 
    jpeg_destroy_compress(&cinfo);
 
  //pour la compression je voudrai récupérer un buffer avec l'image compresser , ou pour la voir il me suffirait de la "fwrite" dans un fichier, en faite si jarrive a avoir que le contenu rgb,sa m'intéresserai.
 
 
 
}
 
int Jpg2Bmp( char * pszJpgFile)    //la j'aimerai bein passer un buffer , quelle sont les fonction de traitement qui vont bien ???  je veut récupérer le contenu en RGB pour l'afficher avec les commande des fenetre X11.
{
  struct jpeg_decompress_struct cinfo;
  struct jpeg_error_mgr jerr;
   djpeg_dest_ptr dest_mgr = NULL;
  FILE * input_file;
  FILE * output_file;
  JDIMENSION num_scanlines;
 
  /* Initialize the JPEG decompression object with default error handling. */
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_decompress(&cinfo);
  /* Add some application-specific error messages (from cderror.h) */
//  jerr.addon_message_table = cdjpeg_message_table;
  jerr.first_addon_message = JMSG_FIRSTADDONCODE;
  jerr.last_addon_message = JMSG_LASTADDONCODE;
 
  /* Open the input file. */
  if ((input_file = fopen(pszJpgFile, "rb")) == NULL) {
      return -1;
  }
 
  /* Open the output file. */
    if ((output_file = fopen("decompressedbmp.bmp", "wb")) == NULL) {
      return -1;
    }
 
  /* Specify data source for decompression */
  jpeg_stdio_src(&cinfo, input_file);
 
  /* Read file header, set default decompression parameters */
  (void) jpeg_read_header(&cinfo, TRUE);
 
  /* Adjust default decompression parameters by re-parsing the options */
  //file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
 
  /* Initialize the output module now to let it override any crucial
   * option settings (for instance, GIF wants to force color quantization).
   */
  dest_mgr = jinit_write_bmp(&cinfo, FALSE);
  dest_mgr->output_file = output_file;
 
  /* Start decompressor */
  (void) jpeg_start_decompress(&cinfo);
 
  /* Write output file header */
  (*dest_mgr->start_output) (&cinfo, dest_mgr);
 
  /* Process data */
  while (cinfo.output_scanline < cinfo.output_height) {
    num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
					dest_mgr->buffer_height);
    (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
  }
 
  /* Finish decompression and release memory.
   * I must do it in this order because output module has allocated memory
   * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
   */
  (*dest_mgr->finish_output) (&cinfo, dest_mgr);
  (void) jpeg_finish_decompress(&cinfo);
  jpeg_destroy_decompress(&cinfo);
 
  /* Close files, if we opened them */
    fclose(input_file);
    fclose(output_file);
 
  /* All done. */
  return jerr.num_warnings ? -1 : 0;
}

les commentaire en fin de compression et debut decompression dise tout.
Merci.