PNG Encoding

Help
nipps
2010-10-06
2013-04-17
  • nipps
    nipps
    2010-10-06

    Hi, we had some problems rendering PDFs with PNG images in it, so we fixed the encoding in jPod ..
    http://www.w3.org/TR/PNG-Filters.html

    PNGAveragePrediction.diff

    @@ -59,11 +59,11 @@
                    result[resultOffset + c] = source[sourceOffset + c];
                }
    
    -           for (int x = 1; x < getResultRowSize(); x++) {
    +           for (int x = colors; x < getResultRowSize(); x++) {
                    raw = source[sourceOffset + x] & 0xff;
                    left = result[(resultOffset + x) - colors] & 0xff;
                    above = 0;
    -               result[resultOffset + x] = (byte) ((raw + (left + above)) >> 1);
    +               result[resultOffset + x] = (byte) (raw + ((left + above) >> 1));
                }
                return;
            }
    @@ -72,14 +72,14 @@
                raw = source[sourceOffset + c] & 0xff;
                left = 0;
                above = result[(resultOffset + c) - getResultRowSize()] & 0xff;
    -           result[resultOffset + c] = (byte) ((raw + (left + above)) >> 1);
    +           result[resultOffset + c] = (byte) (raw + ((left + above) >> 1));
            }
    
    -       for (int x = 1; x < getResultRowSize(); x++) {
    +       for (int x = colors; x < getResultRowSize(); x++) {
                raw = source[sourceOffset + x] & 0xff;
                left = result[(resultOffset + x) - colors] & 0xff;
                above = result[(resultOffset + x) - getResultRowSize()] & 0xff;
    -           result[resultOffset + x] = (byte) ((raw + (left + above)) >> 1);
    +           result[resultOffset + x] = (byte) (raw + ((left + above) >> 1));
            }
        }
     }
    

    PNGPaethPrediction.diff

    @@ -59,7 +59,7 @@
                    result[resultOffset + c] = source[sourceOffset + c];
                }
    
    -           for (int x = 1; x < getResultRowSize(); x++) {
    +           for (int x = colors; x < getResultRowSize(); x++) {
                    raw = source[sourceOffset + x] & 0xff;
                    left = result[(resultOffset + x) - colors] & 0xff;
                    above = 0;
    @@ -79,11 +79,11 @@
                        above, upperLeft)) & 0xff);
            }
    
    -       for (int x = 1; x < getResultRowSize(); x++) {
    +       for (int x = colors; x < getResultRowSize(); x++) {
                raw = source[sourceOffset + x] & 0xff;
                left = result[(resultOffset + x) - colors] & 0xff;
                above = result[(resultOffset + x) - getResultRowSize()] & 0xff;
    -           upperLeft = (resultOffset + x) - getResultRowSize() - colors >= 0 ? result[(resultOffset + x) - getResultRowSize() - colors] & 0xff : 0;
    +           upperLeft = result[(resultOffset + x) - getResultRowSize() - colors] & 0xff;
                result[resultOffset + x] = (byte) ((raw + paethPredictor(left,
                        above, upperLeft)) & 0xff);
            }
    
     
  • mtraut
    mtraut
    2010-10-06

    many thanks. we will check and integrate this.

     
  • Elfi Heck
    Elfi Heck
    2010-10-14

    I had already fixed this and my modifications are almost the same as yours.
    I don't have your first change in both files. I did this in July and I don't remember exactly why but I'm sure I had a reason not to change the first "1" to "colors".
    And I don't understand where the last change in PNGPaethPrediction came from. I never had a source code revision with that 0 check in it.

     
  • nipps
    nipps
    2010-10-30

    I posted a working copy and dont tested the PNGs with the old version, so if your changes are working, just ignore that :)