]> marstr Code Repo - marstr/orthographic.git/commitdiff
Made sure generated patches are not bigger than the ortho itself
authorMarcus Str. <marcus@marstr.online>
Wed, 18 Dec 2024 09:37:16 +0000 (10:37 +0100)
committerMarcus Str. <marcus@marstr.online>
Wed, 18 Dec 2024 09:37:16 +0000 (10:37 +0100)
layergen.py
photogen.py

index fc2db4ec117606dd1f3805f3223411e370ee429c..5f6aa96bbec941d43156498f805a60eae32b720e 100644 (file)
@@ -387,6 +387,11 @@ class mstr_layergen:
                     pick = randrange(0, len(masks))\r
                     patchmask = Image.open(masks[pick])\r
                     patchmask = patchmask.rotate(randrange(0, 360), expand=True)\r
+\r
+                    # Make sure patch is within bounds\r
+                    if patchmask.width > self._imgsize or patchmask.height > self._imgsize:\r
+                        patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR)\r
+\r
                     patchpix = patchmask.load()\r
                     # Pick from possible tags and values for the patches\r
                     numbers = list(range(1, 16))\r
index ce2decf617f3fcc83a393d287e3d531747b29160..17b6b0fccc1975042ef479df72c82dd1dba66813 100644 (file)
@@ -126,6 +126,11 @@ class mstr_photogen:
                 pick = randrange(0, len(masks))\r
                 patchmask = Image.open(masks[pick])\r
                 patchmask = patchmask.rotate(randrange(0, 360), expand=True)\r
+\r
+                # Make sure patch is within bounds\r
+                if patchmask.width > self._tile.width or patchmask.height > self._tile.height:\r
+                    patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR)\r
+\r
                 patchpix = patchmask.load()\r
 \r
                 # Pick from possible tags and values for the patches\r