/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* EffectUtils
*
* @author Created by Jasper Potts (Jun 18, 2007)
*/
class EffectUtils {
/**
* Clear a transparent image to 100% transparent
*
* @param img The image to clear
*/
}
// =================================================================================================================
// Blur
/**
* Apply Gaussian Blur to Image
*
* @param src The image tp
* @param dst The destination image to draw blured src image into, null if you want a new one created
* @param radius The blur kernel radius
* @return The blured image
*/
if (dst == null || dst.getWidth() != width || dst.getHeight() != height || src.getType() != dst.getType()) {
}
// horizontal pass
// vertical pass
//noinspection SuspiciousNameCombination
// the result is now stored in srcPixels due to the 2nd pass
// horizontal pass
// vertical pass
//noinspection SuspiciousNameCombination
// the result is now stored in srcPixels due to the 2nd pass
} else {
throw new IllegalArgumentException("EffectUtils.gaussianBlur() src image is not a supported type, type=[" +
}
return dst;
}
/**
* <p>Blurs the source pixels into the destination pixels. The force of the blur is specified by the radius which
* must be greater than 0.</p> <p>The source and destination pixels arrays are expected to be in the INT_ARGB
* format.</p> <p>After this method is executed, dstPixels contains a transposed and filtered copy of
* srcPixels.</p>
*
* @param srcPixels the source pixels
* @param dstPixels the destination pixels
* @param width the width of the source picture
* @param height the height of the source picture
* @param kernel the kernel of the blur effect
* @param radius the radius of the blur effect
*/
float a;
float r;
float g;
float b;
int ca;
int cr;
int cg;
int cb;
for (int y = 0; y < height; y++) {
int index = y;
for (int x = 0; x < width; x++) {
a = r = g = b = 0.0f;
int subOffset = x + i;
}
}
ca = (int) (a + 0.5f);
cr = (int) (r + 0.5f);
cg = (int) (g + 0.5f);
cb = (int) (b + 0.5f);
}
}
}
/**
* <p>Blurs the source pixels into the destination pixels. The force of the blur is specified by the radius which
* must be greater than 0.</p> <p>The source and destination pixels arrays are expected to be in the BYTE_GREY
* format.</p> <p>After this method is executed, dstPixels contains a transposed and filtered copy of
* srcPixels.</p>
*
* @param srcPixels the source pixels
* @param dstPixels the destination pixels
* @param width the width of the source picture
* @param height the height of the source picture
* @param kernel the kernel of the blur effect
* @param radius the radius of the blur effect
*/
float p;
int cp;
for (int y = 0; y < height; y++) {
int index = y;
for (int x = 0; x < width; x++) {
p = 0.0f;
int subOffset = x + i;
// if (subOffset < 0) subOffset = 0;
// if (subOffset >= width) subOffset = width-1;
}
p += blurFactor * pixel;
}
cp = (int) (p + 0.5f);
}
}
}
if (radius < 1) {
throw new IllegalArgumentException("Radius must be >= 1");
}
float total = 0.0f;
float distance = i * i;
}
}
return data;
}
// =================================================================================================================
/**
* <p>Returns an array of pixels, stored as integers, from a <code>BufferedImage</code>. The pixels are grabbed from
* a rectangular area defined by a location and two dimensions. Calling this method on an image of type different
* from <code>BufferedImage.TYPE_INT_ARGB</code> and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the
* image.</p>
*
* @param img the source image
* @param x the x location at which to start grabbing pixels
* @param y the y location at which to start grabbing pixels
* @param w the width of the rectangle of pixels to grab
* @param h the height of the rectangle of pixels to grab
* @param pixels a pre-allocated array of pixels of size w*h; can be null
* @return <code>pixels</code> if non-null, a new array of integers otherwise
* @throws IllegalArgumentException is <code>pixels</code> is non-null and of length < w*h
*/
int x, int y, int w, int h, byte[] pixels) {
if (w == 0 || h == 0) {
return new byte[0];
}
pixels = new byte[w * h];
throw new IllegalArgumentException("pixels array must have a length >= w*h");
}
} else {
throw new IllegalArgumentException("Only type BYTE_GRAY is supported");
}
}
/**
* <p>Writes a rectangular area of pixels in the destination <code>BufferedImage</code>. Calling this method on an
* image of type different from <code>BufferedImage.TYPE_INT_ARGB</code> and <code>BufferedImage.TYPE_INT_RGB</code>
* will unmanage the image.</p>
*
* @param img the destination image
* @param x the x location at which to start storing pixels
* @param y the y location at which to start storing pixels
* @param w the width of the rectangle of pixels to store
* @param h the height of the rectangle of pixels to store
* @param pixels an array of pixels, stored as integers
* @throws IllegalArgumentException is <code>pixels</code> is non-null and of length < w*h
*/
int x, int y, int w, int h, byte[] pixels) {
return;
throw new IllegalArgumentException("pixels array must have a length >= w*h");
}
} else {
throw new IllegalArgumentException("Only type BYTE_GRAY is supported");
}
}
/**
* <p>Returns an array of pixels, stored as integers, from a
* <code>BufferedImage</code>. The pixels are grabbed from a rectangular
* area defined by a location and two dimensions. Calling this method on
* an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
* and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
*
* @param img the source image
* @param x the x location at which to start grabbing pixels
* @param y the y location at which to start grabbing pixels
* @param w the width of the rectangle of pixels to grab
* @param h the height of the rectangle of pixels to grab
* @param pixels a pre-allocated array of pixels of size w*h; can be null
* @return <code>pixels</code> if non-null, a new array of integers
* otherwise
* @throws IllegalArgumentException is <code>pixels</code> is non-null and
* of length < w*h
*/
int x, int y, int w, int h, int[] pixels) {
if (w == 0 || h == 0) {
return new int[0];
}
pixels = new int[w * h];
throw new IllegalArgumentException("pixels array must have a length" +
" >= w*h");
}
}
// Unmanages the image
}
/**
* <p>Writes a rectangular area of pixels in the destination
* <code>BufferedImage</code>. Calling this method on
* an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
* and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
*
* @param img the destination image
* @param x the x location at which to start storing pixels
* @param y the y location at which to start storing pixels
* @param w the width of the rectangle of pixels to store
* @param h the height of the rectangle of pixels to store
* @param pixels an array of pixels, stored as integers
* @throws IllegalArgumentException is <code>pixels</code> is non-null and
* of length < w*h
*/
int x, int y, int w, int h, int[] pixels) {
return;
throw new IllegalArgumentException("pixels array must have a length" +
" >= w*h");
}
} else {
// Unmanages the image
}
}
/**
* <p>Returns a new <code>BufferedImage</code> using the same color model
* as the image passed as a parameter. The returned image is only compatible
* with the image passed as a parameter. This does not mean the returned
* image is compatible with the hardware.</p>
*
* @param image the reference image from which the color model of the new
* image is obtained
* @return a new <code>BufferedImage</code>, compatible with the color model
* of <code>image</code>
*/
return new BufferedImage(cm,
}
/**
* <p>Returns a new translucent compatible image of the specified width and
* height. That is, the returned <code>BufferedImage</code> is compatible with
* the graphics hardware. If the method is called in a headless
* environment, then the returned BufferedImage will be compatible with
* the source image.</p>
*
* @param width the width of the new image
* @param height the height of the new image
* @return a new translucent compatible <code>BufferedImage</code> of the
* specified width and height
*/
int height) {
return isHeadless() ?
}
private static boolean isHeadless() {
return GraphicsEnvironment.isHeadless();
}
// Returns the graphics configuration for the primary screen
}
}