mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Remove C from imagetype
This commit is contained in:
parent
0af4720cfa
commit
0b612da5fc
@ -1,11 +1,5 @@
|
||||
package imagetype
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -s -w
|
||||
#include "imagetype.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
@ -16,21 +10,21 @@ import (
|
||||
type Type int
|
||||
|
||||
const (
|
||||
Unknown = Type(C.UNKNOWN)
|
||||
JPEG = Type(C.JPEG)
|
||||
PNG = Type(C.PNG)
|
||||
WEBP = Type(C.WEBP)
|
||||
GIF = Type(C.GIF)
|
||||
ICO = Type(C.ICO)
|
||||
SVG = Type(C.SVG)
|
||||
HEIC = Type(C.HEIC)
|
||||
AVIF = Type(C.AVIF)
|
||||
BMP = Type(C.BMP)
|
||||
TIFF = Type(C.TIFF)
|
||||
|
||||
contentDispositionFilenameFallback = "image"
|
||||
Unknown Type = iota
|
||||
JPEG
|
||||
PNG
|
||||
WEBP
|
||||
GIF
|
||||
ICO
|
||||
SVG
|
||||
HEIC
|
||||
AVIF
|
||||
BMP
|
||||
TIFF
|
||||
)
|
||||
|
||||
const contentDispositionFilenameFallback = "image"
|
||||
|
||||
var (
|
||||
Types = map[string]Type{
|
||||
"jpeg": JPEG,
|
||||
|
@ -1,13 +0,0 @@
|
||||
enum ImgproxyImageTypes {
|
||||
UNKNOWN = 0,
|
||||
JPEG,
|
||||
PNG,
|
||||
WEBP,
|
||||
GIF,
|
||||
ICO,
|
||||
SVG,
|
||||
HEIC,
|
||||
AVIF,
|
||||
BMP,
|
||||
TIFF
|
||||
};
|
53
vips/vips.c
53
vips/vips.c
@ -31,59 +31,6 @@ swap_and_clear(VipsImage **in, VipsImage *out) {
|
||||
*in = out;
|
||||
}
|
||||
|
||||
int
|
||||
vips_type_find_load_go(int imgtype) {
|
||||
switch (imgtype)
|
||||
{
|
||||
case (JPEG):
|
||||
return vips_type_find("VipsOperation", "jpegload_buffer");
|
||||
case (PNG):
|
||||
return vips_type_find("VipsOperation", "pngload_buffer");
|
||||
case (WEBP):
|
||||
return vips_type_find("VipsOperation", "webpload_buffer");
|
||||
case (GIF):
|
||||
return vips_type_find("VipsOperation", "gifload_buffer");
|
||||
case (SVG):
|
||||
return vips_type_find("VipsOperation", "svgload_buffer");
|
||||
case (HEIC):
|
||||
return vips_type_find("VipsOperation", "heifload_buffer");
|
||||
case (AVIF):
|
||||
return vips_type_find("VipsOperation", "heifload_buffer");
|
||||
case (BMP):
|
||||
return vips_type_find("VipsOperation", "magickload_buffer");
|
||||
case (TIFF):
|
||||
return vips_type_find("VipsOperation", "tiffload_buffer");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
vips_type_find_save_go(int imgtype) {
|
||||
switch (imgtype)
|
||||
{
|
||||
case (JPEG):
|
||||
return vips_type_find("VipsOperation", "jpegsave_buffer");
|
||||
case (PNG):
|
||||
return vips_type_find("VipsOperation", "pngsave_buffer");
|
||||
case (WEBP):
|
||||
return vips_type_find("VipsOperation", "webpsave_buffer");
|
||||
case (GIF):
|
||||
return vips_type_find("VipsOperation", "magicksave_buffer");
|
||||
#if VIPS_SUPPORT_AVIF
|
||||
case (AVIF):
|
||||
return vips_type_find("VipsOperation", "heifsave_buffer");
|
||||
#endif
|
||||
case (ICO):
|
||||
return vips_type_find("VipsOperation", "pngsave_buffer");
|
||||
case (BMP):
|
||||
return vips_type_find("VipsOperation", "magicksave_buffer");
|
||||
case (TIFF):
|
||||
return vips_type_find("VipsOperation", "tiffsave_buffer");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out) {
|
||||
if (shrink > 1)
|
||||
|
45
vips/vips.go
45
vips/vips.go
@ -116,16 +116,36 @@ func Error() error {
|
||||
return ierrors.NewUnexpected(C.GoString(C.vips_error_buffer()), 1)
|
||||
}
|
||||
|
||||
func hasOperation(name string) bool {
|
||||
return C.vips_type_find(cachedCString("VipsOperation"), cachedCString(name)) != 0
|
||||
}
|
||||
|
||||
func SupportsLoad(it imagetype.Type) bool {
|
||||
if sup, ok := typeSupportLoad[it]; ok {
|
||||
return sup
|
||||
}
|
||||
|
||||
sup := false
|
||||
if it == imagetype.ICO {
|
||||
|
||||
switch it {
|
||||
case imagetype.JPEG:
|
||||
sup = hasOperation("jpegload_buffer")
|
||||
case imagetype.PNG:
|
||||
sup = hasOperation("pngload_buffer")
|
||||
case imagetype.WEBP:
|
||||
sup = hasOperation("webpload_buffer")
|
||||
case imagetype.GIF:
|
||||
sup = hasOperation("gifload_buffer")
|
||||
case imagetype.ICO:
|
||||
sup = true
|
||||
} else {
|
||||
sup = int(C.vips_type_find_load_go(C.int(it))) != 0
|
||||
case imagetype.SVG:
|
||||
sup = hasOperation("svgload_buffer")
|
||||
case imagetype.HEIC, imagetype.AVIF:
|
||||
sup = hasOperation("heifload_buffer")
|
||||
case imagetype.BMP:
|
||||
sup = hasOperation("magickload_buffer")
|
||||
case imagetype.TIFF:
|
||||
sup = hasOperation("tiffload_buffer")
|
||||
}
|
||||
|
||||
typeSupportLoad[it] = sup
|
||||
@ -139,11 +159,20 @@ func SupportsSave(it imagetype.Type) bool {
|
||||
}
|
||||
|
||||
sup := false
|
||||
if it == imagetype.ICO {
|
||||
// We save ICO content as PNG so we need to check it
|
||||
sup = int(C.vips_type_find_save_go(C.int(imagetype.PNG))) != 0
|
||||
} else {
|
||||
sup = int(C.vips_type_find_save_go(C.int(it))) != 0
|
||||
|
||||
switch it {
|
||||
case imagetype.JPEG:
|
||||
return hasOperation("jpegsave_buffer")
|
||||
case imagetype.PNG, imagetype.ICO:
|
||||
return hasOperation("pngsave_buffer")
|
||||
case imagetype.WEBP:
|
||||
return hasOperation("webpsave_buffer")
|
||||
case imagetype.GIF, imagetype.BMP:
|
||||
return hasOperation("magicksave_buffer")
|
||||
case imagetype.AVIF:
|
||||
return hasOperation("heifsave_buffer")
|
||||
case imagetype.TIFF:
|
||||
return hasOperation("tiffsave_buffer")
|
||||
}
|
||||
|
||||
typeSupportSave[it] = sup
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <vips/vips7compat.h>
|
||||
#include <vips/vector.h>
|
||||
|
||||
#include "../imagetype/imagetype.h"
|
||||
|
||||
int vips_initialize();
|
||||
|
||||
void clear_image(VipsImage **in);
|
||||
|
Loading…
Reference in New Issue
Block a user