|
|
|
@ -168,13 +168,31 @@ vips_init_image(void *buf, size_t len, int imageType, VipsImage **out) {
|
|
|
|
return code;
|
|
|
|
return code;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
|
|
vips_watermark_replicate(VipsImage *orig, VipsImage *in, VipsImage **out)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
VipsImage *cache = vips_image_new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
vips_replicate(in, &cache,
|
|
|
|
|
|
|
|
1 + orig->Xsize / in->Xsize,
|
|
|
|
|
|
|
|
1 + orig->Ysize / in->Ysize, NULL) ||
|
|
|
|
|
|
|
|
vips_crop(cache, out, 0, 0, orig->Xsize, orig->Ysize, NULL)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
g_object_unref(cache);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
vips_watermark(VipsImage *in, VipsImage **out, watermarkTextOptions *to, watermarkOptions *o)
|
|
|
|
vips_watermark(VipsImage *in, VipsImage **out, watermarkTextOptions *to, watermarkOptions *o)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double ones[3] = { 1, 1, 1 };
|
|
|
|
double ones[3] = { 1, 1, 1 };
|
|
|
|
|
|
|
|
|
|
|
|
VipsImage *base = vips_image_new();
|
|
|
|
VipsImage *base = vips_image_new();
|
|
|
|
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 12);
|
|
|
|
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 10);
|
|
|
|
t[0] = in;
|
|
|
|
t[0] = in;
|
|
|
|
|
|
|
|
|
|
|
|
// Make the mask.
|
|
|
|
// Make the mask.
|
|
|
|
@ -189,38 +207,39 @@ vips_watermark(VipsImage *in, VipsImage **out, watermarkTextOptions *to, waterma
|
|
|
|
vips_embed(t[3], &t[4], 100, 100, t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
|
|
|
|
vips_embed(t[3], &t[4], 100, 100, t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
g_object_unref(base);
|
|
|
|
g_object_unref(base);
|
|
|
|
return (1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Replicate if necessary
|
|
|
|
// Replicate if necessary
|
|
|
|
if (o->NoReplicate != 1 && (
|
|
|
|
if (o->NoReplicate != 1) {
|
|
|
|
vips_replicate(t[4], &t[5],
|
|
|
|
VipsImage *cache = vips_image_new();
|
|
|
|
1 + t[0]->Xsize / t[4]->Xsize,
|
|
|
|
if (vips_watermark_replicate(t[0], t[4], &cache)) {
|
|
|
|
1 + t[0]->Ysize / t[4]->Ysize, NULL) ||
|
|
|
|
g_object_unref(cache);
|
|
|
|
vips_crop(t[5], &t[6], 0, 0, t[0]->Xsize, t[0]->Ysize, NULL))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
g_object_unref(base);
|
|
|
|
g_object_unref(base);
|
|
|
|
return (1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref(t[4]);
|
|
|
|
|
|
|
|
t[4] = cache;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make the constant image to paint the text with.
|
|
|
|
// Make the constant image to paint the text with.
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
vips_black(&t[7], 1, 1, NULL) ||
|
|
|
|
vips_black(&t[5], 1, 1, NULL) ||
|
|
|
|
vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) ||
|
|
|
|
vips_linear(t[5], &t[6], ones, o->Background, 3, NULL) ||
|
|
|
|
vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) ||
|
|
|
|
vips_cast(t[6], &t[7], VIPS_FORMAT_UCHAR, NULL) ||
|
|
|
|
vips_copy(t[9], &t[10], "interpretation", t[0]->Type, NULL) ||
|
|
|
|
vips_copy(t[7], &t[8], "interpretation", t[0]->Type, NULL) ||
|
|
|
|
vips_embed(t[10], &t[11], 0, 0, t[0]->Xsize, t[0]->Ysize, "extend", VIPS_EXTEND_COPY, NULL)
|
|
|
|
vips_embed(t[8], &t[9], 0, 0, t[0]->Xsize, t[0]->Ysize, "extend", VIPS_EXTEND_COPY, NULL)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
g_object_unref(base);
|
|
|
|
g_object_unref(base);
|
|
|
|
return (1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Blend the mask and text and write to output.
|
|
|
|
// Blend the mask and text and write to output.
|
|
|
|
if (vips_ifthenelse(t[6], t[11], t[0], out, "blend", TRUE, NULL)) {
|
|
|
|
if (vips_ifthenelse(t[4], t[9], t[0], out, "blend", TRUE, NULL)) {
|
|
|
|
g_object_unref(base);
|
|
|
|
g_object_unref(base);
|
|
|
|
return (1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_object_unref(base);
|
|
|
|
g_object_unref(base);
|
|
|
|
return (0);
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|