def parse_crop(crop, xy_image, xy_window):
x_alias_percent = {<EOL>'<STR_LIT:left>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:right>': '<STR_LIT>',<EOL>}<EOL>y_alias_percent = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>xy_crop = crop.split('<STR_LIT:U+0020>')<EOL>if len(xy_crop) == <NUM_LIT:1>:<EOL><INDENT>if crop in x_alias_percent:<EOL><INDENT>x_crop = x_alias_percent[crop]<EOL>y_crop = '<STR_LIT>'<EOL><DEDENT>elif crop in y_alias_percent:<EOL><INDENT>y_crop = y_alias_percent[crop]<EOL>x_crop = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>x_crop, y_crop = crop, crop<EOL><DEDENT><DEDENT>elif len(xy_crop) == <NUM_LIT:2>:<EOL><INDENT>x_crop, y_crop = xy_crop<EOL>x_crop = x_alias_percent.get(x_crop, x_crop)<EOL>y_crop = y_alias_percent.get(y_crop, y_crop)<EOL><DEDENT>else:<EOL><INDENT>raise ThumbnailParseError('<STR_LIT>' % crop)<EOL><DEDENT>def get_offset(crop, epsilon):<EOL><INDENT>m = bgpos_pat.match(crop)<EOL>if not m:<EOL><INDENT>raise ThumbnailParseError('<STR_LIT>' % crop)<EOL><DEDENT>value = int(m.group('<STR_LIT:value>'))  <EOL>unit = m.group('<STR_LIT>')<EOL>if unit == '<STR_LIT:%>':<EOL><INDENT>value = epsilon * value / <NUM_LIT><EOL><DEDENT>return int(max(<NUM_LIT:0>, min(value, epsilon)))<EOL><DEDENT>offset_x = get_offset(x_crop, xy_image[<NUM_LIT:0>] - xy_window[<NUM_LIT:0>])<EOL>offset_y = get_offset(y_crop, xy_image[<NUM_LIT:1>] - xy_window[<NUM_LIT:1>])<EOL>return offset_x, offset_y<EOL>
Returns x, y offsets for cropping. The window area should fit inside
image but it works out anyway