Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flate png filters #114

Merged
merged 25 commits into from
Feb 16, 2018
Merged

Flate png filters #114

merged 25 commits into from
Feb 16, 2018

Conversation

wrkhenddher
Copy link
Collaborator

@wrkhenddher wrkhenddher commented Oct 4, 2017

#113

Flate PNG reverse filters: Up, Average and Paeth

Henddher Pedroza added 22 commits October 4, 2017 13:51
… to X conversion but instead it returns array.array('B')
…as they require at least 2 scanlines. Simplify UP filter.
…sters) used/produced by test_flate_png.py tests: requires matplotlib
…king PDF War of the Worlds) when png data was compressed and filtered using Sub (f=1). New flate_png also generates correct looking PDF War of the Worlds.
@wrkhenddher
Copy link
Collaborator Author

wrkhenddher commented Nov 16, 2017

Generating xxxx.png.log

Modify pngrutil.c from https://github.com/glennrp/libpng

(e.g. printf scanlines before and after if filtering was used)

void /* PRIVATE */
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
    png_const_bytep prev_row, int filter)
{
   /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
    * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
    * implementations.  See png_init_filter_functions above.
    */

    printf("width = %d\n", row_info->width);
    printf("bit_depth = %d\n", row_info->bit_depth);
    printf("channels = %d\n", row_info->channels);
    printf("color_type = %d\n", row_info->color_type);
    printf("pixel_depth = %d\n", row_info->pixel_depth);
    printf("rowbytes = %zu\n", row_info->rowbytes);
    printf("filter = %d\n", filter);
    printf("data = [ ");
    for (int i = 0; i < row_info->rowbytes; i++) {
        printf("0x%.2x,", row[i] & 0xff);
    }
    printf(" ]\n");
               
   if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
   {
      if (pp->read_filter[0] == NULL)
         png_init_filter_functions(pp);

      pp->read_filter[filter-1](row_info, row, prev_row);
   }
   else
       png_debug1(1, "no filter %d", filter);
    
    printf("expected = [ ");
    for (int i = 0; i < row_info->rowbytes; i++) {
        printf("0x%.2x,", row[i] & 0xff);
    }
    printf(" ]\n");
}

https://github.com/glennrp/libpng/blob/fc32eb1662d29a4467bd4fd7d3484d607507420f/pngrutil.c#L4110-L4125

Recompile and run.

For Mac OSX, https://github.com/IGRSoft/libpng-xcode-project is available if you prefer Xcode.

Visualizing Rasters (loaded from xxx.png.log files)

$ cd <..pdfrw>/tests
$ jupyter notebook Render\ Bitmap.ipynb 

The notebook will start on your browser.

screen shot 2017-11-17 at 3 23 16 pm

Henddher Pedroza added 2 commits November 16, 2017 16:48
…id hash, the test is expected to pass and produce a file with same hash. Revert all PDFs with Encrypted content to 'skip' because the roundtrip PDF is 'blank'
@pmaupin pmaupin merged commit 6c89216 into pmaupin:master Feb 16, 2018
@wrkhenddher
Copy link
Collaborator Author

Closes #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants