Java Code Examples for java.awt.image.renderable.ParameterBlock.set()

The following are Jave code examples for showing how to use set() of the java.awt.image.renderable.ParameterBlock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rastertheque   File: CompositeCRIF.java   Source Code and License Vote up 6 votes
/**
    * Creates a <Code>RenderedImage</Code> from the renderable layer.
    *
    * @param renderContext The rendering information associated with
    *        this rendering.
    * @param paramBlock The parameters used to create the image.
    * @return A <code>RenderedImage</code>.
    */
   public RenderedImage create(RenderContext renderContext,
                               ParameterBlock paramBlock) {

// Get the two renderable alpha images from the parameter block
RenderableImage alphaImage1 =
    (RenderableImage)paramBlock.getObjectParameter(0);
RenderableImage alphaImage2 = 
    (RenderableImage)paramBlock.getObjectParameter(1);

// Cause the two renderable alpha images to be rendered
RenderedImage rAlphaImage1 = 
    alphaImage1.createRendering(renderContext);
RenderedImage rAlphaImage2 = 
    alphaImage2.createRendering(renderContext);

ParameterBlock newPB = (ParameterBlock)paramBlock.clone();

// Replace the renderable alpha images in the ParameterBlock with
// their renderings
newPB.set(rAlphaImage1, 0);
newPB.set(rAlphaImage2, 1);

// Return JAI.create("composite") 
       return JAI.create("composite", newPB, 
		  renderContext.getRenderingHints());
   }
 
Example 2
Project: rastertheque   File: CropCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a <Code>RenderedImage</Code> from the renderable layer.
 *
 * @param renderContext The rendering information associated with
 *        this rendering.
 * @param paramBlock The parameters used to create the image.
 * @return A <code>RenderedImage</code>.
 */
public RenderedImage create(RenderContext renderContext,
                            ParameterBlock paramBlock) {
    // Get the destination bounds in rendering-independent coordinates.
    Rectangle2D dstRect2D = getBounds2D(paramBlock);

    // Map the destination bounds to rendered coordinates. This method
    // will cause extra data to be present if there is any rotation or
    // shear.
    AffineTransform tf = renderContext.getTransform();
    Rectangle2D rect = tf.createTransformedShape(dstRect2D).getBounds2D();

    // Make sure that the rendered rectangle is non-empty.
    if(rect.getWidth() < 1.0 || rect.getHeight() < 1.0) {
        double w = Math.max(rect.getWidth(), 1.0);
        double h = Math.max(rect.getHeight(), 1.0);
        rect.setRect(rect.getMinX(), rect.getMinY(), w, h);
    }

    // Initialize the rendered ParameterBlock.
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(paramBlock.getRenderedSource(0));
    pb.set((float)rect.getMinX(), 0);
    pb.set((float)rect.getMinY(), 1);
    pb.set((float)rect.getWidth(), 2);
    pb.set((float)rect.getHeight(), 3);

    // Crop the rendered source.
    return JAI.create("crop", pb, renderContext.getRenderingHints());
}
 
Example 3
Project: rastertheque   File: PeriodicShiftDescriptor.java   Source Code and License Vote up 5 votes
/**
    * Validates the input parameters.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "shiftX" and
    * "shiftY" are between 0 and the source image width and
    * height, respectively.
    */
   public boolean validateArguments(String modeName,
			     ParameterBlock args,
                                    StringBuffer msg) {
       if (!super.validateArguments(modeName, args, msg)) {
           return false;
       }

if (!modeName.equalsIgnoreCase("rendered"))
    return true;

       RenderedImage src = args.getRenderedSource(0);

       // Set non-static default values based on source
       if (args.getObjectParameter(0) == null) {
           args.set(new Integer(src.getWidth()/2), 0);
       }
       if (args.getObjectParameter(1) == null) {
           args.set(new Integer(src.getHeight()/2), 1);
       }

       int shiftX = args.getIntParameter(0);
       int shiftY = args.getIntParameter(1);
       if (shiftX < 0 || shiftX >= src.getWidth() || 
           shiftY < 0 || shiftY >= src.getHeight()) {
           msg.append(getName() + " " +
                      JaiI18N.getString("PeriodicShiftDescriptor3"));
           return false;
       }

       return true;
   }
 
Example 4
Project: rastertheque   File: ColorQuantizerDescriptor.java   Source Code and License Vote up 5 votes
/**
 * Returns <code>true</code> if this operation is capable of handling
 * the input parameters.
 *
 * <p> In addition to the default validations done in the super class,
 * this method verifies that the provided quantization algorithm is one of
 * the three predefined algorithms in this class.
 *
 * @throws IllegalArgumentException  If <code>args</code> is <code>null</code>.
 * @throws IllegalArgumentException  If <code>msg</code> is <code>null</code>
 *         and the validation fails.
 */
protected boolean validateParameters(String modeName,
                                     ParameterBlock args,
                                     StringBuffer msg) {
    if ( args == null || msg == null ) {
        throw new IllegalArgumentException(JaiI18N.getString("Generic0"));
    }

    if (!super.validateParameters(modeName, args, msg))
        return false;

    ColorQuantizerType algorithm =
        (ColorQuantizerType)args.getObjectParameter(0);
    if (algorithm != MEDIANCUT && algorithm != NEUQUANT &&
        algorithm != OCTTREE) {
        msg.append(getName() + " " +
                   JaiI18N.getString("ColorQuantizerDescriptor7"));
        return false;
    }

    Integer secondOne = (Integer)args.getObjectParameter(2);
    if (secondOne == null) {
        int upperBound = 0;
        if (algorithm.equals(MEDIANCUT))
            upperBound = 32768;
        else if (algorithm.equals(NEUQUANT))   // set the cycle for train to 100
            upperBound = 100;
        else if (algorithm.equals(OCTTREE))    // set the maximum tree size to 65536
            upperBound = 65536;

        args.set(upperBound, 2);
    }

    return true;
}
 
Example 5
Project: rastertheque   File: SubsampleAverageDescriptor.java   Source Code and License Vote up 5 votes
/**
 * Validates the input parameters.
 *
 * <p> In addition to the standard checks performed by the
 * superclass method, this method sets "scaleX" to "scaleY"
 * if the latter is not provided in <code>args</code>.
 */
protected boolean validateParameters(String modeName,
                                     ParameterBlock args,
                                     StringBuffer msg) {
    if (!super.validateParameters(modeName, args, msg)) {
        return false;
    }

    if(args.getNumParameters() < 2 || args.getObjectParameter(1) == null) {
        args.set(args.getObjectParameter(0), 1);
    }

    return true;
}
 
Example 6
Project: rastertheque   File: FilteredSubsampleDescriptor.java   Source Code and License Vote up 4 votes
/**
    * Validates the input parameters.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "scaleX" and "scaleY"
    * are both greater than 0 and that the interpolation type
    * is one of 4 standard types: <br>
    * <p> <code>
    *    javax.media.jai.InterpolationNearest <br>
    *    javax.media.jai.InterpolationBilinear <br>
    *    javax.media.jai.InterpolationBicubic <br>
    *    javax.media.jai.InterpolationBicubic2
    * </code>
    */
   protected boolean validateParameters(String modeName,
				 ParameterBlock args,
                                        StringBuffer msg) {
if (!super.validateParameters(modeName, args, msg))
    return false;

       int scaleX = args.getIntParameter(0);
       int scaleY = args.getIntParameter(1);
       if (scaleX < 1 || scaleY < 1) {
           msg.append(getName() + " " +
                      JaiI18N.getString("FilteredSubsampleDescriptor1"));
           return false;
       }

float[] filter = (float[])args.getObjectParameter(2);

// if this parameter is null, generate the kernel based on the
// procedure described above.
if (filter == null) {
    int m = scaleX > scaleY ? scaleX: scaleY;
    if ((m & 1) == 0)
	m++;

    double sigma = (m - 1) / 6.0;

    // when m is 1, sigma is 0; will generate NaN.  Give any number
    // to sigma will generate the correct kernel {1.0}
    if (m == 1)
	sigma = 1.0;

    filter = new float[m/2 + 1];
    float sum = 0;

    for (int i = 0; i < filter.length; i++) {
	filter[i] = (float)gaussian((double)i, sigma);
	if (i == 0)
	    sum += filter[i];
	else
	    sum += filter[i] * 2;
    }

    for (int i = 0; i < filter.length; i++) {
	filter[i] /= sum;
    }

    args.set(filter, 2);
}

       Interpolation interp = (Interpolation)args.getObjectParameter(3);

       // Determine the interpolation type, if not supported throw exception
       if (!((interp instanceof InterpolationNearest)  ||
           (interp instanceof InterpolationBilinear) ||
           (interp instanceof InterpolationBicubic)  ||
           (interp instanceof InterpolationBicubic2))) {
          msg.append(getName() + " " +
                      JaiI18N.getString("FilteredSubsampleDescriptor2"));
          return false;
       }
       return true;

   }
 
Example 7
Project: rastertheque   File: OperationDescriptorImpl.java   Source Code and License Vote up 4 votes
private boolean validateParameters(ParameterListDescriptor pld,
			       ParameterBlock args,
                                      StringBuffer msg) {

if ((args == null) || (msg == null))
           throw new IllegalArgumentException(JaiI18N.getString("Generic0"));

       // The number of parameters this operation should have. 
       int numParams = pld.getNumParameters();

       // The number of parameters supplied. 
       int argNumParams = args.getNumParameters();

Object paramDefaults[] = pld.getParamDefaults();

// Check for the correct number of parameters. 
       if (argNumParams < numParams) {
           // The minimum number of parameters this operation must have. 
           if (argNumParams < getMinNumParameters(pld)) {
               msg.append(JaiI18N.formatMsg("OperationDescriptorImpl9",
	    new Object[] { getName(), new Integer(numParams)}));

               return false;

           } else {	// use default values
               for (int i = argNumParams; i < numParams; i++) {
                   args.add(paramDefaults[i]);
               }
           }
       }

       for (int i = 0; i < numParams; i++) {
           Object p = args.getObjectParameter(i);

    /* Check for null parameter. */
           if (p == null) {
               p = paramDefaults[i];	// get the default parameter value

               if (p == OperationDescriptor.NO_PARAMETER_DEFAULT) {
                   msg.append(
		    JaiI18N.formatMsg("OperationDescriptorImpl11",
		    new Object[] { getName(), new Integer(i) }));
                   return false;

               } else {
                   args.set(p, i);	// replace null parameter with default
               }
           }

    // Now check if the parameter value is valid
    try {
	if (!pld.isParameterValueValid(paramNames[i], p)) {
                   msg.append(
		JaiI18N.formatMsg("OperationDescriptorImpl10",
		    new Object[] { getName(), pld.getParamNames()[i] }));
	    return false;
	}
    } catch (IllegalArgumentException e) {
	msg.append(getName() + " - " + e.getLocalizedMessage());
	return false;
    }
}

       return true;
   }
 
Example 8
Project: rastertheque   File: RenderableOp.java   Source Code and License Vote up 3 votes
/**
 * Sets one of the node's parameters to an Object.
 * This is a convenience method that invokes
 * <code>setParameterBlock()</code> and so adheres to the same event
 * firing behavior.
 *
 * <p> The <code>Object</code> may be a
 * <code>DeferredData</code> instance.  It will not be evaluated
 * until its value is actually required, i.e., when a rendering of
 * the node is requested or the renderable dimensions are queried.
 *
 * @param param the parameter, as an Object.
 * @param index the index of the parameter.
 */
public void setParameter(Object param, int index) {
    ParameterBlock pb =
        (ParameterBlock)nodeSupport.getParameterBlock().clone();
    pb.set(param, index);
    nodeSupport.setParameterBlock(pb);
}
 
Example 9
Project: rastertheque   File: RenderedOp.java   Source Code and License Vote up 3 votes
/**
 * Sets one of the node's parameters to an <code>Object</code>.
 * If the <code>index</code> lies beyond the current source list,
 * the list is extended with nulls as needed.
 * This is a convenience method that invokes
 * <code>setParameterBlock()</code> and so adheres to the same event
 * firing behavior.
 *
 * <p> The <code>Object</code> may be a
 * <code>DeferredData</code> instance.  It will not be evaluated
 * until its value is actually required, i.e., when the node is
 * rendered.
 *
 * @param param The parameter, as an <code>Object</code>.
 * @param index The index of the parameter.
 */
public synchronized void setParameter(Object param, int index) {
    ParameterBlock pb =
        (ParameterBlock)nodeSupport.getParameterBlock().clone();
    pb.set(param, index);
    nodeSupport.setParameterBlock(pb);
}