use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class AbstractDisplacementMapWFFunc method transform.
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount, double pInputX, double pInputY) {
double x = (pInputX - (offsetX + 0.5) + 1.0) / scaleX * (double) (imgWidth - 1);
double y = (pInputY - (offsetY + 0.5) + 1.0) / scaleY * (double) (imgHeight - 1);
int ix = Tools.FTOI(x);
int iy = Tools.FTOI(y);
if (this.tileX == 1) {
if (ix < 0) {
int nx = ix / imgWidth - 1;
ix -= nx * imgWidth;
} else if (ix >= imgWidth) {
int nx = ix / imgWidth;
ix -= nx * imgWidth;
}
}
if (this.tileY == 1) {
if (iy < 0) {
int ny = iy / imgHeight - 1;
iy -= ny * imgHeight;
} else if (iy >= imgHeight) {
int ny = iy / imgHeight;
iy -= ny * imgHeight;
}
}
double r, g, b;
if (ix >= 0 && ix < imgWidth && iy >= 0 && iy < imgHeight) {
if (colorMap instanceof SimpleImage) {
toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
r = (double) toolPixel.r / 255.0;
g = (double) toolPixel.g / 255.0;
b = (double) toolPixel.b / 255.0;
} else {
((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
r = rgbArray[0];
g = rgbArray[0];
b = rgbArray[0];
}
} else {
return;
}
switch(mode) {
case MODE_TRANSLATE:
{
double amountX = (r - 0.5) * pAmount;
double amountY = (g - 0.5) * pAmount;
pVarTP.x += amountX;
pVarTP.y += amountY;
}
break;
case MODE_SCALE:
{
double intensity = calcIntensity(r, g, b) - bias;
if (intensity > 0.0) {
double scl = 1.0 + (intensity - 0.5) * pAmount;
pVarTP.x *= scl;
pVarTP.y *= scl;
}
}
break;
case MODE_SCISSOR:
{
double amountX = (r - 0.5) * pAmount;
double amountY = (g - 0.5) * pAmount;
double newx = pVarTP.x * amountX * amountY + pVarTP.y * amountY;
double newy = pVarTP.x * amountY - pVarTP.y * amountX * amountY;
pVarTP.x = newx;
pVarTP.y = newy;
}
break;
case MODE_ROTATE:
default:
{
double intensity = calcIntensity(r, g, b) - bias;
if (intensity > 0.0) {
double angle = intensity * M_2PI * pAmount;
double sina = sin(angle);
double cosa = cos(angle);
double xnew = pVarTP.x * cosa - pVarTP.y * sina;
double ynew = pVarTP.x * sina + pVarTP.y * cosa;
pVarTP.x = xnew;
pVarTP.y = ynew;
}
}
}
switch(colorMode) {
case COLOR_MODE_INHERIT:
{
pVarTP.rgbColor = true;
pVarTP.redColor = r;
pVarTP.greenColor = g;
pVarTP.blueColor = b;
pVarTP.color = getColorIdx(r, g, b);
}
break;
default:
// nothing to do
break;
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class MeshGenController method refreshFlameImage.
public void refreshFlameImage(boolean pQuickRender, JPanel pRootPanel, FlameHolder pFlameHolder) {
if (!refreshing) {
FlamePanel imgPanel = getFlamePanel(pRootPanel, pFlameHolder);
Rectangle bounds = imgPanel.getImageBounds();
int width = bounds.width;
int height = bounds.height;
if (width >= 16 && height >= 16) {
RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
Flame flame = pFlameHolder.getFlame();
if (flame != null) {
double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
double oldSampleDensity = flame.getSampleDensity();
try {
double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
flame.setWidth(info.getImageWidth());
flame.setHeight(info.getImageHeight());
FlameRenderer renderer = new FlameRenderer(flame, prefs, false, false);
if (pQuickRender) {
renderer.setProgressUpdater(null);
flame.setSampleDensity(3.0);
flame.setSpatialFilterRadius(0.0);
} else {
renderer.setProgressUpdater(renderSequenceProgressUpdater);
flame.setSampleDensity(prefs.getTinaRenderPreviewQuality());
}
RenderedFlame res = renderer.renderFlame(info);
imgPanel.setImage(res.getImage());
} finally {
flame.setSpatialFilterRadius(oldSpatialFilterRadius);
flame.setSampleDensity(oldSampleDensity);
}
}
} else {
imgPanel.setImage(new SimpleImage(width, height));
}
pRootPanel.repaint();
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class MeshGenController method importSequence.
private void importSequence(String pFilenamePattern) {
try {
final int firstIndex = 1;
int count = 0;
String lastFilename = null;
for (int i = firstIndex; i < Integer.MAX_VALUE; i++) {
String filename = String.format(pFilenamePattern, i);
if (filename.equals(lastFilename)) {
break;
}
if (new File(filename).exists()) {
count++;
} else {
break;
}
lastFilename = filename;
}
if (count > 0) {
File first = new File(String.format(pFilenamePattern, firstIndex));
SimpleImage img = new ImageReader(rootPanel).loadImage(first.getAbsolutePath());
if (img != null) {
sequenceWidthREd.setValue(img.getImageWidth());
sequenceHeightREd.setValue(img.getImageHeight());
sequenceSlicesREd.setValue(count);
setCurrSequencePattern(pFilenamePattern);
}
enableControls();
} else
throw new Exception("An image sequence has to contain at least one image");
} catch (Exception ex) {
errorHandler.handleError(ex);
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class ImgPaletteReader method readPaletteFromMapData.
public List<RGBPalette> readPaletteFromMapData(String pMapData, String pFilename) throws Exception {
List<RGBPalette> res = new ArrayList<RGBPalette>();
RGBPalette gradient = new RGBPalette();
res.add(gradient);
gradient.setFlam3Name(new File(pFilename).getName());
SimpleImage img = new ImageReader().loadImage(pFilename);
if (img.getImageWidth() > 0 && img.getImageHeight() > 0) {
Map<Integer, RGBColor> colors = new HashMap<Integer, RGBColor>();
Pixel rgbPixel = new Pixel();
for (int i = 0; i < img.getImageWidth(); i++) {
rgbPixel.setARGBValue(img.getARGBValue(i, 0));
RGBColor color = new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
colors.put(i, color);
}
gradient.setColors(colors, false, false);
}
return res;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class PostBumpMapWFFunc method init.
@Override
public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
bumpMap = null;
if (inlinedImage != null) {
try {
bumpMap = RessourceManager.getImage(inlinedImageHash, inlinedImage);
} catch (Exception e) {
e.printStackTrace();
}
} else if (imageFilename != null && imageFilename.length() > 0) {
try {
bumpMap = RessourceManager.getImage(imageFilename);
} catch (Exception e) {
e.printStackTrace();
}
}
if (bumpMap == null) {
bumpMap = new SimpleImage(320, 256);
}
imgWidth = bumpMap.getImageWidth();
imgHeight = bumpMap.getImageHeight();
}
Aggregations