UnregisterTIFFImage
Posted: 2012-08-28T10:53:06-07:00
I need a function to convert byte streams from png to jpeg.
The function will be used in a program written in vala.
I get the following error when I run for the second time:
> Memory allocation failed `'@ fatal/tiff.c/UnregisterTIFFImage/1831
I write an example for debugging:
I'm not very experienced in C language Someone give me a hint?
Thank you.
The function will be used in a program written in vala.
I get the following error when I run for the second time:
> Memory allocation failed `'@ fatal/tiff.c/UnregisterTIFFImage/1831
I write an example for debugging:
Code: Select all
#include <stdio.h>
#include <wand/magick-wand.h>
void convertImg(unsigned char bufferA[], int sizeA, caddr_t* bufferB, size_t* sizeB, char *format ) {
MagickWand *mw;
MagickBooleanType status;
int w,h;
MagickWandGenesis();
mw = NewMagickWand();
status=MagickReadImageBlob(mw, bufferA, sizeA);
h = MagickGetImageHeight(mw);
w = MagickGetImageWidth(mw);
printf("%ix%i\n",w,h);
MagickSetFormat(mw,format);
*bufferB = MagickGetImagesBlob(mw, sizeB);
DestroyMagickWand(mw);
MagickWandTerminus();
}
int main(void) {
FILE *fr;
FILE *fw;
int size = 8732;
unsigned char buffer[size];
int n;
size_t length = 0;
caddr_t out;
fr = fopen("logo.jpg","rb");
fread(buffer,1,size,fr);
convertImg(buffer,size,&out,&length,"PNG");
convertImg(buffer,size,&out,&length,"PNG");
fw = fopen("logo.png","wb");
fwrite(out,1,length,fw);
fclose(fr);
fclose(fw);
return 0;
}
Thank you.