refactor(vips)

master
Tomas Aparicio 11 years ago
parent 5d13fba8be
commit a29fa25dfc

@ -72,6 +72,8 @@ func Resize(buf []byte, o Options) ([]byte, error) {
residual = float64(shrink) / factor
}
debug("Test %s, %s, %s", shrink, residual, factor)
// Zoom image if necessary
image, err = zoomImage(image, o.Zoom)
if err != nil {

@ -153,6 +153,11 @@ func runBenchmarkResize(file string, o Options, b *testing.B) {
}
}
func BenchmarkRotateJpeg(b *testing.B) {
options := Options{Rotate: 180}
runBenchmarkResize("test.jpg", options, b)
}
func BenchmarkResizeLargeJpeg(b *testing.B) {
options := Options{
Width: 800,

@ -15,6 +15,11 @@ import (
"unsafe"
)
const (
maxCacheMem = 100 * 1024 * 1024
maxCacheSize = 500
)
var (
m sync.Mutex
initialized bool
@ -67,8 +72,9 @@ func Initialize() {
panic("unable to start vips!")
}
C.vips_cache_set_max_mem(100 * 1024 * 1024)
C.vips_cache_set_max(500)
// Set libvips cache params
C.vips_cache_set_max_mem(maxCacheMem)
C.vips_cache_set_max(maxCacheSize)
// Explicit concurrency limit to avoid thread-unsafe issues.
// See: https://github.com/jcupitt/libvips/issues/261#issuecomment-92850414

@ -56,7 +56,7 @@ vips_shrink_bridge(VipsImage *in, VipsImage **out, double xshrink, double yshrin
};
int
vips_rotate(VipsImage *in, VipsImage **buf, int angle)
vips_rotate(VipsImage *in, VipsImage **out, int angle)
{
int rotate = VIPS_ANGLE_D0;
@ -68,7 +68,7 @@ vips_rotate(VipsImage *in, VipsImage **buf, int angle)
rotate = VIPS_ANGLE_D270;
}
return vips_rot(in, buf, rotate, NULL);
return vips_rot(in, out, rotate, NULL);
};
int
@ -158,16 +158,16 @@ vips_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_SEQUENTIAL, NULL);
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_SEQUENTIAL, NULL);
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_SEQUENTIAL, NULL);
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_SEQUENTIAL, NULL);
code = vips_tiffload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#if (VIPS_MAJOR_VERSION >= 8)
} else if (imageType == MAGICK) {
code = vips_magickload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
code = vips_magickload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#endif
}

Loading…
Cancel
Save