2014-02-19 10:38:30 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2006 Jerry Huxtable
|
|
|
|
*
|
|
|
|
* Licensed 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.
|
|
|
|
*/
|
2014-08-20 00:25:57 +02:00
|
|
|
package org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api;
|
2007-05-02 21:55:59 +02:00
|
|
|
|
2014-08-15 23:16:18 +02:00
|
|
|
import java.awt.Rectangle;
|
2007-05-02 21:55:59 +02:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.ColorModel;
|
|
|
|
import java.awt.image.WritableRaster;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A filter which acts as a superclass for filters which need to have the whole image in memory
|
|
|
|
* to do their stuff.
|
|
|
|
*/
|
|
|
|
public abstract class WholeImageFilter extends AbstractBufferedImageOp {
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2007-05-02 21:55:59 +02:00
|
|
|
* The output image bounds.
|
|
|
|
*/
|
|
|
|
protected Rectangle transformedSpace;
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2007-05-02 21:55:59 +02:00
|
|
|
* The input image bounds.
|
|
|
|
*/
|
2017-02-07 22:02:40 +01:00
|
|
|
protected Rectangle originalSpace;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Construct a WholeImageFilter.
|
|
|
|
*/
|
|
|
|
public WholeImageFilter() {
|
|
|
|
}
|
2007-05-02 21:55:59 +02:00
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2016-11-29 12:01:41 +01:00
|
|
|
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
|
2007-05-02 21:55:59 +02:00
|
|
|
int width = src.getWidth();
|
|
|
|
int height = src.getHeight();
|
2017-02-07 22:02:40 +01:00
|
|
|
int type = src.getType();
|
|
|
|
WritableRaster srcRaster = src.getRaster();
|
2007-05-02 21:55:59 +02:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
originalSpace = new Rectangle(0, 0, width, height);
|
|
|
|
transformedSpace = new Rectangle(0, 0, width, height);
|
|
|
|
transformSpace(transformedSpace);
|
2007-05-02 21:55:59 +02:00
|
|
|
|
2016-11-29 12:01:41 +01:00
|
|
|
if (dst == null) {
|
2007-05-02 21:55:59 +02:00
|
|
|
ColorModel dstCM = src.getColorModel();
|
2017-02-07 22:02:40 +01:00
|
|
|
dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
|
|
|
|
}
|
|
|
|
WritableRaster dstRaster = dst.getRaster();
|
2007-05-02 21:55:59 +02:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
int[] inPixels = getRGB(src, 0, 0, width, height, null);
|
|
|
|
inPixels = filterPixels(width, height, inPixels, transformedSpace);
|
|
|
|
setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);
|
2007-05-02 21:55:59 +02:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2007-05-02 21:55:59 +02:00
|
|
|
* Calculate output bounds for given input bounds.
|
|
|
|
* @param rect input and output rectangle
|
|
|
|
*/
|
2017-02-07 22:02:40 +01:00
|
|
|
protected void transformSpace(Rectangle rect) {
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2007-05-02 21:55:59 +02:00
|
|
|
* Actually filter the pixels.
|
|
|
|
* @param width the image width
|
|
|
|
* @param height the image height
|
|
|
|
* @param inPixels the image pixels
|
|
|
|
* @param transformedSpace the output bounds
|
|
|
|
* @return the output pixels
|
|
|
|
*/
|
2017-02-07 22:02:40 +01:00
|
|
|
protected abstract int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace);
|
2007-05-02 21:55:59 +02:00
|
|
|
}
|
|
|
|
|