Support for progressive jpeg in image_filter module

ivan babrou ibobrik at gmail.com
Sat Mar 16 08:07:26 UTC 2013


I added cast to int, fixed order and this is plain text version of the patch.

diff --git a/ngx_http_image_filter_module.c b/ngx_http_image_filter_module.c
index b086e3c..968e460 100644
--- a/ngx_http_image_filter_module.c
+++ b/ngx_http_image_filter_module.c
@@ -52,6 +52,7 @@ typedef struct {
     ngx_uint_t                   offset_y;

     ngx_flag_t                   transparency;
+    ngx_flag_t                   interlace;

     ngx_http_complex_value_t    *wcv;
     ngx_http_complex_value_t    *hcv;
@@ -156,6 +157,13 @@ static ngx_command_t  ngx_http_image_filter_commands[] = {
       offsetof(ngx_http_image_filter_conf_t, transparency),
       NULL },

+   { ngx_string("image_filter_interlace"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_image_filter_conf_t, interlace),
+      NULL },
+
     { ngx_string("image_filter_buffer"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_size_slot,
@@ -1115,10 +1123,13 @@ ngx_http_image_out(ngx_http_request_t *r,
ngx_uint_t type, gdImagePtr img,

     out = NULL;

+    conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
+
+    gdImageInterlace(img, (int) conf->interlace);
+
     switch (type) {

     case NGX_HTTP_IMAGE_JPEG:
-        conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);

         jq = ngx_http_image_filter_get_value(r, conf->jqcv,
conf->jpeg_quality);
         if (jq <= 0) {
@@ -1237,6 +1248,7 @@ ngx_http_image_filter_create_conf(ngx_conf_t *cf)
     conf->sharpen = NGX_CONF_UNSET_UINT;
     conf->angle = NGX_CONF_UNSET_UINT;
     conf->transparency = NGX_CONF_UNSET;
+    conf->interlace = NGX_CONF_UNSET;
     conf->buffer_size = NGX_CONF_UNSET_SIZE;
     conf->offset_x = NGX_CONF_UNSET_UINT;
     conf->offset_y = NGX_CONF_UNSET_UINT;
@@ -1292,6 +1304,8 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf,
void *parent, void *child)

     ngx_conf_merge_value(conf->transparency, prev->transparency, 1);

+    ngx_conf_merge_value(conf->interlace, prev->interlace, 0);
+
     ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
                               1 * 1024 * 1024);



On 16 March 2013 07:56, Ruslan Ermilov <ru at nginx.com> wrote:
> On Wed, Mar 13, 2013 at 10:04:35PM +0400, ivan babrou wrote:
>> This patch adds support for progressive jpeg and pgn encoding with
>> image_filter_interlace on/off setting. Google suggests to use progressive
>> jpegs so why not with nginx?
>
> Your MUA broke the text patch, and HTML with the patch is generally
> meaningless.  Please find a way to properly send patches (experiment
> locally).
>
>> diff --git a/ngx_http_image_filter_module.c b/ngx_http_image_filter_module.c
>> index b086e3c..cc44d90 100644
>> --- a/ngx_http_image_filter_module.c
>> +++ b/ngx_http_image_filter_module.c
>> @@ -52,6 +52,7 @@ typedef struct {
>>      ngx_uint_t                   offset_y;
>>
>>      ngx_flag_t                   transparency;
>> +    ngx_flag_t                   interlace;
>>
>>      ngx_http_complex_value_t    *wcv;
>>      ngx_http_complex_value_t    *hcv;
>> @@ -142,6 +143,13 @@ static ngx_command_t  ngx_http_image_filter_commands[]
>> = {
>>        0,
>>        NULL },
>>
>> +   { ngx_string("image_filter_interlace"),
>> +      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
>> +      ngx_conf_set_flag_slot,
>> +      NGX_HTTP_LOC_CONF_OFFSET,
>> +      offsetof(ngx_http_image_filter_conf_t, interlace),
>> +      NULL },
>> +
>
> Please keep the same order here as in ngx_http_image_filter_conf_t and
> ngx_http_image_filter_{create,merge}_conf().  That is (sharpen,
> transparency, interlace).
>
>>      { ngx_string("image_filter_sharpen"),
>>
>>  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
>>        ngx_http_image_filter_sharpen,
>> @@ -1115,10 +1123,13 @@ ngx_http_image_out(ngx_http_request_t *r,
>> ngx_uint_t type, gdImagePtr img,
>>
>>      out = NULL;
>>
>> +    conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
>> +
>> +    gdImageInterlace(img, conf->interlace);
>> +
>
> conf->interlace which is of type ngx_flag_t isn't the same
> as "int" that this function expects.  This will cause warnings
> if compiled with -Wshorten-64-to-32 on 64-bit platforms.
> While nginx has several such issues at the moment, adding
> another one is not welcome.  Cast it to "int" here.
>
>>      switch (type) {
>>
>>      case NGX_HTTP_IMAGE_JPEG:
>> -        conf = ngx_http_get_module_loc_conf(r,
>> ngx_http_image_filter_module);
>>
>>          jq = ngx_http_image_filter_get_value(r, conf->jqcv,
>> conf->jpeg_quality);
>>          if (jq <= 0) {
>> @@ -1237,6 +1248,7 @@ ngx_http_image_filter_create_conf(ngx_conf_t *cf)
>>      conf->sharpen = NGX_CONF_UNSET_UINT;
>>      conf->angle = NGX_CONF_UNSET_UINT;
>>      conf->transparency = NGX_CONF_UNSET;
>> +    conf->interlace = NGX_CONF_UNSET;
>>      conf->buffer_size = NGX_CONF_UNSET_SIZE;
>>      conf->offset_x = NGX_CONF_UNSET_UINT;
>>      conf->offset_y = NGX_CONF_UNSET_UINT;
>> @@ -1292,6 +1304,8 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void
>> *parent, void *child)
>>
>>      ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
>>
>> +    ngx_conf_merge_value(conf->interlace, prev->interlace, 0);
>> +
>>      ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
>>                                1 * 1024 * 1024);
>>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel



--
Regards, Ian Babrou
http://bobrik.name http://twitter.com/ibobrik skype:i.babrou



More information about the nginx-devel mailing list