use of org.jwildfire.transform.ComposeTransformer in project JWildfire by thargor6.
the class FlameRenderer method renderImageStereo3d.
private RenderedFlame renderImageStereo3d(RenderInfo pRenderInfo) {
Stereo3dEye storedEye = eye;
double storedAngle = flame.getStereo3dAngle();
double storedEyeDist = flame.getStereo3dEyeDist();
try {
switch(pRenderInfo.getRenderMode()) {
case PREVIEW:
switch(flame.getStereo3dPreview()) {
case SIDE_BY_SIDE:
{
RenderedFlame result = renderStereo3dSideBySide(pRenderInfo);
ScaleTransformer scaleTransformer = new ScaleTransformer();
scaleTransformer.setAspect(ScaleAspect.IGNORE);
scaleTransformer.setScaleWidth(pRenderInfo.getImageWidth() * renderScale);
scaleTransformer.setScaleHeight(pRenderInfo.getImageHeight() * renderScale);
scaleTransformer.transformImage(result.getImage());
return result;
}
case SIDE_BY_SIDE_FULL:
{
int oldWidth = pRenderInfo.getImageWidth();
pRenderInfo.setImageWidth(oldWidth / 2);
RenderedFlame result = renderStereo3dSideBySide(pRenderInfo);
pRenderInfo.setImageWidth(oldWidth);
return result;
}
case ANAGLYPH:
{
return renderStereo3dAnaglyph(pRenderInfo);
}
case NONE:
return renderImageNormal(pRenderInfo, 1, 0);
default:
throw new IllegalStateException(pRenderInfo.getRenderMode().toString());
}
case PRODUCTION:
switch(flame.getStereo3dMode()) {
case ANAGLYPH:
return renderStereo3dAnaglyph(pRenderInfo);
case INTERPOLATED_IMAGES:
{
RenderInfo localRenderInfo = pRenderInfo.makeCopy();
localRenderInfo.setRenderHDR(false);
localRenderInfo.setRenderZBuffer(false);
RenderedFlame[] leftRenders = new RenderedFlame[flame.getStereo3dInterpolatedImageCount()];
double dAngle = storedAngle / (double) leftRenders.length;
double dEyeDist = storedEyeDist / (double) leftRenders.length;
int totalImageCount = 2 * leftRenders.length;
int totalImageIdx = 0;
for (int i = 0; i < leftRenders.length; i++) {
eye = Stereo3dEye.LEFT;
flame.setStereo3dAngle((i + 1) * dAngle);
flame.setStereo3dEyeDist((i + 1) * dEyeDist);
leftRenders[i] = renderImageNormal(localRenderInfo, totalImageCount, totalImageIdx++);
}
RenderedFlame[] rightRenders = new RenderedFlame[flame.getStereo3dInterpolatedImageCount()];
for (int i = 0; i < rightRenders.length; i++) {
eye = Stereo3dEye.RIGHT;
flame.setStereo3dAngle((i + 1) * dAngle);
flame.setStereo3dEyeDist((i + 1) * dEyeDist);
rightRenders[i] = renderImageNormal(localRenderInfo, totalImageCount, totalImageIdx++);
}
if (flame.isStereo3dSwapSides()) {
RenderedFlame[] tmp = leftRenders;
leftRenders = rightRenders;
rightRenders = tmp;
}
RenderedFlame mergedRender = new RenderedFlame();
localRenderInfo.setImageWidth(2 * pRenderInfo.getImageWidth());
localRenderInfo.setImageHeight(leftRenders.length * pRenderInfo.getImageHeight());
mergedRender.init(localRenderInfo, flame);
SimpleImage mergedImg = mergedRender.getImage();
ComposeTransformer composeTransformer = new ComposeTransformer();
composeTransformer.setHAlign(HAlignment.OFF);
composeTransformer.setVAlign(VAlignment.OFF);
int yOff = 0;
for (int i = 0; i < leftRenders.length; i++) {
composeTransformer.setLeft(0);
composeTransformer.setTop(yOff);
composeTransformer.setForegroundImage(leftRenders[i].getImage());
composeTransformer.transformImage(mergedImg);
yOff += pRenderInfo.getImageHeight();
}
yOff = 0;
for (int i = 0; i < rightRenders.length; i++) {
composeTransformer.setLeft(pRenderInfo.getImageWidth());
composeTransformer.setTop(yOff);
composeTransformer.setForegroundImage(rightRenders[i].getImage());
composeTransformer.transformImage(mergedImg);
yOff += pRenderInfo.getImageHeight();
}
return mergedRender;
}
case SIDE_BY_SIDE:
return renderStereo3dSideBySide(pRenderInfo);
case NONE:
return renderImageNormal(pRenderInfo, 1, 0);
default:
throw new IllegalStateException(flame.getStereo3dMode().toString());
}
default:
throw new IllegalStateException(pRenderInfo.getRenderMode().toString());
}
} finally {
eye = storedEye;
flame.setStereo3dAngle(storedAngle);
flame.setStereo3dEyeDist(storedEyeDist);
}
}
use of org.jwildfire.transform.ComposeTransformer 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.transform.ComposeTransformer in project JWildfire by thargor6.
the class FlamePreviewHelper method renderFlameImage.
public SimpleImage renderFlameImage(boolean pQuickRender, boolean pMouseDown, int pDownScale, boolean pAllowUseCache) {
if (!pAllowUseCache) {
prevRaster = null;
}
FlamePanel imgPanel = flamePanelProvider.getFlamePanel();
FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
Rectangle panelBounds = imgPanel.getParentImageBounds();
Rectangle bounds;
if (pDownScale != 1) {
bounds = new Rectangle(panelBounds.width / pDownScale, panelBounds.height / pDownScale);
} else {
bounds = panelBounds;
}
int renderScale = pQuickRender && pMouseDown ? 2 : 1;
int width = bounds.width / renderScale;
int height = bounds.height / renderScale;
if (width >= 16 && height >= 16) {
RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
Flame flame = flameHolder.getFlame();
if (flame != null) {
double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
double oldSampleDensity = flame.getSampleDensity();
int oldSpatialOversampling = flame.getSpatialOversampling();
boolean oldPostNoiseFilter = flame.isPostNoiseFilter();
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());
try {
FlameRenderer renderer;
if (pQuickRender) {
flame.setSampleDensity(prefs.getTinaRenderRealtimeQuality());
flame.applyFastOversamplingSettings();
flame.setSpatialOversampling(oldSpatialOversampling);
} else {
flame.setSampleDensity(prefs.getTinaRenderPreviewQuality());
}
if (isDrawFocusPointEnabled(cfg)) {
renderer = new DrawFocusPointFlameRenderer(flame, prefs, isTransparencyEnabled());
} else {
renderer = new FlameRenderer(flame, prefs, isTransparencyEnabled(), false);
}
if (pQuickRender) {
renderer.setProgressUpdater(null);
} else {
renderer.setProgressUpdater(mainProgressUpdater);
}
long t0 = System.currentTimeMillis();
renderer.setRenderScale(renderScale);
RenderedFlame res;
if (prevRaster != null && pAllowUseCache) {
info.setStoreRaster(false);
info.setRestoredRaster(prevRaster);
flame.setSampleDensity(prevRaster.getSampleDensity());
res = renderer.renderFlame(info);
} else {
info.setStoreRaster(true);
res = renderer.renderFlame(info);
prevRaster = res.getRaster();
}
SimpleImage img = res.getImage();
long t1 = System.currentTimeMillis();
img.getBufferedImg().setAccelerationPriority(1.0f);
if (layerAppendBtn != null && layerAppendBtn.isSelected() && !pMouseDown) {
showLayerAppendModeIndicator(img);
}
if (layerPreviewBtn != null && layerPreviewBtn.isSelected() && layerHolder != null) {
SimpleImage layerImg = createLayerPreview(img, renderScale, width, height);
showLayerPreview(img, layerImg, renderScale, width, height);
}
if (pDownScale != 1) {
SimpleImage background = new SimpleImage(panelBounds.width, panelBounds.height);
ComposeTransformer cT = new ComposeTransformer();
cT.setHAlign(ComposeTransformer.HAlignment.CENTRE);
cT.setVAlign(ComposeTransformer.VAlignment.CENTRE);
cT.setForegroundImage(img);
cT.transformImage(background);
img = background;
}
if (!cfg.isNoControls() && messageHelper != null) {
messageHelper.showStatusMessage(flame, "render time: " + Tools.doubleToString((t1 - t0) * 0.001) + "s");
}
return img;
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
} finally {
flame.setSpatialFilterRadius(oldSpatialFilterRadius);
flame.setSampleDensity(oldSampleDensity);
flame.setSpatialOversampling(oldSpatialOversampling);
flame.setPostNoiseFilter(oldPostNoiseFilter);
}
}
}
return null;
}
use of org.jwildfire.transform.ComposeTransformer in project JWildfire by thargor6.
the class FlameRenderer method renderStereo3dSideBySide.
private RenderedFlame renderStereo3dSideBySide(RenderInfo pRenderInfo) {
RenderInfo localRenderInfo = pRenderInfo.makeCopy();
localRenderInfo.setRenderHDR(false);
localRenderInfo.setRenderZBuffer(false);
eye = Stereo3dEye.LEFT;
RenderedFlame leftRender = renderImageNormal(localRenderInfo, 2, 0);
eye = Stereo3dEye.RIGHT;
RenderedFlame rightRender = renderImageNormal(localRenderInfo, 2, 1);
if (flame.isStereo3dSwapSides()) {
RenderedFlame tmp = leftRender;
leftRender = rightRender;
rightRender = tmp;
}
RenderedFlame mergedRender = new RenderedFlame();
localRenderInfo.setImageWidth(2 * leftRender.getImage().getImageWidth());
localRenderInfo.setImageHeight(leftRender.getImage().getImageHeight());
mergedRender.init(localRenderInfo, flame);
SimpleImage mergedImg = mergedRender.getImage();
ComposeTransformer composeTransformer = new ComposeTransformer();
composeTransformer.setHAlign(HAlignment.OFF);
composeTransformer.setVAlign(VAlignment.OFF);
composeTransformer.setForegroundImage(leftRender.getImage());
composeTransformer.transformImage(mergedImg);
composeTransformer.setForegroundImage(rightRender.getImage());
composeTransformer.setLeft(leftRender.getImage().getImageWidth());
composeTransformer.transformImage(mergedImg);
return mergedRender;
}
use of org.jwildfire.transform.ComposeTransformer in project JWildfire by thargor6.
the class FlamePreviewHelper method showLayerPreview.
private void showLayerPreview(SimpleImage img, SimpleImage layerImg, int renderScale, int width, int height) {
if (layerImg != null) {
ComposeTransformer cT = new ComposeTransformer();
cT.setHAlign(ComposeTransformer.HAlignment.LEFT);
cT.setVAlign(ComposeTransformer.VAlignment.TOP);
cT.setTop(10);
cT.setLeft(10);
cT.setForegroundImage(layerImg);
cT.transformImage(img);
}
}
Aggregations