public void copyRect(int x, int y, int w, int h, int srcX, int srcY) {
    int dest = (width_ * y) + x;
    int src = (width_ * srcY) + srcX;
    int inc = width_;

    if (y > srcY) {
      src += (h - 1) * inc;
      dest += (h - 1) * inc;
      inc = -inc;
    }
    int destEnd = dest + h * inc;

    while (dest != destEnd) {
      System.arraycopy(data, src, data, dest, w);
      src += inc;
      dest += inc;
    }
  }