boolean major = grid.getMajor();
    public OMGraphic generate(OMGrid grid, Projection proj) {        Shape gridShape = grid.getShape();        // Don't generate the raster if the grid is off-map...        if (gridShape == null                || !gridShape.intersects(0,                        0,                        proj.getWidth(),                        proj.getHeight())) {            if (Debug.debugging("grid")) {                Debug.output("SlopeGenerator: OMGrid does not overlap map, skipping generation.");            }            return SinkGraphic.getSharedInstance();        }        OMRaster raster = getRaster(grid);        incomplete = false;        if (grid.height == 0 || grid.width == 0) {            Debug.message("grid", "SlopeGenerator: grid height/width ZERO!");            return raster;        }        GridData gd = grid.getData();        if (!(gd instanceof GridData.Short)) {            Debug.message("grid",                    "SlopeGenerator: grid doesn't contain short data.");            return SinkGraphic.getSharedInstance();        }        int rows = grid.getRows();        int columns = grid.getColumns();        short[][] data = ((GridData.Short) gd).getData();        boolean major = grid.getMajor();        double distance = getSlopeRun(grid, getContrast());        // Used for projections of image coordinates. Reused in the        // loops to save memory.        LatLonPoint llp = new LatLonPoint();        Point point = new Point();        ElevationColors colors = getColors();        if (colors == null) {            return SinkGraphic.getSharedInstance();        }        // x is the horizontal pixel being modified        for (short x = 0; x < grid.width; x++) {            // Check to make sure the pixels we're calculating are on            // the map.            int screenx = (int) grid.point1.getX() + x;            if (screenx < 0 || screenx > proj.getWidth()) {                incomplete = true;                continue;            }            for (short y = 0; y < grid.height; y++) {                // Check to make sure the pixels we're calculating are                // on the map.                int screeny = (int) grid.point1.getY() + y;                if (screeny < 0 || screeny > proj.getHeight()) {                    incomplete = true;                    continue;                }                // OK, on the map.                point.setLocation(screenx, screeny);                llp = proj.inverse(point, llp);                int yc = Math.round((llp.getLatitude() - grid.getLatitude())                        / grid.getVerticalResolution());                int xc = Math.round((llp.getLongitude() - grid.getLongitude())                        / grid.getHorizontalResolution());                // If the calculated index is out of the data ranges,                // push it to the end. Don't blow it off, it will                // cause unfilled data pixel lines to appear. You                // only want to blow off pixels that are not on the                // map, or are never going to be on the map.                if (yc < 0)                    yc = 0;                if (yc > rows - 1)                    yc = rows - 1;                if (xc < 0)                    xc = 0;                if (xc > columns - 1)                    xc = columns - 1;                int elevation = 0;                // Otherwise, get the elevation for the data point.                try {                    elevation = (int) data[xc][yc];                } catch (ArrayIndexOutOfBoundsException aioobe) {                    Debug.output("Error Accessing data array:\n\txc: " + xc                            + ", yc: " + yc + " for x: " + x + ", y: " + y);                }                // Slope shading calculations, get the upper left and                // lower right data points.                int xnw = xc - 1;                int xse = xc + 1;                // trying to smooth out the edge of the frame                if (xc == 0 || xnw < 0) {                    xnw = xc;                }                if (xc == columns - 1 || xse > columns - 1) {                    xse = columns - 1;                }                int yse = yc - 1;                int ynw = yc + 1;                //  trying to smooth out the edge of the frame by                // handling the                //  frame limits                if (yse < 0) {                    yse = 0;                }                if (yc == rows - 1 || ynw > rows - 1) {                    ynw = rows - 1;                }                // Get the elevation points for the slope measurement                // points.                try {                    short e2 = data[xse][yse]; // down & right                    // elevation                    short e1 = data[xnw][ynw]; // up and left                    // elevation                    // colormap value darker for negative slopes,                    // brighter for                    // positive slopes.                    // slope relative to nw sun                    double slope = (e2 - e1) / distance;                    raster.setPixel(x, y, colors.getARGB(elevation,                            grid.getUnits(),                            slope));                } catch (ArrayIndexOutOfBoundsException aioobe) {                    Debug.output("Error Accessing data array:\n\txse: " + xse                            + ", yse: " + yse + "\n\txnw: " + xnw + ", ynw: "                            + ynw + "\n\tfor x: " + x + ", y: " + y);                }            }        }        raster.generate(proj);        if (Debug.debugging("grid"))            Debug.output("SlopeGenerator: leaving generate");        return raster;    }