Ejemplo n.º 1
0
 public Color getColor(float[] f, boolean fillAndStroke) {
   init();
   if (colorSpace != null && !failed) {
     try {
       // generate a key for the colour
       int key = generateKey(f);
       if (f.length <= 3) {
         return addColorToCache(iccColorCache3B, key, colorSpace, f);
       } else {
         return addColorToCache(iccColorCache4B, key, colorSpace, f);
       }
     } catch (Exception e) {
       logger.log(Level.FINE, "Error getting ICCBased colour", e);
       failed = true;
     }
   }
   return alternate.getColor(f);
 }
Ejemplo n.º 2
0
  /**
   * Calculate the colours value of the point xy on the line point1 and point2.
   *
   * @param colorSpace colour space to apply to the function output
   * @param xy point to calcualte the colour of.
   * @param point1 start of gradient line
   * @param point2 end of gradient line.
   * @param t0 domain min
   * @param t1 domain max
   * @return colour derived from the input parameters.
   */
  private Color calculateColour(
      PColorSpace colorSpace,
      Point2D.Float xy,
      Point2D.Float point1,
      Point2D.Float point2,
      float t0,
      float t1) {
    // find colour at point 1
    float xPrime = linearMapping(xy, point1, point2);
    float t = parametrixValue(xPrime, t0, t1, extend);
    // find colour at point 2
    float[] input = new float[1];
    input[0] = t;
    // apply the function to the given input
    if (function != null) {

      float[] output;
      int length = function.length;
      // simple 1 in N out function
      if (length == 1) {
        output = function[0].calculate(input);
      } else {
        // vector of function for each colour component, 1 in 1 out.
        output = new float[length];
        for (int i = 0; i < length; i++) {
          output[i] = function[i].calculate(input)[0];
        }
      }

      if (output != null) {
        output = PColorSpace.reverse(output);
        return colorSpace.getColor(output, true);
      } else {
        return null;
      }

    } else {
      logger.fine("Error processing Shading Type 2 Pattern.");
      return null;
    }
  }