We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
memory problem (Read 285 times)
memory problem
Nov 18th, 2008, 7:15pm
 
HI
I want to use processing to realize big artwork image.

I change the available memory for processing to 2000 mb.
But event with this huge amount of memory,  I can't go further than 6000x6000 pixels and this is not anough to make big prints (2m x 2m)

In this work I'm using a image pattern that I reproduce 10000 x in different size, color and rotation.

Any idea?
thanks

Mac OSX 10.5.5, 4GB (more than 2 gb  free for processing)
Re: memory problem
Reply #1 - Nov 18th, 2008, 9:03pm
 
Make 4 or 16 or etc. smaller images. Assemble them with an image program (Gimp, Photoshop, ImageMagick...), perhaps after reducing their color depth (if possible) to reduce overall size.
Should work well given the kind of image you create...
Re: memory problem
Reply #2 - Nov 19th, 2008, 10:42am
 
yes indeed, I can do that but I'm still asking why a 36 megapixels image (= 144 MB if in 32 bits/pixel) can fill the entire memory....
Re: memory problem
Reply #3 - Nov 19th, 2008, 10:09pm
 
I did the same math... and had no answer!

But perhaps you create lot of objects for your variations on images, saturating the memory before the garbage collector kicks in.
Re: memory problem
Reply #4 - Nov 20th, 2008, 1:22pm
 
perhaps the image is buffered multiple times by java and the operating system. If you get an 'OutOfMemoryException' this does not always mean Java run out of heap space, the same exception is raised e.g. of you hit the max thread limmit...

have you tried to create an offscreen image with createGraphics() and render it offscreen without displaying it?
Re: memory problem
Reply #5 - Nov 20th, 2008, 2:22pm
 
I don't think I create a lot of objets in the memory because  I just use  one image (500x500 pixel) as a stamp...
I already use createGraphics() and I render it offscreen without displaying it...

this is the code I'm using actually....




String gStampImageName="p2";  
String gArtworkName= "BigImage";  // this image will be saved in png
int gBigImageSize = 4000; // here I would like to have 12000
float gStampSize=80; // same scale as the displaysize


Stamp gDrawingStamp;
PImage gSourceimage;
int gDisplaySize=1000;// size of the preview
int gBackgroundColor=0;
float gStampRapportSize;
PGraphics gBigImage = createGraphics(gBigImageSize, gBigImageSize, JAVA2D);
Boolean gFiniFlag=false;
int gCounter=0;
int gUpdateFrameCounter=0;
int gUpdateFrameNbr=100;  // we have a preview every 100 stamps
float gStartTime;


void setup()
{
 size(gDisplaySize,gDisplaySize);
 background(gBackgroundColor);
 smooth();
 gStampRapportSize=gBigImageSize/gDisplaySize;  

 gDrawingStamp=new Stamp(gStampImageName,113,606,0,0);  // 4 values x1,y1,x2,y2 for the regpoint and the orientation


 gStartTime= millis();
 gBigImage.beginDraw();
 gBigImage.background(gBackgroundColor);
 gBigImage.smooth();
}

void draw() {
 while (gUpdateFrameCounter<gUpdateFrameNbr) {
   gCounter++;
   gUpdateFrameCounter++;
   float r= gCounter*.5;
   float angle= gCounter*.5;
   gDrawingStamp.Show(gDisplaySize/2+r*cos(angle) ,gDisplaySize/2.0+r*sin(angle),angle,random(255), random(255), random(255), gStampSize);
  }

 gBigImage.endDraw();
 image(gBigImage, 0, 0,gDisplaySize,gDisplaySize);
 gBigImage.beginDraw();
 if (gCounter>=1000) {
   gFiniFlag=true;    
 }
 else{
   gUpdateFrameCounter=0;
 }

 if (gFiniFlag) {
   gBigImage.endDraw();
   float t=millis() - gStartTime;
   println(" Computing Time = " + t );
   gStartTime=millis();
   gBigImage.save( gArtworkName +".png");
   t=millis() - gStartTime;
   println(" Save Time = " + t );
   noLoop();
 }
}

class Stamp {  
 String  myStampName;
 int myStartX;
 int myStartY;
 int myEndX;
 int myEndY;
 float myDirection;
 PImage myStampImage;
 float myStampRealSize;

 Stamp(String Name, int sx,int sy,int ex,int ey) {
   myStampName=Name;
   myStartX = sx;
   myStartY = sy;
   myEndX=ex;
   myEndY=ey;
   myDirection = atan2(ey-sy, ex-sx);
   myStampRealSize=Distance( sx, sy, ex,ey);
   myStampImage = loadImage( myStampName + ".png");

 }

 void Show( float theX,float theY,float theAngle,float theRed,float theGreen,float theBlue,float theStampSize) {
   float MySize= gStampRapportSize*theStampSize/myStampRealSize;
   gBigImage.translate(theX*gStampRapportSize,theY*gStampRapportSize);
   gBigImage.rotate(theAngle+ myDirection);
   gBigImage.tint(theRed,theGreen,theBlue);
   gBigImage.image(myStampImage, -myStartX*MySize,-myStartY*MySize,myStampImage.width*MySize,myStampImage.height*
MySize);
   gBigImage.rotate(-theAngle- myDirection);
   gBigImage.translate(-theX*gStampRapportSize,-theY*gStampRapportSize);
 }
}

float Distance (float x1,float y1,float x2,float y2) {
 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}



Page Index Toggle Pages: 1