This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws MalformedURLException, IOException { | |
// String imgUrl = "http://sipi.usc.edu/database/preview/misc/4.1.07.png"; | |
String imgUrl = "http://sipi.usc.edu/database/preview/misc/boat.512.png"; | |
Img img = Img.createRemoteImg(ImageLoader.loadImage(new URL(imgUrl).openStream(),BufferedImage.TYPE_INT_ARGB)); | |
System.out.println("start"); | |
// to CIE XYZ colorspace (bound to [0..255] missing the factor 1/0.17697) | |
img.forEachParallel(px->{ | |
px.setARGB( px.a(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Graphics; | |
import java.awt.image.BufferedImage; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.util.Random; | |
import java.util.function.BiConsumer; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Img img = new Img(2048,2048); | |
img.fill(0xff000000); | |
Random r = new Random(); | |
img.forEach(px->{px.setG(r.nextInt(256));}); | |
Img copy = img.copy(); | |
int kernelSize = 21; | |
int minus = kernelSize/2; | |
int plus = kernelSize-minus; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
JPanel mainpanel = new JPanel(); | |
mainpanel.setLayout(new BorderLayout()); | |
ImagePanel imgpanel = new ImagePanel(); | |
imgpanel.setPreferredSize(new Dimension(200, 200)); | |
JComboBox<Blending> blendselector = new JComboBox<>(Blending.values()); | |
final JLabel renderlabel = new JLabel(); | |
blendselector.setRenderer((list,blend,idx,selected,focused)->{ | |
renderlabel.setText(blend.name()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
Img[] gammut = new Img[256]; | |
Consumer<Pixel> lab2rgb = (px)->{px.setValue(transformLAB2RGB(px.getValue()));}; | |
for(int l = 0; l < 256; l++){ | |
int L = l; | |
Img img = new Img(256, 256); | |
img.forEach(px->{px.setRGB(L, px.getX(), px.getY());}); | |
img.forEach(lab2rgb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int hotColdMapping(double f){ | |
f*=Math.PI; | |
if(f < Math.PI/2){ | |
float r = (float) Math.cos(f); | |
float g = (float) (1-Math.sin(f)); | |
return Pixel.rgb_fromNormalized(r, g, 0); | |
} else { | |
float b = (float) -Math.cos(f); | |
float g = (float) (1-Math.sin(f)); | |
return Pixel.rgb_fromNormalized(0, g, b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JFrame frame = new JFrame(); | |
JTextField textField = new JTextField(new File("selfie.png").getAbsolutePath()); | |
JButton btn = new JButton("selfie!"); | |
btn.addActionListener((e)->{ | |
Img img = new Img(frame.getWidth(), frame.getHeight()); | |
img.draw(g->{ | |
frame.paintAll(g); | |
}); | |
System.out.println("flash!"); | |
try{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Img img = new Img(200,200); | |
img.fill(0xff000000); | |
Spliterator<float[]> split = new ConvertedPixelSpliterator<>( | |
img.spliterator(), | |
()->{return new float[6];}, | |
testmain::pixel2vec, | |
testmain::vec2Pixel); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Img img1 = new Img(4000, 4000); | |
Img img2 = new Img(4000, 4000) { | |
@Override | |
public Pixel getPixel() { | |
return new Pixol(this, 0); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package misc; | |
import java.util.Arrays; | |
import java.util.Iterator; | |
import java.util.Spliterator; | |
import java.util.function.Consumer; | |
import java.util.stream.Stream; | |
import java.util.stream.StreamSupport; | |
public class Slice<T> implements Iterable<Slice.ArrayAccessor<T>>{ |
OlderNewer