refactor(vips.h)

master
Tomas Aparicio 11 years ago
parent 6f5f7ff644
commit b55834edf2

111
vips.h

@ -171,63 +171,56 @@ vips_init_image(void *buf, size_t len, int imageType, VipsImage **out) {
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), 12);
t[0] = in; t[0] = in;
// Make the mask. // Make the mask.
if ( if (
vips_text(&t[1], to->Text, vips_text(&t[1], to->Text,
"width", o->Width, "width", o->Width,
"dpi", o->DPI, "dpi", o->DPI,
"font", to->Font, "font", to->Font,
NULL) || NULL) ||
vips_linear1(t[1], &t[2], o->Opacity, 0.0, NULL) || vips_linear1(t[1], &t[2], o->Opacity, 0.0, NULL) ||
vips_cast(t[2], &t[3], VIPS_FORMAT_UCHAR, NULL) || vips_cast(t[2], &t[3], VIPS_FORMAT_UCHAR, NULL) ||
vips_embed(t[3], &t[4], 100, 100, vips_embed(t[3], &t[4], 100, 100, t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
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],
vips_replicate(t[4], &t[5], 1 + t[0]->Xsize / t[4]->Xsize,
1 + t[0]->Xsize / t[4]->Xsize, 1 + t[0]->Ysize / t[4]->Ysize, NULL) ||
1 + t[0]->Ysize / t[4]->Ysize, NULL) || vips_crop(t[5], &t[6], 0, 0, t[0]->Xsize, t[0]->Ysize, NULL))
vips_crop(t[5], &t[6], 0, 0, ) {
t[0]->Xsize, t[0]->Ysize, NULL) g_object_unref(base);
)) { return (1);
g_object_unref(base); }
return (1);
} // Make the constant image to paint the text with.
if (
// Make the constant image to paint the text with. vips_black(&t[7], 1, 1, NULL) ||
if ( vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) ||
vips_black(&t[7], 1, 1, NULL) || vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) ||
vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) || vips_copy(t[9], &t[10], "interpretation", t[0]->Type, NULL) ||
vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) || vips_embed(t[10], &t[11], 0, 0, t[0]->Xsize, t[0]->Ysize, "extend", VIPS_EXTEND_COPY, NULL)
vips_copy(t[9], &t[10], ) {
"interpretation", t[0]->Type, g_object_unref(base);
NULL) || return (1);
vips_embed(t[10], &t[11], 0, 0, }
t[0]->Xsize, t[0]->Ysize,
"extend", VIPS_EXTEND_COPY, // Blend the mask and text and write to output.
NULL) if (vips_ifthenelse(t[6], t[11], t[0], out, "blend", TRUE, NULL)) {
) { g_object_unref(base);
g_object_unref(base); return (1);
return (1); }
}
g_object_unref(base);
// Blend the mask and text and write to output. return (0);
if (vips_ifthenelse(t[6], t[11], t[0], out, "blend", TRUE, NULL)) {
g_object_unref(base);
return (1);
}
g_object_unref(base);
return (0);
}; };

Loading…
Cancel
Save