use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class WaveTransformer method waveY_damp.
private void waveY_damp(SimpleImage pImg) {
double damping = this.damping;
double cx = this.centreX - 0.5;
double cy = this.centreY - 0.5;
double zoom = 1.0 / this.zoom;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
double PI2 = 2.0 * Math.PI;
double shift = this.shift;
double wavelength = this.wavelength * this.zoom;
double amplitude = 0.0 - this.amplitude * this.zoom;
double phase = this.phase;
double amp = amplitude;
double t = this.frames != 0 ? (double) this.frame / (double) this.frames : 0.0;
shift = 2.0 * shift / (double) (width - 1);
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
Pixel pPixel = new Pixel();
for (int pY = 0; pY < height; pY++) {
for (int pX = 0; pX < width; pX++) {
pPixel.setARGBValue(pImg.getARGBValue(pX, pY));
double x0 = (double) pX - cx;
double y0 = (double) pY - cy;
double sangle = shift * pX;
double dl = (y0 - sangle) / wavelength;
double dl2 = dl - sangle;
if (dl2 < 0)
dl2 = 0.0 - dl2;
amp = amplitude * Math.exp(dl2 * damping);
double zz = amp * Math.sin((PI2 * (t - dl)) + phase);
x0 += zz;
double x = x0 * zoom + cx;
double y = y0 * zoom + cy;
/* color-wrapping */
if (this.wrap) {
while (x >= ((double) width - 0.5)) x -= (double) (width - 1);
while ((int) x < 0.5) x += (double) (width - 1);
while (y >= ((double) height - 0.5)) y -= (double) (height - 1);
while ((int) y < 0.5) y += (double) (height - 1);
}
/* render it */
double xi = Tools.fmod33(x);
double yi = Tools.fmod33(y);
if ((x < 0.0) || (x > w1) || (y < 0.0) || (y > h1)) {
pPixel.r = pPixel.g = pPixel.b = 0;
} else {
readSrcPixels(x, y);
pPixel.r = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
pPixel.g = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
pPixel.b = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
}
pImg.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method calculateDiffCoverage.
public static double calculateDiffCoverage(SimpleImage pImg, SimpleImage pSimplifiedRefImg) {
SimpleImage img = createSimplifiedRefImage(pImg);
long maxCoverage = img.getImageWidth() * img.getImageHeight();
long coverage = 0;
Pixel pixel = new Pixel();
Pixel refPixel = new Pixel();
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
refPixel.setARGBValue(pSimplifiedRefImg.getARGBValue(l, k));
if (fabs(pixel.r - refPixel.r) > 29.0 || fabs(pixel.g - refPixel.g) > 15.0 || fabs(pixel.b - refPixel.b) > 78.0) {
coverage++;
}
}
}
// System.out.println((double) coverage / (double) maxCoverage);
return (double) coverage / (double) maxCoverage;
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method calculateCoverage.
public static double calculateCoverage(SimpleImage pImg, int bgRed, int bgGreen, int bgBlue, boolean useFilter) {
SimpleImage img;
if (useFilter) {
SimpleImage filteredImg = new SimpleImage(pImg.getBufferedImg(), pImg.getImageWidth(), pImg.getImageHeight());
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(filteredImg);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.transformImage(filteredImg);
img = filteredImg;
} else {
img = pImg;
}
long maxCoverage = img.getImageWidth() * img.getImageHeight();
long coverage = 0;
Pixel pixel = new Pixel();
if (bgRed == 0 && bgGreen == 0 && bgBlue == 0) {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (pixel.r > 29 || pixel.g > 15 || pixel.b > 78) {
coverage++;
}
}
}
} else {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (Math.abs(pixel.r - bgRed) > 29.0 && Math.abs(pixel.g - bgGreen) > 15.0 && Math.abs(pixel.b - bgBlue) > 78.0) {
coverage++;
}
}
}
}
return (double) coverage / (double) maxCoverage;
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class SVGWFFunc method getPoints.
@SuppressWarnings("unchecked")
private List<Point> getPoints() {
if (_points == null) {
String key = makeRessourceKey();
_points = (List<Point>) RessourceManager.getRessource(key);
if (_points == null) {
try {
SVGUniverse svgUniverse = new SVGUniverse();
StringReader reader = new StringReader(svg);
SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(reader, "svgImage"));
int imgWidth = Tools.FTOI(diagram.getWidth() * resolution_multiplier);
int imgHeight = Tools.FTOI(diagram.getHeight() * resolution_multiplier);
// SVGRoot root = diagram.getRoot();
// root.setAttribute("width", AnimationElement.AT_XML, Integer.toString(imgWidth));
// root.setAttribute("height", AnimationElement.AT_XML, Integer.toString(imgHeight));
// root.build();
SimpleImage imgMap = new SimpleImage(imgWidth, imgHeight);
Graphics2D g = imgMap.getBufferedImg().createGraphics();
g.scale(resolution_multiplier, resolution_multiplier);
if (pre_antialias != 0) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
}
diagram.render(g);
Pixel pixel = new Pixel();
_points = new ArrayList<Point>();
int xMin = imgMap.getImageWidth() - 1, xMax = 0;
int yMin = imgMap.getImageHeight() - 1, yMax = 0;
for (int i = 0; i < imgMap.getImageHeight(); i++) {
for (int j = 0; j < imgMap.getImageWidth(); j++) {
int argb = imgMap.getARGBValue(j, i);
if (argb != 0) {
if (j < xMin) {
xMin = j;
} else if (j > xMax) {
xMax = j;
}
if (i < yMin) {
yMin = i;
} else if (i > yMax) {
yMax = i;
}
}
}
}
int xSize = xMax - xMin;
int ySize = yMax - yMin;
int maxSize = xSize > ySize ? xSize : ySize;
if (maxSize > 0) {
for (int i = 0; i < imgMap.getImageHeight(); i++) {
for (int j = 0; j < imgMap.getImageWidth(); j++) {
int argb = imgMap.getARGBValue(j, i);
if (argb != 0) {
double x = ((j - xMin) - xSize / 2.0) / (double) maxSize;
double y = ((i - yMin) - ySize / 2.0) / (double) maxSize;
pixel.setARGBValue(argb);
_points.add(new Point(x, y, pixel.r, pixel.g, pixel.b));
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
_points = new ArrayList<Point>();
}
RessourceManager.putRessource(key, _points);
}
}
return _points;
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ImageWriter method savePalette.
public void savePalette(SimpleImage pImg, String pFilename) throws Exception {
int width = pImg.getImageWidth();
StringBuilder sb = new StringBuilder();
String name = "JWildfire";
sb.append(name + " {\n");
sb.append("gradient:\n");
sb.append(" title=\"" + name + "\" smooth=no\n");
Pixel p = new Pixel();
int lastColor = -1;
for (int i = 0; i < width; i++) {
// swap R and B
p.r = pImg.getBValue(i, 0);
p.g = pImg.getGValue(i, 0);
p.b = pImg.getRValue(i, 0);
p.a = 0;
int color = p.getARGBValue();
if (color != lastColor) {
sb.append(" index=" + i + " color=" + color + "\n");
lastColor = color;
}
}
sb.append("}\n");
Writer out = new OutputStreamWriter(new FileOutputStream(pFilename), Tools.FILE_ENCODING);
try {
out.write(sb.toString());
} finally {
out.close();
}
}
Aggregations