This thread is explaining how to read forms with a depth less than 8 for ZeroLuck.
My JavaScript code is this:
// Sets color to an array of colors for the pixels. If the form does not contain any colors, use the built in array instead.
var colors = this.colors || squeakColors;
// Some variables I coppied from the Java code. I don't exactly know what they do.
var l = this.bits.length / this.height;
var i1 = (1 << this.depth) - 1;
var j1 = 32 / this.depth;
// Loop throught evevy pixel in the Form.
for(var y = 0; y < this.height; y++)
{
for(var x = 0; x < this.width; x++)
{
var i2 = this.bits[y * l + (x - (x % j1)) / j1];
var j2 = this.depth * (j1 - x % j1 - 1);
var ci = i2 >> j2 & i1; // This is the index of the color for the pixel in the color array.
// Insert your pixel setting method here. aka, setPixel(x, y, colors[ci]);
// This is just constructing an array of pixel values that will be pushed into the HTML5 canvas. You probably won't use it.
var pi = (y * this.width + x) * 4;
var c = colors[ci];
if (c)
{
array[pi] = c.r;
array[pi + 1] = c.g;
array[pi + 2] = c.b;
array[pi + 3] = c.a == 0 ? 0 : 255;
}
}
}Offline
Thanks!!
This helps me very much!
But some questions:
1. Is the "bits" array the less than 8 bit encoded bitmap array?
Or have I to split the encoded less than 8 bit bitmap to bits to get the "bits" array?
2.
var colors = this.colors || squeakColors;
What is the this.colors array? I know the "squeakColors" array, but how do you get the
"colors" array?
Is the colors array in the Form object stored too?
Thanks a lot!
ZeroLuck
Last edited by ZeroLuck (2011-12-22 16:56:34)
Offline
MathWizz wrote:
1. The bits array is the decoded bitmap which should be an int array in Java.
2. The color array should be in the Form as the sixth field.
Okay! Thanks!
I think I will be able to read the images now.
( I will try it tomorrow, because I live in germany and here it is over 5 hours later
)
Offline
Okay reading the images works!
Another question:
Where can I find the x position and the y position from a Sprite in its array?
Because the name is item 10, the scripts are in item 12, costumes and sounds in 14...
But I can't find the position...
Last edited by ZeroLuck (2011-12-23 08:31:16)
Offline
MathWizz wrote:
It is a rectangle which is item 1.
I don't get it
The sprite array looks like this:
[
org.me.scratchplayer.Sprite@1f82ab4,
124,
3,
[
204,
138,
297,
202,
],
org.me.scratchplayer.Sprite@1bb9696,
[
],
[...],
](the Sprite has the position 70/50 )
And item 1 is "124"...,
item 3 looks like a Rectangle object, but the coordinates are false.
EDIT
item 3 is the Rectangle.
I got the cordinates so:
Object[] pos = (Object[]) obj[3];
s.setPos(((Number) pos[0]).intValue() + (((Number)pos[2]).intValue() - ((Number)pos[0]).intValue()) /2,
((Number) pos[1]).intValue() + (((Number)pos[3]).intValue() - ((Number)pos[1]).intValue()) /2);Last edited by ZeroLuck (2011-12-27 08:26:56)
Offline