mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Drop vips_ensure_alpha; Refactor vips_apply_watermark
This commit is contained in:
parent
3902155170
commit
dda20f1a1d
43
vips/vips.c
43
vips/vips.c
@ -510,54 +510,51 @@ vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height) {
|
||||
|
||||
int
|
||||
vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height) {
|
||||
VipsImage *tmp;
|
||||
VipsImage *tmp = NULL;
|
||||
|
||||
if (!vips_image_hasalpha(in)) {
|
||||
if (vips_bandjoin_const1(in, &tmp, 255, NULL))
|
||||
return 1;
|
||||
|
||||
in = tmp;
|
||||
}
|
||||
|
||||
int ret =
|
||||
vips_ensure_alpha(in, &tmp) ||
|
||||
vips_embed(tmp, out, x, y, width, height, "extend", VIPS_EXTEND_BLACK, NULL);
|
||||
vips_embed(in, out, x, y, width, height, "extend", VIPS_EXTEND_BLACK, NULL);
|
||||
|
||||
clear_image(&tmp);
|
||||
if (tmp) clear_image(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
vips_ensure_alpha(VipsImage *in, VipsImage **out) {
|
||||
if (vips_image_hasalpha(in))
|
||||
return vips_copy(in, out, NULL);
|
||||
|
||||
return vips_bandjoin_const1(in, out, 255, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, double opacity) {
|
||||
VipsImage *base = vips_image_new();
|
||||
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 6);
|
||||
|
||||
if (vips_ensure_alpha(watermark, &t[0])) {
|
||||
clear_image(&base);
|
||||
return 1;
|
||||
if (!vips_image_hasalpha(watermark)) {
|
||||
if (vips_bandjoin_const1(watermark, &t[0], 255, NULL))
|
||||
return 1;
|
||||
|
||||
watermark = t[0];
|
||||
}
|
||||
|
||||
if (opacity < 1) {
|
||||
if (
|
||||
vips_extract_band(t[0], &t[1], 0, "n", t[0]->Bands - 1, NULL) ||
|
||||
vips_extract_band(t[0], &t[2], t[0]->Bands - 1, "n", 1, NULL) ||
|
||||
vips_extract_band(watermark, &t[1], 0, "n", watermark->Bands - 1, NULL) ||
|
||||
vips_extract_band(watermark, &t[2], watermark->Bands - 1, "n", 1, NULL) ||
|
||||
vips_linear1(t[2], &t[3], opacity, 0, NULL) ||
|
||||
vips_bandjoin2(t[1], t[3], &t[4], NULL)
|
||||
) {
|
||||
clear_image(&base);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (vips_copy(t[0], &t[4], NULL)) {
|
||||
clear_image(&base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
watermark = t[4];
|
||||
}
|
||||
|
||||
int res =
|
||||
vips_composite2(in, t[4], &t[5], VIPS_BLEND_MODE_OVER, "compositing_space", in->Type, NULL) ||
|
||||
vips_composite2(in, watermark, &t[5], VIPS_BLEND_MODE_OVER, "compositing_space", in->Type, NULL) ||
|
||||
vips_cast(t[5], out, vips_image_get_format(in), NULL);
|
||||
|
||||
clear_image(&base);
|
||||
|
11
vips/vips.go
11
vips/vips.go
@ -553,17 +553,6 @@ func (img *Image) Trim(threshold float64, smart bool, color Color, equalHor bool
|
||||
return nil
|
||||
}
|
||||
|
||||
func (img *Image) EnsureAlpha() error {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_ensure_alpha(img.VipsImage, &tmp) != 0 {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (img *Image) Flatten(bg Color) error {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
|
@ -67,8 +67,6 @@ int vips_flatten_go(VipsImage *in, VipsImage **out, double r, double g, double b
|
||||
int vips_replicate_go(VipsImage *in, VipsImage **out, int across, int down);
|
||||
int vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height);
|
||||
|
||||
int vips_ensure_alpha(VipsImage *in, VipsImage **out);
|
||||
|
||||
int vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, double opacity);
|
||||
|
||||
int vips_arrayjoin_go(VipsImage **in, VipsImage **out, int n);
|
||||
|
Loading…
Reference in New Issue
Block a user