1
Lua / Re: TI.Image: Get pixel color
« on: April 18, 2014, 04:25:21 pm »
For anyone who is interested, here is the conversion program (java):
Just paste the result into your lua code. You can access a pixel's color using
Code: [Select]
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
JFileChooser open = new JFileChooser();
if(open.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){
try{
BufferedImage theImg = ImageIO.read(open.getSelectedFile());
String out = "{";
for(int j=0; j<theImg.getWidth(); j++){
out+="{";
for(int i=0; j<theImg.getHeight(); i++){
//System.out.println(i+","+j);
out+="{"+((theImg.getRGB(j, i)&0x00ff0000)>>16) /*red*/
+","+((theImg.getRGB(j, i)&0x0000ff00)>>8) /*green*/
+","+((theImg.getRGB(j, i)&0x000000ff))+"},"; /*blue*/
}
out+="},";
}
out+="}";
System.out.println(out.replaceAll(",}", "}"));
}catch(Exception e){e.printStackTrace();}
}else{
JOptionPane.showMessageDialog(null, "You clicked cancel :_(");
}
}
}
Just paste the result into your lua code. You can access a pixel's color using
Code: [Select]
texture[xIndex][yIndex][color]
(color=1:red, color=2:green, color=3:blue) It is still pretty slow (1 fps with two faces being rendered on a TI-npire CX CAS), maybe I should play with the resolution.