Add a parameter to allow saving RGB PNGs

This commit is contained in:
baldurk
2019-05-06 15:57:02 +01:00
parent 7db90232f9
commit 5c28bd0a31
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -105,13 +105,13 @@ def sanitise_filename(name: str):
return re.sub('^/', '', name)
def png_save(out_path: str, rows: List[bytes], dimensions: Tuple[int, int]):
def png_save(out_path: str, rows: List[bytes], dimensions: Tuple[int, int], has_alpha: bool):
try:
f = open(out_path, 'wb')
except Exception as ex:
raise FileNotFoundError("Can't open {} for write".format(sanitise_filename(out_path)))
writer = png.Writer(dimensions[0], dimensions[1], alpha=True, greyscale=False, compression=7)
writer = png.Writer(dimensions[0], dimensions[1], alpha=has_alpha, greyscale=False, compression=7)
writer.write(f, rows)
f.close()
@@ -165,7 +165,7 @@ def png_compare(test_img: str, ref_img: str, tolerance: int = 2):
if os.path.exists(diff_file):
os.remove(diff_file)
png_save(diff_file, diff_data, (test_w, test_h))
png_save(diff_file, diff_data, (test_w, test_h), True)
return False
@@ -126,8 +126,8 @@ class VK_Sample_Locations(rdtest.TestCase):
degenerate.append(combined_data[row][0:len])
rotated.append(combined_data[row][len:])
rdtest.png_save(degenerate_path, degenerate, halfdim)
rdtest.png_save(rotated_path, rotated, halfdim)
rdtest.png_save(degenerate_path, degenerate, halfdim, True)
rdtest.png_save(rotated_path, rotated, halfdim, True)
# first two degenerate images should be identical, as should the last two, and they should be different.
if not rdtest.png_compare(degenerate_paths[0], degenerate_paths[1], 0):