diff --git a/meson.build b/meson.build index ea08bdf2adb..8137cf8da2f 100644 --- a/meson.build +++ b/meson.build @@ -667,7 +667,13 @@ libtiff = dependency('libtiff-4', version: '>=' + libtiff_minver) MIMEtypes += 'image/tiff' -libjpeg = dependency('libjpeg') +mozjpeg = dependency('mozjpeg', required: get_option('mozjpeg')) +if mozjpeg.found() + libjpeg = mozjpeg +else + libjpeg = dependency('libjpeg') +endif +conf.set('HAVE_MOZJPEG', mozjpeg.found()) MIMEtypes += 'image/jpeg' @@ -1952,6 +1958,7 @@ final_message = [ ''' Detailed backtraces: @0@'''.format(detailed_backtraces), ''' Binary symlinks: @0@'''.format(enable_default_bin), ''' OpenMP: @0@'''.format(have_openmp), +''' MozJPEG: @0@'''.format(mozjpeg.found()), '', '''Optional Plug-Ins:''', ''' Ascii Art: @0@'''.format(libaa.found()), diff --git a/meson_options.txt b/meson_options.txt index f8968898b46..16362e56b8f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -44,6 +44,7 @@ option('ilbm', type: 'feature', value: 'auto', description: 'Amiga option('jpeg2000', type: 'feature', value: 'auto', description: 'Jpeg-2000 support') option('jpeg-xl', type: 'feature', value: 'auto', description: 'JPEG XL support') option('mng', type: 'feature', value: 'auto', description: 'Mng support') +option('mozjpeg', type: 'feature', value: 'auto', description: 'Build JPEG support with mozjpeg specifically') option('openexr', type: 'feature', value: 'auto', description: 'Openexr support') option('openmp', type: 'feature', value: 'auto', description: 'OpenMP support') option('print', type: 'boolean', value: true, description: 'Print support') diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c index d613c69f3ba..7a7de042152 100644 --- a/plug-ins/file-jpeg/jpeg-save.c +++ b/plug-ins/file-jpeg/jpeg-save.c @@ -198,6 +198,7 @@ save_image (GFile *file, GimpImage *image, GimpDrawable *drawable, GimpImage *orig_image, + GimpRunMode run_mode, gboolean preview, GError **error) { @@ -236,6 +237,7 @@ save_image (GFile *file, gint orig_num_quant_tables = -1; gboolean use_arithmetic_coding = FALSE; gboolean use_restart = FALSE; + gboolean mozjpeg = FALSE; gchar *comment; g_object_get (config, @@ -248,6 +250,7 @@ save_image (GFile *file, "baseline", &baseline, "restart", &restart, "dct", &dct, + "use-mozjpeg", &mozjpeg, /* Original quality settings. */ "use-original-quality", &use_orig_quality, @@ -262,6 +265,16 @@ save_image (GFile *file, NULL); + if (run_mode == GIMP_RUN_NONINTERACTIVE && mozjpeg) + { +#ifndef HAVE_MOZJPEG + g_set_error_literal (error, GIMP_PLUG_IN_ERROR, 0, + _("GIMP was not compiled with MozJPEG. " + "The argument 'use-mozjpeg' cannot be set to TRUE.")); + return FALSE; +#endif + } + quality = (gint) (dquality * 100.0 + 0.5); drawable_type = gimp_drawable_type (drawable); @@ -489,6 +502,13 @@ save_image (GFile *file, drawable_type == GIMP_RGBA_IMAGE) ? JCS_RGB : JCS_GRAYSCALE; } + +#ifdef HAVE_MOZJPEG + if (! mozjpeg) + /* Disable mozjpeg code path (upstream jpeg-turbo normal algorithm). */ + jpeg_c_set_int_param (&cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST); +#endif + /* Now use the library's routine to set default compression parameters. * (You must set at least cinfo.in_color_space before calling this, * since the defaults depend on the source color space.) @@ -795,6 +815,7 @@ make_preview (GimpProcedureConfig *config) preview_image, drawable_global, orig_image_global, + GIMP_RUN_NONINTERACTIVE, TRUE, NULL); g_object_unref (file); @@ -995,6 +1016,9 @@ save_dialog (GimpProcedure *procedure, "restart-frame", "sub-sampling", "dct", +#ifdef HAVE_MOZJPEG + "use-mozjpeg", +#endif NULL); gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog), "advanced-frame", "advanced-title", FALSE, diff --git a/plug-ins/file-jpeg/jpeg-save.h b/plug-ins/file-jpeg/jpeg-save.h index 4c98acb0f00..2e4cd0f1536 100644 --- a/plug-ins/file-jpeg/jpeg-save.h +++ b/plug-ins/file-jpeg/jpeg-save.h @@ -24,10 +24,11 @@ extern GimpDrawable *drawable_global; gboolean save_image (GFile *file, - GimpProcedureConfig *config, + GimpProcedureConfig *config, GimpImage *image, GimpDrawable *drawable, GimpImage *orig_image, + GimpRunMode run_mode, gboolean preview, GError **error); gboolean save_dialog (GimpProcedure *procedure, diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c index 7e4dc696a20..0c7333aa3cb 100644 --- a/plug-ins/file-jpeg/jpeg.c +++ b/plug-ins/file-jpeg/jpeg.c @@ -301,6 +301,11 @@ jpeg_create_procedure (GimpPlugIn *plug_in, _("Use restart mar_kers"), NULL, FALSE, G_PARAM_READWRITE); + GIMP_PROC_AUX_ARG_BOOLEAN (procedure, "use-mozjpeg", + _("Value file size over encoding speed (using MozJPEG)"), + _("Use MozJPEG optimizations for better quality/filesize ratio, with slower encoding."), + FALSE, + G_PARAM_READWRITE); gimp_save_procedure_set_support_exif (GIMP_SAVE_PROCEDURE (procedure), TRUE); gimp_save_procedure_set_support_iptc (GIMP_SAVE_PROCEDURE (procedure), TRUE); @@ -597,8 +602,8 @@ jpeg_save (GimpProcedure *procedure, if (status == GIMP_PDB_SUCCESS) { if (! save_image (file, config, - image, drawables[0], orig_image, FALSE, - &error)) + image, drawables[0], orig_image, + run_mode, FALSE, &error)) { status = GIMP_PDB_EXECUTION_ERROR; }