The latest version of this document can be found at www.broad.ology.org.uk/amiga/sketchblock/fadeyellow_py.html
1: # filter yellow pixels make them parially transparent 2: 3: # License: You may use this code modified or otherwise as part of you own scripts 4: # Copyright: Andy Broad 2013. 5: 6: import arexx 7: 8: # Get info on the layer, this simple script simply operates on the currently active layer. 9: 10: (rc,rc2,layerWidth) = arexx.dorexx("SKETCHBLOCK","GETLAYERINFO ATTR "WIDTH"") 11: (rc,rc2,layerHeight) = arexx.dorexx("SKETCHBLOCK","GETLAYERINFO ATTR "HEIGHT"") 12: 13: #iterate over the pixel rows 14: 15: for y in xrange(0, int(layerHeight)): 16: 17: #iterate over the pixel coulmns 18: 19: for x in xrange(0,int(layerWidth)): 20: 21: # this is an easy way to build the pixel coordinate as a string 22: # that can be used to build multiple commands. 23: 24: pixelCoord = " X " + str(x) + " Y " + str(y) 25: 26: # fetch the pixel color data as floats expressed as strings 27: 28: (rc,rc2,pixel) = arexx.dorexx("SKETCHBLOCK","GETPIXEL " + pixelCoord) 29: 30: # split the result string and convert to floating point numbers 31: 32: channels = pixel.split(" ") 33: a = float(channels[0]) 34: r = float(channels[1]) 35: g = float(channels[2]) 36: b = float(channels[3]) 37: 38: # a simple algorithm for determiing the yellowness of a pixel 39: 40: if r < g: 41: yellow = r 42: else: 43: yellow = g 44: 45: yellow = yellow - b 46: 47: if yellow > 0.0: 48: 49: # calculate the new alpha value 50: a = a * ( 0.5 + 0.5 * (1.0 - yellow)) 51: 52: # write it back to the pixel, we only want to change the alpha channel 53: # so we only need to write the alpha data 54: # NOTE: the reuse of the pixelCoord string created above. 55: 56: (rc,rc2,dummy) = arexx.dorexx("SKETCHBLOCK","SETPIXEL " + pixelCoord + " A " + str(a)) 57: 58: # update the display of the process project. 59: 60: arexx.dorexx("SKETCHBLOCK","DISPLAYPROJECT") 61: 62: 63: 64: 65: