Colour Cube: Difference between revisions

Added information on 16*16*16 cubes (e.g. for NFS:HP)
No edit summary
(Added information on 16*16*16 cubes (e.g. for NFS:HP))
Line 33:
 
== Xbox 360 Swizzle Algorithm ==
The following algorithm assumes that the data is stored and accessed as m_sizea cubescube of size 32, each m_size*m_size pixels, oriented left to right with an m_size*m_size*3 bytes stridepixels, rather than as m_size cubes orientedaccessed topaccording to bottom with a m_size*3certain bytes stride (i.ealgorithm. onlyThe one cube's data per line). Regardless of whichalgorithm is true,different itfor seemsBurnout thatParadise the following algorithm works to produce exact conversions from Xbox 360 colourcubes to PC colourcubes. Smaller32*32*32 cubes, like those fromand NFS:HP will16*16*16 likely need a different algorithm for calculating the offsetscubes.
 
With the above in mind, toTo find the 3-byte bytes (R, G and B) of 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 z are represented as a number of bits, x0 to x4, y0 to y4 and z0 to z4 (all values between 0 and m_size - 1).
 
{| class="wikitable"
|-
! x !! y !! z !! offset (m_size = 16)
|- style="vertical-align:top;"
| <syntaxhighlight>xxxx
3210</syntaxhighlight> || <syntaxhighlight>yyyy
3210</syntaxhighlight> || <syntaxhighlight>zzzz
3210</syntaxhighlight> || <syntaxhighlight>o0=x0
o1=x1
o2=y0
o3=x2
o4=x3
o5=y1
o6=y2
o7=z0
o8=y3^z2
o9=z1
o10=z2
o11=z3</syntaxhighlight>
|}
 
{| class="wikitable"
|-
! x !! y !! z !! offset (m_size = 32)
|- style="vertical-align:top;"
| <syntaxhighlight>xxxxx
Line 72 ⟶ 93:
# 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(m_size, x, y, z)
case m_size
when 16
calc_offset16(x, y, z)
when 32
calc_offset32(x, y, z)
else
raise "Unsupported m_size: #{m_size}"
end
end
 
def calc_offset16(x, y, z)
x0 = (x >> 0) & 0b1
x1 = (x >> 1) & 0b1
x2 = (x >> 2) & 0b1
x3 = (x >> 3) & 0b1
y0 = (y >> 0) & 0b1
y1 = (y >> 1) & 0b1
y2 = (y >> 2) & 0b1
y3 = (y >> 3) & 0b1
z0 = (z >> 0) & 0b1
z1 = (z >> 1) & 0b1
z2 = (z >> 2) & 0b1
z3 = (z >> 3) & 0b1
 
o=(z3<<11)|
(z2<<10)|
(z1<<9)|
((y3<<8)^(z2<<8))|
(z0<<7)|
(y2<<6)|
(y1<<5)|
(x3<<4)|
(x2<<3)|
(y0<<2)|
(x1<<1)|
(x0<<0)
end
 
def calc_offset32(x, y, z)
x0 = (x >> 0) & 0b1
x1 = (x >> 1) & 0b1
6

edits