1 Reply Latest reply on Nov 5, 2008 9:28 PM by scribintoons

    How to pass bitmap or bitmapdata as input?

    omuppi1 Level 1
      I am trying to write a downsampler kernel using Pixel Bender. In the Pixel Bender code, I am using a very simple sampleNearest calculation::

      <languageVersion : 1.0;>

      kernel NewFilter
      < namespace : "Your Namespace";
      vendor : "Your Vendor";
      version : 1;
      description : "your description";
      >
      {
      input image4 src;
      output pixel4 dst;

      void
      evaluatePixel()
      {
      dst = sampleNearest(src,outCoord()*2.0);
      }
      }

      Can someone explain the flex/actionscript code I need to write to use this kernel? I am allowing the user to select a .jpg file from the hard disk. Hence I have access to the input image/bitmap. How do I pass this to the pixel bender code and how to get the downsampled image back?

      thanks,
      Om
        • 1. Re: How to pass bitmap or bitmapdata as input?
          scribintoons
          //to initialize
          var shader = new Shader();
          var urlRequest:URLRequest = new URLRequest("file.pbj");
          var urlLoader:URLLoader = new URLLoader(urlRequest);
          urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
          urlLoader.addEventListener(Event.COMPLETE, onLoad, false, 0, true);

          function onLoad(event:Event):void {
          shader.byteCode = event.target.data;
          }


          //to use
          _shader.data.src.input = myBitmapData;

          with (graphics) {
          clear();
          beginShaderFill(shader);
          drawRect(0, 0, width, height);
          }