UnregisterTIFFImage

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
zwolf
Posts: 2
Joined: 2012-08-28T10:43:09-07:00
Authentication code: 67789

UnregisterTIFFImage

Post by zwolf »

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:

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;

}
I'm not very experienced in C language Someone give me a hint?
Thank you.
zwolf
Posts: 2
Joined: 2012-08-28T10:43:09-07:00
Authentication code: 67789

Re: UnregisterTIFFImage

Post by zwolf »

I solved.

//MagickWandTerminus();

Boh!.
Post Reply