1
0
mirror of https://github.com/RPCS3/ps3autotests.git synced 2024-11-08 11:52:58 +01:00

Test added: rsx/texture_formats

This commit is contained in:
Alexandro Sánchez Bach 2014-05-18 18:34:55 +02:00
parent 48b3c59971
commit fcba7ac75e
5 changed files with 245 additions and 0 deletions

8
tests/rsx/texture_formats/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Source code (not relevant for the test)
*.cpp
# Ignore .RAW textures generated with the script
*.raw
!Texture-COMPRESSED_DXT1.raw
!Texture-COMPRESSED_DXT23.raw
!Texture-COMPRESSED_DXT45.raw

View File

@ -0,0 +1,35 @@
Before you run the test, make sure you run the `Texture_Generate.py` in order to generate all the remaining .RAW textures that will be used by the sample. In the end, following files should be present along the binary:
* *Texture-B8.raw*
* *Texture-A1R5G5B5.raw*
* *Texture-A4R4G4B4.raw*
* *Texture-R5G6B5.raw*
* *Texture-A8R8G8B8.raw*
* *Texture-COMPRESSED_DXT1.raw*
* *Texture-COMPRESSED_DXT23.raw*
* *Texture-COMPRESSED_DXT45.raw*
* *Texture-G8B8.raw*
* *Texture-R6G5B5.raw*
* *Texture-DEPTH24_D8.raw*
* *Texture-DEPTH24_D8_FLOAT.raw*
* *Texture-DEPTH16.raw*
* *Texture-DEPTH16_FLOAT.raw*
* *Texture-X16.raw*
* *Texture-Y16_X16.raw*
* *Texture-R5G5B5A1.raw*
* *Texture-COMPRESSED_HILO8.raw*
* *Texture-COMPRESSED_HILO_S8.raw*
* *Texture-W16_Z16_Y16_X16_FLOAT.raw*
* *Texture-D1R5G5B5.raw*
* *Texture-D8R8G8B8.raw*
* *Texture-Y16_X16_FLOAT.raw*
* *Texture-COMPRESSED_B8R8_G8R8.raw*
* *Texture-COMPRESSED_R8B8_R8G8.raw*
This test is a 5x5 grid with following texture formats:
* `D1R5G5B5`, `D8R8G8B8`, `Y16_X16_FLOAT`, `COMPRESSED_B8R8_G8R8`, `COMPRESSED_R8B8_R8G8`
* `Y16_X16`, `R5G5B5A1`, `COMPRESSED_HILO8`, `COMPRESSED_HILO_S8`, `W16_Z16_Y16_X16_FLOAT`
* `DEPTH24_D8`, `DEPTH24_D8_FLOAT`, `DEPTH16`, `DEPTH16_FLOAT`, `X16`
* `COMPRESSED_DXT1`, `COMPRESSED_DXT23`, `COMPRESSED_DXT45`, `G8B8`, `R6G5B5`
* `B8`, `A1R5G5B5`, `A4R4G4B4`, `R5G6B5`, `A8R8G8B8`
White/Black squares are formats that are not yet included in the test.

View File

@ -0,0 +1,202 @@
#######################
# Auxiliary Functions #
#######################
import struct, binascii
def FP32toFP16(float32):
F16_EXPONENT_BITS = 0x1F
F16_EXPONENT_SHIFT = 10
F16_EXPONENT_BIAS = 15
F16_MANTISSA_BITS = 0x3ff
F16_MANTISSA_SHIFT = (23 - F16_EXPONENT_SHIFT)
F16_MAX_EXPONENT = (F16_EXPONENT_BITS << F16_EXPONENT_SHIFT)
a = struct.pack('>f',float32)
b = binascii.hexlify(a)
f32 = int(b,16)
f16 = 0
sign = (f32 >> 16) & 0x8000
exponent = ((f32 >> 23) & 0xff) - 127
mantissa = f32 & 0x007fffff
if exponent == 128:
f16 = sign | F16_MAX_EXPONENT
if mantissa:
f16 |= (mantissa & F16_MANTISSA_BITS)
elif exponent > 15:
f16 = sign | F16_MAX_EXPONENT
elif exponent > -15:
exponent += F16_EXPONENT_BIAS
mantissa >>= F16_MANTISSA_SHIFT
f16 = sign | exponent << F16_EXPONENT_SHIFT | mantissa
else:
f16 = sign
return f16
########
# Main #
########
from PIL import Image
img = Image.open("Texture_Original.png")
pix = img.load()
#A1R5G5B5
w = open("Texture-A1R5G5B5.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
ARGB = (pix[x,y][3] & 0x80) << 8
ARGB |= (pix[x,y][0] & 0xF8) << 7
ARGB |= (pix[x,y][1] & 0xF8) << 2
ARGB |= (pix[x,y][2] & 0xF8) >> 3
w.write(chr((ARGB >> 8) & 0xFF))
w.write(chr((ARGB >> 0) & 0xFF))
w.close()
#A4R4G4B4
w = open("Texture-A4R4G4B4.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
AR = (pix[x,y][3] & 0xF0) | (pix[x,y][0] >> 4)
GB = (pix[x,y][1] & 0xF0) | (pix[x,y][2] >> 4)
w.write(chr(AR))
w.write(chr(GB))
w.close()
#A8R8G8B8
w = open("Texture-A8R8G8B8.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
w.write(chr(pix[x,y][3]))
w.write(chr(pix[x,y][0]))
w.write(chr(pix[x,y][1]))
w.write(chr(pix[x,y][2]))
w.close()
#B8
w = open("Texture-B8.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
w.write(chr(pix[x,y][2]))
w.close()
#D1R5G5B5
w = open("Texture-D1R5G5B5.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
ARGB = (0x00 & 0x80) << 8
ARGB |= (pix[x,y][0] & 0xF8) << 7
ARGB |= (pix[x,y][1] & 0xF8) << 2
ARGB |= (pix[x,y][2] & 0xF8) >> 3
w.write(chr((ARGB >> 8) & 0xFF))
w.write(chr((ARGB >> 0) & 0xFF))
w.close()
#D8R8G8B8
w = open("Texture-D8R8G8B8.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
w.write(chr(0x00))
w.write(chr(pix[x,y][0]))
w.write(chr(pix[x,y][1]))
w.write(chr(pix[x,y][2]))
w.close()
#G8B8
w = open("Texture-G8B8.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
w.write(chr(pix[x,y][1]))
w.write(chr(pix[x,y][2]))
w.close()
#R5G5B5A1
w = open("Texture-R5G5B5A1.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
ARGB = (pix[x,y][0] & 0xF8) << 8
ARGB |= (pix[x,y][1] & 0xF8) << 3
ARGB |= (pix[x,y][2] & 0xF8) >> 2
ARGB |= (pix[x,y][3] & 0x80) >> 7
w.write(chr((ARGB >> 8) & 0xFF))
w.write(chr((ARGB >> 0) & 0xFF))
w.close()
#R5G6B5
w = open("Texture-R5G6B5.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
ARGB = (pix[x,y][0] & 0xF8) << 8
ARGB |= (pix[x,y][1] & 0xFC) << 3
ARGB |= (pix[x,y][2] & 0xF8) >> 3
w.write(chr((ARGB >> 8) & 0xFF))
w.write(chr((ARGB >> 0) & 0xFF))
w.close()
#R6G5B5
w = open("Texture-R6G5B5.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
ARGB = (pix[x,y][0] & 0xFC) << 8
ARGB |= (pix[x,y][1] & 0xF8) << 2
ARGB |= (pix[x,y][2] & 0xF8) >> 3
w.write(chr((ARGB >> 8) & 0xFF))
w.write(chr((ARGB >> 0) & 0xFF))
w.close()
#W16_Z16_Y16_X16_FLOAT
w = open("Texture-W16_Z16_Y16_X16_FLOAT.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
W = FP32toFP16(float(pix[x,y][0]/255.0))
Z = FP32toFP16(float(pix[x,y][1]/255.0))
Y = FP32toFP16(float(pix[x,y][2]/255.0))
X = FP32toFP16(float(pix[x,y][3]/255.0))
w.write(chr(W >> 8))
w.write(chr(W & 0xFF))
w.write(chr(Z >> 8))
w.write(chr(Z & 0xFF))
w.write(chr(Y >> 8))
w.write(chr(Y & 0xFF))
w.write(chr(X >> 8))
w.write(chr(X & 0xFF))
w.close()
#Y16_X16
w = open("Texture-Y16_X16.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
w.write(chr(pix[x,y][2]))
w.write('\x00')
w.write(chr(pix[x,y][3]))
w.write('\x00')
w.close()
#Y16_X16_FLOAT
w = open("Texture-Y16_X16_FLOAT.raw", "wb")
for y in range(img.size[0])[::-1]:
for x in range(img.size[1]):
Y = FP32toFP16(float(pix[x,y][2]/255.0))
X = FP32toFP16(float(pix[x,y][3]/255.0))
w.write(chr(Y >> 8))
w.write(chr(Y & 0xFF))
w.write(chr(X >> 8))
w.write(chr(X & 0xFF))
w.close()

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.