Problems converting AVFrame to gdImagePtr

[email protected] (Udo Pokojski) Sat, 30 May 2009 16:44:10 +0200
Newsgroups php.gd.devel
Message-ID <[email protected]>
Hi,

I am trying to extract single frame from a MP2-File. The frames are
extracted and saved as AVFrame. For further processing I want to convert
the AVFrame to an gdImagePtr. The conversion should be done by this
code:
-------------------------------------------------------------------------
void SaveFrame_png(AVFrame *pFrame, int width, int height, int iFrame) {
  FILE *pFile;
  char szFilename[32];
  int  x,y;
  gdImagePtr im;
  int *src;
  
  im=gdImageCreateTrueColor(width, height);
    //gdImageInterlace(im, 1);
  src = (int *) pFrame->data[0];
  for(y=0; y < height; y++) {
    for (x=0; x < width; x++) {
       gdImageSetPixel(im, x, y, src[x] & 0x00FFFFFF);
       //   im->tpixels[y][x] = src[x] & 0x00FFFFFF;
	}
	src += width;
  }
   
  sprintf(szFilename, "frame%d.png", iFrame);
  pFile=fopen(szFilename, "wb");
  if(pFile==NULL)
    return;
  gdImageInterlace(im,1);
  gdImagePng(im,pFile);
  
  fclose(pFile);
  
}

------------------------------------------------------------------------------

For a quick test, I save the gdImagePtr as a PNG-File.
The resulting file shows a kind of interlace and a multiple horizontal
shift. I have uploaded an example to
http://www.freeimagehosting.net/uploads/081ff0fcb2.png

Write a JPG-File gives the same result. 
Where is the error in this code?

Thx,
Udo