Skip to content

Commit

Permalink
Replace t[] array with individual references
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Gasienica committed May 2, 2015
1 parent a8a5da6 commit 057acca
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ int Composite(VipsObject *context, VipsImage *src, VipsImage *dst, VipsImage **o
if (src->Bands != 4 || dst->Bands != 4)
return -1;

// These images will all be unreffed when context is unreffed:
VipsImage **t = (VipsImage **) vips_object_local_array(context, 3);

// Extract RGB bands:
VipsImage *srcRGB;
VipsImage *dstRGB;
Expand Down Expand Up @@ -55,15 +52,19 @@ int Composite(VipsObject *context, VipsImage *src, VipsImage *dst, VipsImage **o
//
// out_a = src_a + dst_a * (1 - src_a)
// ^^^^^^^^^^^
// t[0]
// t0
// ^^^^^^^^^^^^^^^^^^^
// t[1]
// t1
VipsImage *t0;
VipsImage *t1;
VipsImage *outAlphaNormalized;
if (vips_linear1(srcAlphaNormalized, &t[0], -1.0, 1.0, NULL) ||
vips_multiply(dstAlphaNormalized, t[0], &t[1], NULL) ||
vips_add(srcAlphaNormalized, t[1], &outAlphaNormalized, NULL))
if (vips_linear1(srcAlphaNormalized, &t0, -1.0, 1.0, NULL) ||
vips_multiply(dstAlphaNormalized, t0, &t1, NULL) ||
vips_add(srcAlphaNormalized, t1, &outAlphaNormalized, NULL))
return -1;

vips_object_local(context, t0);
vips_object_local(context, t1);
vips_object_local(context, outAlphaNormalized);

//
Expand Down Expand Up @@ -113,12 +114,15 @@ int Composite(VipsObject *context, VipsImage *src, VipsImage *dst, VipsImage **o
vips_object_local(context, outAlpha);

// Combine RGB and alpha channel into output image:
if (vips_bandjoin2(outRGB, outAlpha, &t[2], NULL))
VipsImage *joined;
if (vips_bandjoin2(outRGB, outAlpha, &joined, NULL))
return -1;

vips_object_local(context, joined);

// Return a reference to the output image:
g_object_ref(t[2]);
*out = t[2];
g_object_ref(joined);
*out = joined;

return 0;
}

0 comments on commit 057acca

Please sign in to comment.