if (!rgb) { mSurface->Unlock(); aNewFrame->UnlockImageData(); aNewFrame->UnlockAlphaData(); return NS_ERROR_FAILURE; }
nsSVGImageFrame::ConvertFrame(gfxIImageFrame *aNewFrame){  PRInt32 width, height;  aNewFrame->GetWidth(&width);  aNewFrame->GetHeight(&height);    nsISVGOuterSVGFrame *outerSVGFrame = GetOuterSVGFrame();  nsCOMPtr<nsISVGRenderer> renderer;  outerSVGFrame->GetRenderer(getter_AddRefs(renderer));  renderer->CreateSurface(width, height, getter_AddRefs(mSurface));    PRUint8 *data, *target;  PRUint32 length;  PRInt32 stride;  mSurface->Lock();  mSurface->GetData(&data, &length, &stride);#ifdef XP_WIN  stride = -stride;#endif  aNewFrame->LockImageData();  aNewFrame->LockAlphaData();    PRUint8 *rgb, *alpha = nsnull;  PRUint32 bpr, abpr;  aNewFrame->GetImageData(&rgb, &length);  aNewFrame->GetImageBytesPerRow(&bpr);    aNewFrame->GetAlphaData(&alpha, &length);  aNewFrame->GetAlphaBytesPerRow(&abpr);#ifdef XP_WIN  // nsImageWin returns either 3bpp or 4bpp, depending on optimization  PRUint32 bpp = bpr/width;#endif    if (!alpha) {    for (PRInt32 y=0; y<height; y++) {      if (stride > 0)        target = data + stride * y;      else        target = data + stride * (1 - height) + stride * y;      for (PRInt32 x=0; x<width; x++) {#ifdef XP_WIN        *target++ = rgb[y*bpr + bpp*x];        *target++ = rgb[y*bpr + bpp*x + 1];        *target++ = rgb[y*bpr + bpp*x + 2];#else        *target++ = rgb[y*bpr + 3*x + 2];        *target++ = rgb[y*bpr + 3*x + 1];        *target++ = rgb[y*bpr + 3*x];#endif        *target++ = 255;      }    }  } else {    if (abpr >= width) {      /* 8-bit alpha */      for (PRInt32 y=0; y<height; y++) {        if (stride > 0)          target = data + stride * y;        else          target = data + stride * (1 - height) + stride * y;        for (PRInt32 x=0; x<width; x++) {          PRUint32 a = alpha[y*abpr + x];#ifdef XP_WIN          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + bpp*x] * a);          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + bpp*x + 1] * a);          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + bpp*x + 2] * a);#else          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + 3*x + 2] * a);          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + 3*x + 1] * a);          FAST_DIVIDE_BY_255(*target++, rgb[y*bpr + 3*x] * a);#endif          *target++ = a;        }      }    } else {      /* 1-bit alpha */      for (PRInt32 y=0; y<height; y++) {        if (stride > 0)          target = data + stride * y;        else          target = data + stride * (1 - height) + stride * y;        PRUint8 *alphaRow = alpha + y*abpr;                for (PRUint32 x=0; x<width; x++) {          if (NS_GET_BIT(alphaRow, x)) {#ifdef XP_WIN            *target++ = rgb[y*bpr + bpp*x];            *target++ = rgb[y*bpr + bpp*x + 1];            *target++ = rgb[y*bpr + bpp*x + 2];#else            *target++ = rgb[y*bpr + 3*x + 2];            *target++ = rgb[y*bpr + 3*x + 1];            *target++ = rgb[y*bpr + 3*x];#endif            *target++ = 255;          } else {            *target++ = 0;            *target++ = 0;            *target++ = 0;            *target++ = 0;          }        }      }    }  }    mSurface->Unlock();  aNewFrame->UnlockImageData();  aNewFrame->UnlockAlphaData();    return NS_OK;}