Use mozjpeg defaults by default
Since mozjpeg is now backward ABI-compatible with libjpeg[-turbo], it is now possible to temporarily load mozjpeg into a binary application and cause that application to generate uber-compressed JPEGs (at the expense of an extreme performance loss, of course.) For instance, someone could do LD_LIBRARY_PATH=/opt/mozjpeg/lib convert blah_blah_blah to make ImageMagick use mozjpeg instead of the system's pre-installed JPEG library (libjpeg-turbo, in most cases.) However, this only makes sense if mozjpeg is actually producing different behavior by default than libjpeg-turbo. Currently it isn't. Currently it requires the application to set JBOOLEAN_USE_MOZ_DEFAULTS to TRUE in order to enable the mozjpeg-specific behavior, but of course applications that were built to use libjpeg[-turbo] won't do that. Thus, this patch sets use_moz_defaults to TRUE by default, requiring an application to explicitly set it to FALSE in order to revert to the libjpeg[-turbo] behavior (makes sense, since the only applications that would need to revert to the libjpeg[-turbo] behavior would be mozjpeg-aware applications.) Note that we discussed the possibility of adding a function (jpeg_revert_defaults()), which would act the same as jpeg_set_defaults() does in libjpeg[-turbo]. This is a good solution for implementing the -revert switch in cjpeg, but unfortunately it doesn't work for jpegtran. The reason is that jpeg_set_defaults() is called within the body of jpeg_copy_critical_parameters(), which is part of the API. So yet again, if mozjpeg were loaded into a non-mozjpeg-aware application at run time, it would be desirable for jpeg_copy_critical_parameters() to set the parameters to mozjpeg defaults. That means that, in order to implement the -revert switch in jpegtran, it would be necessary to introduce a new function (jpeg_revert_critical_parameters(), perhaps). It seems cleaner to just keep using the JBOOLEAN_USE_MOZ_DEFAULTS parameter to control the behavior of jpeg_set_defaults(), even though this represents a minor abuse of the libjpeg API (jpeg_set_defaults() is technically supposed to set all of the parameters to defaults, irrespective of any previous state. However, as long as we document that JBOOLEAN_USE_MOZ_DEFAULTS works differently, then it should be OK.)
This commit is contained in:
2
cjpeg.c
2
cjpeg.c
@@ -634,8 +634,6 @@ main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
|
||||
if (jpeg_c_bool_param_supported(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
|
||||
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, TRUE);
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
/* Scan command line to find file names.
|
||||
|
||||
@@ -126,8 +126,6 @@ write_JPEG_file (char * filename, int quality)
|
||||
cinfo.image_height = image_height;
|
||||
cinfo.input_components = 3; /* # of color components per pixel */
|
||||
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
|
||||
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, TRUE); /* use Mozilla defaults for improved compression */
|
||||
|
||||
/* 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.)
|
||||
|
||||
@@ -99,6 +99,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
|
||||
cinfo->master = (struct jpeg_comp_master *)
|
||||
jpeg_get_small ((j_common_ptr) cinfo, sizeof(struct jpeg_comp_master));
|
||||
MEMZERO(cinfo->master, sizeof(struct jpeg_comp_master));
|
||||
cinfo->master->use_moz_defaults = TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011 D. R. Commander. All Rights Reserved.
|
||||
* mozjpeg Modifications:
|
||||
* Copyright (C) 2014, Mozilla Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -87,8 +85,6 @@ int main(void)
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
cinfo.input_components = 3;
|
||||
if (jpeg_c_bool_param_supported(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
|
||||
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, TRUE);
|
||||
jpeg_set_defaults(&cinfo);
|
||||
cinfo.in_color_space = JCS_EXT_RGB;
|
||||
jpeg_default_colorspace(&cinfo);
|
||||
|
||||
@@ -415,8 +415,6 @@ main (int argc, char **argv)
|
||||
/* Initialize the JPEG compression object with default error handling. */
|
||||
dstinfo.err = jpeg_std_error(&jdsterr);
|
||||
jpeg_create_compress(&dstinfo);
|
||||
if (jpeg_c_bool_param_supported(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
|
||||
jpeg_c_set_bool_param(&dstinfo, JBOOLEAN_USE_MOZ_DEFAULTS, TRUE);
|
||||
|
||||
/* Scan command line to find file names.
|
||||
* It is convenient to use just one switch-parsing routine, but the switch
|
||||
|
||||
@@ -206,7 +206,6 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo,
|
||||
}
|
||||
|
||||
cinfo->input_components=tjPixelSize[pixelFormat];
|
||||
cinfo->master->use_moz_defaults = TRUE;
|
||||
jpeg_set_defaults(cinfo);
|
||||
|
||||
if((env=getenv("TJ_OPTIMIZE"))!=NULL && strlen(env)>0 && !strcmp(env, "1"))
|
||||
|
||||
@@ -217,9 +217,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
jpeg_stdio_dest(&cinfo, jpg_fd);
|
||||
|
||||
if (jpeg_c_bool_param_supported(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS))
|
||||
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, TRUE);
|
||||
|
||||
cinfo.image_width = luma_width;
|
||||
cinfo.image_height = luma_height;
|
||||
cinfo.input_components = 3;
|
||||
|
||||
Reference in New Issue
Block a user