Add png_compress to the model pipeline and update TownSquare lighting plus MaleExplorer/plaza textures. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
1005 B
Python
32 lines
1005 B
Python
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from png_compress import compress_png
|
|
|
|
|
|
class CompressPngTests(unittest.TestCase):
|
|
def test_pixels_unchanged_and_smaller(self):
|
|
from PIL import Image
|
|
|
|
w = h = 64
|
|
pixels = [(40, 80, 120, 255)] * (w * h)
|
|
with tempfile.TemporaryDirectory() as d:
|
|
path = os.path.join(d, "a.png")
|
|
im = Image.new("RGBA", (w, h))
|
|
im.putdata(pixels)
|
|
im.save(path, format="PNG", compress_level=0, optimize=False)
|
|
before = os.path.getsize(path)
|
|
src_bytes = list(Image.open(path).getdata())
|
|
sizes = compress_png(path)
|
|
after_im = Image.open(path)
|
|
self.assertEqual(list(after_im.getdata()), src_bytes)
|
|
self.assertLess(sizes["after"], before)
|
|
self.assertEqual(sizes["before"], before)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|