bool MCRegionTransform(MCRegionRef p_region, const MCGAffineTransform &p_transform, MCRegionRef &r_transformed_region) { bool t_success; t_success = true; MCRegionRef t_new_region; t_new_region = nil; t_success = MCRegionCreate(t_new_region); if (t_success) { MCRegionTransformContext t_context; t_context.region = t_new_region; t_context.transform = p_transform; t_success = MCRegionForEachRect(p_region, MCRegionTransformCallback, &t_context); } if (t_success) r_transformed_region = t_new_region; else MCRegionDestroy(t_new_region); return t_success; }
bool MCWin32ApplyMaskToRasterRegion(MCGRaster &p_raster, uint32_t p_x_origin, uint32_t p_y_origin, const MCGRaster &p_mask, MCRegionRef p_region) { // IM-2013-09-11: [[ ResIndependence ]] reduce mask params to single MCGRaster bool t_success; t_success = true; MCGContextRef t_gcontext; t_gcontext = nil; if (t_success) t_success = MCGContextCreateWithRaster(p_raster, t_gcontext); MCGImageRef t_mask_image; t_mask_image = nil; if (t_success) t_success = MCGImageCreateWithRasterNoCopy(p_mask, t_mask_image); if (t_success) { // IM-2013-09-11: [[ ResIndependence ]] Apply scaled mask to target raster. // Drawing the mask directly will not work as the effective shape of the drawing operation // will be defined by the opaque parts of the mask - areas outside will be unaffected. Instead we // draw a solid rectangle over the intended areas using the mask as a pattern. MCGFloat t_scale; t_scale = MCResGetPixelScale(); MCGContextSetFillPattern(t_gcontext, t_mask_image, MCGAffineTransformMakeScale(t_scale, t_scale), kMCGImageFilterNearest); MCGContextTranslateCTM(t_gcontext, -(MCGFloat)p_x_origin, -(MCGFloat)p_y_origin); MCGContextSetBlendMode(t_gcontext, kMCGBlendModeDestinationIn); t_success = MCRegionForEachRect(p_region, __MCApplyMaskCallback, t_gcontext); } MCGImageRelease(t_mask_image); MCGContextRelease(t_gcontext); return t_success; }