diff --git a/vips/foreign.go b/vips/foreign.go index 5e515523..e2972f39 100644 --- a/vips/foreign.go +++ b/vips/foreign.go @@ -6,12 +6,10 @@ import ( "bytes" "encoding/xml" "fmt" - "image/png" "math" "runtime" "unsafe" - "golang.org/x/image/bmp" "golang.org/x/net/html/charset" ) @@ -257,19 +255,8 @@ func vipsLoadFromBuffer(buf []byte, params *ImportParams) (*C.VipsImage, ImageTy // Reference src here so it's not garbage collected during image initialization. defer runtime.KeepAlive(src) - var err error - imageType := DetermineImageType(src) - if imageType == ImageTypeBMP { - src, err = bmpToPNG(src) - if err != nil { - return nil, ImageTypeUnknown, err - } - - imageType = ImageTypePNG - } - if !IsTypeSupported(imageType) { govipsLog("govips", LogLevelInfo, fmt.Sprintf("failed to understand image format size=%d", len(src))) return nil, ImageTypeUnknown, ErrUnsupportedImageFormat @@ -284,24 +271,6 @@ func vipsLoadFromBuffer(buf []byte, params *ImportParams) (*C.VipsImage, ImageTy return importParams.outputImage, imageType, nil } -func bmpToPNG(src []byte) ([]byte, error) { - i, err := bmp.Decode(bytes.NewReader(src)) - if err != nil { - return nil, err - } - - var w bytes.Buffer - pngEnc := png.Encoder{ - CompressionLevel: png.NoCompression, - } - err = pngEnc.Encode(&w, i) - if err != nil { - return nil, err - } - - return w.Bytes(), nil -} - func maybeSetBoolParam(p BoolParameter, cp *C.Param) { if p.IsSet() { C.set_bool_param(cp, toGboolean(p.Get())) diff --git a/vips/image_test.go b/vips/image_test.go index 621597bc..b0a36934 100644 --- a/vips/image_test.go +++ b/vips/image_test.go @@ -132,22 +132,6 @@ func TestImageRef_HEIF_ftypmsf1(t *testing.T) { assert.Equal(t, ImageTypeHEIF, metadata.Format) } -func TestImageRef_BMP__ImplicitConversionToPNG(t *testing.T) { - Startup(nil) - - raw, err := ioutil.ReadFile(resources + "bmp.bmp") - require.NoError(t, err) - - img, err := NewImageFromBuffer(raw) - require.NoError(t, err) - require.NotNil(t, img) - - exported, metadata, err := img.ExportNative() - assert.NoError(t, err) - assert.Equal(t, ImageTypePNG, metadata.Format) - assert.NotNil(t, exported) -} - func TestImageRef_SVG(t *testing.T) { Startup(nil) diff --git a/vips/resample.go b/vips/resample.go index 37d6efb2..c220c48e 100644 --- a/vips/resample.go +++ b/vips/resample.go @@ -3,7 +3,6 @@ package vips // #include "resample.h" import "C" import ( - "io/ioutil" "runtime" "unsafe" ) @@ -75,13 +74,7 @@ func vipsThumbnailFromFile(filename string, width, height int, crop Interesting, if err := C.thumbnail(cFileName, &out, C.int(width), C.int(height), C.int(crop), C.int(size)); err != 0 { err := handleImageError(out) - if src, err2 := ioutil.ReadFile(filename); err2 == nil { - if isBMP(src) { - if src2, err3 := bmpToPNG(src); err3 == nil { - return vipsThumbnailFromBuffer(src2, width, height, crop, size, params) - } - } - } + return nil, ImageTypeUnknown, err } @@ -109,11 +102,6 @@ func vipsThumbnailFromBuffer(buf []byte, width, height int, crop Interesting, si } if err != 0 { err := handleImageError(out) - if isBMP(src) { - if src2, err2 := bmpToPNG(src); err2 == nil { - return vipsThumbnailFromBuffer(src2, width, height, crop, size, params) - } - } return nil, ImageTypeUnknown, err }