From b55834edf283a171b27b98fababa7145634c5c7f Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Sat, 11 Apr 2015 03:12:49 +0200 Subject: [PATCH] refactor(vips.h) --- vips.h | 111 +++++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/vips.h b/vips.h index a896310..4886056 100644 --- a/vips.h +++ b/vips.h @@ -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); };