Skip to content

Commit

Permalink
refactor(vips.h)
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Apr 11, 2015
1 parent 6f5f7ff commit b55834e
Showing 1 changed file with 52 additions and 59 deletions.
111 changes: 52 additions & 59 deletions vips.h
Expand Up @@ -171,63 +171,56 @@ vips_init_image(void *buf, size_t len, int imageType, VipsImage **out) {
int
vips_watermark(VipsImage *in, VipsImage **out, watermarkTextOptions *to, watermarkOptions *o)
{
double ones[3] = { 1, 1, 1 };

VipsImage *base = vips_image_new();
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 12);
t[0] = in;

// Make the mask.
if (
vips_text(&t[1], to->Text,
"width", o->Width,
"dpi", o->DPI,
"font", to->Font,
NULL) ||
vips_linear1(t[1], &t[2], o->Opacity, 0.0, NULL) ||
vips_cast(t[2], &t[3], VIPS_FORMAT_UCHAR, NULL) ||
vips_embed(t[3], &t[4], 100, 100,
t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
) {
g_object_unref(base);
return (1);
}

// Replicate if necessary
if (o->NoReplicate != 1 && (
vips_replicate(t[4], &t[5],
1 + t[0]->Xsize / t[4]->Xsize,
1 + t[0]->Ysize / t[4]->Ysize, NULL) ||
vips_crop(t[5], &t[6], 0, 0,
t[0]->Xsize, t[0]->Ysize, NULL)
)) {
g_object_unref(base);
return (1);
}

// Make the constant image to paint the text with.
if (
vips_black(&t[7], 1, 1, NULL) ||
vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) ||
vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) ||
vips_copy(t[9], &t[10],
"interpretation", t[0]->Type,
NULL) ||
vips_embed(t[10], &t[11], 0, 0,
t[0]->Xsize, t[0]->Ysize,
"extend", VIPS_EXTEND_COPY,
NULL)
) {
g_object_unref(base);
return (1);
}

// Blend the mask and text and write to output.
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);
double ones[3] = { 1, 1, 1 };

VipsImage *base = vips_image_new();
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 12);
t[0] = in;

// Make the mask.
if (
vips_text(&t[1], to->Text,
"width", o->Width,
"dpi", o->DPI,
"font", to->Font,
NULL) ||
vips_linear1(t[1], &t[2], o->Opacity, 0.0, NULL) ||
vips_cast(t[2], &t[3], VIPS_FORMAT_UCHAR, NULL) ||
vips_embed(t[3], &t[4], 100, 100, t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
) {
g_object_unref(base);
return (1);
}

// Replicate if necessary
if (o->NoReplicate != 1 && (
vips_replicate(t[4], &t[5],
1 + t[0]->Xsize / t[4]->Xsize,
1 + t[0]->Ysize / t[4]->Ysize, NULL) ||
vips_crop(t[5], &t[6], 0, 0, t[0]->Xsize, t[0]->Ysize, NULL))
) {
g_object_unref(base);
return (1);
}

// Make the constant image to paint the text with.
if (
vips_black(&t[7], 1, 1, NULL) ||
vips_linear( t[7], &t[8], ones, o->Background, 3, NULL) ||
vips_cast(t[8], &t[9], VIPS_FORMAT_UCHAR, NULL) ||
vips_copy(t[9], &t[10], "interpretation", t[0]->Type, NULL) ||
vips_embed(t[10], &t[11], 0, 0, t[0]->Xsize, t[0]->Ysize, "extend", VIPS_EXTEND_COPY, NULL)
) {
g_object_unref(base);
return (1);
}

// Blend the mask and text and write to output.
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);
};

0 comments on commit b55834e

Please sign in to comment.