PDA

View Full Version : displaying the decoded image source which received data from socket to the screen




JinRyu
Apr 10, 2009, 02:36 AM
This program source displays the decoded image source which received data from socket to the screen.
There is some problem in this source which I do not know...
If I make comment the last end of the code ( [imgview setImage:processedImage] ) it works fine but
image doesn't displays.
but if I use the code ( [imgview setImage:processedImage] ) in the end of the code the program dies in 5 minute.
I would like to know why.....


retvalue = DecompressFrame(aBuffer, [data length], _rgbdata, buffersize);

size_t pixelsWide = 176;
size_t pixelsHigh = 144;
int m_xy_size = pixelsWide * pixelsHigh;
int bitsPerComponent = 8;
int bitmapByteCount;

int numberOfCompponents = 3;//CGColorSpaceGetNumberOfComponents(colorSpace); //always returns 3 -> unsupported parameter combination
int bitsPerPixel = bitsPerComponent * numberOfCompponents;
int bitmapBytesPerRow = (pixelsWide * numberOfCompponents);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();


// 화면 뒤집기
unsigned char *imageData;
imageData = (unsigned char *)malloc(m_xy_size*3);
memcpy(imageData, _rgbdata, m_xy_size*3 * sizeof(unsigned char));
int i,j,k;
for(j=0, k=pixelsHigh-1; j< pixelsHigh; j++, k--)
{
for ( i = 0; i < pixelsWide; i++)
{
imageData[(j*pixelsWide+i)*3+2] = imageDataAsInts[(k*pixelsWide+i)+3];
imageData[(j*pixelsWide+i)*3+1] = imageDataAsInts[(k*pixelsWide+i)*3+1];
imageData[(j*pixelsWide+i)*3] = imageDataAsInts[(k*pixelsWide+i)*3+2];
}
}

CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, imageData, bitmapByteCount, NULL);

CGImageRef cgImage = CGImageCreate(pixelsWide, pixelsHigh, bitsPerComponent,
bitsPerPixel, bitmapBytesPerRow, colorSpace, kCGImageAlphaNone,
dataProvider, NULL, false, kCGRenderingIntentDefault);

UIImage *processedImage = [UIImage imageWithCGImage:cgImage];
CGDataProviderRelease(dataProvider);
CGColorSpaceRelease(colorSpace);



[imgview setImage:processedImage];