FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   savePNG ... only 16 pixel rows?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: savePNG ... only 16 pixel rows?  (Read 314 times)
mKoser

WWW Email
savePNG ... only 16 pixel rows?
« on: May 5th, 2004, 11:36pm »

i just tried using the savePNG code provided by TomC  
http://processing.org/discourse/yabb/board_Proce55ing_Software__action_display_num_1081190619.html
 
the code-snippet saves a PNG, but when i open it in photoshop, i find that the image consist of the first 16 pixel rows repeated over and over again... like this:
http://proce55ing.beyondthree.com/testing/savePNG/test.png
 
and here what i thought it would look like:
http://proce55ing.beyondthree.com/testing/savePNG/img.jpg
 
 
here the code i am running:
Code:

// PNG SAVING CODE BY TOMC :)
 
/*use "sketchbook/default/YOUR_SKETCH_NAME/data/"  
to save and load from the same directory*/
String savePath = "";  
 
BImage bg;
 
void setup(){
  size(390,280);
  bg = loadImage("img.jpg");
  background(bg);
}
 
void draw(){
  savePNG(bg, "test");
}
 
void savePNG(BImage img, String filename) {
  /* true means encode alpha, 0 means no filter, 9 means best compression */
  PngEncoder encoder = new PngEncoder(img, true, 0, 9);  
  byte[] toWrite = encoder.pngEncode();
  if (toWrite != null) {
    if (!filename.toLowerCase().endsWith(".png")) {
 filename += ".png";
    }
    saveBytes(savePath+filename, toWrite);
  }
}

 
what could be the cause of this
can anyone else replicate this error
 
( i'm running XP 0069 expert )
 
Thanks,
Mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
TomC

WWW
Re: savePNG ... only 16 pixel rows?
« Reply #1 on: May 5th, 2004, 11:56pm »

Eek!  Embarrassing
 
Yes, I get exactly the same problem.  I'm looking into it now, but no promises!
 
mKoser

WWW Email
Re: savePNG ... only 16 pixel rows?
« Reply #2 on: May 6th, 2004, 12:02am »

I just gave it a go with a much smaller image, and the result was that i now get more lines...  
...but same error:
 
original: http://proce55ing.beyondthree.com/testing/savePNG/flower.jpg
 
png-saved: http://proce55ing.beyondthree.com/testing/savePNG/flower.png
 
 
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
TomC

WWW
Re: savePNG ... only 16 pixel rows?
« Reply #3 on: May 6th, 2004, 12:27am »

OK, I think I've fixed it.
 
http://www.tom-carden.co.uk/p5/PngEncoder.java is updated.
 
The problem was that I simplified, and broke, the original implementation, because it used a pixel grabber to get pixels for each line, but I replaced the incremental pixel grab with a reference to image.pixels.  I'm now calculating an offset.  I hope that's it.
 
I'm a little bit concerned that it comes out at over 300Kb now though, but I guess it's quite a detailed image.
 
Also, it looks like the different filters are broken (UP and SUB), but I don't know what they're meant to do, so I can't be sure.
 
So, it looks like it works, but I could do with some more test cases like this one... thanks Mikkel!
 
mKoser

WWW Email
Re: savePNG ... only 16 pixel rows?
« Reply #4 on: May 6th, 2004, 12:43am »

yep ... it seems like it's working here as well!
 
i am going to use this code in some extensive testing/sketching over the weekend, i'll let you if the code acts up again!
 
(btw. i think you win the prize for fastest reply in the forum!)
 
thanks!
mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
Pages: 1 

« Previous topic | Next topic »