6 Replies Latest reply on Jan 5, 2009 6:24 PM by the chuck

    sampleNearest() reading next leftmost pixels AFTER writing

    the chuck
      I'm trying to understand how to use SampleNearest() correctly. I have an image that is 2048px by 1px. basically a byteArray that is 2048 units. To emulate this, I created a .png that is all black of size 2048x1. Here is basically what I want to do:

      b = image, our input byteArray 2048 units in width, 1 unit in height.
      index = current coordinate.x, because we don't care about the y coord because it's always 1.
      freq = 262hz / 44100; a constant

      b[index].r = b[index-1].r + freq;
      if (b[index].r > 1)
      b[index].r = b[index].r - 1;

      Essentially, if we're working on pixel (25,0), this reads pixel (24,0) after being computed, and adds the freq constant to the value.

      I'm trying to understand how to do this with sampleNearest and outCoord(), but am missing something.

      dst.g = float (0.0);
      dst.b = float (0.0);
      float index = outCoord.x;
      float newC;
      float oldC;
      if (index == float(1.0)) //the first leftmost pixel. always start at 0...
      { oldC = sampleNearest(src, outCoord);
      newC = oldC.r; }
      { //ok to read the nearest pixel to the left
      oldC = sampleNearest(src, outCoord() - float2(1.0, 0.0) ); //get the next nearest left pixel
      newC = oldC.r + freq;
      if (newC > float(1.0))
      { newC = newC - float(1.0); }

      I'm thinking that the problem is that PixelBender is not sequential in how it calculates values. as in, I need to calculate coordinate (24,0) and write it to the final image, before I can compute coordinate (25,0), which is calculated based on coordinate (24,0)'s final value.

      It would be really great if this forum didn't remove indentations and spaces in text... the AttachCode button completely sucks, because you can't actually SEE where the attached code is going to show up. some BBCode tags would be way easier to work with...