0001: /*
0002: * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/ParameterBlockUtil.java,v 1.7 2007/07/05 18:19:44 forklabs Exp $
0003: *
0004: * Copyright (C) 2007 Forklabs Daniel Léonard
0005: *
0006: * This program is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU General Public License
0008: * as published by the Free Software Foundation; either version 2
0009: * of the License, or (at your option) any later version.
0010: *
0011: * This program is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0014: * GNU General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU General Public License
0017: * along with this program; if not, write to the Free Software
0018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0019: */
0020:
0021: package ca.forklabs.media.jai;
0022:
0023: import java.awt.image.DataBuffer;
0024: import java.awt.image.RenderedImage;
0025: import java.awt.image.renderable.RenderableImage;
0026: import java.net.URL;
0027: import javax.media.jai.BorderExtender;
0028: import javax.media.jai.ImageFunction;
0029: import javax.media.jai.Interpolation;
0030: import javax.media.jai.ParameterBlockJAI;
0031: import javax.media.jai.ROI;
0032: import javax.media.jai.operator.DFTDataNature;
0033: import javax.media.jai.operator.DFTDescriptor;
0034: import javax.media.jai.operator.DFTScalingType;
0035: import javax.media.jai.operator.IDFTDescriptor;
0036: import javax.media.jai.registry.RenderableRegistryMode;
0037: import javax.media.jai.registry.RenderedRegistryMode;
0038: import com.sun.media.jai.codec.ImageDecodeParam;
0039: import com.sun.media.jai.codec.ImageEncodeParam;
0040: import ca.forklabs.baselib.util.Pair;
0041:
0042: /**
0043: * Class {@code ParameterBlockUtil} is a factory for JAI parameter blocks. This
0044: * class can be extended to provide more methods and only have one class name to
0045: * remember.
0046: *
0047: * @author <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.ParameterBlockUtil">Daniel Léonard</a>
0048: * @version $Revision: 1.7 $
0049: */
0050: public class ParameterBlockUtil {
0051:
0052: //---------------------------
0053: // Constructors
0054: //---------------------------
0055:
0056: /**
0057: * Only allow factory subclasses.
0058: */
0059: protected ParameterBlockUtil() {
0060: // nothing
0061: }
0062:
0063: //---------------------------
0064: // Class methods
0065: //---------------------------
0066:
0067: /**
0068: * Creates a {@link ParameterBlockJAI} for the specified operation in
0069: * rendered mode.
0070: * @param name the name of the operation.
0071: * @param source the source image.
0072: * @return the parameter block.
0073: */
0074: public static ParameterBlockJAI createParameterBlock(String name,
0075: RenderedImage source) {
0076: String mode = RenderedRegistryMode.MODE_NAME;
0077: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0078: name, mode, source);
0079: return pb;
0080: }
0081:
0082: /**
0083: * Creates a {@link ParameterBlockJAI} for the specified operation and
0084: * parameters in rendered mode.
0085: * @param name the name of the operation.
0086: * @param source the source image.
0087: * @param parameters the parameters.
0088: * @return the parameter block.
0089: */
0090: public static ParameterBlockJAI createParameterBlock(String name,
0091: RenderedImage source, Pair<String, ?>... parameters) {
0092: String mode = RenderedRegistryMode.MODE_NAME;
0093: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0094: name, mode, source, parameters);
0095: return pb;
0096: }
0097:
0098: /**
0099: * Creates a {@link ParameterBlockJAI} for the specified operation in
0100: * renderable mode.
0101: * @param name the name of the operation.
0102: * @param source the source image.
0103: * @return the parameter block.
0104: */
0105: public static ParameterBlockJAI createParameterBlock(String name,
0106: RenderableImage source) {
0107: String mode = RenderableRegistryMode.MODE_NAME;
0108: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0109: name, mode, source);
0110: return pb;
0111: }
0112:
0113: /**
0114: * Creates a {@link ParameterBlockJAI} for the specified operation and
0115: * parameters in renderable mode.
0116: * @param name the name of the operation.
0117: * @param source the source image.
0118: * @param parameters the parameters.
0119: * @return the parameter block.
0120: */
0121: public static ParameterBlockJAI createParameterBlock(String name,
0122: RenderableImage source, Pair<String, ?>... parameters) {
0123: String mode = RenderableRegistryMode.MODE_NAME;
0124: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0125: name, mode, source, parameters);
0126: return pb;
0127: }
0128:
0129: /**
0130: * Creates a {@link ParameterBlockJAI} for the specified operation.
0131: * @param name the name of the operation.
0132: * @param mode the render mode.
0133: * @return the parameter block.
0134: */
0135: public static ParameterBlockJAI createParameterBlock(String name,
0136: String mode) {
0137: ParameterBlockJAI pb = new ParameterBlockJAI(name, mode);
0138: return pb;
0139: }
0140:
0141: /**
0142: * Creates and fills a {@link ParameterBlockJAI}.
0143: * @param operation the name of the JAI operation.
0144: * @param mode the mode of the operation.
0145: * @param source the source image.
0146: * @param parameters the list of parameters.
0147: * @return the parameter block.
0148: */
0149: public static ParameterBlockJAI createParameterBlock(
0150: String operation, String mode, Object source,
0151: Pair<String, ?>... parameters) {
0152: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0153: operation, mode);
0154: if (null != source) {
0155: pb.addSource(source);
0156: }
0157: for (Pair<String, ?> parameter : parameters) {
0158: String name = parameter.getFirst();
0159: Object value = parameter.getSecond();
0160: pb.setParameter(name, value);
0161: }
0162: return pb;
0163: }
0164:
0165: //-----------------
0166: // addconst
0167: //-----------------
0168:
0169: /**
0170: * Creates a parameter block for core JAI operation <em>addconst</em>.
0171: * @param source the source image.
0172: * @return the parameter block.
0173: */
0174: public static ParameterBlockJAI createAddConstParameterBlock(
0175: RenderedImage source) {
0176: double[] constants = new double[] { 0.0, };
0177: ParameterBlockJAI pb = ParameterBlockUtil
0178: .createAddConstParameterBlock(source, constants);
0179: return pb;
0180: }
0181:
0182: /**
0183: * Creates a parameter block for core JAI operation <em>addconst</em>.
0184: * @param source the source image.
0185: * @param constants the constants to be added.
0186: * @return the parameter block.
0187: */
0188: @SuppressWarnings({"nls","unchecked"})
0189: public static ParameterBlockJAI createAddConstParameterBlock(
0190: RenderedImage source, double[] constants) {
0191: String name = "addconst";
0192: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0193: name, source, Pair.makePair("constants", constants));
0194: return pb;
0195: }
0196:
0197: //-----------------
0198: // bandmerge
0199: //-----------------
0200:
0201: /**
0202: * Creates a parameter block for core JAI operation <em>bandmerge</em>.
0203: * @param source0 the first source image.
0204: * @param source1 the second source image.
0205: * @param sourcen other source images.
0206: * @return the parameter block.
0207: */
0208: @SuppressWarnings("nls")
0209: public static ParameterBlockJAI createBandMergeParameterBlock(
0210: RenderedImage source0, RenderedImage source1,
0211: RenderedImage... sourcen) {
0212: String name = "bandmerge";
0213: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0214: name, source0);
0215: pb.addSource(source1);
0216: for (RenderedImage source : sourcen) {
0217: pb.addSource(source);
0218: }
0219: return pb;
0220: }
0221:
0222: //-----------------
0223: // bandselect
0224: //-----------------
0225:
0226: /**
0227: * Creates a parameter block for core JAI operation <em>bandselect</em>.
0228: * @param source the source image.
0229: * @param indices the bands to select.
0230: * @return the parameter block.
0231: */
0232: @SuppressWarnings({"nls","unchecked"})
0233: public static ParameterBlockJAI createBandSelectParameterBlock(
0234: RenderedImage source, int... indices) {
0235: String name = "bandselect";
0236: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0237: name, source, Pair.makePair("bandIndices", indices));
0238: return pb;
0239: }
0240:
0241: //-----------------
0242: // border
0243: //-----------------
0244:
0245: /**
0246: * Creates a parameter block for core JAI operation <em>border</em>.
0247: * @param source the source image.
0248: * @param pad the border size all around the image.
0249: * @return the parameter block.
0250: */
0251: public static ParameterBlockJAI createBorderParameterBlock(
0252: RenderedImage source, int pad) {
0253: BorderExtender extender = BorderExtender
0254: .createInstance(BorderExtender.BORDER_ZERO);
0255: ParameterBlockJAI pb = ParameterBlockUtil
0256: .createBorderParameterBlock(source, pad, extender);
0257: return pb;
0258: }
0259:
0260: /**
0261: * Creates a parameter block for core JAI operation <em>border</em>.
0262: * @param source the source image.
0263: * @param pad the border size all around the image.
0264: * @param extender the type of border.
0265: * @return the parameter block.
0266: */
0267: public static ParameterBlockJAI createBorderParameterBlock(
0268: RenderedImage source, int pad, BorderExtender extender) {
0269: int left_pad = pad;
0270: int right_pad = pad;
0271: int top_pad = pad;
0272: int bottom_pad = pad;
0273: ParameterBlockJAI pb = ParameterBlockUtil
0274: .createBorderParameterBlock(source, left_pad,
0275: right_pad, top_pad, bottom_pad, extender);
0276: return pb;
0277: }
0278:
0279: /**
0280: * Creates a parameter block for core JAI operation <em>border</em>.
0281: * @param source the source image.
0282: * @param left_pad the border size on the left.
0283: * @param right_pad the border size on the right.
0284: * @param top_pad the border size on the top.
0285: * @param bottom_pad the border size on the bottom.
0286: * @param extender the type of border.
0287: * @return the parameter block.
0288: */
0289: @SuppressWarnings({"nls","boxing","unchecked"})
0290: public static ParameterBlockJAI createBorderParameterBlock(
0291: RenderedImage source, int left_pad, int right_pad,
0292: int top_pad, int bottom_pad, BorderExtender extender) {
0293: String name = "border";
0294: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0295: name, source, Pair.makePair("leftPad", left_pad), Pair
0296: .makePair("rightPad", right_pad), Pair
0297: .makePair("topPad", top_pad), Pair.makePair(
0298: "bottomPad", bottom_pad), Pair.makePair("type",
0299: extender));
0300: return pb;
0301: }
0302:
0303: //-----------------
0304: // boxfilter
0305: //-----------------
0306:
0307: /**
0308: * Creates a parameter block for core JAI operation <em>boxfilter</em>.
0309: * @param source the source image.
0310: * @param size the size of the box.
0311: * @return the parameter block.
0312: */
0313: public static ParameterBlockJAI createBoxFilterParameterBlock(
0314: RenderedImage source, int size) {
0315: int width = size;
0316: int height = size;
0317: int key_x = size / 2;
0318: int key_y = size / 2;
0319: ParameterBlockJAI pb = ParameterBlockUtil
0320: .createBoxFilterParameterBlock(source, width, height,
0321: key_x, key_y);
0322: return pb;
0323: }
0324:
0325: /**
0326: * Creates a parameter block for core JAI operation <em>boxfilter</em>.
0327: * @param source the source image.
0328: * @param width the width of the box.
0329: * @param height the height of the box.
0330: * @param key_x the <em>x</em> position of the key element.
0331: * @param key_y the <em>y</em> position of the key element.
0332: * @return the parameter block.
0333: */
0334: @SuppressWarnings({"nls","unchecked","boxing"})
0335: public static ParameterBlockJAI createBoxFilterParameterBlock(
0336: RenderedImage source, int width, int height, int key_x,
0337: int key_y) {
0338: String name = "boxfilter";
0339: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0340: name, source, Pair.makePair("width", width), Pair
0341: .makePair("height", height), Pair.makePair(
0342: "xKey", key_x), Pair.makePair("yKey", key_y));
0343: return pb;
0344: }
0345:
0346: //-----------------
0347: // constant
0348: //-----------------
0349:
0350: /**
0351: * Creates a parameter block for core JAI operation <em>constant</em>.
0352: * @param width the width of the image.
0353: * @param height the height of the image.
0354: * @param values the values for each band.
0355: * @return the parameter block.
0356: */
0357: @SuppressWarnings({"nls","unchecked","boxing"})
0358: public static ParameterBlockJAI createConstantParameterBlock(
0359: float width, float height, Number[] values) {
0360: String name = "constant";
0361: RenderedImage source = null;
0362: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0363: name, source, Pair.makePair("width", width), Pair
0364: .makePair("height", height), Pair.makePair(
0365: "bandValues", values));
0366: return pb;
0367: }
0368:
0369: //-----------------
0370: // crop
0371: //-----------------
0372:
0373: /**
0374: * Creates a parameter block for core JAI operation <em>crop</em>.
0375: * @param source the source image.
0376: * @param x the x origin of the cropping operation.
0377: * @param y the y origin of the cropping operation.
0378: * @param width the width of the cropping operation.
0379: * @param height the height of the cropping operation.
0380: * @return the parameter block.
0381: */
0382: @SuppressWarnings({"nls","unchecked","boxing"})
0383: public static ParameterBlockJAI createCropParameterBlock(
0384: RenderedImage source, float x, float y, float width,
0385: float height) {
0386: String name = "crop";
0387: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0388: name, source, Pair.makePair("x", x), Pair.makePair("y",
0389: y), Pair.makePair("width", width), Pair
0390: .makePair("height", height));
0391: return pb;
0392: }
0393:
0394: //-----------------
0395: // dft
0396: //-----------------
0397:
0398: /**
0399: * Creates a parameter block for core JAI operation <em>dft</em>.
0400: * @param source the source image.
0401: * @return the parameter block.
0402: */
0403: public static ParameterBlockJAI createDFTParameterBlock(
0404: RenderedImage source) {
0405: DFTScalingType type = DFTDescriptor.SCALING_NONE;
0406: DFTDataNature nature = DFTDescriptor.REAL_TO_COMPLEX;
0407: ParameterBlockJAI pb = ParameterBlockUtil
0408: .createDFTParameterBlock(source, type, nature);
0409: return pb;
0410: }
0411:
0412: /**
0413: * Creates a parameter block for core JAI operation <em>dft</em>.
0414: * @param source the source image.
0415: * @param type the type of scaling.
0416: * @param nature the nature of the data.
0417: * @return the parameter block.
0418: */
0419: @SuppressWarnings({"nls","unchecked"})
0420: public static ParameterBlockJAI createDFTParameterBlock(
0421: RenderedImage source, DFTScalingType type,
0422: DFTDataNature nature) {
0423: String name = "dft";
0424: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0425: name, source, Pair.makePair("scalingType", type), Pair
0426: .makePair("dataNature", nature));
0427: return pb;
0428: }
0429:
0430: //-----------------
0431: // exp
0432: //-----------------
0433:
0434: /**
0435: * Creates a parameter block for core JAI operation <em>exp</em>.
0436: * @param source the source image.
0437: * @return the parameter block.
0438: */
0439: @SuppressWarnings("nls")
0440: public static ParameterBlockJAI createExpParameterBlock(
0441: RenderedImage source) {
0442: String name = "exp";
0443: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0444: name, source);
0445: return pb;
0446: }
0447:
0448: //-----------------
0449: // extrema
0450: //-----------------
0451:
0452: /**
0453: * Creates a parameter block for core JAI operation <em>extrema</em>.
0454: * @param source the source image.
0455: * @return the parameter block.
0456: */
0457: @SuppressWarnings("nls")
0458: public static ParameterBlockJAI createExtremaParameterBlock(
0459: RenderedImage source) {
0460: ROI roi = null;
0461: int x_period = 1;
0462: int y_period = 1;
0463: ParameterBlockJAI pb = ParameterBlockUtil
0464: .createExtremaParameterBlock(source, roi, x_period,
0465: y_period);
0466: return pb;
0467: }
0468:
0469: /**
0470: * Creates a parameter block for core JAI operation <em>extrema</em>.
0471: * @param source the source image.
0472: * @param roi the region of interest.
0473: * @param x_period the horizontal sampling.
0474: * @param y_period the vertical sampling.
0475: * @return the parameter block.
0476: */
0477: @SuppressWarnings("nls")
0478: public static ParameterBlockJAI createExtremaParameterBlock(
0479: RenderedImage source, ROI roi, int x_period, int y_period) {
0480: boolean save_locations = false;
0481: int max_runs = 1;
0482: ParameterBlockJAI pb = ParameterBlockUtil
0483: .createExtremaParameterBlock(source, roi, x_period,
0484: y_period, save_locations, max_runs);
0485: return pb;
0486: }
0487:
0488: /**
0489: * Creates a parameter block for core JAI operation <em>extrema</em>.
0490: * @param source the source image.
0491: * @param roi the region of interest.
0492: * @param x_period the horizontal sampling.
0493: * @param y_period the vertical sampling.
0494: * @param save_locations whether or not to save the extrema locations.
0495: * @param max_runs the number of extrema locations to save for both the
0496: * minima and the maxima.
0497: * @return the parameter block.
0498: */
0499: @SuppressWarnings({"nls","unchecked","boxing"})
0500: public static ParameterBlockJAI createExtremaParameterBlock(
0501: RenderedImage source, ROI roi, int x_period, int y_period,
0502: boolean save_locations, int max_runs) {
0503: String name = "extrema";
0504: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0505: name, source, Pair.makePair("roi", roi), Pair.makePair(
0506: "xPeriod", x_period), Pair.makePair("yPeriod",
0507: y_period), Pair.makePair("saveLocations",
0508: save_locations), Pair.makePair("maxRuns",
0509: max_runs));
0510: return pb;
0511: }
0512:
0513: //-----------------
0514: // fileload
0515: //-----------------
0516:
0517: /**
0518: * Creates a parameter block for core JAI operation <em>fileload</em>.
0519: * @param filename the name of the file containing the image.
0520: * @return the parameter block.
0521: */
0522: public static ParameterBlockJAI createFileLoadParameterBlock(
0523: String filename) {
0524: ImageDecodeParam param = null;
0525: ParameterBlockJAI pb = ParameterBlockUtil
0526: .createFileLoadParameterBlock(filename, param);
0527: return pb;
0528: }
0529:
0530: /**
0531: * Creates a parameter block for core JAI operation <em>fileload</em>.
0532: * @param filename the name of the file containing the image.
0533: * @param param decoding parameters.
0534: * @return the parameter block.
0535: */
0536: public static ParameterBlockJAI createFileLoadParameterBlock(
0537: String filename, ImageDecodeParam param) {
0538: boolean check_local = true;
0539: ParameterBlockJAI pb = ParameterBlockUtil
0540: .createFileLoadParameterBlock(filename, param,
0541: check_local);
0542: return pb;
0543: }
0544:
0545: /**
0546: * Creates a parameter block for core JAI operation <em>fileload</em>.
0547: * @param filename the name of the file containing the image.
0548: * @param param decoding parameters.
0549: * @param check_local if the image is local.
0550: * @return the parameter block.
0551: */
0552: @SuppressWarnings({"nls","unchecked","boxing"})
0553: public static ParameterBlockJAI createFileLoadParameterBlock(
0554: String filename, ImageDecodeParam param, boolean check_local) {
0555: String name = "fileload";
0556: RenderedImage source = null;
0557: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0558: name, source, Pair.makePair("filename", filename), Pair
0559: .makePair("param", param), Pair.makePair(
0560: "checkFileLocally", check_local));
0561: return pb;
0562: }
0563:
0564: //-----------------
0565: // filestore
0566: //-----------------
0567:
0568: /**
0569: * Creates a parameter block for core JAI operation <em>filestore</em>.
0570: * @param source the source image.
0571: * @param filename the name of the file containing the image.
0572: * @return the parameter block.
0573: */
0574: @SuppressWarnings("nls")
0575: public static ParameterBlockJAI createFileStoreParameterBlock(
0576: RenderedImage source, String filename) {
0577: String format = "TIFF";
0578:
0579: int dot = filename.lastIndexOf('.');
0580: boolean dot_exists = (-1 != dot);
0581: boolean more_text_after_dot = (filename.length() > (dot + 1));
0582: if (dot_exists && more_text_after_dot) {
0583: format = filename.substring(dot + 1);
0584: }
0585:
0586: ParameterBlockJAI pb = ParameterBlockUtil
0587: .createFileStoreParameterBlock(source, filename, format);
0588: return pb;
0589: }
0590:
0591: /**
0592: * Creates a parameter block for core JAI operation <em>filestore</em>.
0593: * @param source the source image.
0594: * @param filename the name of the file containing the image.
0595: * @param format the image format.
0596: * @return the parameter block.
0597: */
0598: public static ParameterBlockJAI createFileStoreParameterBlock(
0599: RenderedImage source, String filename, String format) {
0600: ImageEncodeParam param = null;
0601: ParameterBlockJAI pb = ParameterBlockUtil
0602: .createFileStoreParameterBlock(source, filename,
0603: format, param);
0604: return pb;
0605: }
0606:
0607: /**
0608: * Creates a parameter block for core JAI operation <em>filestore</em>.
0609: * @param source the source image.
0610: * @param filename the name of the file containing the image.
0611: * @param format the image format.
0612: * @param param decoding parameters.
0613: * @return the parameter block.
0614: */
0615: public static ParameterBlockJAI createFileStoreParameterBlock(
0616: RenderedImage source, String filename, String format,
0617: ImageEncodeParam param) {
0618: boolean check_local = true;
0619: ParameterBlockJAI pb = ParameterBlockUtil
0620: .createFileStoreParameterBlock(source, filename,
0621: format, param, check_local);
0622: return pb;
0623: }
0624:
0625: /**
0626: * Creates a parameter block for core JAI operation <em>filestore</em>.
0627: * @param source the source image.
0628: * @param filename the name of the file containing the image.
0629: * @param format the image format.
0630: * @param param decoding parameters.
0631: * @param check_local if the image is local.
0632: * @return the parameter block.
0633: */
0634: @SuppressWarnings({"nls","unchecked","boxing"})
0635: public static ParameterBlockJAI createFileStoreParameterBlock(
0636: RenderedImage source, String filename, String format,
0637: ImageEncodeParam param, boolean check_local) {
0638: String name = "filestore";
0639: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0640: name, source, Pair.makePair("filename", filename), Pair
0641: .makePair("format", format), Pair.makePair(
0642: "param", param), Pair.makePair(
0643: "checkFileLocally", check_local));
0644: return pb;
0645: }
0646:
0647: //-----------------
0648: // format
0649: //-----------------
0650:
0651: /**
0652: * Creates a parameter block for core JAI operation <em>format</em>.
0653: * @param source the source image.
0654: * @param type the data type.
0655: * @return the parameter block.
0656: */
0657: public static ParameterBlockJAI createFormatParameterBlock(
0658: RenderedImage source, FormatDataType type) {
0659: int raw_type = type.getDataBufferType();
0660: ParameterBlockJAI pb = ParameterBlockUtil
0661: .createFormatParameterBlock(source, raw_type);
0662: return pb;
0663: }
0664:
0665: /**
0666: * Creates a parameter block for core JAI operation <em>format</em>.
0667: * @param source the source image.
0668: * @param type the data type.
0669: * @return the parameter block.
0670: * @see DataBuffer
0671: */
0672: @SuppressWarnings({"nls","unchecked","boxing"})
0673: public static ParameterBlockJAI createFormatParameterBlock(
0674: RenderedImage source, int type) {
0675: String name = "format";
0676: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0677: name, source, Pair.makePair("dataType", type));
0678: return pb;
0679: }
0680:
0681: //-----------------
0682: // idft
0683: //-----------------
0684:
0685: /**
0686: * Creates a parameter block for core JAI operation <em>idft</em>.
0687: * @param source the source image.
0688: * @return the parameter block.
0689: */
0690: public static ParameterBlockJAI createIDFTParameterBlock(
0691: RenderedImage source) {
0692: DFTScalingType type = IDFTDescriptor.SCALING_DIMENSIONS;
0693: DFTDataNature nature = IDFTDescriptor.COMPLEX_TO_REAL;
0694: ParameterBlockJAI pb = ParameterBlockUtil
0695: .createIDFTParameterBlock(source, type, nature);
0696: return pb;
0697: }
0698:
0699: /**
0700: * Creates a parameter block for core JAI operation <em>idft</em>.
0701: * @param source the source image.
0702: * @param type the type of scaling.
0703: * @param nature the nature of the data.
0704: * @return the parameter block.
0705: */
0706: @SuppressWarnings({"nls","unchecked"})
0707: public static ParameterBlockJAI createIDFTParameterBlock(
0708: RenderedImage source, DFTScalingType type,
0709: DFTDataNature nature) {
0710: String name = "idft";
0711: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0712: name, source, Pair.makePair("scalingType", type), Pair
0713: .makePair("dataNature", nature));
0714: return pb;
0715: }
0716:
0717: //-----------------
0718: // imagefunction
0719: //-----------------
0720:
0721: /**
0722: * Creates a parameter block for core JAI operation <em>imagefunction</em>.
0723: * @param function the function.
0724: * @param width the width.
0725: * @param height the height.
0726: * @return the parameter block.
0727: */
0728: public static ParameterBlockJAI createImageFunctionParameterBlock(
0729: ImageFunction function, int width, int height) {
0730: float sx = 1.0f;
0731: float sy = 1.0f;
0732: float tx = 0.0f;
0733: float ty = 0.0f;
0734: ParameterBlockJAI pb = ParameterBlockUtil
0735: .createImageFunctionParameterBlock(function, width,
0736: height, sx, sy, tx, ty);
0737: return pb;
0738: }
0739:
0740: /**
0741: * Creates a parameter block for core JAI operation <em>imagefunction</em>.
0742: * @param function the function.
0743: * @param width the width.
0744: * @param height the height.
0745: * @param sx the scaling factor in the <em>x</em> dimension.
0746: * @param sy the scaling factor in the <em>y</em> dimension.
0747: * @param tx the translation value in the <em>x</em> dimension.
0748: * @param ty the translation value in the <em>y</em> dimension.
0749: * @return the parameter block.
0750: */
0751: @SuppressWarnings({"nls","boxing","unchecked"})
0752: public static ParameterBlockJAI createImageFunctionParameterBlock(
0753: ImageFunction function, int width, int height, float sx,
0754: float sy, float tx, float ty) {
0755: String name = "imagefunction";
0756: RenderedImage source = null;
0757: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0758: name, source, Pair.makePair("function", function), Pair
0759: .makePair("width", width), Pair.makePair(
0760: "height", height), Pair.makePair("xScale", sx),
0761: Pair.makePair("yScale", sy), Pair
0762: .makePair("xTrans", tx), Pair.makePair(
0763: "yTrans", ty));
0764: return pb;
0765: }
0766:
0767: //-----------------
0768: // log
0769: //-----------------
0770:
0771: /**
0772: * Creates a parameter block for core JAI operation <em>log</em>.
0773: * @param source the source image.
0774: * @return the parameter block.
0775: */
0776: @SuppressWarnings("nls")
0777: public static ParameterBlockJAI createLogParameterBlock(
0778: RenderedImage source) {
0779: String name = "log";
0780: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0781: name, source);
0782: return pb;
0783: }
0784:
0785: //-----------------
0786: // mean
0787: //-----------------
0788:
0789: /**
0790: * Creates a parameter block for core JAI operation <em>mean</em>.
0791: * @param source the source image.
0792: * @return the parameter block.
0793: */
0794: public static ParameterBlockJAI createMeanParameterBlock(
0795: RenderedImage source) {
0796: int h_sampling = 1;
0797: int v_sampling = 1;
0798: ParameterBlockJAI pb = ParameterBlockUtil
0799: .createMeanParameterBlock(source, h_sampling,
0800: v_sampling);
0801: return pb;
0802: }
0803:
0804: /**
0805: * Creates a parameter block for core JAI operation <em>mean</em>.
0806: * @param source the source image.
0807: * @param roi the region of interest.
0808: * @return the parameter block.
0809: */
0810: public static ParameterBlockJAI createMeanParameterBlock(
0811: RenderedImage source, ROI roi) {
0812: int h_sampling = 1;
0813: int v_sampling = 1;
0814: ParameterBlockJAI pb = ParameterBlockUtil
0815: .createMeanParameterBlock(source, roi, h_sampling,
0816: v_sampling);
0817: return pb;
0818: }
0819:
0820: /**
0821: * Creates a parameter block for core JAI operation <em>mean</em>.
0822: * @param source the source image.
0823: * @param h_sampling the horizontal sampling rate.
0824: * @param v_sampling the vertical sampling rate.
0825: * @return the parameter block.
0826: */
0827: public static ParameterBlockJAI createMeanParameterBlock(
0828: RenderedImage source, int h_sampling, int v_sampling) {
0829: ROI roi = null;
0830: ParameterBlockJAI pb = ParameterBlockUtil
0831: .createMeanParameterBlock(source, roi, h_sampling,
0832: v_sampling);
0833: return pb;
0834: }
0835:
0836: /**
0837: * Creates a parameter block for core JAI operation <em>mean</em>.
0838: * @param source the source image.
0839: * @param roi the region of interest.
0840: * @param h_sampling the horizontal sampling rate.
0841: * @param v_sampling the vertical sampling rate.
0842: * @return the parameter block.
0843: */
0844: @SuppressWarnings({"nls","unchecked","boxing"})
0845: public static ParameterBlockJAI createMeanParameterBlock(
0846: RenderedImage source, ROI roi, int h_sampling,
0847: int v_sampling) {
0848: String name = "mean";
0849: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0850: name, source, Pair.makePair("roi", roi), Pair.makePair(
0851: "xPeriod", h_sampling), Pair.makePair(
0852: "yPeriod", v_sampling));
0853: return pb;
0854: }
0855:
0856: //-----------------
0857: // multiply
0858: //-----------------
0859:
0860: /**
0861: * Creates a parameter block for core JAI operation <em>multiply</em>.
0862: * @param source0 the first source image.
0863: * @param source1 the second source image.
0864: * @return the parameter block.
0865: */
0866: @SuppressWarnings("nls")
0867: public static ParameterBlockJAI createMultiplyParameterBlock(
0868: RenderedImage source0, RenderedImage source1) {
0869: String name = "multiply";
0870: String mode = RenderedRegistryMode.MODE_NAME;
0871: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0872: name, mode);
0873: if (null != source0) {
0874: pb.setSource("source0", source0);
0875: }
0876: if (null != source1) {
0877: pb.setSource("source1", source1);
0878: }
0879: return pb;
0880: }
0881:
0882: //-----------------
0883: // multiplycomplex
0884: //-----------------
0885:
0886: /**
0887: * Creates a parameter block for core JAI operation <em>multiplycomplex</em>.
0888: * @param source0 the first source image.
0889: * @param source1 the second source image.
0890: * @return the parameter block.
0891: */
0892: @SuppressWarnings("nls")
0893: public static ParameterBlockJAI createMultiplyComplexParameterBlock(
0894: RenderedImage source0, RenderedImage source1) {
0895: String name = "multiplycomplex";
0896: String mode = RenderedRegistryMode.MODE_NAME;
0897: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0898: name, mode);
0899: if (null != source0) {
0900: pb.setSource("source0", source0);
0901: }
0902: if (null != source1) {
0903: pb.setSource("source1", source1);
0904: }
0905: return pb;
0906: }
0907:
0908: //-----------------
0909: // multiplyconst
0910: //-----------------
0911:
0912: /**
0913: * Creates a parameter block for core JAI operation <em>multiplyconst</em>.
0914: * @param source the source image.
0915: * @return the parameter block.
0916: */
0917: public static ParameterBlockJAI createMultiplyConstParameterBlock(
0918: RenderedImage source) {
0919: double[] constants = new double[] { 1.0, };
0920: ParameterBlockJAI pb = ParameterBlockUtil
0921: .createMultiplyConstParameterBlock(source, constants);
0922: return pb;
0923: }
0924:
0925: /**
0926: * Creates a parameter block for core JAI operation <em>multiplyconst</em>.
0927: * @param source the source image.
0928: * @param constants the constants to be multiplied.
0929: * @return the parameter block.
0930: */
0931: @SuppressWarnings({"nls","unchecked"})
0932: public static ParameterBlockJAI createMultiplyConstParameterBlock(
0933: RenderedImage source, double[] constants) {
0934: String name = "multiplyconst";
0935: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0936: name, source, Pair.makePair("constants", constants));
0937: return pb;
0938: }
0939:
0940: //-----------------
0941: // null
0942: //-----------------
0943:
0944: /**
0945: * Creates a parameter block for core JAI operation <em>null</em>.
0946: * @param source the source image.
0947: * @return the parameter block.
0948: */
0949: @SuppressWarnings("nls")
0950: public static ParameterBlockJAI createNullParameterBlock(
0951: RenderedImage source) {
0952: String name = "null";
0953: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0954: name, source);
0955: return pb;
0956: }
0957:
0958: /**
0959: * Creates a parameter block for core JAI operation <em>null</em>.
0960: * @param source the source image.
0961: * @return the parameter block.
0962: */
0963: @SuppressWarnings("nls")
0964: public static ParameterBlockJAI createNullParameterBlock(
0965: RenderableImage source) {
0966: String name = "null";
0967: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
0968: name, source);
0969: return pb;
0970: }
0971:
0972: //-----------------
0973: // periodic shift
0974: //-----------------
0975:
0976: /**
0977: * Creates a parameter block for core JAI operation <em>periodicshift</em>.
0978: * @param source the source image.
0979: * @return the parameter block.
0980: */
0981: @SuppressWarnings("boxing")
0982: public static ParameterBlockJAI createPeriodicShiftParameterBlock(
0983: RenderedImage source) {
0984: int width = source.getWidth();
0985: int height = source.getHeight();
0986: int dx = width / 2;
0987: int dy = height / 2;
0988: ParameterBlockJAI pb = ParameterBlockUtil
0989: .createPeriodicShiftParameterBlock(source, dx, dy);
0990: return pb;
0991: }
0992:
0993: /**
0994: * Creates a parameter block for core JAI operation <em>periodicshift</em>.
0995: * @param source the source image.
0996: * @param dx the displacement in the <em>x</em> direction.
0997: * @param dy the displacement in the <em>y</em> direction.
0998: * @return the parameter block.
0999: */
1000: @SuppressWarnings({"nls","unchecked"})
1001: public static ParameterBlockJAI createPeriodicShiftParameterBlock(
1002: RenderedImage source, Integer dx, Integer dy) {
1003: String name = "periodicshift";
1004: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1005: name, source, Pair.makePair("shiftX", dx), Pair
1006: .makePair("shiftY", dy));
1007: return pb;
1008: }
1009:
1010: /**
1011: * Creates a parameter block for core JAI operation <em>periodicshift</em>.
1012: * @param source the source image.
1013: * @return the parameter block.
1014: */
1015: @SuppressWarnings("boxing")
1016: public static ParameterBlockJAI createPeriodicShiftParameterBlock(
1017: RenderableImage source) {
1018: float width = source.getWidth();
1019: float height = source.getHeight();
1020: int dx = (int) (width / 2.0f);
1021: int dy = (int) (height / 2.0f);
1022: ParameterBlockJAI pb = ParameterBlockUtil
1023: .createPeriodicShiftParameterBlock(source, dx, dy);
1024: return pb;
1025: }
1026:
1027: /**
1028: * Creates a parameter block for core JAI operation <em>periodicshift</em>.
1029: * @param source the source image.
1030: * @param dx the displacement in the <em>x</em> direction.
1031: * @param dy the displacement in the <em>y</em> direction.
1032: * @return the parameter block.
1033: */
1034: @SuppressWarnings({"nls","unchecked"})
1035: public static ParameterBlockJAI createPeriodicShiftParameterBlock(
1036: RenderableImage source, Integer dx, Integer dy) {
1037: String name = "periodicshift";
1038: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1039: name, source, Pair.makePair("shiftX", dx), Pair
1040: .makePair("shiftY", dy));
1041: return pb;
1042: }
1043:
1044: //-----------------
1045: // rescale
1046: //-----------------
1047:
1048: /**
1049: * Creates a parameter block for core JAI operation <em>rescale</em>.
1050: * @param source the source image.
1051: * @return the parameter block.
1052: */
1053: public static ParameterBlockJAI createRescaleParameterBlock(
1054: RenderedImage source) {
1055: double[] constants = new double[] { 1.0, };
1056: double[] offsets = new double[] { 0.0, };
1057: ParameterBlockJAI pb = ParameterBlockUtil
1058: .createRescaleParameterBlock(source, constants, offsets);
1059: return pb;
1060: }
1061:
1062: /**
1063: * Creates a parameter block for core JAI operation <em>scale</em>.
1064: * @param source the source image.
1065: * @param constants the per-band constants to multiply by.
1066: * @param offsets the per-band offsets to be added.
1067: * @return the parameter block.
1068: */
1069: @SuppressWarnings({"nls","unchecked"})
1070: public static ParameterBlockJAI createRescaleParameterBlock(
1071: RenderedImage source, double[] constants, double[] offsets) {
1072: String name = "rescale";
1073: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1074: name, source, Pair.makePair("offsets", offsets), Pair
1075: .makePair("constants", constants));
1076: return pb;
1077: }
1078:
1079: //-----------------
1080: // scale
1081: //-----------------
1082:
1083: /**
1084: * Creates a parameter block for core JAI operation <em>scale</em>.
1085: * @param source the source image.
1086: * @param s_x the scale factor along the <em>x</em> axis.
1087: * @param s_y the scale factor along the <em>y</em> axis.
1088: * @return the parameter block.
1089: */
1090: public static ParameterBlockJAI createScaleParameterBlock(
1091: RenderedImage source, float s_x, float s_y) {
1092: float t_x = 0.0f;
1093: float t_y = 0.0f;
1094: ParameterBlockJAI pb = ParameterBlockUtil
1095: .createScaleParameterBlock(source, s_x, s_y, t_x, t_y);
1096: return pb;
1097: }
1098:
1099: /**
1100: * Creates a parameter block for core JAI operation <em>scale</em>.
1101: * @param source the source image.
1102: * @param s_x the scale factor along the <em>x</em> axis.
1103: * @param s_y the scale factor along the <em>y</em> axis.
1104: * @param t_x the translation distance along the <em>x</em> axis.
1105: * @param t_y the translation distance along the <em>y</em> axis.
1106: * @return the parameter block.
1107: */
1108: public static ParameterBlockJAI createScaleParameterBlock(
1109: RenderedImage source, float s_x, float s_y, float t_x,
1110: float t_y) {
1111: Interpolation interpolation = null;
1112: ParameterBlockJAI pb = ParameterBlockUtil
1113: .createScaleParameterBlock(source, s_x, s_y, t_x, t_y,
1114: interpolation);
1115: return pb;
1116: }
1117:
1118: /**
1119: * Creates a parameter block for core JAI operation <em>scale</em>.
1120: * @param source the source image.
1121: * @param s_x the scale factor along the <em>x</em> axis.
1122: * @param s_y the scale factor along the <em>y</em> axis.
1123: * @param interpolation the interpolation.
1124: * @return the parameter block.
1125: */
1126: public static ParameterBlockJAI createScaleParameterBlock(
1127: RenderedImage source, float s_x, float s_y,
1128: Interpolation interpolation) {
1129: float t_x = 0.0f;
1130: float t_y = 0.0f;
1131: ParameterBlockJAI pb = ParameterBlockUtil
1132: .createScaleParameterBlock(source, s_x, s_y, t_x, t_y,
1133: interpolation);
1134: return pb;
1135: }
1136:
1137: /**
1138: * Creates a parameter block for the core JAI operation <em>scale</em>.
1139: * @param source the source image.
1140: * @param s_x the scale factor along the <em>x</em> axis.
1141: * @param s_y the scale factor along the <em>y</em> axis.
1142: * @param t_x the translation distance along the <em>x</em> axis.
1143: * @param t_y the translation distance along the <em>y</em> axis.
1144: * @param interpolation the interpolation.
1145: * @return the parameter block.
1146: */
1147: @SuppressWarnings({"nls","unchecked","boxing"})
1148: public static ParameterBlockJAI createScaleParameterBlock(
1149: RenderedImage source, float s_x, float s_y, float t_x,
1150: float t_y, Interpolation interpolation) {
1151: String name = "scale";
1152: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1153: name, source, Pair.makePair("xScale", s_x), Pair
1154: .makePair("yScale", s_y), Pair.makePair(
1155: "xTrans", t_x), Pair.makePair("yTrans", t_y));
1156: if (null != interpolation) {
1157: pb.setParameter("interpolation", interpolation);
1158: }
1159: return pb;
1160: }
1161:
1162: //-----------------
1163: // subsampleaverage
1164: //-----------------
1165:
1166: /**
1167: * Creates a parameter block for the core JAI operation <em>subsampleaverage</em>.
1168: * @param source the source image.
1169: * @param s_x the scale factor along the <em>x</em> axis.
1170: * @param s_y the scale factor along the <em>y</em> axis.
1171: * @return the parameter block.
1172: */
1173: @SuppressWarnings({"nls","boxing","unchecked"})
1174: public static ParameterBlockJAI createSubSampleAverageParameterBlock(
1175: RenderedImage source, double s_x, double s_y) {
1176: String name = "subsampleaverage";
1177: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1178: name, source, Pair.makePair("scaleX", s_x), Pair
1179: .makePair("scaleY", s_y));
1180: return pb;
1181: }
1182:
1183: //-----------------
1184: // subtract
1185: //-----------------
1186:
1187: /**
1188: * Creates a parameter block for core JAI operation <em>subtract</em>.
1189: * @param source0 the first source image.
1190: * @param source1 the second source image.
1191: * @return the parameter block.
1192: */
1193: @SuppressWarnings("nls")
1194: public static ParameterBlockJAI createSubtractParameterBlock(
1195: RenderedImage source0, RenderedImage source1) {
1196: String name = "subtract";
1197: String mode = RenderedRegistryMode.MODE_NAME;
1198: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1199: name, mode);
1200: if (null != source0) {
1201: pb.setSource("source0", source0);
1202: }
1203: if (null != source1) {
1204: pb.setSource("source1", source1);
1205: }
1206: return pb;
1207: }
1208:
1209: //-----------------
1210: // subtractconst
1211: //-----------------
1212:
1213: /**
1214: * Creates a parameter block for core JAI operation <em>subtractconst</em>.
1215: * @param source the source image.
1216: * @return the parameter block.
1217: */
1218: public static ParameterBlockJAI createSubtractConstParameterBlock(
1219: RenderedImage source) {
1220: double[] constants = new double[] { 0.0, };
1221: ParameterBlockJAI pb = ParameterBlockUtil
1222: .createSubtractConstParameterBlock(source, constants);
1223: return pb;
1224: }
1225:
1226: /**
1227: * Creates a parameter block for core JAI operation <em>subtractconst</em>.
1228: * @param source the source image.
1229: * @param constants the constants to be subtracted.
1230: * @return the parameter block.
1231: */
1232: @SuppressWarnings({"nls","unchecked"})
1233: public static ParameterBlockJAI createSubtractConstParameterBlock(
1234: RenderedImage source, double[] constants) {
1235: String name = "subtractconst";
1236: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1237: name, source, Pair.makePair("constants", constants));
1238: pb.setParameter("constants", constants);
1239: return pb;
1240: }
1241:
1242: //-----------------
1243: // url
1244: //-----------------
1245:
1246: /**
1247: * Creates a parameter block for core JAI operation <em>url</em>.
1248: * @param url the location of the image data.
1249: * @return the parameter block.
1250: */
1251: public static ParameterBlockJAI createUrlParameterBlock(URL url) {
1252: ImageDecodeParam param = null;
1253: ParameterBlockJAI pb = ParameterBlockUtil
1254: .createUrlParameterBlock(url, param);
1255: return pb;
1256: }
1257:
1258: /**
1259: * Creates a parameter block for core JAI operation <em>scale</em>.
1260: * @param url the location of the image data.
1261: * @param param decoding parameters.
1262: * @return the parameter block.
1263: */
1264: @SuppressWarnings({"nls","unchecked"})
1265: public static ParameterBlockJAI createUrlParameterBlock(URL url,
1266: ImageDecodeParam param) {
1267: String name = "url";
1268: ParameterBlockJAI pb = ParameterBlockUtil.createParameterBlock(
1269: name, (RenderedImage) null, Pair.makePair("URL", url),
1270: Pair.makePair("param", param));
1271: return pb;
1272: }
1273:
1274: }
1275:
1276: /*
1277: * $Log: ParameterBlockUtil.java,v $
1278: * Revision 1.7 2007/07/05 18:19:44 forklabs
1279: * New factory for operator format using the FormatDataType enum.
1280: *
1281: * Revision 1.6 2007/06/13 18:54:42 forklabs
1282: * Added many more parameter block factories.
1283: *
1284: * Revision 1.5 2007/06/05 20:48:25 forklabs
1285: * More factories.
1286: *
1287: * Revision 1.4 2007/06/05 02:08:42 forklabs
1288: * Added new factories.
1289: *
1290: * Revision 1.3 2007/05/10 17:56:17 forklabs
1291: * Added factory for operation url.
1292: *
1293: * Revision 1.2 2007/05/03 20:25:34 forklabs
1294: * Trimmed trailing spaces.
1295: *
1296: * Revision 1.1 2007/05/03 20:23:57 forklabs
1297: * Class ParameterBlockUtil.
1298: *
1299: */
|