float * get_image_chunk(texture_info * tex, int xmin, int ymin, int xmax, int ymax) { int xbound; int ybound; float * image_buf = NULL; constrain_boundaries(&xmin, &ymin, &xmax, &ymax, tex->width, tex->height); xbound = xmax - xmin + 1; ybound = ymax - ymin + 1; image_buf = allocate_texture(xbound, ybound); for(int y = 0; y < ybound; y++) for(int x = 0; x < xbound; x++) { int buf_index = 4 * (x + y * xbound); int offset = calc_pixel_offset(tex, x + xmin, y + ymin); color_copy(tex->td_array + offset, image_buf + buf_index); } return image_buf; }
void MxPropSlim::initialize() { collect_quadrics(); if( boundary_weight > 0.0 ) constrain_boundaries(); is_initialized = true; }
void create_subtexture_and_sync_to_gl(image_bounds * img_bounds, texture_info * tex) { /* image vars */ int xbound, ybound; float * sub = NULL; /* make the current action's boundaries sane; left until this point because we only know height/width here */ constrain_boundaries(&img_bounds->xmin, &img_bounds->ymin, &img_bounds->xmax, &img_bounds->ymax, tex->width, tex->height); /* helper variables */ ybound = img_bounds->ymax - img_bounds->ymin + 1; xbound = img_bounds->xmax - img_bounds->xmin + 1; sub = get_image_chunk(tex, img_bounds->xmin, img_bounds->ymin, img_bounds->xmax, img_bounds->ymax); sync_to_gl(tex->tname, tex->x_offset + img_bounds->xmin, tex->y_offset + img_bounds->ymin, xbound, ybound, (void*)sub); free(sub); }
/** splice algorithm **/ void splice_do_action(int x0, int y0, int cx1, int cy1, int cx2, int cy2, texture_info * splice_tex, texture_info * tex, VALUE hash_arg, texplay_sync sync_mode, bool primary, action_struct * payload) { action_struct cur; int xbound; int ybound; rgba chromakey; float * image_buf = NULL; bool inverse_chroma = false; bool same_image = false; bool has_chroma = false; constrain_boundaries(&cx1, &cy1, &cx2, &cy2, splice_tex->width, splice_tex->height); xbound = cx2 - cx1 + 1; ybound = cy2 - cy1 + 1; draw_prologue(&cur, tex, x0, y0, x0 + xbound, y0 + ybound, &hash_arg, sync_mode, primary, &payload); if(has_optional_hash_arg(hash_arg, "chroma_key")) { VALUE c = get_from_hash(hash_arg, "chroma_key"); chromakey = convert_rb_color_to_rgba(c); has_chroma = true; } else if(has_optional_hash_arg(hash_arg, "chroma_key_not")) { chromakey = convert_rb_color_to_rgba(get_from_hash(hash_arg, "chroma_key_not")); inverse_chroma = true; has_chroma = true; } if(splice_tex->image == tex->image) same_image = true; /* NB: we do not use this in the general case since it's almost 1.5 times as slow. It is necessary for splicing from/to the same region of pixels though. */ if(same_image) image_buf = get_image_chunk(splice_tex, cx1, cy1, cx2, cy2); for(int y = 0; y < ybound; y++) for(int x = 0; x < xbound; x++) { if(!same_image) payload->color = get_pixel_color(splice_tex, cx1 + x, cy1 + y); else payload->color = get_pixel_color_from_chunk(image_buf, xbound, ybound, x, y); if(has_chroma) { bool chroma_match = cmp_color(payload->color, chromakey); /* look at released 0.2.0 code to see how USED to do this. this is now a simplified boolean expression (XOR) */ if(chroma_match == inverse_chroma) set_pixel_color_with_style(payload, tex, x0 + x, y0 + y); } else set_pixel_color_with_style(payload, tex, x0 + x, y0 + y); } if(same_image) free(image_buf); draw_epilogue(&cur, tex, primary); }