I am posed with a weird compression/De-compression problem using QuickTime JPEG2000 codec.
Platform: PC, Win2k
QuickTime SDK 7.0.4
I am using the QuickTime call CompressImage to compress image raw data using JPEG2000 codec.
The compress image function works fine , I am sure because when i use the equivalent but opposite DecompressImage ,
it draws the proper image onto the default port , because I dont set any specific port with the PixMapHandle parameter.
But the DecompressImage function is not populating the PixMapHandle parameter which it is supposed to.
My problem is that i want the decompressed "raw data" back from the compressed data.
And since I have to write the compressed data to a file , I would love to avoid writing the ImageDescriptionHandle to the file.
So in effect I want the raw data back from compressed image and the size but not using the ImageDescriptionHandle.
Probably the code and the comments below would make the problem more clear.
//Create GWorld from the raw image data.
//data is char *imageData.
GWorldPtr gWorldPtr = NULL;
Rect imageRect;
imageRect.left = 0;
imageRect.top = 0;
imageRect.right = imageWidth;
imageRect.bottom = imageHeight;
long rowBytes = imageWidth*4; //image is a 32 bit image
QTNewGWorldFromPtr( (GWorldPtr *) &gWorldPtr,
k32BGRAPixelFormat),
&imageRect, 0, 0, (GWorldFlags)0, (unsigned char
*)imageData, rowBytes);
//Get the PixMapHandle
PixMapHandle srcPM;
if (gWorldPtr != NULL) {
srcPM = GetGWorldPixMap(gWorldPtr);
}
//Compression Details
Ptr compressedImage = NULL;
ImageDescriptionHandle compressionImageDesc;
//get compression size
OSErr err =
GetMaxCompressionSize(srcPM,&imageRect,0,codecHighQuality,kJPEG2000CodecType,anyCodec,&compressedSize);
if (err == noErr ) {
//Allocate memory for compressed Image..
compressedImage = NewPtr(compressedSize);
compressionImageDesc =(ImageDescriptionHandle)NewHandle(4);
if ( ( compressedImage!=NULL ) && (imageDesc !=NULL)) {
//Compress image
err = CompressImage(srcPM, &imageRect, codecHighQuality,
kJPEG2000CodecType, compressionImageDesc,compressedImage);
}
}
Till this the code is proper.
Now lets suppose that the compressedImage and the compressedSize = (**compressionImageDesc).dataSize are written to a file.
Now in another application , these two parameters are read , and decompression has to be achieved as stated before.
I tried using QuickTime exporter to export the data to a handle and used the importer to draw the image to an off screen GWorld.
In both cases either I encounter error in some step or get an invalid image data.
Any help in this regard would be highly appreciated.
Thanks in advance.
Regards,