@Override
  public void paste(int x, int y, BaseImage img) {
    if(img.getMode() != mode) {
      img = img.changeMode(mode);
    }
    if (img.getHeight()+y < 0 || y >= this.height) {
      return;
    }

    if (img.getWidth()+x < 0 || x >= this.width) {
      return;
    }

    int imgXOff = 0;
    int imgYOff = 0;
    if(x < 0) {
      imgXOff = Math.abs(x);
      x=0;
    }
    if(y < 0) {
      imgYOff = Math.abs(y);
      y=0;
    }

    int thisLineWidth = width * getColors();
    int imgLineWidth = img.getWidth() * img.getColors();
    int imgXOffBytes = imgXOff * img.getColors();
    int XBytes = x * getColors();

    for(int h=y; h < height; h++) {
      int imgYPos = h-y+imgYOff;
      if( imgYPos >= img.getHeight()) {
        break;
      }
      int thisStart = thisLineWidth*h;
      int imgStart = imgLineWidth*(imgYPos);
      System.arraycopy(img.getArray(), imgStart+(imgXOffBytes), this.MAP, thisStart+(XBytes), Math.min(imgLineWidth-(imgXOffBytes), thisLineWidth-(XBytes)));
    }
  }