fix(#42): change interlace type. fix C bindings

master
Tomas Aparicio 11 years ago
commit 7be9d7bad5

@ -166,6 +166,7 @@ options := bimg.Options{
Crop: true,
Quality: 95,
Rotate: 180,
Interlace: 1,
}
buffer, err := bimg.Read("image.jpg")
@ -625,6 +626,7 @@ type Options struct {
Flip bool
Flop bool
NoAutoRotate bool
Interlace int
Rotate Angle
Gravity Gravity
Watermark Watermark

@ -88,6 +88,7 @@ type Options struct {
Flip bool
Flop bool
NoAutoRotate bool
Interlace bool
Rotate Angle
Gravity Gravity
Watermark Watermark

@ -126,6 +126,7 @@ func Resize(buf []byte, o Options) ([]byte, error) {
Quality: o.Quality,
Type: o.Type,
Compression: o.Compression,
Interlace: o.Interlace,
}
// Finally save as buffer

@ -23,13 +23,16 @@ func DetermineImageTypeName(buf []byte) string {
// Check if a given image type is supported
func IsTypeSupported(t ImageType) bool {
return t == JPEG || t == PNG || t == WEBP
return t == JPEG || t == PNG || t == WEBP || t == MAGICK
}
// Check if a given image type name is supported
func IsTypeNameSupported(t string) bool {
return t == "jpeg" || t == "jpg" ||
t == "png" || t == "webp"
return t == "jpeg" ||
t == "jpg" ||
t == "png" ||
t == "webp" ||
t == "magick"
}
func getImageTypeName(code ImageType) string {

@ -35,6 +35,7 @@ type vipsSaveOptions struct {
Quality int
Compression int
Type ImageType
Interlace bool
}
type vipsWatermarkOptions struct {
@ -223,18 +224,19 @@ func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) {
var ptr unsafe.Pointer
length := C.size_t(0)
err := C.int(0)
interlace := C.int(boolToInt(o.Interlace))
defer C.g_object_unref(C.gpointer(image))
switch o.Type {
case PNG:
err = C.vips_pngsave_bridge(image, &ptr, &length, 1, C.int(o.Compression), C.int(o.Quality), 0)
err = C.vips_pngsave_bridge(image, &ptr, &length, 1, C.int(o.Compression), C.int(o.Quality), interlace)
break
case WEBP:
err = C.vips_webpsave_bridge(image, &ptr, &length, 1, C.int(o.Quality), 0)
err = C.vips_webpsave_bridge(image, &ptr, &length, 1, C.int(o.Quality))
break
default:
err = C.vips_jpegsave_bridge(image, &ptr, &length, 1, C.int(o.Quality), 0)
err = C.vips_jpegsave_bridge(image, &ptr, &length, 1, C.int(o.Quality), interlace)
break
}
@ -358,3 +360,10 @@ func catchVipsError() error {
C.vips_thread_shutdown()
return errors.New(s)
}
func boolToInt(b bool) int {
if b {
return 1
}
return 0
}

@ -129,28 +129,52 @@ vips_extract_area_bridge(VipsImage *in, VipsImage **out, int left, int top, int
return vips_extract_area(in, out, left, top, width, height, NULL);
};
gboolean
with_interlace(int interlace) {
return interlace > 0 ? TRUE : FALSE;
};
int
vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace)
{
return vips_jpegsave_buffer(in, buf, len, "strip", strip, "Q", quality, "optimize_coding", TRUE, "interlace", interlace, NULL);
return vips_jpegsave_buffer(in, buf, len,
"strip", strip,
"Q", quality,
"optimize_coding", TRUE,
"interlace", with_interlace(interlace),
NULL
);
};
int
vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace)
{
#if (VIPS_MAJOR_VERSION >= 8 || (VIPS_MAJOR_VERSION >= 7 && VIPS_MINOR_VERSION >= 42))
return vips_pngsave_buffer(in, buf, len, "strip", FALSE, "compression", compression,
"interlace", interlace, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, NULL);
return vips_pngsave_buffer(in, buf, len,
"strip", FALSE,
"compression", compression,
"interlace", with_interlace(interlace),
"filter", VIPS_FOREIGN_PNG_FILTER_NONE,
NULL
);
#else
return vips_pngsave_buffer(in, buf, len, "strip", FALSE, "compression", compression,
"interlace", interlace, NULL);
return vips_pngsave_buffer(in, buf, len,
"strip", FALSE,
"compression", compression,
"interlace", with_interlace(interlace),
NULL
);
#endif
};
int
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace)
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality)
{
return vips_webpsave_buffer(in, buf, len, "strip", strip, "Q", quality, NULL);
return vips_webpsave_buffer(in, buf, len,
"strip", strip,
"Q", quality,
NULL
);
};
int

@ -30,7 +30,7 @@ func TestVipsRead(t *testing.T) {
func TestVipsSave(t *testing.T) {
image, _, _ := vipsRead(readImage("test.jpg"))
options := vipsSaveOptions{Quality: 95, Type: JPEG}
options := vipsSaveOptions{Quality: 95, Type: JPEG, Interlace: true}
buf, err := vipsSave(image, options)
if err != nil {

Loading…
Cancel
Save