Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

PNG Encoder Filter Options

normanholz
Beginner
1,276 Views
Hi everyone,

I am looking for the option to encode my png image with optional filtering (Sub, Average, Paeth).

Does anyone have a pointer where I can start with that. THe UIC sample encoder do not offer filtering rigth now, do they?

Kind regards,
Norman
0 Kudos
1 Solution
Pavel_V_Intel
Employee
1,276 Views
Quoting - normanholz

Sorry, my fault. I indeed was using using the PNG_FILTER_NONE flag. Actually I tried every flag, rebuild the uic libs, started the encodign and got no changing file sizes.

It feels like the flag has no impact at all.

Do I have to configure something else?

For instance, I tried:

png_set_filter(m_png_ptr, 0, PNG_FILTER_VALUE_UP);

Then, in png_set_IHDR() I can only keep the flag set to PNG_FILTER_TYPE_BASE (orPNG_FILTER_NONE) without getting an error from libpng.

png_set_IHDR(
m_png_ptr, m_info_ptr, m_width, m_height, m_bit_depth, png_cmap[m_color],
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

In insights would be appreciated.

Kind regards,
Norman

You don't need to change png_set_IHDR() params, this function must use PNG_FILTER_TYPE_BASE flag.

It's strange, I just inserted png_set_filter() function and nowfiltration changingproperly.
May be attached file willhelp.

In next release UIC will bewithoption to control filtration.

View solution in original post

0 Kudos
8 Replies
Pavel_V_Intel
Employee
1,276 Views
Quoting - normanholz
Hi everyone,

I am looking for the option to encode my png image with optional filtering (Sub, Average, Paeth).

Does anyone have a pointer where I can start with that. THe UIC sample encoder do not offer filtering rigth now, do they?

Kind regards,
Norman

UIC doesn't support filtering by default, but you can easily fix that.

Open file "UICcodecimagepngencsrcuic_png_enc.cpp",
find "ExcStatus WriteHeader()" function,
and just after thefunction "png_set_write_fn(m_png_ptr, &m_write_info, pngWriteFunc, NULL);"
add new filter function "png_set_filter(m_png_ptr, 0,PNG_FILTER_SUB | PNG_FILTER_AVG| PNG_FILTER_PAETH);".

For detail information check "UICcodecimagepngcommonsrclibpng-1.2.35.txt" file.
0 Kudos
normanholz
Beginner
1,276 Views
Quoting - Pavel Vlasov

UIC doesn't support filtering by default, but you can easily fix that.

Open file "UICcodecimagepngencsrcuic_png_enc.cpp",
find "ExcStatus WriteHeader()" function,
and just after thefunction "png_set_write_fn(m_png_ptr, &m_write_info, pngWriteFunc, NULL);"
add new filter function "png_set_filter(m_png_ptr, 0,PNG_FILTER_SUB | PNG_FILTER_AVG| PNG_FILTER_PAETH);".

For detail information check "UICcodecimagepngcommonsrclibpng-1.2.35.txt" file.

Hi Pavel,

thanks for your quick reply.

I changed the code to the following (just in order to force a change in the resulting file size):

ExcStatus WriteHeader(void)
{
m_png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(m_png_ptr == NULL)
return ExcStatusFail;

m_info_ptr = png_create_info_struct(m_png_ptr);
if(m_info_ptr == NULL)
{
png_destroy_write_struct(&m_png_ptr, png_infopp_NULL);
return ExcStatusFail;
}

if(setjmp(png_jmpbuf(m_png_ptr)))
{
png_destroy_write_struct(&m_png_ptr, &m_info_ptr);
return ExcStatusFail;
}

png_set_write_fn(m_png_ptr, &m_write_info, pngWriteFunc, NULL);


png_set_filter(m_png_ptr, 0, PNG_ALL_FILTERS);
printf("filteringn");

png_set_IHDR(
m_png_ptr, m_info_ptr, m_width, m_height, m_bit_depth, png_cmap[m_color],
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

png_write_info(m_png_ptr, m_info_ptr);

if(m_byteOrder)
png_set_swap(m_png_ptr);

return ExcStatusOk;
}

Unfortunately, the filtering does not change my resulting file size. Do I have to change the png_set_IHDR method accordingly? Do I miss something else?

Many thanks in advance and kind regards,
Norman
0 Kudos
Pavel_V_Intel
Employee
1,276 Views
Quoting - normanholz

Hi Pavel,

thanks for your quick reply.

skipped...

Unfortunately, the filtering does not change my resulting file size. Do I have to change the png_set_IHDR method accordingly? Do I miss something else?

Many thanks in advance and kind regards,
Norman
Sorry, my mistake. I didn't notice what it turns onall filters by default in png_write_info() function.There isno changes beacuse itused PNG_ALL_FILTERSflag before.
So it seems that UIC used maximum filtrationall this time. :)
0 Kudos
normanholz
Beginner
1,276 Views
Quoting - Pavel Vlasov
Sorry, my mistake. I didn't notice what it turns onall filters by default in png_write_info() function.There isno changes beacuse itused PNG_ALL_FILTERSflag before.
So it seems that UIC used maximum filtrationall this time. :)

Thanks for the insight.

With this in mind, is there any possibility to configure the filtering in UIC. Lets say to disable to disable the filtering in order to get more encoding performance? I tried the NO_FILTER flag as well, without any result changing as well.

Kind regards,
Norman
0 Kudos
Pavel_V_Intel
Employee
1,276 Views
Quoting - normanholz

Thanks for the insight.

With this in mind, is there any possibility to configure the filtering in UIC. Lets say to disable to disable the filtering in order to get more encoding performance? I tried the NO_FILTER flag as well, without any result changing as well.

Kind regards,
Norman

There is no shuch flag as "NO_FILTER".

Filter flags described in png.h as follow:

#define PNG_FILTER_NONE 0x08
#define PNG_FILTER_SUB 0x10
#define PNG_FILTER_UP 0x20
#define PNG_FILTER_AVG 0x40
#define PNG_FILTER_PAETH 0x80
#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP |
PNG_FILTER_AVG | PNG_FILTER_PAETH)

They works for me just fine.
0 Kudos
normanholz
Beginner
1,276 Views
Quoting - Pavel Vlasov

There is no shuch flag as "NO_FILTER".

Filter flags described in png.h as follow:

#define PNG_FILTER_NONE 0x08
#define PNG_FILTER_SUB 0x10
#define PNG_FILTER_UP 0x20
#define PNG_FILTER_AVG 0x40
#define PNG_FILTER_PAETH 0x80
#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP |
PNG_FILTER_AVG | PNG_FILTER_PAETH)

They works for me just fine.

Sorry, my fault. I indeed was using using the PNG_FILTER_NONE flag. Actually I tried every flag, rebuild the uic libs, started the encodign and got no changing file sizes.

It feels like the flag has no impact at all.

Do I have to configure something else?

For instance, I tried:

png_set_filter(m_png_ptr, 0, PNG_FILTER_VALUE_UP);

Then, in png_set_IHDR() I can only keep the flag set to PNG_FILTER_TYPE_BASE (orPNG_FILTER_NONE) without getting an error from libpng.

png_set_IHDR(
m_png_ptr, m_info_ptr, m_width, m_height, m_bit_depth, png_cmap[m_color],
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

In insights would be appreciated.

Kind regards,
Norman
0 Kudos
Pavel_V_Intel
Employee
1,277 Views
Quoting - normanholz

Sorry, my fault. I indeed was using using the PNG_FILTER_NONE flag. Actually I tried every flag, rebuild the uic libs, started the encodign and got no changing file sizes.

It feels like the flag has no impact at all.

Do I have to configure something else?

For instance, I tried:

png_set_filter(m_png_ptr, 0, PNG_FILTER_VALUE_UP);

Then, in png_set_IHDR() I can only keep the flag set to PNG_FILTER_TYPE_BASE (orPNG_FILTER_NONE) without getting an error from libpng.

png_set_IHDR(
m_png_ptr, m_info_ptr, m_width, m_height, m_bit_depth, png_cmap[m_color],
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

In insights would be appreciated.

Kind regards,
Norman

You don't need to change png_set_IHDR() params, this function must use PNG_FILTER_TYPE_BASE flag.

It's strange, I just inserted png_set_filter() function and nowfiltration changingproperly.
May be attached file willhelp.

In next release UIC will bewithoption to control filtration.
0 Kudos
normanholz
Beginner
1,276 Views
Quoting - Pavel Vlasov

You don't need to change png_set_IHDR() params, this function must use PNG_FILTER_TYPE_BASE flag.

It's strange, I just inserted png_set_filter() function and nowfiltration changingproperly.
May be attached file willhelp.

In next release UIC will bewithoption to control filtration.

Thanks for your help. The filtering works. The mistake was on my side.

Best regards,
Norman
0 Kudos
Reply