1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/**
*
*/
package cinemascope;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import millie.plugins.GenericPluginFilter;
import millie.plugins.parameters.CheckBoxParameter;
import millie.plugins.parameters.ComboBoxEntry;
import millie.plugins.parameters.ComboBoxParameter;
import millie.plugins.parameters.IntSliderParameter;
/**
* @author millie
*
*/
public class CinemascopePlugin extends GenericPluginFilter {
public CinemascopePlugin() {
setPluginName("Cinemascope");
setLongProcessing(true);
setRefreshable(true);
setCacheable(false);
ComboBoxParameter type = new ComboBoxParameter("type", "Crop type");
type.setItems(new ComboBoxEntry[] {new ComboBoxEntry("cinemascope", "Cinemascope (2.39/1)"),
new ComboBoxEntry("16/9", "16/9"), new ComboBoxEntry("panoramique", "Panoramique (3/1)")});
addParameter(type);
addParameter(new IntSliderParameter("position", "Position", 0,100,0));
addParameter(new CheckBoxParameter("blackBorder", "Add Black Border", false));
}
@Override
public BufferedImage filter() throws Exception {
float position = (float) getIntValue("position");
String type = getStringValue("type");
boolean black = getBooleanValue("blackBorder");
BufferedImage input = getInputImage();
float cropFactor = 0;
if(type.equals("cinemascope")) {
cropFactor = 2.39f;
}
else if(type.equals("panoramique")) {
cropFactor = 3f;
}
else {
cropFactor = 16.f/9.f;
}
int newHeight = (int) (((float) input.getWidth()) / cropFactor);
int newWidth = input.getWidth();
int startY = (int) (((float) (input.getHeight()-newHeight)* position)/100.f );
int endY = startY + newHeight;
if(!black) {
BufferedImage output = new BufferedImage(newWidth, newHeight, input.getType());
Graphics2D g = output.createGraphics();
g.drawImage(input, 0, 0, newWidth, newHeight, 0, startY, newWidth, endY, null);
g.dispose();
return output;
}
else {
BufferedImage output = new BufferedImage(input.getWidth(), input.getHeight(), input.getType());
int outputStart = (int) ((float) (output.getHeight() - newHeight) /2.f);
Graphics2D g = output.createGraphics();
g.drawImage(input, 0, outputStart, input.getWidth(), outputStart+newHeight, 0, startY, newWidth, endY, null);
g.dispose();
return output;
}
}
} |
Partager