refactor(vips.h)

This commit is contained in:
Tomas Aparicio 2015-04-11 03:12:49 +02:00
parent 6f5f7ff644
commit b55834edf2

99
vips.h
View file

@ -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, vips_crop(t[5], &t[6], 0, 0, t[0]->Xsize, t[0]->Ysize, NULL))
t[0]->Xsize, t[0]->Ysize, NULL) ) {
)) { g_object_unref(base);
g_object_unref(base); return (1);
return (1); }
}
// 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[7], 1, 1, NULL) ||
vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) || vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) ||
vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) || vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) ||
vips_copy(t[9], &t[10], vips_copy(t[9], &t[10], "interpretation", t[0]->Type, NULL) ||
"interpretation", t[0]->Type, vips_embed(t[10], &t[11], 0, 0, t[0]->Xsize, t[0]->Ysize, "extend", VIPS_EXTEND_COPY, NULL)
NULL) || ) {
vips_embed(t[10], &t[11], 0, 0, g_object_unref(base);
t[0]->Xsize, t[0]->Ysize, return (1);
"extend", VIPS_EXTEND_COPY, }
NULL)
) {
g_object_unref(base);
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[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); g_object_unref(base);
return (0); return (0);
}; };