private int computeOneChannelSSIM(int[] data1, int[] data2, int x, int y, int w, int h, int ds)
   {
       if (data1 == data2)
          return 1024;

       if (x < 0)
          x = 0;

       if (y < 0)
          y = 0;

       if (x + w > this.width)
          w = this.width - x;

       if (y + h > this.height)
          h = this.height - y;

       final SSIMContext ctx = new SSIMContext(data1, data2, x, y, w, h, ds, this.kernel32);
       x <<= ds;
       y <<= ds;
       final int inc = 1 << ds;
       final int endi = x + w;
       final int endj = y + h;
       int pixels = 0;

       for (int j=y; j<endj; j+=inc)
       {
          ctx.y = j;

          for (int i=x; i<endi; i+=inc)
          {
             ctx.x = i;
             computeBlockSSIM(ctx);
             pixels++;
          }
       }

       if (pixels == 0) 
          return 0;
       
       int res = (int) (ctx.sumSSIM + (pixels >> 1)) / pixels;       
       return (res < 0 ) ? 0 : res;
   }