2008-10-21 14:00:00 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Rustem V. Rafikov
|
|
|
|
* @version $Revision: 1.3 $
|
|
|
|
*/
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
package javax.imageio;
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* The IIOParam abstract class is superclass for ImageReadParam and
|
|
|
|
* ImageWriteParam classes and provides methods and variables which they share.
|
|
|
|
*
|
|
|
|
* @since Android 1.0
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public abstract class IIOParam {
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The source region.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected Rectangle sourceRegion;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The source x subsampling.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected int sourceXSubsampling = 1;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The source y subsampling.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected int sourceYSubsampling = 1;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The subsampling x offset.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected int subsamplingXOffset;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The subsampling y offset.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected int subsamplingYOffset;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The source bands.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected int[] sourceBands;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The destination type.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected ImageTypeSpecifier destinationType;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The destination offset.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected Point destinationOffset = new Point(0, 0);
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default controller.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected IIOParamController defaultController;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The controller.
|
|
|
|
*/
|
2008-10-21 14:00:00 +00:00
|
|
|
protected IIOParamController controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new IIOParam.
|
|
|
|
*/
|
2008-12-18 02:05:43 +00:00
|
|
|
protected IIOParam() {
|
|
|
|
}
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the source region as a Rectangle object.
|
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param sourceRegion
|
|
|
|
* the Rectangle which specifies the source region.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public void setSourceRegion(Rectangle sourceRegion) {
|
|
|
|
if (sourceRegion != null) {
|
|
|
|
if (sourceRegion.x < 0) {
|
|
|
|
throw new IllegalArgumentException("x < 0");
|
|
|
|
}
|
|
|
|
if (sourceRegion.y < 0) {
|
|
|
|
throw new IllegalArgumentException("y < 0");
|
|
|
|
}
|
|
|
|
if (sourceRegion.width <= 0) {
|
|
|
|
throw new IllegalArgumentException("width <= 0");
|
|
|
|
}
|
|
|
|
if (sourceRegion.height <= 0) {
|
|
|
|
throw new IllegalArgumentException("height <= 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceRegion.width <= subsamplingXOffset) {
|
|
|
|
throw new IllegalArgumentException("width <= subsamplingXOffset");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceRegion.height <= subsamplingYOffset) {
|
|
|
|
throw new IllegalArgumentException("height <= subsamplingXOffset");
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
// -- clone it to avoid unexpected modifications
|
|
|
|
this.sourceRegion = (Rectangle)sourceRegion.clone();
|
2008-10-21 14:00:00 +00:00
|
|
|
} else {
|
|
|
|
this.sourceRegion = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the source region.
|
|
|
|
*
|
|
|
|
* @return the source region as Rectangle.
|
|
|
|
*/
|
|
|
|
public Rectangle getSourceRegion() {
|
|
|
|
if (sourceRegion == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
// -- clone it to avoid unexpected modifications
|
|
|
|
return (Rectangle)sourceRegion.clone();
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Sets the source subsampling. The sourceXSubsampling and
|
|
|
|
* sourceYSubsampling parameters specify the number of rows and columns to
|
|
|
|
* advance after every source pixel.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param sourceXSubsampling
|
|
|
|
* the source X subsampling.
|
|
|
|
* @param sourceYSubsampling
|
|
|
|
* the source Y subsampling.
|
|
|
|
* @param subsamplingXOffset
|
|
|
|
* the subsampling X offset.
|
|
|
|
* @param subsamplingYOffset
|
|
|
|
* the subsampling Y offset.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
2008-12-18 02:05:43 +00:00
|
|
|
public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling,
|
|
|
|
int subsamplingXOffset, int subsamplingYOffset) {
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
if (sourceXSubsampling <= 0) {
|
|
|
|
throw new IllegalArgumentException("sourceXSubsampling <= 0");
|
|
|
|
}
|
|
|
|
if (sourceYSubsampling <= 0) {
|
|
|
|
throw new IllegalArgumentException("sourceYSubsampling <= 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subsamplingXOffset <= 0 || subsamplingXOffset >= sourceXSubsampling) {
|
|
|
|
throw new IllegalArgumentException("subsamplingXOffset is wrong");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subsamplingYOffset <= 0 || subsamplingYOffset >= sourceYSubsampling) {
|
|
|
|
throw new IllegalArgumentException("subsamplingYOffset is wrong");
|
|
|
|
}
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
// -- does region contain pixels
|
2008-10-21 14:00:00 +00:00
|
|
|
if (sourceRegion != null) {
|
2008-12-18 02:05:43 +00:00
|
|
|
if (sourceRegion.width <= subsamplingXOffset
|
|
|
|
|| sourceRegion.height <= subsamplingYOffset) {
|
2008-10-21 14:00:00 +00:00
|
|
|
throw new IllegalArgumentException("there are no pixels in region");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sourceXSubsampling = sourceXSubsampling;
|
|
|
|
this.sourceYSubsampling = sourceYSubsampling;
|
|
|
|
this.subsamplingXOffset = subsamplingXOffset;
|
|
|
|
this.subsamplingYOffset = subsamplingYOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Gets the source X subsampling - the number of source columns to advance
|
|
|
|
* for each pixel.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
|
|
|
* @return the source X subsampling.
|
|
|
|
*/
|
|
|
|
public int getSourceXSubsampling() {
|
|
|
|
return sourceXSubsampling;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Gets the source Y subsampling - the number of source rows to advance for
|
|
|
|
* each pixel.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
|
|
|
* @return the source Y subsampling.
|
|
|
|
*/
|
|
|
|
public int getSourceYSubsampling() {
|
|
|
|
return sourceYSubsampling;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the horizontal offset of the subsampling grid.
|
|
|
|
*
|
|
|
|
* @return the horizontal offset of the subsampling grid.
|
|
|
|
*/
|
|
|
|
public int getSubsamplingXOffset() {
|
|
|
|
return subsamplingXOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the vertical offset of the subsampling grid.
|
|
|
|
*
|
|
|
|
* @return the vertical offset of the subsampling grid.
|
|
|
|
*/
|
|
|
|
public int getSubsamplingYOffset() {
|
|
|
|
return subsamplingYOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the indices of the source bands.
|
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param sourceBands
|
|
|
|
* the indices of the source bands.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public void setSourceBands(int[] sourceBands) {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the array of source bands.
|
|
|
|
*
|
|
|
|
* @return the array of source bands.
|
|
|
|
*/
|
|
|
|
public int[] getSourceBands() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the specified ImageTypeSpecifier for the destination image.
|
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param destinationType
|
|
|
|
* the ImageTypeSpecifier.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public void setDestinationType(ImageTypeSpecifier destinationType) {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the type of the destination image as an ImageTypeSpecifier. .
|
2008-12-18 02:05:43 +00:00
|
|
|
*
|
2008-10-21 14:00:00 +00:00
|
|
|
* @return the ImageTypeSpecifier.
|
|
|
|
*/
|
|
|
|
public ImageTypeSpecifier getDestinationType() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Sets the offset in the destination image where the decoded pixels are
|
|
|
|
* placed as a result of reading, or specified an area to be written while
|
|
|
|
* writing operation.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param destinationOffset
|
|
|
|
* the destination offset.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public void setDestinationOffset(Point destinationOffset) {
|
|
|
|
if (destinationOffset == null) {
|
|
|
|
throw new IllegalArgumentException("destinationOffset == null!");
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
this.destinationOffset = (Point)destinationOffset.clone();
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the offset in the destination image for placing pixels.
|
|
|
|
*
|
|
|
|
* @return the offset in the destination image.
|
|
|
|
*/
|
|
|
|
public Point getDestinationOffset() {
|
2008-12-18 02:05:43 +00:00
|
|
|
return (Point)destinationOffset.clone();
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Sets the IIOParamController to this IIOParam object for providing
|
|
|
|
* settings to this IIOParam.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @param controller
|
|
|
|
* the new IIOParamController.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public void setController(IIOParamController controller) {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Gets the current IIOParamController controller for this IIOParam.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @return the current IIOParamController controller for this IIOParam.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public IIOParamController getController() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Gets the default IIOParamController controller for this IIOParam.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @return the default IIOParamController controller for this IIOParam, or
|
|
|
|
* null.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public IIOParamController getDefaultController() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-18 02:05:43 +00:00
|
|
|
* Returns true if IIOParamController is installed for this IIOParam.
|
2008-10-21 14:00:00 +00:00
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* @return true, if IIOParamController is installed for this IIOParam, false
|
|
|
|
* otherwise.
|
2008-10-21 14:00:00 +00:00
|
|
|
*/
|
|
|
|
public boolean hasController() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates the controller.
|
|
|
|
*
|
|
|
|
* @return true, if successful, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean activateController() {
|
|
|
|
// TODO implement
|
|
|
|
throw new UnsupportedOperationException("not implemented yet");
|
|
|
|
}
|
|
|
|
}
|