From 1df4cd2ffc5c65de2d2d154c1fba7604a0d71e00 Mon Sep 17 00:00:00 2001 From: "Marcus Str." Date: Wed, 25 Sep 2024 21:24:06 +0200 Subject: [PATCH] Implemented fix to correct alpha on final image so that DDSTool for X-Plane works correctly --- photogen.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/photogen.py b/photogen.py index 6ce11fa..c1ffeb0 100644 --- a/photogen.py +++ b/photogen.py @@ -129,6 +129,17 @@ class mstr_photogen: wp = wtr_pix[x,y] if wp[0] == 255 and wp[1] == 0 and wp[2] == 255 and wp[3] == 255: tilepix[x,y] = (0,0,0,0) + + # Alpha correction on final image + corrpix = self._tile.load() + for y in range(0, self._tile.height): + for x in range(0, self._tile.width): + c = corrpix[x,y] + if c[3] > 0: + nc = (c[0], c[1], c[2], 255) + corrpix[x,y] = nc + if c[3] == 0: + corrpix[x,y] = (0,0,0,0) # We are now in posession of the final image. @@ -172,18 +183,18 @@ class mstr_photogen: # This returns a mask of the empty space to cover, should there be any def buildCompletionMask(self): - mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,255)) - #mask_pix = mask.load() + mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,0)) + mask_pix = mask.load() # Load photo - #layer_pix = self._tile.load() + layer_pix = self._tile.load() # Scan! - #for y in range(self._tile.width-1): - # for x in range(self._tile.height-1): - # p = layer_pix[x,y] - # if p[3] < 255: # <- Check for empty or non-complete alpha - # mask_pix[x,y] = (0,0,0,255) + for y in range(self._tile.width-1): + for x in range(self._tile.height-1): + p = layer_pix[x,y] + if p[3] < 255: # <- Check for empty or non-complete alpha + mask_pix[x,y] = (0,0,0,255) # We do not apply any blur or other effects here - we only want the # exact pixel positions. -- 2.30.2