Page 1 of 1

Time taken to create new images from a wand

Posted: 2012-05-19T14:54:01-07:00
by rohitkrishna
Hi everyone...

im trying to create individual sub-images of specific size from a single wand of whole image using magick_wand. The time taken to create sub-images is increasing each time an image is created.Can anyone tell me why? i will include my code that i have written here...i wrote two types of code one using magickcropimage and other is creating empty wand and filling in pixels in there...

Code using magick crop image

Code: Select all

for(i=0;i<v.height-v.sbimg_hgt+1;i=i+v.sbimg_hgt/2)
		{
			for(j=0;j<v.width-v.sbimg_wdt+1;j=j+v.sbimg_wdt/2)
			{	
				
				MagickBooleanType status;
				
				MagickCropImage(wand,v.sbimg_wdt,v.sbimg_hgt,i,j);
				PixelIterator *new_iterator;
				PixelWand **new_pixels;
				new_iterator=NewPixelIterator(wand);
				for(y=0;y<v.sbimg_hgt;y++)
				{
					new_pixels = PixelGetNextIteratorRow(new_iterator, &v.sbimg_wdt);
					for(x=0;x<v.sbimg_wdt;x++)
					{						
						int gx,gy,lx,ly,img_id;
						gy=i+y;
						gx=j+x;
						img_id=round(gx/v.sbimg_wdt,1)+round(gy/v.sbimg_hgt,1)*(v.width/v.sbimg_wdt);
						lx=gx%v.sbimg_wdt;
						ly=gy%v.sbimg_hgt;
						
						int t=loc(ly,lx,v.sbimg_wdt)+img_id*v.sbimg_pxl;

						unsigned char r=new_data[t],g=new_data[t+1],b=new_data[t+2];
						if((r!=pxl_data[t])&&(g!=pxl_data[t+1])&&(b!=pxl_data[t+2]))
						{
							char color[64];				
							sprintf(color,"rgb(%d,%d,%d)",r,g,b);
							PixelSetColor(new_pixels[x],color); // this function sets the color of pixel.
							PixelSyncIterator(new_iterator);
						}
					}
				}
				char *str1=argv[6],*str2=".png",final_str[50];
				sprintf(final_str,"%s_%d%s",str1,a,str2);
				printf(" %s\n",final_str);
				status=MagickWriteImages(wand,final_str,MagickTrue);
				if (status == MagickFalse)
				{
					printf ("status problem");
				}
Code which creates empty wand each time

Code: Select all

for(i=0;i<v.height-v.sbimg_hgt+1;i=i+v.sbimg_hgt/2)
		{
			for(j=0;j<v.width-v.sbimg_wdt+1;j=j+v.sbimg_wdt/2)
			{

				MagickWand    *image;
				MagickBooleanType status;
				MagickWandGenesis(); // to initialize the magick-wand Environment
				image=NewMagickWand(); // To create the wand to store image
				MagickSetSize(image,v.sbimg_wdt,v.sbimg_hgt);
				status = MagickReadImage(image, "xc:none" );
				if (status == MagickFalse)
					printf ("status problem");
				PixelIterator *new_iterator;
				PixelWand **new_pixels;
				new_iterator=NewPixelIterator(image);
				for(y=0;y<v.sbimg_hgt;y++)
				{
					new_pixels = PixelGetNextIteratorRow(new_iterator, &v.sbimg_wdt);
					for(x=0;x<v.sbimg_wdt;x++)
					{						
						int gx,gy,lx,ly,img_id;
						gy=i+y;
						gx=j+x;
						img_id=round(gx/v.sbimg_wdt,1)+round(gy/v.sbimg_hgt,1)*(v.width/v.sbimg_wdt);
						lx=gx%v.sbimg_wdt;
						ly=gy%v.sbimg_hgt;
						//printf("%d,%d :",y,x);
						int t=loc(ly,lx,v.sbimg_wdt)+img_id*v.sbimg_pxl;
						//printf("%d,%d\n",a,t);
						//getchar();
						unsigned char r=new_data[t],g=new_data[t+1],b=new_data[t+2];
						char color[64];				
						sprintf(color,"rgb(%d,%d,%d)",r,g,b);
						PixelSetColor(new_pixels[x],color); // this function sets the color of pixel.
						PixelSyncIterator(new_iterator);
					}
				}