Skip to content

Commit

Permalink
Merge pull request #7 from davidbyttow/d/export
Browse files Browse the repository at this point in the history
 Adds direct bridge methods
  • Loading branch information
davidbyttow authored Sep 29, 2017
2 parents d48ce30 + 9ffeab4 commit 96e5904
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 169 deletions.
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ sudo: required
dist: trusty

go:
# - 1.6
- 1.7
# - tip
- 1.9

env:
# - LIBVIPS=8.3
- LIBVIPS=8.4
# - LIBVIPS=master
- VIPS_VERSION=8.5.8

matrix:
allow_failures:
- env: LIBVIPS=8.2
- env: LIBVIPS=8.3
- env: VIPS_VERSION=8.2
- env: VIPS_VERSION=8.3

cache: apt

Expand All @@ -39,9 +35,9 @@ addons:

# VIPS 8.3.3 requires Poppler 0.30 which is not released on Trusty.
before_install:
- wget https://github.com/jcupitt/libvips/archive/$LIBVIPS.zip
- unzip $LIBVIPS
- cd libvips-$LIBVIPS
- wget https://github.com/jcupitt/libvips/archive/v${VIPS_VERSION}.zip
- unzip v${VIPS_VERSION}
- cd libvips-${VIPS_VERSION}
- test -f autogen.sh && ./autogen.sh || ./bootstrap.sh
- >
CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
Expand Down
176 changes: 171 additions & 5 deletions bridge.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,177 @@

#include "bridge.h"

void SetProperty(VipsObject *object, const char *name, const GValue *value) {
int is_16bit(VipsInterpretation interpretation) {
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
}

int init_image(void *buf, size_t len, int imageType, VipsImage **out) {
int code = 1;

if (imageType == JPEG) {
code = vips_jpegload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == PNG) {
code = vips_pngload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == WEBP) {
code = vips_webpload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == TIFF) {
code = vips_tiffload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#if (VIPS_MAJOR_VERSION >= 8)
#if (VIPS_MINOR_VERSION >= 3)
} else if (imageType == GIF) {
code = vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == PDF) {
code = vips_pdfload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == SVG) {
code = vips_svgload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#endif
} else if (imageType == MAGICK) {
code = vips_magickload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#endif
}

return code;
}

int remove_icc_profile(VipsImage *in) {
return vips_image_remove(in, VIPS_META_ICC_NAME);
}

int load_jpeg_buffer(void *buf, size_t len, VipsImage **out, int shrink) {
if (shrink > 0) {
return vips_jpegload_buffer(buf, len, out, "shrink", shrink, NULL);
} else {
return vips_jpegload_buffer(buf, len, out, NULL);
}
}

int save_jpeg_buffer(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace) {
return vips_jpegsave_buffer(in, buf, len,
"strip", INT_TO_GBOOLEAN(strip),
"Q", quality,
"optimize_coding", TRUE,
"interlace", INT_TO_GBOOLEAN(interlace),
NULL
);
}

int save_png_buffer(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace) {
return vips_pngsave_buffer(in, buf, len,
"strip", INT_TO_GBOOLEAN(strip),
"compression", compression,
"interlace", INT_TO_GBOOLEAN(interlace),
"filter", VIPS_FOREIGN_PNG_FILTER_NONE,
NULL
);
}

int save_webp_buffer(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
return vips_webpsave_buffer(in, buf, len,
"strip", INT_TO_GBOOLEAN(strip),
"Q", quality,
NULL
);
}

int save_tiff_buffer(VipsImage *in, void **buf, size_t *len) {
return vips_tiffsave_buffer(in, buf, len, NULL);
}

int is_colorspace_supported(VipsImage *in) {
return vips_colourspace_issupported(in) ? 1 : 0;
}

int to_colorspace(VipsImage *in, VipsImage **out, VipsInterpretation space) {
return vips_colourspace(in, out, space, NULL);
}

int flip_image(VipsImage *in, VipsImage **out, int direction) {
return vips_flip(in, out, direction, NULL);
}

int shrink_image(VipsImage *in, VipsImage **out, double xshrink, double yshrink) {
return vips_shrink(in, out, xshrink, yshrink, NULL);
}

int reduce_image(VipsImage *in, VipsImage **out, double xshrink, double yshrink) {
return vips_reduce(in, out, xshrink, yshrink, NULL);
}

int zoom_image(VipsImage *in, VipsImage **out, int xfac, int yfac) {
return vips_zoom(in, out, xfac, yfac, NULL);
}

int embed_image(VipsImage *in, VipsImage **out, int left, int top, int width, int height, int extend, double r, double g, double b) {
if (extend == VIPS_EXTEND_BACKGROUND) {
double background[3] = {r, g, b};
VipsArrayDouble *vipsBackground = vips_array_double_new(background, 3);
return vips_embed(in, out, left, top, width, height, "extend", extend, "background", vipsBackground, NULL);
}
return vips_embed(in, out, left, top, width, height, "extend", extend, NULL);
}

int extract_image_area(VipsImage *in, VipsImage **out, int left, int top, int width, int height) {
return vips_extract_area(in, out, left, top, width, height, NULL);
}

int flatten_image_background(VipsImage *in, VipsImage **out, double r, double g, double b) {
if (is_16bit(in->Type)) {
r = 65535 * r / 255;
g = 65535 * g / 255;
b = 65535 * b / 255;
}

double background[3] = {r, g, b};
VipsArrayDouble *vipsBackground = vips_array_double_new(background, 3);

return vips_flatten(in, out,
"background", vipsBackground,
"max_alpha", is_16bit(in->Type) ? 65535.0 : 255.0,
NULL
);
}

int transform_image(VipsImage *in, VipsImage **out, double a, double b, double c, double d, VipsInterpolate *interpolator) {
return vips_affine(in, out, a, b, c, d, "interpolate", interpolator, NULL);
}

int find_image_loader(int t) {
switch (t) {
case GIF:
return vips_type_find("VipsOperation", "gifload");
case PDF:
return vips_type_find("VipsOperation", "pdfload");
case TIFF:
return vips_type_find("VipsOperation", "tiffload");
case SVG:
return vips_type_find("VipsOperation", "svgload");
case WEBP:
return vips_type_find("VipsOperation", "webpload");
case PNG:
return vips_type_find("VipsOperation", "pngload");
case JPEG:
return vips_type_find("VipsOperation", "jpegload");
case MAGICK:
return vips_type_find("VipsOperation", "magickload");
}
return 0;
}

int find_image_type_saver(int t) {
switch (t) {
case TIFF:
return vips_type_find("VipsOperation", "tiffsave_buffer");
case WEBP:
return vips_type_find("VipsOperation", "webpsave_buffer");
case PNG:
return vips_type_find("VipsOperation", "pngsave_buffer");
case JPEG:
return vips_type_find("VipsOperation", "jpegsave_buffer");
}
return 0;
}

void gobject_set_property(VipsObject *object, const char *name, const GValue *value) {
VipsObjectClass *object_class = VIPS_OBJECT_GET_CLASS( object );
GType type = G_VALUE_TYPE( value );

Expand Down Expand Up @@ -38,7 +208,3 @@ void SetProperty(VipsObject *object, const char *name, const GValue *value) {
g_object_set_property( G_OBJECT( object ), name, value );
}
}

int VipsJpegsaveBuffer(VipsImage* in, void **buf, size_t *len, int strip, int quality, int interlace) {
return vips_jpegsave_buffer(in, buf, len, NULL);
}
Loading

0 comments on commit 96e5904

Please sign in to comment.