define(['mac/palette16'], function(palette) {

  'use strict';

  return function(resource) {
    if (resource.data.length !== 128) {
      console.error('ics4 resource expected to be 128 bytes, got ' + resource.data.length);
      return;
    }
    var img = document.createElement('CANVAS');
    img.width = 16;
    img.height = 16;
    var ctx = img.getContext('2d');
    var pix = ctx.createImageData(16, 16);
    for (var ibyte = 0; ibyte < 128; ibyte++) {
      pix.data.set(palette[resource.data[ibyte] >> 4], ibyte*8);
      pix.data.set(palette[resource.data[ibyte] & 15], ibyte*8 + 4);
    }
    ctx.putImageData(pix, 0, 0);
    resource.image = {url: img.toDataURL(), width:16, height:16};
  };
  
});

@@ -79,24 +79,70 @@
 ion(
-resource
+item) %7B%0A    return item.getBytes().then(function(bytes
 ) %7B%0A    
 if (
@@ -141,25 +141,19 @@
     
+ 
+ 
 if (
-resource.data
+bytes
 .len
@@ -177,21 +177,31 @@
     
-console.error
+  return Promise.reject
 ('ic
@@ -246,29 +246,21 @@
 got ' + 
-resource.data
+bytes
 .length)
@@ -271,190 +271,66 @@
     
-return;%0A    %7D%0A    var img = document.createElement('CANVAS');%0A    img
+%7D%0A      item
 .wi
-d
 th
- = 16;%0A    img.height = 16;%0A    var ctx = img.getContext('2d');%0A    var pix = ctx.createImageData(16, 16);%0A
+Pixels(16, 16, function(pixelData) %7B%0A    
     
@@ -375,29 +375,34 @@
 ++) %7B%0A      
-pix.d
+    pixelD
 ata.set(pale
@@ -401,37 +401,29 @@
 set(palette%5B
-resource.data
+bytes
 %5Bibyte%5D %3E%3E 4
@@ -445,13 +445,18 @@
     
-pix.d
+    pixelD
 ata.
@@ -471,21 +471,13 @@
 tte%5B
-resource.data
+bytes
 %5Biby
@@ -501,16 +501,20 @@
 8 + 4);%0A
+    
     %7D%0A  
@@ -519,101 +519,20 @@
     
-ctx.putImageData(pix, 0, 0);%0A    resource.image = %7Burl: img.toDataURL(), width:16, height:16%7D
+  %7D);%0A    %7D)
 ;%0A  

use new loader format