Hi everyone,

I've found a radial gradient implementation that is about 2x faster
(according to my very limited measurements) than the one in batik 1.7
(and than the one in the JDK). If anyone is interested, I have
attached the code. There's still a part missing if the focus is close
to or outside the circle, but I'm too tired right now to write it up.

Cheers,

-- Ulf
/*

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */

    private void cyclicCircularGradientFillRaster(int pixels[], int off, 
                                                  int adjust, 
                                                  int x, int y, 
                                                  int w, int h)
    {
        // constant parts of X, Y coordinates
        final float constX = (a00*x) + (a01*y) + a02;
        final float constY = (a10*x) + (a11*y) + a12;

        // used to index pixels array
        int indexer = off;

        // incremental index change for pixels array
        int pixInc = w+adjust;

        float d2 = 
(focusX-centerX)*(focusX-centerX)+(focusY-centerY)*(focusY-centerY);
        float r2 = radiusSq;
        if (d2 >= r2) {
          throw new RuntimeException();
        }
        float c = d2 - r2; // d2 < r2 => c < 0, so the sqrt is always 
well-defined
        float dX = a00;
        float dY = a10;

        // for every row
        for (int j = 0; j < h; j++) {

            // user space point; these are constant from column to column
            float X = (a01*j) + constX;
            float Y = (a11*j) + constY;
            float vX = (X-focusX)*(focusX-centerX);
            float vY = (Y-focusY)*(focusY-centerY);
            float b = vX+vY;
            float db = dX*(focusX-centerX)+dY*(focusY-centerY);
            float aX = (X-focusX);
            float aY = (Y-focusY);

            // for every column (inner loop begins here)
            for (int i = 0; i < w; i++) {
              float a = aX*aX + aY*aY;
              float g = (float) (a / (-b + Math.sqrt(b * b - a * c)));

              // store the color at this point
              pixels[indexer + i] = indexIntoGradientsArrays(g);

              // incremental change
              b += db;
              aX += dX;
              aY += dY;
            } //end inner loop

            indexer += pixInc;
        } //end outer loop
    }
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to