<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>benchmarks/gradient.jpeg</filename>
    </added>
    <added>
      <filename>benchmarks/green-square.gif</filename>
    </added>
    <added>
      <filename>benchmarks/obama_smoking.jpg</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,7 +4,7 @@
 &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=windows-1250&quot;&gt;
 &lt;meta name=&quot;generator&quot; content=&quot;PSPad editor, www.pspad.com&quot;&gt;
 &lt;title&gt;Processing.js Benchmarks&lt;/title&gt;
-&lt;script type=&quot;text/javascript&quot; src=&quot;../processing.min.js&quot;&gt;&lt;/script&gt;
+&lt;script type=&quot;text/javascript&quot; src=&quot;../processing.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
 /*
  * This code searches for all the &lt;script type=&quot;application/processing&quot; target=&quot;canvasid&quot;&gt;
@@ -39,33 +39,140 @@ if ( document.addEventListener ) {
   body{font-size:70%;font-family:lucida-console;padding:0;margin:0;}
   h1{font-family:verdana;background:steelblue;color:#fff;padding:5px 25px;margin:0;}
   h2{font-family:verdana;background:lightgrey;color:dimgrey;padding:5px 25px;margin:0;font-size:120%}
-  div{border:1px dotted dimgrey;padding:0 5px;float:left;margin:5px;}
+  div{border:1px dotted dimgrey;padding:0 5px;float:left;margin:5px;font-size:.7em;height:100px;}
 &lt;/style&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;h1&gt;Processing.js Benchmarks&lt;/h1&gt;
 &lt;h2&gt;All Canvas elements should render green&lt;/h2&gt;
 
+
+  &lt;div&gt;&lt;p&gt;set() pixel&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+    size( 50, 50 );
+    color black = color(0);
+    set(10, 10, black);
+    set(40, 10, black);
+    set(40, 40, black);
+    set(10, 40, black);
+  &lt;/script&gt;&lt;canvas style=&quot;background:#0f0;&quot;&gt;&lt;/canvas&gt;
+  &lt;/div&gt;
+
+  &lt;div&gt;&lt;p&gt;get() pixel&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+    void setup(){
+      size( 50, 50 );
+      frameRate(5);
+    }
+    PImage myImage = loadImage(&quot;obama_smoking.jpg&quot;);
+    void draw(){
+      image( myImage, 0, 0 );
+      color cp = get(30, 20);
+      fill(cp);
+      rect(5, 25, 20, 20);
+      if( frameCount &gt; 10 ){ exit(); }
+    }
+  &lt;/script&gt;&lt;canvas style=&quot;background:#f00;&quot;&gt;&lt;/canvas&gt;
+  &lt;/div&gt;
+
+  &lt;div&gt;&lt;p&gt;get() pixels&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+    void setup(){
+      size( 50, 50 );
+      frameRate(5);
+    }
+    PImage myImage = loadImage(&quot;obama_smoking.jpg&quot;);
+    void draw(){
+      image( myImage, 0, 0 );
+      PImage cp = get();
+      image( cp, 20, 20 );
+      if( frameCount &gt; 10 ){ exit(); }
+    }
+  &lt;/script&gt;&lt;canvas style=&quot;background:#f00;&quot;&gt;&lt;/canvas&gt;
+  &lt;/div&gt;
+
+  &lt;div&gt;&lt;p&gt;updatePixels()&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+    size( 50, 50 );
+    int halfImage = width*height / 2;
+    PImage myImage = loadImage(&quot;gradient.jpeg&quot;);    
+    void setup(){
+        frameRate(5);
+    }    
+    void draw(){
+      image( myImage, 0, 0 );
+      loadPixels();
+      for (int i = 0; i &lt; halfImage; i++) {
+        pixels[i+halfImage] = pixels[i];
+      }
+      updatePixels()
+      if( frameCount &gt; 10 ){ exit(); }
+    }
+  &lt;/script&gt;&lt;canvas style=&quot;background:#f00;&quot;&gt;&lt;/canvas&gt;    
+  &lt;/div&gt;
+
+  &lt;div&gt;&lt;p&gt;background()&lt;br /&gt; as image&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+      pImage a;
+      void setup(){
+        size( 50, 50 );
+        frameRate(5);
+        a = loadImage( &quot;green-square.gif&quot; );
+      }
+      void draw(){
+        
+        // Image is not drawn if it's not ready
+        background( a );
+        
+        // Image load may be delayed, so wait a while...
+        if( frameCount &gt; 10 ){
+          exit();
+        }        
+      }
+  &lt;/script&gt;&lt;canvas style=&quot;background:#f00;&quot;&gt;&lt;/canvas&gt;    
+  &lt;/div&gt;
+
+  &lt;div&gt;&lt;p&gt;loadImage()&lt;p&gt;
+  &lt;script type=&quot;application/processing&quot;&gt;
+      pImage a;
+      void setup(){
+        size( 50, 50 );
+        frameRate(5);
+        a = loadImage( &quot;green-square.gif&quot; );
+      }
+      void draw(){
+        
+        // Image is not drawn if it's not ready
+        image( a, 0, 0 );
+        
+        // Image load may be delayed, so wait a while...
+        if( frameCount &gt; 10 ){
+          exit();
+        }        
+      }
+  &lt;/script&gt;&lt;canvas style=&quot;background:#f00;&quot;&gt;&lt;/canvas&gt;    
+  &lt;/div&gt;
+  
   &lt;div&gt;&lt;p&gt;text()&lt;p&gt;
   &lt;script type=&quot;application/processing&quot;&gt;
-    size(50,50);    
+    size(50,50);
     noStroke();
     PFont fontA = loadFont(&quot;Biotyp.svg&quot;);
     textFont(fontA, 12); 
     fill(0);
     text(&quot;Working!&quot;, 0, 0);        
   &lt;/script&gt;&lt;canvas style=&quot;background:#0f0;&quot;&gt;&lt;/canvas&gt;    
-  &lt;/div&gt;
-  
+  &lt;/div&gt; 
+
   &lt;div&gt;&lt;p&gt;println()&lt;p&gt;
   &lt;script type=&quot;application/processing&quot;&gt;
-    size(50,50);    
+    size(50,50);
     noStroke();
     void lnPrinted(){
       fill(ln[0],ln[1],ln[2]);
       rect(0,0,50,50);
     }
-    println(0,255,0);    
+    println(0,255,0);
   &lt;/script&gt;&lt;canvas style=&quot;background:red;&quot;&gt;&lt;/canvas&gt;    
   &lt;/div&gt;
   
@@ -194,8 +301,7 @@ if ( document.addEventListener ) {
     background(0,G,0,G);
   &lt;/script&gt;&lt;canvas style=&quot;background:red&quot;&gt;&lt;/canvas&gt;      
   &lt;/div&gt;
-    
-  
+      
   &lt;div&gt;&lt;p&gt;lerp&lt;p&gt;
   &lt;script type=&quot;application/processing&quot;&gt;
     size(50,50);
@@ -237,5 +343,6 @@ if ( document.addEventListener ) {
   &lt;/script&gt;&lt;canvas style=&quot;background:url(arc_fill.gif);&quot;&gt;&lt;/canvas&gt;    
   &lt;/div&gt;
 
+
 &lt;/body&gt;
 &lt;/html&gt;</diff>
      <filename>benchmarks/index.html</filename>
    </modified>
    <modified>
      <diff>@@ -24,10 +24,10 @@ float drag = 30.0;
 void setup() 
 {
   size(200,200);
-  teddy = loadImage(&quot;teddy.gif&quot;);
+  teddy = loadImage(&quot;data/teddy.gif&quot;);
   xpos = width/2;
   ypos = height/2;
-  frameRate(60);
+  frameRate(60);  
 }
 
 void draw() 
@@ -47,7 +47,7 @@ void draw()
   }  
   
   // Display the sprite at the position xpos, ypos
-  image(teddy, xpos, ypos);
+  image( teddy, xpos, ypos );
 }
 &lt;/script&gt;&lt;canvas width=&quot;200&quot; height=&quot;200&quot;&gt;&lt;/canvas&gt;&lt;/p&gt;
 &lt;div style=&quot;height:0px;width:0px;overflow:hidden;&quot;&gt;&lt;img src='data/sky.jpg' id='sky.jpg'/&gt;&lt;img src='data/teddy.gif' id='teddy.gif'/&gt;&lt;/div&gt;
@@ -63,7 +63,7 @@ float drag = 30.0;
 void setup() 
 {
   size(200,200);
-  teddy = loadImage(&quot;teddy.gif&quot;);
+  teddy = loadImage(&quot;data/teddy.gif&quot;);
   xpos = width/2;
   ypos = height/2;
   frameRate(60);</diff>
      <filename>examples/basic/sprite.html</filename>
    </modified>
    <modified>
      <diff>@@ -35,10 +35,7 @@
     return p;
     
   };
-  
-  // Auto-load Processing sketches
-  addEventListener( 'DOMContentLoaded', USInit, false );
-  
+   
   // IE Unfriendly AJAX Method
   var ajax=function( url ){
     var AJAX;
@@ -277,6 +274,7 @@
     var p = {};
     
     // Set Processing defaults / environment variables
+    p.name            = 'Processing.js Instance';
     p.PI              = Math.PI;
     p.TWO_PI          = 2 * p.PI;
     p.HALF_PI         = p.PI / 2;
@@ -726,7 +724,7 @@
     p.ceil    = function ceil   ( aNumber             ){ return Math.ceil( aNumber );                    };    
     p.round   = function round  ( aNumber             ){ return Math.round( aNumber );                   };
     p.lerp    = function lerp   ( value1, value2, amt ){ return ( ( value2 - value1 ) * amt ) + value1;  };
-     p.abs    = function abs    ( aNumber             ){ return Math.abs( aNumber );                     };
+    p.abs    = function abs     ( aNumber             ){ return Math.abs( aNumber );                     };
     p.cos     = function cos    ( aNumber             ){ return Math.cos( aNumber );                     };
     p.sin     = function sin    ( aNumber             ){ return Math.sin( aNumber );                     };
     p.pow     = function pow    ( aNumber, aExponent  ){ return Math.pow( aNumber, aExponent );          };
@@ -1178,7 +1176,7 @@
     
     p.rect = function rect( x, y, width, height ){
 
-      if( width + height ){ return; }       
+      if( !( width + height ) ){ return; }
 
       curContext.beginPath();
       
@@ -1267,26 +1265,35 @@
 
     p.save = function save( file ){};
 
-    p.loadImage = function loadImage( file ){
-      var img = document.getElementById( file );
-      
-      if ( !img ){ return; }
+    // Loads an image for display. Type is unused. Callback is fired on load.
+    p.loadImage = function loadImage( file, type, callback ){
       
-      var h = img.height,
-          w = img.width;
-
-      var canvas = document.createElement( &quot;canvas&quot; );
-      canvas.width = w;
-      canvas.height = h;
-      var context = canvas.getContext( &quot;2d&quot; );
+      var img = document.createElement( 'img' );
+      img.src = file;
+     
+      img.onload = function(){
+        
+        var h = this.height,
+            w = this.width;
+        
+        var canvas = document.createElement( &quot;canvas&quot; );
+        canvas.width = w;
+        canvas.height = h;
+        var context = canvas.getContext( &quot;2d&quot; );
+     
+        context.drawImage( this, 0, 0 );
+        this.data = buildImageObject( context.getImageData( 0, 0, w, h ) );
+        this.data.img = img;
 
-      context.drawImage( img, 0, 0 );
-      var data = buildImageObject( context.getImageData( 0, 0, w, h ) );
-      data.img = img;
-      return data;
+        callback?callback():0;
+        
+      }
+      
+      return img;
+          
     };
-
-    // Gets a single pixel from Canvas
+    
+    // Gets a single pixel or block of pixels from the current Canvas Context
     p.get = function get( x, y ){
       
       if( !arguments.length ){
@@ -1303,6 +1310,17 @@
       
     };
 
+    // Creates a new Processing instance and passes it back for... processing
+    p.createGraphics = function createGraphics( w, h ){
+ 
+      var canvas = document.createElement( &quot;canvas&quot; );
+      var ret = buildProcessing( canvas );
+      ret.size( w, h );
+      ret.canvas = canvas;
+      return ret;
+ 
+    };
+
     // Paints a pixel array into the canvas
     p.set = function set( x, y, obj ){
       
@@ -1362,39 +1380,35 @@
       
     };
 
+    // Draw an image or a color to the background
     p.background = function background( img ) {
       
-      if( arguments.length ){
+       if( arguments.length ){
         
-        if( img &amp;&amp; img.img ){
-          curBackground = img;
+        if( img.data &amp;&amp; img.data.img ){
+          curBackground = img.data;
         }else{
           curBackground = p.color.apply( this, arguments );
         }
-      
+        
       }
 
       if( curBackground.img ){
-        p.image( curBackground, 0, 0 );
+      
+        p.image( img, 0, 0 );
+        
       }else{
+
         var oldFill = curContext.fillStyle;
         curContext.fillStyle = curBackground + &quot;&quot;;
         curContext.fillRect( 0, 0, p.width, p.height );
         curContext.fillStyle = oldFill;
+
       }
       
-    };
-    
-    // Clears hole in the Canvas or the whole Canvas
-    p.clear = function clear ( x, y, width, height ) {    
-      if( arguments.length == 0 ){
-        curContext.clearRect( x, y, width, height );
-      }else{
-        curContext.clearRect( 0, 0, p.width, p.height );
-      }
-    }
+    };    
     
-    p.AniSprite = function( prefix, frames ){    
+    p.AniSprite = function( prefix, frames ){
       this.images = [];
       this.pos = 0;
 
@@ -1403,15 +1417,15 @@
       }
 
       this.display = function( x, y ){
-        p.image( this.images[ this.pos ], x, y );
+        p.image_old( this.images[ this.pos ], x, y );
 
         if( ++this.pos &gt;= frames ){
           this.pos = 0;
         }
       };
 
-      this.getWidth   = function(){ return getImage( this.images[ 0 ] ).width;  };
-      this.getHeight  = function(){ return getImage( this.images[ 0 ] ).height; };
+      this.getWidth   = function(){ return getImage_old( this.images[ 0 ] ).width;  };
+      this.getHeight  = function(){ return getImage_old( this.images[ 0 ] ).height; };
     };
 
     function buildImageObject( obj ){
@@ -1463,7 +1477,7 @@
     }
 
     p.createImage = function createImage( w, h, mode ){
-      
+            
       var data    = {};
       data.width  = w;
       data.height = h;
@@ -1492,29 +1506,19 @@
       
     };
 
-    p.createGraphics = function createGraphics( w, h ){
- 
-      var canvas = document.createElement( &quot;canvas&quot; );
-      var ret = buildProcessing( canvas );
-      ret.size( w, h );
-      ret.canvas = canvas;
-      return ret;
- 
-    };
-
-
-    p.tint = function tint( rgb, a ){
-      curTint = a;
-    };
-
     function getImage( img ){
- 
+      
       if( typeof img == &quot;string&quot; ){
         return document.getElementById( img );
       }
 
-      if( img.img || img.canvas ){
-        return img.img || img.canvas;
+      if( img.img ){
+      
+        return img.img;
+        
+      }else if( img.getContext || img.canvas ){
+
+        img.pixels = img.getContext( '2d' ).createImageData( img.width, img.height );
       }
 
       for( var i = 0, l = img.pixels.length; i &lt; l; i++ ){
@@ -1534,43 +1538,114 @@
       canvas.height = img.height;
       
       var context = canvas.getContext( &quot;2d&quot; );
-      context.putImageData( img, 0, 0 );
+      context.putImageData( img.pixels, 0, 0 );
 
       img.canvas = canvas;
 
-      return canvas;
+      return img;
     }
 
-    p.image = function image( img, x, y, w, h ){
-      
+    // Depreciating &quot;getImage_old&quot; from PJS - currently here to support AniSprite
+    function getImage_old( img ){ 
+      if( typeof img == &quot;string&quot; ){
+        return document.getElementById( img );
+      } 
+      if( img.img || img.canvas ){
+        return img.img || img.canvas;
+      } 
+      for( var i = 0, l = img.pixels.length; i &lt; l; i++ ){        
+        var pos = i * 4;
+        var c = ( img.pixels[ i ] || &quot;rgba(0,0,0,1)&quot; ).slice( 5, - 1 ).split( &quot;,&quot; );        
+        img.data[ pos + 0 ] = parseInt( c[ 0 ] );
+        img.data[ pos + 1 ] = parseInt( c[ 1 ] );
+        img.data[ pos + 2 ] = parseInt( c[ 2 ] );
+        img.data[ pos + 3 ] = parseFloat( c[ 3 ] ) * 100;      
+      } 
+      var canvas = document.createElement( &quot;canvas&quot; );
+      canvas.width = img.width;
+      canvas.height = img.height;      
+      var context = canvas.getContext( &quot;2d&quot; );
+      context.putImageData( img, 0, 0 ); 
+      img.canvas = canvas; 
+      return canvas;
+    }
+    // Depreciating &quot;getImage_old&quot; from PJS - currently here to support AniSprite
+    p.image_old=function image_old(img,x,y,w,h){
       x = x || 0;
-      y = y || 0;
-
-      var obj = getImage( img );
-
+      y = y || 0; 
+      var obj = getImage( img ); 
       if( curTint &gt;= 0 ){
         var oldAlpha = curContext.globalAlpha;
         curContext.globalAlpha = curTint / opacityRange;
-      }
-
+      } 
       if( arguments.length == 3 ){
         curContext.drawImage( obj, x, y );
       }else{
         curContext.drawImage( obj, x, y, w, h );
-      }
-
+      } 
       if( curTint &gt;= 0 ){
         curContext.globalAlpha = oldAlpha;
-      }
-
+      } 
       if( img._mask ){
         var oldComposite = curContext.globalCompositeOperation;
         curContext.globalCompositeOperation = &quot;darker&quot;;
         p.image( img._mask, x, y );
         curContext.globalCompositeOperation = oldComposite;
+      }      
+    };
+
+    // Draws an image to the Canvas
+    p.image = function image( img, x, y, w, h ){
+      
+      if( img.data || img.canvas ){
+
+        x = x || 0;
+        y = y || 0;
+
+        var obj = getImage( img.data || img.canvas );
+
+        if( curTint &gt;= 0 ){
+          var oldAlpha = curContext.globalAlpha;
+          curContext.globalAlpha = curTint / opacityRange;
+        }
+
+        if( arguments.length == 3 ){
+          curContext.drawImage( obj, x, y );
+        }else{
+          curContext.drawImage( obj, x, y, w, h );
+        }
+
+        if( curTint &gt;= 0 ){
+          curContext.globalAlpha = oldAlpha;
+        }
+
+        if( img._mask ){
+          var oldComposite = curContext.globalCompositeOperation;
+          curContext.globalCompositeOperation = &quot;darker&quot;;
+          p.image( img._mask, x, y );
+          curContext.globalCompositeOperation = oldComposite;
+        }
+      
+      }
+      
+      if( typeof img == 'string' ){
+        
       }
       
     };    
+    
+    // Clears hole in the Canvas or the whole Canvas
+    p.clear = function clear ( x, y, width, height ) {    
+      if( arguments.length == 0 ){
+        curContext.clearRect( x, y, width, height );
+      }else{
+        curContext.clearRect( 0, 0, p.width, p.height );
+      }
+    }
+
+    p.tint = function tint( rgb, a ){
+      curTint = a;
+    };
 
 
 </diff>
      <filename>processing.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>30200170c7904936d75d6ff32811e7870c93f173</id>
    </parent>
  </parents>
  <author>
    <name>f1lt3r</name>
    <email>f1lt3r@f1lt3r-desktop.(none)</email>
  </author>
  <url>http://github.com/jeresig/processing-js/commit/bc2b97200a7d74e8ef498c55d20ab1aca7545745</url>
  <id>bc2b97200a7d74e8ef498c55d20ab1aca7545745</id>
  <committed-date>2009-10-27T14:00:10-07:00</committed-date>
  <authored-date>2009-10-27T14:00:10-07:00</authored-date>
  <message>PJS handled IMG loads, ignores &amp; onload callbacks.</message>
  <tree>e9668ecbf5d9844ad4257c68fe23f7170cf64c5d</tree>
  <committer>
    <name>f1lt3r</name>
    <email>f1lt3r@f1lt3r-desktop.(none)</email>
  </committer>
</commit>
