int endX = startX + width; int endY = startY + height;  int startTileX = (int) Math.floor(startX / TILE_SIZE); int endTileX = (int) Math.floor(endX / TILE_SIZE);  int startTileY = (int) Math.floor(startY / TILE_SIZE); int endTileY = (int) Math.floor(endY / TILE_SIZE);  Tile tile;  int tileX; int tileY;  int xoffset; int yoffset; int totalOffset;  int x; int y; int w; int h;  for (tileY = startTileY; tileY < endTileY; tileY++) { for (tileX = startTileX; tileX < endTileX; tileX++) { tile = validateTile(tileX, tileY);  xoffset = tile.getXLocation() - startX; if (xoffset < 0) { xoffset = 0; }  yoffset = tile.getYLocation() - startY; if (yoffset < 0) { yoffset = 0; }  totalOffset = yoffset * width + xoffset;  x = startX + xoffset; y = startY + yoffset;  w = tile.getXLocation() + TILE_SIZE - x; if ((x + w) > endX) { w = endX - x; }  h = tile.getYLocation() + TILE_SIZE - y; if ((y + h) > endY) { h = endY - y; }  tile.setPixels(x, y, w, h, pixels, totalOffset, w); } }
raster.setPixels(startX, startY, width, height, pixels);
   public void setPixels(      int startX,      int startY,      int width,      int height,      int[] pixels)   {      // Sets the pixels in the rectangle originating at (x,y) with width w and height h      int endX = startX + width;      int endY = startY + height;      int startTileX = (int) Math.floor(startX / TILE_SIZE);      int endTileX = (int) Math.floor(endX / TILE_SIZE);      int startTileY = (int) Math.floor(startY / TILE_SIZE);      int endTileY = (int) Math.floor(endY / TILE_SIZE);      Tile tile;      int tileX;      int tileY;      int xoffset;      int yoffset;      int totalOffset;      int x;      int y;      int w;      int h;      for (tileY = startTileY; tileY < endTileY; tileY++)      {         for (tileX = startTileX; tileX < endTileX; tileX++)         {            tile = validateTile(tileX, tileY);            xoffset = tile.getXLocation() - startX;            if (xoffset < 0)            {               xoffset = 0;            }            yoffset = tile.getYLocation() - startY;            if (yoffset < 0)            {               yoffset = 0;            }            totalOffset = yoffset * width + xoffset;            x = startX + xoffset;            y = startY + yoffset;            w = tile.getXLocation() + TILE_SIZE - x;            if ((x + w) > endX)            {               w = endX - x;            }            h = tile.getYLocation() + TILE_SIZE - y;            if ((y + h) > endY)            {               h = endY - y;            }            tile.setPixels(x, y, w, h, pixels, totalOffset, w);         }      }   }