if(a>5 || b>5 || c>5 || d>5)
return;
//Create the affine operation.
//ColorSpaces.hints causes single lines to vanish);
AffineTransformOp invert;
if(w>1 && h>1){
//fix image inversion if matrix (0,x,-y,0)
if(CTM[0][0]==0 && CTM[1][1]==0 && CTM[0][1]>0 && CTM[1][0]<0){
image_at.scale(-1,1);
image_at.translate(-current_image.getWidth(),0);
}
invert = new AffineTransformOp(image_at, ColorSpaces.hints);
}else{
//allow for line with changing values
boolean isSolid=true;
if(h==1){
//test all pixels set so we can keep a solid line
Raster ras=current_image.getRaster();
int bands=ras.getNumBands();
int width=ras.getWidth();
int[] elements=new int[(width*bands)+1];
ras.getPixels(0,0,width,1, elements);
for(int j=0;j<bands;j++){
int first=elements[0];
for(int i=1;i<width;i++){
if(elements[i*j]!=first){
isSolid=false;
i=width;
j=bands;
}
}
}
}
if(isSolid)
invert = new AffineTransformOp(image_at, null);
else
invert = new AffineTransformOp(image_at, ColorSpaces.hints);
}
//ShowGUIMessage.showGUIMessage("x",current_image,"x");
//if there is a rotation make image ARGB so we can clip
if (CTM[1][0] != 0 || CTM[0][1] != 0)
current_image = ColorSpaceConvertor.convertToARGB(current_image);
//scale image to produce final version
if(scaleImage){
/**if not sheer/rotate, then bicubic*/
if (true || CTM[1][0] != 0 || CTM[0][1] != 0){
if(h>1){
boolean imageProcessed=false;
//do not use
/**if(1==2 && ( h>32 && w>32 && JAIHelper.isJAIused() && (CTM[0][0]!=0 && CTM[1][1]!=-0))){ //don't use if small or rotation included
imageProcessed=true;
float iw=CTM[0][0];
if(iw==0)
iw=(int)CTM[0][1];
float ih=CTM[1][1];
if(ih==0)
ih=(int)CTM[1][0];
if(iw<0)
iw=-iw;
if(ih<0)
ih=-ih;
float xScale = iw/w;
float yScale = ih/h;
if(xScale==1.0 && yScale==1.0){
}else{
long start=System.currentTimeMillis();
java.awt.image.renderable.ParameterBlock pb = new java.awt.image.renderable.ParameterBlock();
pb.addSource(current_image); // The source image
pb.add(xScale); // The xScale
pb.add(yScale); // The yScale
pb.add(0.0F); // The x translation
pb.add(0.0F); // The y translation
pb.add(new javax.media.jai.InterpolationNearest()); // The interpolation
try{
current_image = (javax.media.jai.JAI.create("scale", pb, null)).getAsBufferedImage();
//if(timeChange==true)
// System.out.println("jai="+(System.currentTimeMillis()-start));
}catch(Exception ee){
imageProcessed=false;
}catch(Error err){
imageProcessed=false;
}
}
if(!imageProcessed) {
//System.err.println("Unable to use JAI for image");
LogWriter.writeLog("Unable to use JAI for image");
}
} /**/
if(!imageProcessed){
//long start=System.currentTimeMillis();
boolean failed=false;
//allow for odd behaviour on some files
try{
current_image = invert.filter(current_image,null);
}catch(Exception e){
failed=true;
}
if(failed){
try{
invert = new AffineTransformOp(image_at,null);
current_image = invert.filter(current_image,null);
}catch(Exception e){
}
}
//if(timeChange==true)
// System.out.println("non-jai="+(System.currentTimeMillis()-start));
}
}
}else{
int dx=1,dy=1;
/**workout size and if needs to be inverted*/
w=(int)CTM[0][0];
if(w==0)
w=(int)CTM[0][1];
h=(int)CTM[1][1];
if(h==0)
h=(int)CTM[1][0];
if(w<0){
w=-w;
dx=-1;
}
if(h<0){
h=-h;
dy=-1;
}
/**turn around if needed*/
if(dx==-1 || dy==-1){
image_at =new AffineTransform();
image_at.scale(dx,dy);
if(dx==-1)
image_at.translate(-current_image.getWidth(),0);
if(dy==-1)
image_at.translate(0,-current_image.getHeight());
//Create the affine operation.
invert = new AffineTransformOp(image_at, ColorSpaces.hints);
current_image = invert.filter(current_image,null);
}
Image scaledImage= current_image.getScaledInstance(w,h,BufferedImage.SCALE_SMOOTH);