VALUE delete_from_hash(VALUE hash, char * sym) { if(TYPE(hash) != T_HASH) rb_raise(rb_eArgError, "hash argument expected"); return rb_hash_delete(hash, string2sym(sym)); }
static VALUE frametype_name(VALUE flag) { switch (flag & VM_FRAME_MAGIC_MASK) { case VM_FRAME_MAGIC_METHOD: return string2sym("method"); case VM_FRAME_MAGIC_BLOCK: return string2sym("block"); case VM_FRAME_MAGIC_CLASS: return string2sym("class"); case VM_FRAME_MAGIC_TOP: return string2sym("top"); case VM_FRAME_MAGIC_FINISH: return string2sym("finish"); case VM_FRAME_MAGIC_CFUNC: return string2sym("cfunc"); case VM_FRAME_MAGIC_PROC: return string2sym("proc"); case VM_FRAME_MAGIC_IFUNC: return string2sym("ifunc"); case VM_FRAME_MAGIC_EVAL: return string2sym("eval"); case VM_FRAME_MAGIC_LAMBDA: return string2sym("lambda"); default: rb_raise(rb_eRuntimeError, "Unknown frame type! got flag: %d", FIX2INT(flag)); } }
VALUE set_hash_value(VALUE hash, char * sym, VALUE val) { if(TYPE(hash) != T_HASH) rb_raise(rb_eArgError, "hash argument expected"); rb_hash_aset(hash, string2sym(sym), val); return val; }
static void prepare_alpha_blend(action_struct * cur) { if(has_optional_hash_arg(cur->hash_arg, "alpha_blend")) { VALUE blend_mode = get_from_hash(cur->hash_arg, "alpha_blend"); /* true is equivalent to default blend mode, 'source' */ if(blend_mode == Qtrue) blend_mode = string2sym("source"); /* where false or nil is passed */ if(!RTEST(blend_mode)) { cur->pen.alpha_blend = false; return; } cur->pen.alpha_blend = true; Check_Type(blend_mode, T_SYMBOL); if(blend_mode == string2sym("source")) { cur->pen.alpha_blend_mode = source; } else if(blend_mode == string2sym("dest")) { cur->pen.alpha_blend_mode = dest; } else if(blend_mode == string2sym("source_with_fixed_alpha")) { cur->pen.alpha_blend_mode = source_with_fixed_alpha; } else if(blend_mode == string2sym("dest_with_fixed_alpha")) { cur->pen.alpha_blend_mode = dest_with_fixed_alpha; } else rb_raise(rb_eArgError, "unrecognized blend mode: %s\n.", sym2string(blend_mode)); } }
static void prepare_drawing_mode(action_struct * cur) { if(is_a_hash(cur->hash_arg)) { /* drawing mode */ if(has_optional_hash_arg(cur->hash_arg, "mode")) { cur->pen.has_drawing_mode = true; VALUE draw_mode = get_from_hash(cur->hash_arg, "mode"); Check_Type(draw_mode, T_SYMBOL); if(draw_mode == string2sym("default")) { cur->pen.has_drawing_mode = false; return; } else if(draw_mode == string2sym("clear")) cur->pen.drawing_mode = clear; else if(draw_mode == string2sym("copy")) cur->pen.drawing_mode = copy; else if(draw_mode == string2sym("noop")) cur->pen.drawing_mode = noop; else if(draw_mode == string2sym("set")) cur->pen.drawing_mode = set; else if(draw_mode == string2sym("copy_inverted")) cur->pen.drawing_mode = copy_inverted; else if(draw_mode == string2sym("invert")) cur->pen.drawing_mode = invert; else if(draw_mode == string2sym("and_reverse")) cur->pen.drawing_mode = and_reverse; else if(draw_mode == string2sym("and")) cur->pen.drawing_mode = and; else if(draw_mode == string2sym("or")) cur->pen.drawing_mode = or; else if(draw_mode == string2sym("nand")) cur->pen.drawing_mode = nand; else if(draw_mode == string2sym("nor")) cur->pen.drawing_mode = nor; else if(draw_mode == string2sym("xor")) cur->pen.drawing_mode = xor; else if(draw_mode == string2sym("equiv")) cur->pen.drawing_mode = equiv; else if(draw_mode == string2sym("and_inverted")) cur->pen.drawing_mode = and_inverted; else if(draw_mode == string2sym("or_inverted")) cur->pen.drawing_mode = or_inverted; else if(draw_mode == string2sym("additive")) cur->pen.drawing_mode = additive; else if(draw_mode == string2sym("multiply")) cur->pen.drawing_mode = multiply; else if(draw_mode == string2sym("screen")) cur->pen.drawing_mode = screen; else if(draw_mode == string2sym("overlay")) cur->pen.drawing_mode = overlay; else if(draw_mode == string2sym("darken")) cur->pen.drawing_mode = darken; else if(draw_mode == string2sym("lighten")) cur->pen.drawing_mode = lighten; else if(draw_mode == string2sym("color_dodge")) cur->pen.drawing_mode = color_dodge; else if(draw_mode == string2sym("color_burn")) cur->pen.drawing_mode = color_burn; else if(draw_mode == string2sym("hard_light")) cur->pen.drawing_mode = hard_light; else if(draw_mode == string2sym("soft_light")) cur->pen.drawing_mode = soft_light; else if(draw_mode == string2sym("difference")) cur->pen.drawing_mode = difference; else if(draw_mode == string2sym("exclusion")) cur->pen.drawing_mode = exclusion; else rb_raise(rb_eArgError, "unrecognized drawing mode: %s\n.", sym2string(draw_mode)); } } }
/* TODO: fix this function below, it's too ugly and bulky and weird **/ static void process_common_hash_args(action_struct * cur, VALUE * hash_arg, sync_ sync_mode, bool primary) { VALUE user_defaults; VALUE hash_blend; /* if a hash doesn't exist then create one */ if(!is_a_hash(*hash_arg)) *hash_arg = rb_hash_new(); /* init the action to default values */ initialize_action_struct(cur, *hash_arg, sync_mode); /* get the user default options & merge with given options */ user_defaults = get_image_local(cur->tex->image, USER_DEFAULTS); hash_blend = rb_funcall(user_defaults, rb_intern("merge"), 1, *hash_arg); rb_funcall(*hash_arg, rb_intern("merge!"), 1, hash_blend); if(has_optional_hash_arg(*hash_arg, "color")) { VALUE c = get_from_hash(*hash_arg, "color"); cur->color = convert_rb_color_to_rgba(c); if(c == string2sym("random")) { set_hash_value(*hash_arg, "color", convert_rgba_to_rb_color(&cur->color)); } } /* shadows */ if(RTEST(get_from_hash(*hash_arg, "shadow"))) { cur->pen.color_mult.red = 0.66; cur->pen.color_mult.green = 0.66; cur->pen.color_mult.blue = 0.66; cur->pen.color_mult.alpha = 1; cur->pen.has_color_control_transform = true; } /* tolerance */ if(RTEST(get_from_hash(*hash_arg, "tolerance"))) { cur->pen.tolerance = NUM2DBL(get_from_hash(*hash_arg, "tolerance")); /* maximum length of hypotonese extended in 4-space (color space) is sqrt(4) */ if (cur->pen.tolerance >= 2) cur->pen.tolerance = 2; if (cur->pen.tolerance < 0) cur->pen.tolerance = 0; cur->pen.has_tolerance = true; } /* lerp */ if(RTEST(get_from_hash(*hash_arg, "lerp"))) { cur->pen.lerp = NUM2DBL(get_from_hash(*hash_arg, "lerp")); /* bounds */ if(cur->pen.lerp > 1.0) cur->pen.lerp = 1.0; if(cur->pen.lerp < 0.0) cur->pen.lerp = 0.0; cur->pen.has_lerp = true; } /* sync mode */ if(has_optional_hash_arg(*hash_arg, "sync_mode")) { VALUE user_sync_mode = get_from_hash(*hash_arg, "sync_mode"); Check_Type(user_sync_mode, T_SYMBOL); if(user_sync_mode == string2sym("lazy_sync")) cur->sync_mode = lazy_sync; else if(user_sync_mode == string2sym("eager_sync")) cur->sync_mode = eager_sync; else if(user_sync_mode == string2sym("no_sync")) cur->sync_mode = no_sync; else rb_raise(rb_eArgError, "unrecognized sync mode: %s\n. Allowable modes are " ":lazy_sync, :eager_sync, :no_sync.", sym2string(user_sync_mode)); delete_from_hash(*hash_arg, "sync_mode"); } /* prepare color selection */ prepare_color_select(cur); /* process drawing mode */ prepare_drawing_mode(cur); /* process the color_control block or transform (if there is one) */ prepare_color_control(cur); /* process the filling texture (if there is one) */ prepare_fill_texture(cur); /* does the user want to blend alpha values ? */ prepare_alpha_blend(cur); }