0.2 Release & PImage Revision

I previously wrote blogs on my 0.2 release revision as well as my initial implementation of PImage. After reading more on the native processing 1.0 (Java) I realized that the loadPixels() method of PImage should only be called if some pixel manipulation needs to be performed. Also, you should just be able to call the PImage constructor and pass in an image returned by loadImage(). Here is a visual from processing.org

PImage b;
b = loadImage("laDefense.jpg");
image(b, 0, 0);

Notice that the loadPixels() was never called. This lead me to believe that the pixel array is not only instantiated by loadPixels() but also inside the constructor. Since then I made the appropriate changes, and I even got the image appearing on the screen. I decided to move on to PImage’s get(). This function either returns a whole PImage, a color of a pixel, or a rectangle of pixels. Once I was done I decided to test it. So in my processing js code (looks exactly like the example above) i added b.get() and what did firebug say? ERROR: b.get is not a function! (Stay tunned to my JavaScript function blog.) What do u mean its not a function, I just wrote it! After rearranging my class to use prototype methods, internally defined methods, and then storing functions in variables (once again JavaScript junction blog coming soon) I noticed the real problem. Take another look at the code above. JavaScript, being the awesome language that it is, lets you instantiate variables and doesn’t care about type. I took a closer look at loadImage() and realized that it returns a var img. So even though i declared b as a PImage, once I used the loadImage(), b became just a regular var!!!

Here is the revised code:

PImage b= new PImage(loadImage("fish.jpg"));

I was happy to see the ERROR message disappear. Unfortunately, so did the image on the screen! Was I suppose to use loadPixels() after all? After spending hours looking through references, and troubleshooting with JavaScript’s alert() (yes it does work in processing.js) I decided to take a look at the image(). I added a couple of alert() inside the function and realized it was never going inside the code that drew the image on the screen. Which brings me to my 0.2 revision: change image() to accept PImage as the img variable. Here is the image reference in Java’s Processing: image(). I cannot test any of my PImage implementation until image() displays the PImage on the screen.


View all of my blogs on Processing.js
View all of my blogs


One thought on “0.2 Release & PImage Revision

  1. Pingback: PImage… an update « Anna on Stuff (Processing.js/Open Source)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s