psd_status psd_layer_effects_blend_color_overlay(psd_context * context, psd_layer_record * layer, psd_layer_effects * data) { psd_layer_effects_color_overlay * color_overlay = &data->color_overlay; psd_bitmap src_bmp, dst_bmp; psd_layer_mask_info layer_mask_info; data->left[psd_layer_effects_type_color_overlay] = 0; data->top[psd_layer_effects_type_color_overlay] = 0; data->right[psd_layer_effects_type_color_overlay] = layer->width; data->bottom[psd_layer_effects_type_color_overlay] = layer->height; data->blend_mode[psd_layer_effects_type_color_overlay] = color_overlay->blend_mode; data->opacity[psd_layer_effects_type_color_overlay] = color_overlay->opacity; data->width[psd_layer_effects_type_color_overlay] = layer->width; data->height[psd_layer_effects_type_color_overlay] = layer->height; if(data->image_data[psd_layer_effects_type_color_overlay] == NULL) { data->image_data[psd_layer_effects_type_color_overlay] = (psd_argb_color *)psd_malloc(layer->width * layer->height * 4); if(data->image_data[psd_layer_effects_type_color_overlay] == NULL) return psd_status_malloc_failed; } src_bmp.width = layer->width; src_bmp.height = layer->height; src_bmp.image_data = layer->image_data; dst_bmp.width = layer->width; dst_bmp.height = layer->height; dst_bmp.image_data = data->image_data[psd_layer_effects_type_color_overlay]; psd_fill_bitmap(&dst_bmp, color_overlay->color); psd_bitmap_copy_alpha_channel(&dst_bmp, &src_bmp); memcpy(&layer_mask_info, &layer->layer_mask_info, sizeof(psd_layer_mask_info)); if(layer_mask_info.disabled == psd_false && (layer_mask_info.default_color != 255 || layer_mask_info.mask_data != NULL)) { layer_mask_info.left -= layer->left; layer_mask_info.top -= layer->top; layer_mask_info.right -= layer->left; layer_mask_info.bottom -= layer->top; psd_bitmap_blend_mask(&dst_bmp, &layer_mask_info); } data->valid[psd_layer_effects_type_color_overlay] = psd_false; return psd_status_done; }
psd_status psd_layer_effects_blend_drop_shadow(psd_context * context, psd_layer_record * layer, psd_layer_effects * data) { psd_layer_effects_drop_shadow * drop_shadow = &data->drop_shadow; psd_int width, height; psd_int angle; psd_int distance_x, distance_y; psd_bitmap src_bmp, dst_bmp, knock_bmp; psd_layer_mask_info layer_mask_info; psd_int spread_size, blur_size; if(drop_shadow->use_global_light == psd_true) angle = context->global_angle; else angle = drop_shadow->angle; distance_x = -(psd_int)(drop_shadow->distance * cos(PSD_PI * angle / 180) + 0.5); distance_y = (psd_int)(drop_shadow->distance * sin(PSD_PI * angle / 180) + 0.5); data->left[psd_layer_effects_type_drop_shadow] = -drop_shadow->size + distance_x; data->top[psd_layer_effects_type_drop_shadow] = -drop_shadow->size + distance_y; width = layer->width + drop_shadow->size * 2; height = layer->height + drop_shadow->size * 2; data->right[psd_layer_effects_type_drop_shadow] = data->left[psd_layer_effects_type_drop_shadow] + width; data->bottom[psd_layer_effects_type_drop_shadow] = data->top[psd_layer_effects_type_drop_shadow] + height; data->blend_mode[psd_layer_effects_type_drop_shadow] = drop_shadow->blend_mode; data->opacity[psd_layer_effects_type_drop_shadow] = drop_shadow->opacity; if(data->image_data[psd_layer_effects_type_drop_shadow] != NULL) { if(data->width[psd_layer_effects_type_drop_shadow] != width || data->height[psd_layer_effects_type_drop_shadow] != height) { psd_free(data->image_data[psd_layer_effects_type_drop_shadow]); data->image_data[psd_layer_effects_type_drop_shadow] = (psd_argb_color *)psd_malloc(width * height * 4); if(data->image_data[psd_layer_effects_type_drop_shadow] == NULL) return psd_status_malloc_failed; } } else { data->image_data[psd_layer_effects_type_drop_shadow] = (psd_argb_color *)psd_malloc(width * height * 4); if(data->image_data[psd_layer_effects_type_drop_shadow] == NULL) return psd_status_malloc_failed; } data->width[psd_layer_effects_type_drop_shadow] = width; data->height[psd_layer_effects_type_drop_shadow] = height; psd_color_memset(data->image_data[psd_layer_effects_type_drop_shadow], drop_shadow->color, width * height); src_bmp.width = layer->width; src_bmp.height = layer->height; src_bmp.image_data = layer->image_data; dst_bmp.width = width; dst_bmp.height = height; dst_bmp.image_data = data->image_data[psd_layer_effects_type_drop_shadow]; if(drop_shadow->size == 0) { psd_fill_bitmap(&dst_bmp, drop_shadow->color); psd_bitmap_copy_alpha_channel(&dst_bmp, &src_bmp); } else { psd_inflate_bitmap(&dst_bmp, &src_bmp, drop_shadow->size, drop_shadow->size); psd_fill_bitmap_without_alpha_channel(&dst_bmp, drop_shadow->color); } memcpy(&layer_mask_info, &layer->layer_mask_info, sizeof(psd_layer_mask_info)); if(layer_mask_info.disabled == psd_false && (layer_mask_info.default_color != 255 || layer_mask_info.mask_data != NULL)) { layer_mask_info.left -= layer->left - drop_shadow->size; layer_mask_info.top -= layer->top - drop_shadow->size; layer_mask_info.right -= layer->left - drop_shadow->size; layer_mask_info.bottom -= layer->top - drop_shadow->size; psd_bitmap_blend_mask(&dst_bmp, &layer_mask_info); } if(drop_shadow->knocks_out == psd_true) { psd_create_bitmap(&knock_bmp, width, height); psd_copy_bitmap(&knock_bmp, &dst_bmp); psd_offset_bitmap(&knock_bmp, distance_x, distance_y, psd_color_clear); } spread_size = (drop_shadow->spread * drop_shadow->size + 50) / 100; blur_size = drop_shadow->size - spread_size; if(spread_size != 0) { psd_bitmap_gaussian_blur_alpha_channel(&dst_bmp, spread_size); psd_bitmap_find_edge(&dst_bmp, psd_true); } if(blur_size != 0) { psd_bitmap_gaussian_blur_alpha_channel(&dst_bmp, blur_size); } psd_bitmap_contour_alpha_channel(&dst_bmp, drop_shadow->contour_lookup_table, drop_shadow->anti_aliased, psd_true); if(drop_shadow->noise > 0) { psd_effects_add_noise(&dst_bmp, drop_shadow->noise, data->left[psd_layer_effects_type_drop_shadow] + layer->left, data->top[psd_layer_effects_type_drop_shadow] + layer->top, context); } if(drop_shadow->knocks_out == psd_true) { psd_bitmap_knock_out(&dst_bmp, &knock_bmp); psd_free_bitmap(&knock_bmp); } data->valid[psd_layer_effects_type_drop_shadow] = psd_false; return psd_status_done; }
psd_status psd_layer_effects_blend_inner_glow(psd_context * context, psd_layer_record * layer, psd_layer_effects * data) { psd_layer_effects_inner_glow * inner_glow = &data->inner_glow; psd_int width, height; psd_bitmap src_bmp, dst_bmp, knock_bmp; psd_layer_mask_info layer_mask_info; psd_int choke_size, blur_size; psd_argb_color gradient_table[256]; data->left[psd_layer_effects_type_inner_glow] = -inner_glow->size; data->top[psd_layer_effects_type_inner_glow] = -inner_glow->size; width = layer->width + inner_glow->size * 2; height = layer->height + inner_glow->size * 2; data->right[psd_layer_effects_type_inner_glow] = data->left[psd_layer_effects_type_inner_glow] + width; data->bottom[psd_layer_effects_type_inner_glow] = data->top[psd_layer_effects_type_inner_glow] + height; data->blend_mode[psd_layer_effects_type_inner_glow] = inner_glow->blend_mode; data->opacity[psd_layer_effects_type_inner_glow] = inner_glow->opacity; if(data->image_data[psd_layer_effects_type_inner_glow] != NULL) { if(data->width[psd_layer_effects_type_inner_glow] != width || data->height[psd_layer_effects_type_inner_glow] != height) { psd_free(data->image_data[psd_layer_effects_type_inner_glow]); data->image_data[psd_layer_effects_type_inner_glow] = (psd_argb_color *)psd_malloc(width * height * 4); if(data->image_data[psd_layer_effects_type_inner_glow] == NULL) return psd_status_malloc_failed; } } else { data->image_data[psd_layer_effects_type_inner_glow] = (psd_argb_color *)psd_malloc(width * height * 4); if(data->image_data[psd_layer_effects_type_inner_glow] == NULL) return psd_status_malloc_failed; } data->width[psd_layer_effects_type_inner_glow] = width; data->height[psd_layer_effects_type_inner_glow] = height; psd_color_memset(data->image_data[psd_layer_effects_type_inner_glow], inner_glow->color, width * height); src_bmp.width = layer->width; src_bmp.height = layer->height; src_bmp.image_data = layer->image_data; dst_bmp.width = width; dst_bmp.height = height; dst_bmp.image_data = data->image_data[psd_layer_effects_type_inner_glow]; if(inner_glow->size == 0) { psd_fill_bitmap(&dst_bmp, inner_glow->color); psd_bitmap_copy_alpha_channel(&dst_bmp, &src_bmp); } else { psd_inflate_bitmap(&dst_bmp, &src_bmp, inner_glow->size, inner_glow->size); psd_fill_bitmap_without_alpha_channel(&dst_bmp, inner_glow->color); } memcpy(&layer_mask_info, &layer->layer_mask_info, sizeof(psd_layer_mask_info)); if(layer_mask_info.disabled == psd_false && (layer_mask_info.default_color != 255 || layer_mask_info.mask_data != NULL)) { layer_mask_info.left -= layer->left - inner_glow->size; layer_mask_info.top -= layer->top - inner_glow->size; layer_mask_info.right -= layer->left - inner_glow->size; layer_mask_info.bottom -= layer->top - inner_glow->size; psd_bitmap_blend_mask(&dst_bmp, &layer_mask_info); } psd_bitmap_reverse_alpha_channel(&dst_bmp); psd_create_bitmap(&knock_bmp, width, height); psd_copy_bitmap(&knock_bmp, &dst_bmp); if(inner_glow->technique == psd_technique_precise) psd_bitmap_find_edge(&dst_bmp, psd_false); choke_size = (inner_glow->choke * inner_glow->size + 50) / 100; blur_size = inner_glow->size - choke_size; if(choke_size != 0) { psd_bitmap_gaussian_blur_alpha_channel(&dst_bmp, choke_size); psd_bitmap_find_edge(&dst_bmp, psd_false); } if(blur_size != 0) { psd_bitmap_gaussian_blur_alpha_channel(&dst_bmp, blur_size); } psd_bitmap_ajust_range(&dst_bmp, inner_glow->range); if(inner_glow->source == psd_glow_center) psd_bitmap_reverse_alpha_channel(&dst_bmp); psd_bitmap_contour_alpha_channel(&dst_bmp, inner_glow->contour_lookup_table, inner_glow->anti_aliased, psd_false); if(inner_glow->noise > 0) { psd_effects_add_noise(&dst_bmp, inner_glow->noise, data->left[psd_layer_effects_type_inner_glow] + layer->left, data->top[psd_layer_effects_type_inner_glow] + layer->top, context); } if(inner_glow->fill_type == psd_fill_gradient) { psd_gradient_color_get_table(&inner_glow->gradient_color, gradient_table, 256, psd_false); psd_effects_apply_gradient(&dst_bmp, gradient_table, psd_false, inner_glow->jitter, data->left[psd_layer_effects_type_inner_glow] + layer->left, data->top[psd_layer_effects_type_inner_glow] + layer->top, context); } psd_bitmap_knock_out(&dst_bmp, &knock_bmp); psd_free_bitmap(&knock_bmp); data->valid[psd_layer_effects_type_inner_glow] = psd_false; return psd_status_done; }