40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
package io.swtc.proccessing;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
public class ImageEffectEngine {
|
|
|
|
private static final ColorProccessor colorProcessor = new ColorProccessor();
|
|
private static final DenoiseProccessor denoiseProcessor = new DenoiseProccessor();
|
|
private static final SharpnessProccessor sharpnessProcessor = new SharpnessProccessor();
|
|
|
|
public static BufferedImage applyEffects(BufferedImage img, EffectState state, float[] currentGains) {
|
|
if (img == null) return null;
|
|
|
|
// 1. Extract raw data (High Performance)
|
|
int width = img.getWidth();
|
|
int height = img.getHeight();
|
|
int[] pixels = ImageUtils.getPixels(img);
|
|
|
|
// NOTE: If we want to avoid modifying the original image's backing array,
|
|
// we should clone 'pixels' here. If in-place modification is okay, we proceed.
|
|
// int[] workingPixels = pixels.clone();
|
|
int[] workingPixels = pixels; // Assuming in-place is fine for performance
|
|
|
|
// 2. Apply Color Pipeline (In-Place)
|
|
colorProcessor.process(workingPixels, state, currentGains);
|
|
|
|
// 3. Apply Sharpness (Returns new array if applied)
|
|
if (state.sharpness() != 100 || state.edgeEnhance()) {
|
|
workingPixels = sharpnessProcessor.process(workingPixels, width, height, state.sharpness(), state.edgeEnhance());
|
|
}
|
|
|
|
// 4. Apply Denoise (Returns new array if applied)
|
|
if (state.dnrEnabled()) {
|
|
workingPixels = denoiseProcessor.process(workingPixels, width, height, state.dnrSpatial());
|
|
}
|
|
|
|
// 5. Reconstruct Image
|
|
return ImageUtils.createFromPixels(workingPixels, width, height);
|
|
}
|
|
} |