mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-02 17:09:48 +02:00
Merge branch 'master' into version/4
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- (pro) Add [color_profile](https://docs.imgproxy.net/latest/usage/processing#color-profile) processing option and [IMGPROXY_COLOR_PROFILES_DIR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_COLOR_PROFILES_DIR) config
|
||||
- Add [IMGPROXY_GRACEFUL_STOP_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_GRACEFUL_STOP_TIMEOUT) config.
|
||||
- (pro) Add [color_profile](https://docs.imgproxy.net/latest/usage/processing#color-profile) processing option and [IMGPROXY_COLOR_PROFILES_DIR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_COLOR_PROFILES_DIR) config.
|
||||
|
||||
### Changed
|
||||
- Update the default graceful stop timeout to twice the [IMGPROXY_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_TIMEOUT) config value.
|
||||
- (pro) Improve video decoding performance.
|
||||
- (pro) Respond with `422 Unprocessable Entity` on error during video decoding.
|
||||
|
||||
|
@@ -23,6 +23,7 @@ var (
|
||||
Network string
|
||||
Bind string
|
||||
Timeout int
|
||||
GracefulStopTimeout int
|
||||
ReadRequestTimeout int
|
||||
WriteResponseTimeout int
|
||||
KeepAliveTimeout int
|
||||
@@ -231,6 +232,7 @@ func Reset() {
|
||||
Network = "tcp"
|
||||
Bind = ":8080"
|
||||
Timeout = 10
|
||||
GracefulStopTimeout = 20
|
||||
ReadRequestTimeout = 10
|
||||
WriteResponseTimeout = 10
|
||||
KeepAliveTimeout = 10
|
||||
@@ -438,6 +440,9 @@ func Configure() error {
|
||||
}
|
||||
configurators.Int(&Timeout, "IMGPROXY_TIMEOUT")
|
||||
|
||||
GracefulStopTimeout = Timeout * 2
|
||||
configurators.Int(&GracefulStopTimeout, "IMGPROXY_GRACEFUL_STOP_TIMEOUT")
|
||||
|
||||
if _, ok := os.LookupEnv("IMGPROXY_READ_TIMEOUT"); ok {
|
||||
log.Warning("IMGPROXY_READ_TIMEOUT is deprecated, use IMGPROXY_READ_REQUEST_TIMEOUT instead")
|
||||
configurators.Int(&ReadRequestTimeout, "IMGPROXY_READ_TIMEOUT")
|
||||
|
2
main.go
2
main.go
@@ -208,9 +208,9 @@ func initialize() error {
|
||||
}
|
||||
|
||||
func shutdown() {
|
||||
vips.Shutdown()
|
||||
monitoring.Stop()
|
||||
errorreport.Close()
|
||||
vips.Shutdown()
|
||||
}
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
|
@@ -9,11 +9,6 @@ import (
|
||||
"github.com/imgproxy/imgproxy/v3/ensure"
|
||||
)
|
||||
|
||||
const (
|
||||
// gracefulTimeout represents graceful shutdown timeout
|
||||
gracefulTimeout = time.Duration(5 * time.Second)
|
||||
)
|
||||
|
||||
// Config represents HTTP server config
|
||||
type Config struct {
|
||||
Listen string // Address to listen on
|
||||
@@ -42,7 +37,7 @@ func NewDefaultConfig() Config {
|
||||
ReadRequestTimeout: 10 * time.Second,
|
||||
KeepAliveTimeout: 10 * time.Second,
|
||||
WriteResponseTimeout: 10 * time.Second,
|
||||
GracefulTimeout: gracefulTimeout,
|
||||
GracefulTimeout: 20 * time.Second,
|
||||
CORSAllowOrigin: "",
|
||||
Secret: "",
|
||||
DevelopmentErrorsMode: false,
|
||||
@@ -61,7 +56,7 @@ func LoadConfigFromEnv(c *Config) (*Config, error) {
|
||||
c.MaxClients = config.MaxClients
|
||||
c.ReadRequestTimeout = time.Duration(config.ReadRequestTimeout) * time.Second
|
||||
c.KeepAliveTimeout = time.Duration(config.KeepAliveTimeout) * time.Second
|
||||
c.GracefulTimeout = gracefulTimeout
|
||||
c.GracefulTimeout = time.Duration(config.GracefulStopTimeout) * time.Second
|
||||
c.CORSAllowOrigin = config.AllowOrigin
|
||||
c.Secret = config.Secret
|
||||
c.DevelopmentErrorsMode = config.DevelopmentErrorsMode
|
||||
|
75
vips/vips.c
75
vips/vips.c
@@ -30,10 +30,9 @@ vips_initialize()
|
||||
}
|
||||
|
||||
void
|
||||
clear_image(VipsImage **in)
|
||||
unref_image(VipsImage *in)
|
||||
{
|
||||
if (G_IS_OBJECT(*in))
|
||||
g_clear_object(in);
|
||||
VIPS_UNREF(in);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -42,13 +41,6 @@ g_free_go(void **buf)
|
||||
g_free(*buf);
|
||||
}
|
||||
|
||||
void
|
||||
swap_and_clear(VipsImage **in, VipsImage *out)
|
||||
{
|
||||
clear_image(in);
|
||||
*in = out;
|
||||
}
|
||||
|
||||
int
|
||||
gif_resolution_limit()
|
||||
{
|
||||
@@ -65,7 +57,7 @@ vips_health()
|
||||
int res = vips_black(&t[0], 4, 4, "bands", 4, NULL) ||
|
||||
!(t[1] = vips_image_copy_memory(t[0]));
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -154,12 +146,12 @@ vips_tiffload_source_go(VipsImgproxySource *source, VipsImage **out)
|
||||
int
|
||||
vips_black_go(VipsImage **out, int width, int height, int bands)
|
||||
{
|
||||
VipsImage *tmp;
|
||||
VipsImage *tmp = NULL;
|
||||
|
||||
int res = vips_black(&tmp, width, height, "bands", bands, NULL) ||
|
||||
vips_copy(tmp, out, "interpretation", VIPS_INTERPRETATION_sRGB, NULL);
|
||||
|
||||
clear_image(&tmp);
|
||||
VIPS_UNREF(tmp);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -184,7 +176,7 @@ vips_fix_scRGB_alpha_tiff(VipsImage *in, VipsImage **out)
|
||||
vips_cast(t[2], &t[3], in->BandFmt, NULL) ||
|
||||
vips_bandjoin2(t[0], t[3], out, NULL);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
#endif
|
||||
@@ -213,7 +205,7 @@ vips_fix_BW_float_tiff(VipsImage *in, VipsImage **out)
|
||||
vips_linear1(t[1], &t[2], 65535.0, 0, NULL) ||
|
||||
vips_cast_ushort(t[2], &t[3], NULL) ||
|
||||
vips_copy(t[3], &t[4], "interpretation", VIPS_INTERPRETATION_GREY16, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -229,7 +221,7 @@ vips_fix_BW_float_tiff(VipsImage *in, VipsImage **out)
|
||||
vips_bandjoin(rgb, &t[5], 3, NULL) ||
|
||||
vips_colourspace(t[5], &t[6], VIPS_INTERPRETATION_GREY16,
|
||||
"source_space", VIPS_INTERPRETATION_scRGB, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -242,7 +234,7 @@ vips_fix_BW_float_tiff(VipsImage *in, VipsImage **out)
|
||||
else
|
||||
res = vips_icc_remove(t[6], out);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -396,7 +388,7 @@ vips_resize_go(VipsImage *in, VipsImage **out, double wscale, double hscale)
|
||||
vips_unpremultiply(t[2], &t[3], NULL) ||
|
||||
vips_cast(t[3], out, format, NULL);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -529,7 +521,7 @@ vips_icc_import_go(VipsImage *in, VipsImage **out)
|
||||
|
||||
if (vips_extract_band(in, &t[0], 0, "n", bands, NULL) ||
|
||||
vips_extract_band(in, &t[1], bands, "n", 1, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -538,7 +530,7 @@ vips_icc_import_go(VipsImage *in, VipsImage **out)
|
||||
}
|
||||
|
||||
if (vips_icc_import(in, out, "embedded", TRUE, "pcs", vips_icc_get_pcs(in), NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -551,14 +543,14 @@ vips_icc_import_go(VipsImage *in, VipsImage **out)
|
||||
if (vips_cast(t[1], &t[3], t[2]->BandFmt, NULL) ||
|
||||
vips_linear1(t[3], &t[4], 1.0 / 255.0, 0, NULL) ||
|
||||
vips_bandjoin2(t[2], t[4], out, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
vips_image_set_int(*out, "imgproxy-icc-imported", 1);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -636,7 +628,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
if (
|
||||
vips_premultiply(in, &t[0], NULL) ||
|
||||
vips_cast(t[0], &t[1], format, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -646,7 +638,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
|
||||
if (blur_sigma > 0.0) {
|
||||
if (vips_gaussblur(in, &t[2], blur_sigma, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -655,7 +647,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
|
||||
if (sharp_sigma > 0.0) {
|
||||
if (vips_sharpen(in, &t[3], "sigma", sharp_sigma, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -675,7 +667,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
|
||||
if (tw > w || th > h) {
|
||||
if (vips_embed(in, &t[4], 0, 0, tw, th, "extend", VIPS_EXTEND_MIRROR, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -685,7 +677,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
if (
|
||||
vips_shrink(in, &t[5], pixelate_pixels, pixelate_pixels, NULL) ||
|
||||
vips_zoom(t[5], &t[6], pixelate_pixels, pixelate_pixels, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -693,7 +685,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
|
||||
if (tw > w || th > h) {
|
||||
if (vips_extract_area(in, &t[7], 0, 0, w, h, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -703,7 +695,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
|
||||
if (premultiplied) {
|
||||
if (vips_unpremultiply(in, &t[8], NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -714,7 +706,7 @@ vips_apply_filters(VipsImage *in, VipsImage **out, double blur_sigma,
|
||||
vips_colourspace(in, &t[9], interpretation, NULL) ||
|
||||
vips_cast(t[9], out, format, NULL);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -749,7 +741,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||
|
||||
if (vips_image_guess_interpretation(in) != VIPS_INTERPRETATION_sRGB) {
|
||||
if (vips_colourspace(in, &t[0], VIPS_INTERPRETATION_sRGB, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
tmp = t[0];
|
||||
@@ -758,7 +750,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||
if (vips_image_hasalpha(tmp)) {
|
||||
RGB f_bg = { 255.0, 0, 255.0 };
|
||||
if (vips_flatten_go(tmp, &t[1], f_bg)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
tmp = t[1];
|
||||
@@ -770,7 +762,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||
|
||||
if (smart) {
|
||||
if (vips_getpoint(tmp, &img_bg, &img_bgn, 0, 0, NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
bga = vips_array_double_new(img_bg, img_bgn);
|
||||
@@ -782,7 +774,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||
int left, right, top, bot, width, height, diff;
|
||||
int res = vips_find_trim(tmp, &left, &top, &width, &height, "background", bga, "threshold", threshold, NULL);
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
vips_area_unref((VipsArea *) bga);
|
||||
g_free(img_bg);
|
||||
|
||||
@@ -824,7 +816,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||
int
|
||||
vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height, int centered)
|
||||
{
|
||||
VipsImage *tmp;
|
||||
VipsImage *tmp = NULL;
|
||||
|
||||
int across = ceil((double) width / in->Xsize);
|
||||
int down = ceil((double) height / in->Ysize);
|
||||
@@ -843,11 +835,11 @@ vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height, int cen
|
||||
const int top = centered ? (tmp->Ysize - height) / 2 : 0;
|
||||
|
||||
if (vips_extract_area(tmp, out, left, top, width, height, NULL)) {
|
||||
clear_image(&tmp);
|
||||
VIPS_UNREF(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
clear_image(&tmp);
|
||||
VIPS_UNREF(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -867,8 +859,7 @@ vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int heigh
|
||||
int ret =
|
||||
vips_embed(in, out, x, y, width, height, "extend", VIPS_EXTEND_BLACK, NULL);
|
||||
|
||||
if (tmp)
|
||||
clear_image(&tmp);
|
||||
VIPS_UNREF(tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -892,7 +883,7 @@ vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, int l
|
||||
vips_extract_band(watermark, &t[2], watermark->Bands - 1, "n", 1, NULL) ||
|
||||
vips_linear1(t[2], &t[3], opacity, 0, NULL) ||
|
||||
vips_bandjoin2(t[1], t[3], &t[4], NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -907,7 +898,7 @@ vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, int l
|
||||
"x", left, "y", top, "compositing_space", in->Type,
|
||||
NULL) ||
|
||||
vips_cast(t[5], &t[6], vips_image_get_format(in), NULL)) {
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -920,7 +911,7 @@ vips_apply_watermark(VipsImage *in, VipsImage *watermark, VipsImage **out, int l
|
||||
res = vips_copy(t[6], out, NULL);
|
||||
}
|
||||
|
||||
clear_image(&base);
|
||||
VIPS_UNREF(base);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
70
vips/vips.go
70
vips/vips.go
@@ -336,6 +336,13 @@ func ptrToBytes(ptr unsafe.Pointer, size int) []byte {
|
||||
return (*[math.MaxInt32]byte)(ptr)[:int(size):int(size)]
|
||||
}
|
||||
|
||||
func (img *Image) swapAndUnref(newImg *C.VipsImage) {
|
||||
if img.VipsImage != nil {
|
||||
C.unref_image(img.VipsImage)
|
||||
}
|
||||
img.VipsImage = newImg
|
||||
}
|
||||
|
||||
func (img *Image) Width() int {
|
||||
return int(img.VipsImage.Xsize)
|
||||
}
|
||||
@@ -401,11 +408,11 @@ func (img *Image) Load(imgdata imagedata.ImageData, shrink int, scale float64, p
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
if imgdata.Format() == imagetype.TIFF {
|
||||
if C.vips_fix_float_tiff(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warnf("Can't fix TIFF: %s", Error())
|
||||
}
|
||||
@@ -428,7 +435,7 @@ func (img *Image) LoadThumbnail(imgdata imagedata.ImageData) error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -488,7 +495,8 @@ func (img *Image) Save(imgtype imagetype.Type, quality int) (imagedata.ImageData
|
||||
|
||||
func (img *Image) Clear() {
|
||||
if img.VipsImage != nil {
|
||||
C.clear_image(&img.VipsImage)
|
||||
C.unref_image(img.VipsImage)
|
||||
img.VipsImage = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,7 +507,7 @@ func (img *Image) LineCache(lines int) error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -515,7 +523,7 @@ func (img *Image) Arrayjoin(in []*Image) error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -538,7 +546,7 @@ func (img *Image) RemoveAnimation() error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -650,7 +658,7 @@ func (img *Image) CastUchar() error {
|
||||
if C.vips_cast_go(img.VipsImage, &tmp, C.VIPS_FORMAT_UCHAR) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -663,7 +671,7 @@ func (img *Image) Rad2Float() error {
|
||||
if C.vips_rad2float_go(img.VipsImage, &tmp) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -680,7 +688,7 @@ func (img *Image) Resize(wscale, hscale float64) error {
|
||||
C.vips_image_set_int(tmp, cachedCString("imgproxy-scaled-down"), 1)
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -700,7 +708,7 @@ func (img *Image) Rotate(angle int) error {
|
||||
|
||||
C.vips_autorot_remove_angle(tmp)
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -711,7 +719,7 @@ func (img *Image) Flip() error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -722,7 +730,7 @@ func (img *Image) Crop(left, top, width, height int) error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -740,7 +748,7 @@ func (img *Image) SmartCrop(width, height int) error {
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -756,7 +764,7 @@ func (img *Image) Trim(threshold float64, smart bool, color Color, equalHor bool
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -766,7 +774,7 @@ func (img *Image) Flatten(bg Color) error {
|
||||
if C.vips_flatten_go(img.VipsImage, &tmp, cRGB(bg)) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -778,7 +786,7 @@ func (img *Image) ApplyFilters(blurSigma, sharpSigma float32, pixelatePixels int
|
||||
return Error()
|
||||
}
|
||||
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -798,7 +806,7 @@ func (img *Image) BackupColourProfile() {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_icc_backup(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't backup ICC profile: %s", Error())
|
||||
}
|
||||
@@ -808,7 +816,7 @@ func (img *Image) RestoreColourProfile() {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_icc_restore(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't restore ICC profile: %s", Error())
|
||||
}
|
||||
@@ -833,7 +841,7 @@ func (img *Image) ImportColourProfile() error {
|
||||
}
|
||||
|
||||
if C.vips_icc_import_go(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't import ICC profile: %s", Error())
|
||||
}
|
||||
@@ -855,7 +863,7 @@ func (img *Image) ExportColourProfile() error {
|
||||
}
|
||||
|
||||
if C.vips_icc_export_go(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't export ICC profile: %s", Error())
|
||||
}
|
||||
@@ -872,7 +880,7 @@ func (img *Image) ExportColourProfileToSRGB() error {
|
||||
}
|
||||
|
||||
if C.vips_icc_export_srgb(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't export ICC profile: %s", Error())
|
||||
}
|
||||
@@ -891,7 +899,7 @@ func (img *Image) TransformColourProfileToSRGB() error {
|
||||
}
|
||||
|
||||
if C.vips_icc_transform_srgb(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't transform ICC profile to sRGB: %s", Error())
|
||||
}
|
||||
@@ -903,7 +911,7 @@ func (img *Image) RemoveColourProfile() error {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_icc_remove(img.VipsImage, &tmp) == 0 {
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
} else {
|
||||
log.Warningf("Can't remove ICC profile: %s", Error())
|
||||
}
|
||||
@@ -926,7 +934,7 @@ func (img *Image) Colorspace(colorspace C.VipsInterpretation) error {
|
||||
if C.vips_colourspace_go(img.VipsImage, &tmp, colorspace) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -937,7 +945,7 @@ func (img *Image) CopyMemory() error {
|
||||
if tmp = C.vips_image_copy_memory(img.VipsImage); tmp == nil {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -947,7 +955,7 @@ func (img *Image) Replicate(width, height int, centered bool) error {
|
||||
if C.vips_replicate_go(img.VipsImage, &tmp, C.int(width), C.int(height), gbool(centered)) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -958,7 +966,7 @@ func (img *Image) Embed(width, height int, offX, offY int) error {
|
||||
if C.vips_embed_go(img.VipsImage, &tmp, C.int(offX), C.int(offY), C.int(width), C.int(height)) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -969,7 +977,7 @@ func (img *Image) ApplyWatermark(wm *Image, left, top int, opacity float64) erro
|
||||
if C.vips_apply_watermark(img.VipsImage, wm.VipsImage, &tmp, C.int(left), C.int(top), C.double(opacity)) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -980,7 +988,7 @@ func (img *Image) Strip(keepExifCopyright bool) error {
|
||||
if C.vips_strip(img.VipsImage, &tmp, gbool(keepExifCopyright)) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -991,7 +999,7 @@ func (img *Image) StripAll() error {
|
||||
if C.vips_strip_all(img.VipsImage, &tmp) != 0 {
|
||||
return Error()
|
||||
}
|
||||
C.swap_and_clear(&img.VipsImage, tmp)
|
||||
img.swapAndUnref(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -18,11 +18,9 @@ typedef struct _RGB {
|
||||
|
||||
int vips_initialize();
|
||||
|
||||
void clear_image(VipsImage **in);
|
||||
void unref_image(VipsImage *in);
|
||||
void g_free_go(void **buf);
|
||||
|
||||
void swap_and_clear(VipsImage **in, VipsImage *out);
|
||||
|
||||
int gif_resolution_limit();
|
||||
|
||||
int vips_health();
|
||||
|
Reference in New Issue
Block a user