use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class CloudCreator method fillImage.
@Override
protected void fillImage(SimpleImage res) {
int width = res.getImageWidth();
int height = res.getImageHeight();
Random rnd = new Random();
rnd.setSeed(this.seed);
double cover = 1.0 - this.cover;
double aspect = (double) width / (double) height;
int frequency = this.initialFrequency;
int frequencyX = (int) (frequency * aspect + 0.5);
int frequencyY = (int) (frequency * aspect + 0.5);
double alphaInt = 1.0f;
BufferedImage mainImage = res.getBufferedImg();
Graphics2D mainGr = mainImage.createGraphics();
for (int i = 0; i < this.octaves; i++) {
// create a small random image
BufferedImage rndMap = new BufferedImage(frequencyX, frequencyY, BufferedImage.TYPE_INT_ARGB);
{
Graphics2D g = rndMap.createGraphics();
try {
switch(colorMode) {
case COLOR:
for (int x = 0; x < frequencyX; x++) {
for (int y = 0; y < frequencyY; y++) {
int rVal = rnd.nextInt(255);
int gVal = rnd.nextInt(255);
int bVal = rnd.nextInt(255);
g.setColor(new Color(rVal, gVal, bVal, (int) (255.0 * alphaInt + 0.5)));
g.fillRect(x, y, 1, 1);
}
}
break;
case GREY:
for (int x = 0; x < frequencyX; x++) {
for (int y = 0; y < frequencyY; y++) {
int val = rnd.nextInt(255);
g.setColor(new Color(val, val, val, (int) (255.0 * alphaInt + 0.5)));
g.fillRect(x, y, 1, 1);
}
}
break;
case BASE_COLOR:
int rBase = this.cloudColor.getRed();
int gBase = this.cloudColor.getGreen();
int bBase = this.cloudColor.getBlue();
for (int x = 0; x < frequencyX; x++) {
for (int y = 0; y < frequencyY; y++) {
int val = rnd.nextInt(255);
int rVal = (rBase * val) / 255;
int gVal = (gBase * val) / 255;
int bVal = (bBase * val) / 255;
g.setColor(new Color(rVal, gVal, bVal, (int) (255.0 * alphaInt + 0.5)));
g.fillRect(x, y, 1, 1);
}
}
break;
}
} finally {
g.dispose();
}
}
// scale up the image using Java-built-in interpolation
{
BufferedImage scaledRndMap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = scaledRndMap.createGraphics();
try {
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.drawImage(rndMap, 0, 0, width, height, 0, 0, frequencyX, frequencyY, null);
} finally {
g.dispose();
}
mainGr.drawImage(scaledRndMap, null, 0, 0);
}
alphaInt *= this.persistence;
frequency += frequency;
frequencyX = (int) (frequency * aspect + 0.5);
frequencyY = (int) (frequency * aspect + 0.5);
}
// apply an exponential filter to let the noise more look like clouds
if (mode == Mode.CLOUDS) {
final double rWeight = 0.2990;
final double gWeight = 0.5880;
final double bWeight = 0.1130;
SimpleImage bgImg = (this.backgroundImg != null) ? backgroundImg.getImage() : null;
Pixel pixel = new Pixel();
Pixel bgPixel = new Pixel();
for (int i = 0; i < mainImage.getWidth(); i++) {
for (int j = 0; j < mainImage.getHeight(); j++) {
pixel.setARGBValue(res.getARGBValue(i, j));
double lum = pixel.r * rWeight + pixel.g * gWeight + pixel.b * bWeight;
double c = lum - (cover * 255);
if (c < 0)
c = 0;
int iVal = Tools.roundColor(255.0 - (Math.pow(this.sharpness, c) * 255.0));
int bgRed = 0, bgGreen = 0, bgBlue = 0;
switch(bgMode) {
case IMAGE:
if (bgImg != null) {
bgPixel.setARGBValue(bgImg.getARGBValueIgnoreBounds(i, j));
bgRed = bgPixel.r;
bgGreen = bgPixel.g;
bgBlue = bgPixel.b;
}
break;
case COLOR:
bgRed = this.bgColor.getRed();
bgGreen = this.bgColor.getGreen();
bgBlue = this.bgColor.getBlue();
break;
}
switch(colorMode) {
case GREY:
pixel.r = expose(iVal + 1.5 * bgRed);
pixel.g = expose(iVal + 1.5 * bgGreen);
pixel.b = expose(iVal + 1.5 * bgBlue);
break;
default:
pixel.r = expose((iVal * pixel.r) / 255 + 1.5 * bgRed);
pixel.g = expose((iVal * pixel.g) / 255 + 1.5 * bgGreen);
pixel.b = expose((iVal * pixel.b) / 255 + 1.5 * bgBlue);
break;
}
res.setRGB(i, j, pixel);
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class ImageCreator method createImage.
public SimpleImage createImage(int pWidth, int pHeight) {
long t0 = initTime();
BufferedImage bufferedImg = new BufferedImage(pWidth, pHeight, BufferedImage.TYPE_INT_RGB);
SimpleImage res = new SimpleImage(bufferedImg, pWidth, pHeight);
fillImage(res);
showElapsedTime(t0);
return res;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class TileBrickCreator method fillImage.
@Override
protected void fillImage(SimpleImage res) {
Tools.srand123(this.seed);
double rprob = (double) ((double) 1.0 - (double) probability / (double) 100.0);
SimpleImage brickImg = this.brickImage.getImage().clone();
{
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setScaleWidth(brickSize);
scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
scaleT.transformImage(brickImg);
}
int width = res.getImageWidth();
int height = res.getImageHeight();
int brickWidth = brickImg.getImageWidth();
int brickHeight = brickImg.getImageHeight();
int colCount = width / brickWidth;
if (colCount * brickWidth < width)
colCount++;
int rowCount = height / brickHeight;
if (rowCount * brickHeight < height)
rowCount++;
for (int i = 0; i < rowCount; i++) {
int off = i * this.brickShift;
while (off > 0) off -= brickWidth;
for (int j = 0; j < (off == 0 ? colCount : colCount + 1); j++) {
SimpleImage compImg = brickImg;
if (Tools.drand() >= rprob) {
int bRed = (int) (redVariance - Tools.drand() * 2 * redVariance + 0.5);
int bGreen = (int) (greenVariance - Tools.drand() * 2 * greenVariance + 0.5);
int bBlue = (int) (blueVariance - Tools.drand() * 2 * blueVariance + 0.5);
compImg = compImg.clone();
BalancingTransformer bT = new BalancingTransformer();
bT.setRed(bRed);
bT.setGreen(bGreen);
bT.setBlue(bBlue);
bT.transformImage(compImg);
}
ComposeTransformer cT = new ComposeTransformer();
cT.setHAlign(ComposeTransformer.HAlignment.OFF);
cT.setVAlign(ComposeTransformer.VAlignment.OFF);
cT.setTop(i * brickHeight);
int left = j * brickWidth + off;
cT.setLeft(left);
cT.setForegroundImage(compImg);
cT.transformImage(res);
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DancingFractalsController method getFlamePanel.
private FlamePanel getFlamePanel() {
if (flamePanel == null) {
// flameRootPanel can't be null !?
int borderWidth = flameRootPanel.getBorder().getBorderInsets(flameRootPanel).left;
int width = flameRootPanel.getWidth() - borderWidth;
int height = flameRootPanel.getHeight() - borderWidth;
if (width < 16 || height < 16)
return null;
SimpleImage img = new SimpleImage(width, height);
img.fillBackground(0, 0, 0);
flamePanel = new FlamePanel(prefs, img, 0, 0, flameRootPanel.getWidth() - borderWidth, null, null);
flamePanel.setRenderWidth(640);
flamePanel.setRenderHeight(480);
flameRootPanel.add(flamePanel, BorderLayout.CENTER);
flameRootPanel.getParent().validate();
flameRootPanel.repaint();
}
flamePanel.setFlameHolder(renderThread);
return flamePanel;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DancingFractalsController method getGraph1Panel.
private ImagePanel getGraph1Panel() {
if (graph1Panel == null && graph1RootPanel != null) {
int width = graph1RootPanel.getWidth();
int height = graph1RootPanel.getHeight();
SimpleImage img = new SimpleImage(width, height);
img.fillBackground(0, 0, 0);
graph1Panel = new ImagePanel(img, 0, 0, graph1RootPanel.getWidth());
graph1RootPanel.add(graph1Panel, BorderLayout.CENTER);
graph1RootPanel.getParent().validate();
graph1RootPanel.repaint();
}
return graph1Panel;
}
Aggregations