Page 1 of 1

DrawAnnotation problem

Posted: 2010-01-26T01:46:58-07:00
by erotavlas_turbo
Hi all,

I'm writing a C code that use the following method:

DrawAnnotation(d_wand,x,y,(const unsigned char *) member_list->callername), where member_list is data structure with char* callername field.

When i run the program I get the following error:

Code: Select all

asterisk: wand/drawing-wand.c:770: DrawAnnotation: Assertion `text != (const unsigned char *) ((void *)0)' failed.
If i write the same data to a text file, the program will work well
fprintf(file,"CallerName %s, member_list->callername);

Can you help me?

Thank you in advance

Re: DrawAnnotation problem

Posted: 2010-01-26T07:15:58-07:00
by magick
You are triggering an assert. In the wand/drawing-wand.c code we have:
  • WandExport void DrawAnnotation(DrawingWand *wand,const double x,const double y,
    const unsigned char *text)
    {
    ...
    assert(text != (const unsigned char *) NULL);
Text must be NULL for this assert to complain suggesting unequivocally that member_list->callername is NULL.

Re: DrawAnnotation problem

Posted: 2010-01-26T10:45:07-07:00
by erotavlas_turbo
ok, thank.

Now I have the same problem with different variable. I have the same data structure with a field int callerID type

DrawAnnotation(d_wand,x,y,(const unsigned char *) callerID)

I get Segmentation Fault

If i write the same data to a text file, the program will work well
fprintf(file,"CallerName %s, callerID);

the code is the following

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wand/magick_wand.h"



#define ThrowWandException(wand) \
{ \
  char \
    *description; \
\
  ExceptionType \
  severity; \
\
description=MagickGetException(wand,&severity); \
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
description=(char *) MagickRelinquishMemory(description); \
exit(-1); \
}

void DrawText(char* inputImage, char* outputImage, char* outputFormat, char* time) {

	MagickBooleanType status;
        MagickWand* magick_wand = NULL;
        DrawingWand* d_wand = NULL;
        PixelWand* p_wand = NULL;

        magick_wand = NewMagickWand();
        d_wand = NewDrawingWand();
        p_wand = NewPixelWand();

	// initialize MagickWand environment
	MagickWandGenesis();
	
        // read the image. 
        status = MagickReadImage(magick_wand, inputImage);
	if (status == MagickFalse) {
		printf("Unable to Read\n");
		ThrowWandException(magick_wand);
	}
    
	// scale the image dimension
	if (strcmp(outputFormat,"CIF") == 0) 
		status = MagickScaleImage(magick_wand, 352, 288);
	else if (strcmp(outputFormat,"QCIF") == 0) 
		status = MagickScaleImage(magick_wand, 176, 144);
	else 
		printf("Invalid output format %s\n", outputFormat);

	if (status == MagickFalse) {
		printf("Unable to Scale\n");
		ThrowWandException(magick_wand);
	}
		
	// fixed data
	char* user = "Utente";
	char* ID = "ID";
					
	// set up the font size and colour
        DrawSetFont(d_wand,"Helvetica");
        PixelSetColor(p_wand,"black");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,32);
        // now draw conference name
	DrawAnnotation(d_wand,10,50,(const unsigned char *) user);

	DrawSetFontSize(d_wand,14);
	DrawAnnotation(d_wand,150,15,(const unsigned char *) time);
        // different font, colour and size
        PixelSetColor(p_wand,"green");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,25);
        DrawSetFont(d_wand,"Times-Roman");
	// now draw the text
        DrawAnnotation(d_wand,30,90,(const unsigned char *) user);
	DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);
	//char * total = (const unsigned char*) conf->membercount;
	//DrawAnnotation(d_wand,240,90,(const unsigned char *) conf->membercount );
	
	PixelSetColor(p_wand,"black");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,23);
	int id = 10;
		FILE *file;
		file = fopen("/home/tore/Scrivania/prova/file.txt","w");
		fprintf(file,"%d\n", id);
		DrawAnnotation(d_wand,150,200,(const unsigned char *) id);
		

	fclose(file);
	

        // draw the image on to the magick_wand
        MagickDrawImage(magick_wand, d_wand);

        // and write it
        status = MagickWriteImage(magick_wand, outputImage);

        /* clean up */
        if (status == MagickFalse)
		ThrowWandException(magick_wand);
        if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
        if(d_wand) d_wand = DestroyDrawingWand(d_wand);
        if(p_wand) p_wand = DestroyPixelWand(p_wand);
	
	// terminate the MagickWand environment
	MagickWandTerminus();
	
}


int main() {

	char *inputImage = "/home/tore/Scrivania/prova/Asterisk_logo.jpg";
	char *outputImage = "/home/tore/Scrivania/prova/prova.jpg"; 
	char *outputFormat = "CIF";
	char *time = "2/12/2009 17:03";
	// draw the text over the input image
	DrawText(inputImage, outputImage, outputFormat, time);
	

	
	return 0;
}

I think that there isn't possible to write a int type in text field.

Thank you

Re: DrawAnnotation problem

Posted: 2010-01-27T04:01:19-07:00
by erotavlas_turbo
I have solved with the following trick

Code: Select all

char buffer[50];
			
       			
			sprintf( buffer, "%d", member_list->id );	
        		DrawAnnotation(d_wand,x+175,y,(const unsigned char *) buffer );
:D