Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Shujal

Pages: [1]
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):


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.

2
Lua / Re: TI.Image: Get pixel color
« on: April 18, 2014, 02:38:44 pm »
Thank you for your reply. I will try to use low-resolution (probably 16x16) matrix. I'm just going to have to write a simple converter program.

3
Lua / TI.Image: Get pixel color
« on: April 18, 2014, 11:27:10 am »
Is there a way to obtain the color of one pixel and plot that to the screen. I'd like to do some textured 3D rendering.
I don't think there is a method to do that and image metatables are hiden.
I thought of implementing it like this:
Code: [Select]
function plotPixelFromImage(gc, sx, sy, img, ix, iy)
    gc:clipRect("set", sx, sy, 1, 1)
    gc:drawImage(img, sx-ix, sy-iy)
    gc:clipRect("reset")
end
but I think it would be quite CPU intensive. Or would it be easier to make my own image format?

Pages: [1]