diff --git a/server/plugin/plg_image_c/image_jpeg.c b/server/plugin/plg_image_c/image_jpeg.c index 5df34032f..f141e9a54 100644 --- a/server/plugin/plg_image_c/image_jpeg.c +++ b/server/plugin/plg_image_c/image_jpeg.c @@ -6,17 +6,12 @@ #define JPEG_QUALITY 50 -struct filestash_jpeg_error_mgr { +typedef struct filestash_jpeg_error_mgr { struct jpeg_error_mgr pub; jmp_buf jmp; -}; +} *filestash_jpeg_error_ptr; -typedef struct filestash_jpeg_error_mgr *filestash_jpeg_error_ptr; - -void filestash_jpeg_error_exit (j_common_ptr cinfo) { - filestash_jpeg_error_ptr filestash_err = (filestash_jpeg_error_ptr) cinfo->err; - longjmp(filestash_err->jmp, 1); -} +void filestash_jpeg_error_exit (j_common_ptr cinfo); int jpeg_to_jpeg(int inputDesc, int outputDesc, int targetSize) { #ifdef HAS_DEBUG @@ -123,8 +118,11 @@ int jpeg_to_jpeg(int inputDesc, int outputDesc, int targetSize) { CLEANUP_AND_ABORT: jpeg_destroy_decompress(&jpeg_config_input); jpeg_destroy_compress(&jpeg_config_output); - fclose(input); - fclose(output); DEBUG("final"); return status; } + +void filestash_jpeg_error_exit (j_common_ptr cinfo) { + filestash_jpeg_error_ptr filestash_err = (filestash_jpeg_error_ptr) cinfo->err; + longjmp(filestash_err->jmp, 1); +} diff --git a/server/plugin/plg_image_c/image_jpeg.h b/server/plugin/plg_image_c/image_jpeg.h index cc48cf78d..2487f94af 100644 --- a/server/plugin/plg_image_c/image_jpeg.h +++ b/server/plugin/plg_image_c/image_jpeg.h @@ -1,3 +1 @@ -#include - int jpeg_to_jpeg(int input, int output, int targetSize); diff --git a/server/plugin/plg_image_c/image_png.c b/server/plugin/plg_image_c/image_png.c index caf9165af..3c8c8b224 100644 --- a/server/plugin/plg_image_c/image_png.c +++ b/server/plugin/plg_image_c/image_png.c @@ -113,6 +113,7 @@ int png_to_webp(int inputDesc, int outputDesc, int targetSize) { goto CLEANUP_AND_ABORT_C; } fwrite(webp_output_data, webp_output_size, 1, output); + fflush(output); DEBUG("after webp written"); CLEANUP_AND_ABORT_C: @@ -125,7 +126,5 @@ int png_to_webp(int inputDesc, int outputDesc, int targetSize) { if (png_ptr != NULL) png_destroy_read_struct(&png_ptr, (info_ptr != NULL) ? &info_ptr : NULL, NULL); CLEANUP_AND_ABORT: - fclose(output); - fclose(input); return status; } diff --git a/server/plugin/plg_image_c/index.go b/server/plugin/plg_image_c/index.go index 5904de492..edd75a2d6 100644 --- a/server/plugin/plg_image_c/index.go +++ b/server/plugin/plg_image_c/index.go @@ -28,6 +28,7 @@ import ( func init() { Hooks.Register.Thumbnailer("image/jpeg", &transcoder{runner(jpeg), "image/jpeg", -200}) Hooks.Register.Thumbnailer("image/png", &transcoder{runner(png), "image/webp", -200}) + Hooks.Register.Thumbnailer("image/gif", &transcoder{runner(gif), "image/webp", -300}) Hooks.Register.Thumbnailer("image/heic", &transcoder{runner(heif), "image/jpeg", -200}) rawMimeType := []string{ "image/x-canon-cr2", "image/x-tif", "image/x-canon-cr2", "image/x-canon-crw", @@ -89,33 +90,36 @@ func (this transcoder) Generate(reader io.ReadCloser, ctx *App, res *http.Respon func runner(fn func(uintptr, uintptr, int)) func(io.ReadCloser, int) (io.ReadCloser, error) { return func(inputGo io.ReadCloser, size int) (io.ReadCloser, error) { inputC, tmpw, err := os.Pipe() + logErrors(err, "plg_image_c::pipe") if err != nil { return nil, err } outputGo, outputC, err := os.Pipe() + logErrors(err, "plg_image_c::pipe") if err != nil { tmpw.Close() - Log.Stdout("ERR0 %+v", err.Error()) return nil, err } go func() { fn(inputC.Fd(), outputC.Fd(), size) // <-- all this code so we can do that - inputC.Close() - outputC.Close() + logErrors(inputC.Close(), "plg_image_c::inputC") + logErrors(inputGo.Close(), "plg_image_c::inputGo") + logErrors(outputC.Close(), "plg_image_c::outputC") }() - _, err = io.Copy(tmpw, inputGo) - inputGo.Close() - tmpw.Close() - if err != nil { - outputGo.Close() - Log.Stdout("ERR1 %+v", err.Error()) - return nil, err - } + io.Copy(tmpw, inputGo) + logErrors(tmpw.Close(), "plg_image_c::tmpw") return outputGo, nil } } +func logErrors(err error, msg string) { + if err == nil { + return + } + Log.Debug(msg + ": " + err.Error()) +} + func contains(s []string, str string) bool { for _, v := range s { if v == str {