@ -61,6 +61,7 @@ public class ymageMatrix {
public static final byte FILTER_ANTIALIASING = 0 ;
public static final byte FILTER_ANTIALIASING = 0 ;
public static final byte FILTER_BLUR = 1 ;
public static final byte FILTER_BLUR = 1 ;
public static final byte FILTER_INVERT = 2 ;
protected int width , height ;
protected int width , height ;
private BufferedImage image ;
private BufferedImage image ;
@ -391,7 +392,46 @@ public class ymageMatrix {
* /
* /
public void insertBitmap ( BufferedImage bitmap , int x , int y , int transRGB , byte filter ) {
public void insertBitmap ( BufferedImage bitmap , int x , int y , int transRGB , byte filter ) {
insertBitmap ( bitmap , x , y , transRGB ) ;
insertBitmap ( bitmap , x , y , transRGB ) ;
filter ( x - 1 , y - 1 , x + bitmap . getWidth ( ) , y + bitmap . getHeight ( ) , filter , image . getRGB ( x , y ) ) ;
int bitmapWidth = bitmap . getWidth ( ) ;
int bitmapHeight = bitmap . getHeight ( ) ;
if ( filter = = FILTER_ANTIALIASING ) {
int transX = - 1 ;
int transY = - 1 ;
int imageWidth = image . getWidth ( ) ;
int imageHeight = image . getHeight ( ) ;
// find first pixel in bitmap that equals transRGB
// and also lies in area of image that will be covered by bitmap
int i = 0 ;
int j = 0 ;
boolean found = false ;
while ( ( i < bitmapWidth ) & & ( i + x < imageWidth ) & & ! found ) {
while ( ( j < bitmapHeight ) & & ( j + y < imageHeight ) & & ! found ) {
if ( bitmap . getRGB ( i , j ) = = transRGB ) {
transX = i ;
transY = j ;
}
j + + ;
}
i + + ;
}
// if there is a transparent pixel in the bitmap that covers an area
// of the image, the fiter will be used. If no such pixel has been found that
// means that there either is no transparent pixel in the bitmap or part
// of the bitmap that covers part of tha image is not within the borders of
// the image (i.e. bitmap is larger than image)
if ( transX ! = - 1 ) {
filter ( x - 1 , y - 1 , x + bitmapWidth , y + bitmapHeight , filter , image . getRGB ( transX + x , transY + y ) ) ;
}
} else {
filter ( x - 1 , y - 1 , x + bitmapWidth , y + bitmapHeight , filter , - 1 ) ;
}
}
}
/ * *
/ * *
@ -419,6 +459,18 @@ public class ymageMatrix {
filter ( lox , loy , rux , ruy , FILTER_BLUR , - 1 ) ;
filter ( lox , loy , rux , ruy , FILTER_BLUR , - 1 ) ;
}
}
/ * *
* invert filter for a square part of the ymageMatrix
* @param lox x value for left upper coordinate
* @param loy y value for left upper coordinate
* @param rux x value for right lower coordinate
* @param ruy y value for right lower coordinate
* @author Marc Nause
* /
public void invert ( int lox , int loy , int rux , int ruy ) {
filter ( lox , loy , rux , ruy , FILTER_INVERT , - 1 ) ;
}
/ * *
/ * *
* filter for a square part of the ymageMatrix
* filter for a square part of the ymageMatrix
* @param lox x value for left upper coordinate
* @param lox x value for left upper coordinate
@ -438,7 +490,7 @@ public class ymageMatrix {
if ( lox > width ) { lox = width - 1 ; }
if ( lox > width ) { lox = width - 1 ; }
if ( loy > height ) { loy = height - 1 ; }
if ( loy > height ) { loy = height - 1 ; }
if ( rux > width ) { rux = width - 1 ; }
if ( rux > width ) { rux = width - 1 ; }
if ( ruy > height ) { ruy = width - 1 ; }
if ( ruy > height ) { ruy = height - 1 ; }
if ( lox > rux ) {
if ( lox > rux ) {
int tmp = lox ;
int tmp = lox ;
lox = rux ;
lox = rux ;
@ -468,77 +520,80 @@ public class ymageMatrix {
rgbG = 0 ;
rgbG = 0 ;
rgbB = 0 ;
rgbB = 0 ;
if ( filter = = FILTER_ANTIALIASING | | filter = = FILTER_BLUR ) {
// taking samples from neighbours of pixel
// taking samples from neighbours of pixel
if ( i > lox ) {
if ( i > lox ) {
rgb = image . getRGB ( i - 1 , j ) ;
rgb = image . getRGB ( i - 1 , j ) ;
if ( rgb = = bgcolor ) {
if ( rgb = = bgcolor ) {
border = true ;
border = true ;
}
}
rgbR + = rgb > > 16 & 0xff ;
rgbR + = rgb > > 16 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbB + = rgb & 0xff ;
rgbB + = rgb & 0xff ;
numberOfNeighbours + + ;
numberOfNeighbours + + ;
}
}
if ( j > loy ) {
if ( j > loy ) {
rgb = image . getRGB ( i , j - 1 ) ;
rgb = image . getRGB ( i , j - 1 ) ;
if ( rgb = = bgcolor ) {
if ( rgb = = bgcolor ) {
border = true ;
border = true ;
}
}
rgbR + = rgb > > 16 & 0xff ;
rgbR + = rgb > > 16 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbB + = rgb & 0xff ;
rgbB + = rgb & 0xff ;
numberOfNeighbours + + ;
numberOfNeighbours + + ;
}
}
if ( i < width - 1 ) {
if ( i < width - 1 ) {
rgb = image . getRGB ( i + 1 , j ) ;
rgb = image . getRGB ( i + 1 , j ) ;
if ( rgb = = bgcolor ) {
if ( rgb = = bgcolor ) {
border = true ;
border = true ;
}
}
rgbR + = rgb > > 16 & 0xff ;
rgbR + = rgb > > 16 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbB + = rgb & 0xff ;
rgbB + = rgb & 0xff ;
numberOfNeighbours + + ;
numberOfNeighbours + + ;
}
}
if ( i < height - 1 ) {
if ( i < height - 1 ) {
rgb = image . getRGB ( i , j + 1 ) ;
rgb = image . getRGB ( i , j + 1 ) ;
if ( rgb = = bgcolor ) {
if ( rgb = = bgcolor ) {
border = true ;
border = true ;
}
}
rgbR + = rgb > > 16 & 0xff ;
rgbR + = rgb > > 16 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbG + = rgb > > 8 & 0xff ;
rgbB + = rgb & 0xff ;
rgbB + = rgb & 0xff ;
numberOfNeighbours + + ;
numberOfNeighbours + + ;
}
}
}
rgb = image . getRGB ( i , j ) ;
rgb = image . getRGB ( i , j ) ;
// put more weight on pixle than on neighbours
// add value of pixel
if ( filter = = FILTER_ANTIALIASING & & border ) {
// in case filter is used for antialiasing this will only be done if
// rgbR += (rgb >> 16 & 0xff) * numberOfNeighbours;
// the pixel is on the edge to the background color
// rgbG += (rgb >> 8 & 0xff) * numberOfNeighbours;
if ( ( filter = = FILTER_ANTIALIASING & & border ) | | ( filter = = FILTER_BLUR ) ) {
// rgbB += (rgb & 0xff) * numberOfNeighbours;
// numberOfNeighbours += numberOfNeighbours;
rgbR + = ( rgb > > 16 & 0xff ) ;
rgbR + = ( rgb > > 16 & 0xff ) ;
rgbG + = ( rgb > > 8 & 0xff ) ;
rgbG + = ( rgb > > 8 & 0xff ) ;
rgbB + = ( rgb & 0xff ) ;
rgbB + = ( rgb & 0xff ) ;
numberOfNeighbours + + ;
numberOfNeighbours + + ;
border = false ;
border = false ;
}
}
// set to value of pixel => keep value
else if ( filter = = FILTER_ANTIALIASING ) {
else if ( filter = = FILTER_ANTIALIASING ) {
rgbR = ( rgb > > 16 & 0xff ) ;
rgbR = ( rgb > > 16 & 0xff ) ;
rgbG = ( rgb > > 8 & 0xff ) ;
rgbG = ( rgb > > 8 & 0xff ) ;
rgbB = ( rgb & 0xff ) ;
rgbB = ( rgb & 0xff ) ;
numberOfNeighbours = 1 ;
numberOfNeighbours = 1 ;
}
}
// put same weight in neighbours as on pixel
// set value of pixel to inverted value (using XOR)
else if ( filter = = FILTER_BLUR ) {
else if ( filter = = FILTER_INVERT ) {
rgbR + = ( rgb > > 16 & 0xff ) ;
rgb = rgb ^ 0xffffff ;
rgbG + = ( rgb > > 8 & 0xff ) ;
rgbR = ( rgb > > 16 & 0xff ) ;
rgbB + = ( rgb & 0xff ) ;
rgbG = ( rgb > > 8 & 0xff ) ;
numberOfNeighbours + + ;
rgbB = ( rgb & 0xff ) ;
numberOfNeighbours = 1 ;
}
}
// calculatin c the average
// calculatin g the average
rgbR = ( int ) ( rgbR / numberOfNeighbours ) ;
rgbR = ( int ) ( rgbR / numberOfNeighbours ) ;
rgbG = ( int ) ( rgbG / numberOfNeighbours ) ;
rgbG = ( int ) ( rgbG / numberOfNeighbours ) ;
rgbB = ( int ) ( rgbB / numberOfNeighbours ) ;
rgbB = ( int ) ( rgbB / numberOfNeighbours ) ;