Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching for python script islands to layers
#21
Suggestions:

Code:
tile_cols = int(layer.height / 64)
   if(layer.width % 64 > 0):
       tile_cols += 1

Better written as:
Code:
tile_cols = int( (layer.height+63) / 64)

And:
Code:
pixel = srcTile[tile_x, tile_y]
# if pixel is not completely transparent
if ord( pixel[3] ) > 0:

can be:

Code:
R,G,B,A = srcTile[tile_x, tile_y]
# if pixel is not completely transparent
if ord( A) > 0:
or even:
Code:
R,G,B,A = [ord(c) for c in srcTile[tile_x, tile_y]]
# if pixel is not completely transparent
if A > 0:

Did you try tile.flush() (see https://www.gimp.org/docs/python/index.html)?

Now, the real problem with your code is that you are using fuzzy select (that selects on color) when you should really be selecting on opacity. There may be corner cases where this won't work (for instance, if your drawable has all pixels with identical RGB, the only difference being the alpha value). pdb.gimp_fuzzy_select() is deprecated and replaced by two more recent calls that seem to allow to include opacity in the selection criteria. You should look into this.
Reply


Messages In This Thread
RE: Searching for python script islands to layers - by Ofnuts - 01-24-2018, 05:36 PM

Forum Jump: