Colour Cube: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 35:
The following algorithm assumes that the data is stored and accessed as m_size cubes of size 32, each m_size*m_size pixels, oriented left to right with an m_size*m_size*3 bytes stride, rather than as m_size cubes oriented top to bottom with a m_size*3 bytes stride (i.e. only one cube's data per line). Regardless of which is true, it seems that the following algorithm works to produce exact conversions from Xbox 360 colourcubes to PC colourcubes. Smaller cubes, like those from NFS:HP will likely need a different algorithm for calculating the offsets.
 
With the above in mind, to find the 3-byte (R, G and B) pixel data for position (x,y,z) in the PC m_pixels data, 3 bytes (R, G and B) can be read from the Xbox 360 m_pixels data at the offset calculated as follows where x, y and yz are represented as a number of bits, x0 to x9x4, (valuesy0 0-m_size*m_size)to y4 and y0z0 to y4z4 (all values between 0- and m_size).
 
{| class="wikitable"
|-
! x !! y !! z !! offset
|- style="vertical-align:top;"
| <syntaxhighlight>xxxxxxxxxxxxxxx
987654321043210</syntaxhighlight> || <syntaxhighlight>yyyyy
43210</syntaxhighlight> || <syntaxhighlight>zzzzz
43210</syntaxhighlight> || <syntaxhighlight>o0=x0
o1=x1
o2=x5y0
o3=x2
o4=x3
o5=x4^x8y3^y2z2
o6=x6y1
o7=x7y2
o8=y0z0
o9=x8y3^y2z2
o10=y1z1
o11=x9y4
o12=y2z2
o13=y3z3
o14=y4z4</syntaxhighlight>
|}
 
Line 69 ⟶ 70:
end
 
# calculate offset, in pixels, of where to find the (x,y,z) pixel in the Xbox 360 data
# pixel offset in PC file is m_size * m_size * z + m_size * y + x
def calc_offset(x, y, z)
x0 = (x >> 0) & 0b1
x1 = (x >> 1) & 0b1
Line 76 ⟶ 78:
x3 = (x >> 3) & 0b1
x4 = (x >> 4) & 0b1
x5 = (x >> 5) & 0b1
x6 = (x >> 6) & 0b1
x7 = (x >> 7) & 0b1
x8 = (x >> 8) & 0b1
x9 = (x >> 9) & 0b1
y0 = (y >> 0) & 0b1
y1 = (y >> 1) & 0b1
Line 86 ⟶ 83:
y3 = (y >> 3) & 0b1
y4 = (y >> 4) & 0b1
x5z0 = (xz >> 50) & 0b1
x6z1 = (xz >> 61) & 0b1
x7z2 = (xz >> 72) & 0b1
x8z3 = (xz >> 83) & 0b1
x9z4 = (xz >> 94) & 0b1
 
o=(y4z4<<14)|
(y3z3<<13)|
(y2z2<<12)|
(x9y4<<11)|
(y1z1<<10)|
((y2z2<<9)^(x8y3<<9))|
(y0z0<<8)|
(x7y2<<7)|
(x6y1<<6)|
((y2z2<<5)^(x8y3<<5)^(x4<<5))|
(x3<<4)|
(x2<<3)|
(x5y0<<2)|
(x1<<1)|
(x0<<0)
Line 109 ⟶ 111:
# now, convert the m_pixels data
data="".b
m_size.times do |yz|
(m_size * m_size).times do |xy|
m_size.times do |x|
offset = calc_offset(x, y)
pixel_data = m_pixels[offset.pixels... = calc_offset(offsetx, +y, 1z).pixels]
data << pixel_data = m_pixels[offset.pixels...(offset + 1).pixels]
data << pixel_data
end
end
end
6

edits