public Raster getRaster(int x, int y, int w, int h) {
            ColorSpace cs = getColorModel().getColorSpace();
            
            PDFFunction functions[] = getFunctions();
            int numComponents = cs.getNumComponents();

            float x0 = (float) start.getX();
            float x1 = (float) end.getX();
            float y0 = (float) start.getY();
            float y1 = (float) end.getY();
            
            float[] inputs = new float[1];
            float[] outputs = new float[numComponents];
            
            // all the data, plus alpha channel
            int[] data = new int[w * h * (numComponents + 1)];
            
            // for each device coordinate
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < w + 8; i += 8) {
                    // find t for that user coordinate
                    float xp = getXPrime(i + x, j + y, x0, y0, x1, y1);
                    float t = getT(xp);
                    
                    // calculate the pixel values at t
                    inputs[0] = t;
                    if (functions.length == 1) {
                        functions[0].calculate(inputs, 0, outputs, 0);
                    } else {
                        for (int c = 0; c < functions.length; c++) {
                            functions[c].calculate(inputs, 0, outputs, c);
                        } 
                    }
                 
                    for (int q = i; q < i + 8 && q < w; q++) {
                        int base = (j * w + q) * (numComponents + 1);
                        for (int c = 0; c < numComponents; c++) {
                            data[base + c] = (int) (outputs[c] * 255);
                        }
                        data[base + numComponents] = 255; 
                    }
                }
            }
            
            WritableRaster raster =
                getColorModel().createCompatibleWritableRaster(w, h);
            raster.setPixels(0, 0, w, h, data);
          
            Raster child = raster.createTranslatedChild(x, y);
            return child;
        }