All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.machinezoo.sourceafis.visualization.TransparencyImage Maven / Gradle / Ivy

// Part of SourceAFIS Visualization: https://sourceafis.machinezoo.com/transparency/
package com.machinezoo.sourceafis.visualization;

import static com.machinezoo.sourceafis.visualization.TransparencyMarkers.*;
import java.nio.charset.*;
import com.machinezoo.pushmode.dom.*;
import com.machinezoo.sourceafis.transparency.*;

public class TransparencyImage {
	private final double width;
	public double width() {
		return width;
	}
	private final double height;
	public double height() {
		return height;
	}
	public TransparencyImage(double width, double height) {
		this.width = width;
		this.height = height;
	}
	public TransparencyImage(IntPoint size) {
		this(size.x, size.y);
	}
	public TransparencyImage(BlockMap blocks) {
		this(blocks.pixels);
	}
	private double padding;
	public double padding() {
		return padding;
	}
	public TransparencyImage padding(double padding) {
		this.padding = padding;
		return this;
	}
	private DomFragment fragment = new DomFragment();
	public DomContent content() {
		return fragment;
	}
	public TransparencyImage add(DomContent content) {
		fragment.add(content);
		return this;
	}
	public TransparencyImage png(TransparencyPixmap pixmap) {
		return add(embedPngPixmap(pixmap));
	}
	public TransparencyImage jpeg(TransparencyPixmap pixmap) {
		return add(embedJpegPixmap(pixmap));
	}
	public TransparencyImage image(byte[] image) {
		return add(embedImage(width, height, image));
	}
	public DomElement tree() {
		return Svg.svg()
			.version("1.1")
			.viewBox((-padding) + " " + (-padding) + " " + (width + 2 * padding) + " " + (height + 2 * padding))
			.add(fragment);
	}
	public byte[] bytes() {
		return DomFormatter.svg()
			.format(tree())
			.toString()
			.getBytes(StandardCharsets.UTF_8);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy