def debug_image(image, step=2): for x in range(0, image.width(), step): for y in range(0, image.height(), step): pixel = image.get_pixel(x, y) red, green, blue, alpha = pixel2channels(pixel) print "rgba(%s,%s,%s,%s) at %s,%s" % (red, green, blue, alpha, x, y)
def validate_pixels_are_not_premultiplied2(image): looks_not_multiplied = False for x in range(0,image.width(),2): for y in range(0,image.height(),2): pixel = image.get_pixel(x,y) red,green,blue,alpha = pixel2channels(pixel) #each value of the color channels will never be bigger than that of the alpha channel. if alpha > 0: if red > 0 and red > alpha: print 'red: %s, a: %s' % (red,alpha) looks_not_multiplied = True return looks_not_multiplied
def validate_pixels_are_not_premultiplied2(image): looks_not_multiplied = False for x in range(0, image.width(), 2): for y in range(0, image.height(), 2): pixel = image.get_pixel(x, y) red, green, blue, alpha = pixel2channels(pixel) #each value of the color channels will never be bigger than that of the alpha channel. if alpha > 0: if red > 0 and red > alpha: print 'red: %s, a: %s' % (red, alpha) looks_not_multiplied = True return looks_not_multiplied
def validate_pixels_are_premultiplied(image): bad_pixels = [] for x in range(0,image.width(),2): for y in range(0,image.height(),2): pixel = image.get_pixel(x,y) red,green,blue,alpha = pixel2channels(pixel) if alpha > 0: pixel = image.get_pixel(x,y) is_valid = ((0 <= red <= alpha) and is_pre(red,alpha)) \ and ((0 <= green <= alpha) and is_pre(green,alpha)) \ and ((0 <= blue <= alpha) and is_pre(blue,alpha)) \ and (alpha >= 0 and alpha <= 255) if not is_valid: bad_pixels.append("rgba(%s,%s,%s,%s) at %s,%s" % (red,green,blue,alpha,x,y)) num_bad = len(bad_pixels) return (num_bad == 0,bad_pixels)
def validate_pixels_are_not_premultiplied(image): over_alpha = False transparent = True fully_opaque = True for x in range(0,image.width(),2): for y in range(0,image.height(),2): pixel = image.get_pixel(x,y) red,green,blue,alpha = pixel2channels(pixel) if alpha > 0: transparent = False if alpha < 255: fully_opaque = False color_max = max(red,green,blue) if color_max > alpha: over_alpha = True return over_alpha or transparent or fully_opaque
def validate_pixels_are_not_premultiplied(image): over_alpha = False transparent = True fully_opaque = True for x in range(0, image.width(), 2): for y in range(0, image.height(), 2): pixel = image.get_pixel(x, y) red, green, blue, alpha = pixel2channels(pixel) if alpha > 0: transparent = False if alpha < 255: fully_opaque = False color_max = max(red, green, blue) if color_max > alpha: over_alpha = True return over_alpha or transparent or fully_opaque
def debug_image(image,step=2): for x in range(0,image.width(),step): for y in range(0,image.height(),step): pixel = image.get_pixel(x,y) red,green,blue,alpha = pixel2channels(pixel) print "rgba(%s,%s,%s,%s) at %s,%s" % (red,green,blue,alpha,x,y)