Program: 28445
Project: 28445
Buggy source:
/** 
 * StackBlur By Java Bitmap
 * @param original         Original Image
 * @param radius           Blur radius
 * @param canReuseInBitmap Can reuse In original Bitmap
 * @return Image Bitmap
 */
public static Bitmap blur(Bitmap original,int radius,boolean canReuseInBitmap){
  if (radius < 1) {
    return (null);
  }
  Bitmap bitmap=buildBitmap(original,canReuseInBitmap);
  if (radius == 1) {
    return bitmap;
  }
  int w=bitmap.getWidth();
  int h=bitmap.getHeight();
  int[] pix=new int[w * h];
  bitmap.getPixels(pix,0,w,0,0,w,h);
  int wm=w - 1;
  int hm=h - 1;
  int wh=w * h;
  int div=radius + radius + 1;
  int r[]=new int[wh];
  int g[]=new int[wh];
  int b[]=new int[wh];
  int rSum, gSum, bSum, x, y, i, p, yp, yi, yw;
  int vMin[]=new int[Math.max(w,h)];
  int divSum=(div + 1) >> 1;
  divSum*=divSum;
  int dv[]=new int[256 * divSum];
  for (i=0; i < 256 * divSum; i++) {
    dv[i]=(i / divSum);
  }
  yw=yi=0;
  int[][] stack=new int[div][3];
  int stackPointer;
  int stackStart;
  int[] sir;
  int rbs;
  int r1=radius + 1;
  int routSum, goutSum, boutSum;
  int rinSum, ginSum, binSum;
  for (y=0; y < h; y++) {
    rinSum=ginSum=binSum=routSum=goutSum=boutSum=rSum=gSum=bSum=0;
    for (i=-radius; i <= radius; i++) {
      p=pix[yi + Math.min(wm,Math.max(i,0))];
      sir=stack[i + radius];
      sir[0]=(p & 0xff0000) >> 16;
      sir[1]=(p & 0x00ff00) >> 8;
      sir[2]=(p & 0x0000ff);
      rbs=r1 - Math.abs(i);
      rSum+=sir[0] * rbs;
      gSum+=sir[1] * rbs;
      bSum+=sir[2] * rbs;
      if (i > 0) {
        rinSum+=sir[0];
        ginSum+=sir[1];
        binSum+=sir[2];
      }
 else {
        routSum+=sir[0];
        goutSum+=sir[1];
        boutSum+=sir[2];
      }
    }
    stackPointer=radius;
    for (x=0; x < w; x++) {
      r[yi]=dv[rSum];
      g[yi]=dv[gSum];
      b[yi]=dv[bSum];
      rSum-=routSum;
      gSum-=goutSum;
      bSum-=boutSum;
      stackStart=stackPointer - radius + div;
      sir=stack[stackStart % div];
      routSum-=sir[0];
      goutSum-=sir[1];
      boutSum-=sir[2];
      if (y == 0) {
        vMin[x]=Math.min(x + radius + 1,wm);
      }
      p=pix[yw + vMin[x]];
      sir[0]=(p & 0xff0000) >> 16;
      sir[1]=(p & 0x00ff00) >> 8;
      sir[2]=(p & 0x0000ff);
      rinSum+=sir[0];
      ginSum+=sir[1];
      binSum+=sir[2];
      rSum+=rinSum;
      gSum+=ginSum;
      bSum+=binSum;
      stackPointer=(stackPointer + 1) % div;
      sir=stack[(stackPointer) % div];
      routSum+=sir[0];
      goutSum+=sir[1];
      boutSum+=sir[2];
      rinSum-=sir[0];
      ginSum-=sir[1];
      binSum-=sir[2];
      yi++;
    }
    yw+=w;
  }
  for (x=0; x < w; x++) {
    rinSum=ginSum=binSum=routSum=goutSum=boutSum=rSum=gSum=bSum=0;
    yp=-radius * w;
    for (i=-radius; i <= radius; i++) {
      yi=Math.max(0,yp) + x;
      sir=stack[i + radius];
      sir[0]=r[yi];
      sir[1]=g[yi];
      sir[2]=b[yi];
      rbs=r1 - Math.abs(i);
      rSum+=r[yi] * rbs;
      gSum+=g[yi] * rbs;
      bSum+=b[yi] * rbs;
      if (i > 0) {
        rinSum+=sir[0];
        ginSum+=sir[1];
        binSum+=sir[2];
      }
 else {
        routSum+=sir[0];
        goutSum+=sir[1];
        boutSum+=sir[2];
      }
      if (i < hm) {
        yp+=w;
      }
    }
    yi=x;
    stackPointer=radius;
    for (y=0; y < h; y++) {
      pix[yi]=(0xff000000 & pix[yi]) | (dv[rSum] << 16) | (dv[gSum] << 8)| dv[bSum];
      rSum-=routSum;
      gSum-=goutSum;
      bSum-=boutSum;
      stackStart=stackPointer - radius + div;
      sir=stack[stackStart % div];
      routSum-=sir[0];
      goutSum-=sir[1];
      boutSum-=sir[2];
      if (x == 0) {
        vMin[y]=Math.min(y + r1,hm) * w;
      }
      p=x + vMin[y];
      sir[0]=r[p];
      sir[1]=g[p];
      sir[2]=b[p];
      rinSum+=sir[0];
      ginSum+=sir[1];
      binSum+=sir[2];
      rSum+=rinSum;
      gSum+=ginSum;
      bSum+=binSum;
      stackPointer=(stackPointer + 1) % div;
      sir=stack[stackPointer];
      routSum+=sir[0];
      goutSum+=sir[1];
      boutSum+=sir[2];
      rinSum-=sir[0];
      ginSum-=sir[1];
      binSum-=sir[2];
      yi+=w;
    }
  }
  bitmap.setPixels(pix,0,w,0,0,w,h);
  return (bitmap);
}

Fixed version (ground truth):
/** 
 * StackBlur By Java Bitmap
 * @param original         Original Image
 * @param radius           Blur radius
 * @param canReuseInBitmap Can reuse In original Bitmap
 * @return Image Bitmap
 */
public static Bitmap blur(Bitmap original,int radius,boolean canReuseInBitmap){
  if (radius < 1) {
    return (null);
  }
  Bitmap bitmap=buildBitmap(original,canReuseInBitmap);
  if (radius == 1) {
    return bitmap;
  }
  int w=bitmap.getWidth();
  int h=bitmap.getHeight();
  int[] pix=new int[w * h];
  bitmap.getPixels(pix,0,w,0,0,w,h);
  int wm=w - 1;
  int hm=h - 1;
  int wh=w * h;
  int div=radius + radius + 1;
  short r[]=new short[wh];
  short g[]=new short[wh];
  short b[]=new short[wh];
  int rSum, gSum, bSum, x, y, i, p, yp, yi, yw;
  int vMin[]=new int[Math.max(w,h)];
  int divSum=(div + 1) >> 1;
  divSum*=divSum;
  short dv[]=new short[256 * divSum];
  for (i=0; i < 256 * divSum; i++) {
    dv[i]=(short)(i / divSum);
  }
  yw=yi=0;
  int[][] stack=new int[div][3];
  int stackPointer;
  int stackStart;
  int[] sir;
  int rbs;
  int r1=radius + 1;
  int routSum, goutSum, boutSum;
  int rinSum, ginSum, binSum;
  for (y=0; y < h; y++) {
    rinSum=ginSum=binSum=routSum=goutSum=boutSum=rSum=gSum=bSum=0;
    for (i=-radius; i <= radius; i++) {
      p=pix[yi + Math.min(wm,Math.max(i,0))];
      sir=stack[i + radius];
      sir[0]=(p & 0xff0000) >> 16;
      sir[1]=(p & 0x00ff00) >> 8;
      sir[2]=(p & 0x0000ff);
      rbs=r1 - Math.abs(i);
      rSum+=sir[0] * rbs;
      gSum+=sir[1] * rbs;
      bSum+=sir[2] * rbs;
      if (i > 0) {
        rinSum+=sir[0];
        ginSum+=sir[1];
        binSum+=sir[2];
      }
 else {
        routSum+=sir[0];
        goutSum+=sir[1];
        boutSum+=sir[2];
      }
    }
    stackPointer=radius;
    for (x=0; x < w; x++) {
      r[yi]=dv[rSum];
      g[yi]=dv[gSum];
      b[yi]=dv[bSum];
      rSum-=routSum;
      gSum-=goutSum;
      bSum-=boutSum;
      stackStart=stackPointer - radius + div;
      sir=stack[stackStart % div];
      routSum-=sir[0];
      goutSum-=sir[1];
      boutSum-=sir[2];
      if (y == 0) {
        vMin[x]=Math.min(x + radius + 1,wm);
      }
      p=pix[yw + vMin[x]];
      sir[0]=(p & 0xff0000) >> 16;
      sir[1]=(p & 0x00ff00) >> 8;
      sir[2]=(p & 0x0000ff);
      rinSum+=sir[0];
      ginSum+=sir[1];
      binSum+=sir[2];
      rSum+=rinSum;
      gSum+=ginSum;
      bSum+=binSum;
      stackPointer=(stackPointer + 1) % div;
      sir=stack[(stackPointer) % div];
      routSum+=sir[0];
      goutSum+=sir[1];
      boutSum+=sir[2];
      rinSum-=sir[0];
      ginSum-=sir[1];
      binSum-=sir[2];
      yi++;
    }
    yw+=w;
  }
  for (x=0; x < w; x++) {
    rinSum=ginSum=binSum=routSum=goutSum=boutSum=rSum=gSum=bSum=0;
    yp=-radius * w;
    for (i=-radius; i <= radius; i++) {
      yi=Math.max(0,yp) + x;
      sir=stack[i + radius];
      sir[0]=r[yi];
      sir[1]=g[yi];
      sir[2]=b[yi];
      rbs=r1 - Math.abs(i);
      rSum+=r[yi] * rbs;
      gSum+=g[yi] * rbs;
      bSum+=b[yi] * rbs;
      if (i > 0) {
        rinSum+=sir[0];
        ginSum+=sir[1];
        binSum+=sir[2];
      }
 else {
        routSum+=sir[0];
        goutSum+=sir[1];
        boutSum+=sir[2];
      }
      if (i < hm) {
        yp+=w;
      }
    }
    yi=x;
    stackPointer=radius;
    for (y=0; y < h; y++) {
      pix[yi]=(0xff000000 & pix[yi]) | (dv[rSum] << 16) | (dv[gSum] << 8)| dv[bSum];
      rSum-=routSum;
      gSum-=goutSum;
      bSum-=boutSum;
      stackStart=stackPointer - radius + div;
      sir=stack[stackStart % div];
      routSum-=sir[0];
      goutSum-=sir[1];
      boutSum-=sir[2];
      if (x == 0) {
        vMin[y]=Math.min(y + r1,hm) * w;
      }
      p=x + vMin[y];
      sir[0]=r[p];
      sir[1]=g[p];
      sir[2]=b[p];
      rinSum+=sir[0];
      ginSum+=sir[1];
      binSum+=sir[2];
      rSum+=rinSum;
      gSum+=ginSum;
      bSum+=binSum;
      stackPointer=(stackPointer + 1) % div;
      sir=stack[stackPointer];
      routSum+=sir[0];
      goutSum+=sir[1];
      boutSum+=sir[2];
      rinSum-=sir[0];
      ginSum-=sir[1];
      binSum-=sir[2];
      yi+=w;
    }
  }
  bitmap.setPixels(pix,0,w,0,0,w,h);
  return (bitmap);
}