PRInt32 k = (i * (num - 1)) / 255;
PRInt32 k = (i * num) / 255; k = PR_MIN(k, num - 1);
nsSVGComponentTransferFunctionElement::GenerateLookupTable(PRUint8 *aTable){  PRUint16 type;  mType->GetAnimVal(&type);  PRUint32 i;  switch (type) {  case nsIDOMSVGComponentTransferFunctionElement::SVG_FECOMPONENTTRANSFER_TYPE_TABLE:  {    nsCOMPtr<nsIDOMSVGNumberList> list;    nsCOMPtr<nsIDOMSVGNumber> number;    mTableValues->GetAnimVal(getter_AddRefs(list));    PRUint32 num = 0;    if (list)      list->GetNumberOfItems(&num);    if (num <= 1)      break;    for (i = 0; i < 256; i++) {      PRInt32 k = (i * (num - 1)) / 255;      float v1, v2;      list->GetItem(k, getter_AddRefs(number));      number->GetValue(&v1);      list->GetItem(PR_MIN(k + 1, num - 1), getter_AddRefs(number));      number->GetValue(&v2);      PRInt32 val =        PRInt32(255 * (v1 + (i/255.0f - k/float(num-1))*(num - 1)*(v2 - v1)));      val = PR_MIN(255, val);      val = PR_MAX(0, val);      aTable[i] = val;    }    break;  }  case nsIDOMSVGComponentTransferFunctionElement::SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE:  {    nsCOMPtr<nsIDOMSVGNumberList> list;    nsCOMPtr<nsIDOMSVGNumber> number;    mTableValues->GetAnimVal(getter_AddRefs(list));    PRUint32 num = 0;    if (list)      list->GetNumberOfItems(&num);    if (num <= 1)      break;    for (i = 0; i < 256; i++) {      PRInt32 k = (i * (num - 1)) / 255;      float v;      list->GetItem(k, getter_AddRefs(number));      number->GetValue(&v);      PRInt32 val = PRInt32(255 * v);      val = PR_MIN(255, val);      val = PR_MAX(0, val);      aTable[i] = val;    }    break;  }  case nsIDOMSVGComponentTransferFunctionElement::SVG_FECOMPONENTTRANSFER_TYPE_LINEAR:  {    float slope, intercept;    mSlope->GetAnimVal(&slope);    mIntercept->GetAnimVal(&intercept);    for (i = 0; i < 256; i++) {      PRInt32 val = PRInt32(slope * i + 255 * intercept);      val = PR_MIN(255, val);      val = PR_MAX(0, val);      aTable[i] = val;    }    break;  }  case nsIDOMSVGComponentTransferFunctionElement::SVG_FECOMPONENTTRANSFER_TYPE_GAMMA:  {    float amplitude, exponent, offset;    mAmplitude->GetAnimVal(&amplitude);    mExponent->GetAnimVal(&exponent);    mOffset->GetAnimVal(&offset);    for (i = 0; i < 256; i++) {      PRInt32 val = PRInt32(255 * (amplitude * pow(i / 255.0f, exponent) + offset));      val = PR_MIN(255, val);      val = PR_MAX(0, val);      aTable[i] = val;    }    break;  }  case nsIDOMSVGComponentTransferFunctionElement::SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY:  default:    break;  }  return NS_OK;}