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.
IndexProgramming Questions & HelpSyntax Questions › Loading a part of image only
Page Index Toggle Pages: 1
Loading a part of image only (Read 1228 times)
Loading a part of image only
Feb 22nd, 2007, 4:24am
 
Hail to your wisdom..

Im trying to load some images to the processing, but there is a problem with their dimensions, which are vary and  extremely huge (w = 14000px+). I know that my gCard cant hold the whole pixels at all, but i need only a part of them each time, for instance each 32nd px only. What is interesting for me is the variable size of this "pixJump".
I would like to rescale the image instantly, but have no idea how to access the pixels without loadImage.
 
I have a notion that solution could be through loadBytes and some bitmask (?).
posting a rough idea..

Code:

int pixJump = 32;

byte b[] = loadBytes("source.bmp");
image = createImage(x???,y???,RGB);/*no idea how to detect an image(s) size without loading them*/
for(int i = 0;i<b.length;i+=pixJump){
image.pixels[i/pixJump] = (b[i]);/* add some translation to 0..255 for w&b images. */
}


..is this possible or its totally wrong way? Im new to such a pixel conception, ill be glad for any suggestion.

Regards, kof  

 
Re: Loading a part of image only
Reply #1 - Feb 22nd, 2007, 8:49am
 
to do this you would need to have access to the actual pixel-data in the file. you might want to look at the source files to see how processing loads the images and use something similar to PImage.loadTIFF or PApplet.loadImageTGA.

be aware that loading images from file is slow.

what you describe sounds like you are trying to make a zoomable map .. right like googlemaps that's done differently: the big picture is split up into many squares at different resolutions. that way you just load and display the squares (images) that intersect the window and are currently visible.

F
Re: Loading a part of image only
Reply #2 - Feb 23rd, 2007, 7:22pm
 
Thanks fjen,
 
 ..the googleEaths principle is not exactly what i need. I want to buid something more expressive.. wierd interpretation of images {and even more filetypes}, with direct access to the bytes of files. Ive managed to get and visualise the bytes from a bitmap file.. but i dont fully understand the decoding of bytes to a color.

Posting the experiment..
 
Quote:
byte base[];
int[] Pix;
int cntr;

void setup()
{
 size(320, 240,P3D);
 Pix = new intwidth*height];
 noFill();
 stroke(255);
 frameRate(30);
 base = loadBytes("source.bmp");
 frame.setTitle("pixJump 0.2");
}

void draw()
{
   for(int i=2; i<width*height; i+=1) {
 if((i%int(constrain(mouseX,1,width))/8)  ==0){
    cntr+=1;
  }
 
   Pix[cntr] =color((base[i]>>16& 0xff)+(base[i]>>8& 0xff)+(base[i]& 0xff)) ;
  }

 cntr = 0;
   loadPixels();
   for (int i=0; i<width*height; i++) {
     pixels[i] = Pix[i];  
  }
   updatePixels();
   
   
}



 I am using a mouseX value to scale the "pixJumping".. for testing purposes, but i dont think that the whole loop is correct. In fact i dont uderstand the way how to decode a bit map files. I would like to have nice looking image extracted from bytes, then have a free hand to manipulate with them. Have anyone some idea?

Thanks, kof  
Re: Loading a part of image only
Reply #3 - Feb 23rd, 2007, 8:22pm
 
bmp, that should be covered somewhere on the net ... right, have a look here:

http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

F
Re: Loading a part of image only
Reply #4 - Feb 23rd, 2007, 8:31pm
 
Oh, lighting fast reply.. thank you it seems handy. Finally get upside down, strange looking corp of image!  Sounds like a success. Thanks, kof
Page Index Toggle Pages: 1