memcpy(dptr, sptr, rowsize); dptr += rowsize;
memcpy(dptr, sptr, PR_MIN(rowsize, newImg->bytes_per_line)); dptr += newImg->bytes_per_line;
NNScaleImage(Display *display, XImage *img,             double factorX, double factorY,             PRInt32 aSWidth, PRInt32 aSHeight,             PRInt32 newWidth, PRInt32 newHeight){  XImage *newImg;  PRUint32 pixel;  PRInt16 i, j, xsrc, ysrc;  PRUint32 size;  char *data;  size = newWidth * newHeight * img->depth;  data = (char *) PR_Malloc(size);   if (!data) {    return (XImage *) NULL;  }  newImg = XCreateImage(display, DefaultVisual(display, 0),                        img->depth,                        img->format,                        0, 0, newWidth, newHeight,                        img->bitmap_pad, 0);  newImg->data = data;  if (factorX == 1) {    /* an obvious optimization is to bypass XPutPixel        and to memcpy rows in img->data if factorX is 1    */         char *dptr, *sptr;    PRUint32 rowsize;     dptr = newImg->data;     rowsize = img->bytes_per_line;    for (i = 0; i < newHeight; i++) {      ysrc = (PRInt16) (i * factorY);      sptr = img->data + ysrc * rowsize;      memcpy(dptr, sptr, rowsize);      dptr += rowsize;    }  } else {    for (i = 0; i < newWidth; i++) {      xsrc = (PRInt16) (i * factorX);      for (j = 0; j < newHeight; j++) {        ysrc = (PRInt16) (j * factorY);        pixel = XGetPixel(img, xsrc, ysrc);        XPutPixel(newImg, i, j, pixel);      }    }  }  return newImg;}