[ 
https://issues.apache.org/jira/browse/XGC-134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17685385#comment-17685385
 ] 

Joshua Marquart commented on XGC-134:
-------------------------------------

I threw your fop_broken.png file downloaded from here into the following code 
to see if it hit true to any of the checks in ImageLoaderFactoryRaw, but 
nothing flagged true.

{code:java}
package test;

import java.io.FileInputStream;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSource;
import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext;
import org.apache.xmlgraphics.image.loader.impl.ImageLoaderRawPNG;
import org.apache.xmlgraphics.image.loader.util.Penalty;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class TestInfo {
        
        public static void main(String args[]) {

                try {

                        ImageInputStream iis = 
ImageIO.createImageInputStream(new 
FileInputStream("./testing/images/fop_broken.png"));

                        // pre-load the image
                        ImageManager imageManager = new ImageManager(new 
DefaultImageContext());                        
                        ImageInfo imageInfo = imageManager.preloadImage(null, 
new ImageSource(iis, null, true));

                        review(imageInfo);
                        
                } catch (Exception e) {

                        e.printStackTrace();
                }
        }
        
    public static void review(ImageInfo imageInfo) {
        
        System.out.println("MIME TYPE = image/png ? " + 
"image/png".equals(imageInfo.getMimeType()));
        
        Map additionalPenalties = (Map) 
imageInfo.getCustomObjects().get("additionalPenalties");

        int penalty = 0;

        if (additionalPenalties == null) {
                
                System.out.println("ADDITIONAL PENALTIES IS NULL");

        } else {

                Penalty penaltyObj = 
((Penalty)additionalPenalties.get(ImageLoaderRawPNG.class.getName()));

                if (penaltyObj != null) {
                
                        System.out.println("SETTING PENALTY");

                        penalty = penaltyObj.getValue();

                } else {
                        
                        System.out.println("PENALTY IS NULL");

                }
        }        

        System.out.println("PENALTY = " + penalty);

        IIOMetadata metadata = (IIOMetadata) 
imageInfo.getCustomObjects().get(IIOMetadata.class);

        if (metadata == null) {

                System.out.println("METADATA IS NULL");

        } else {
                
            IIOMetadataNode children = 
(IIOMetadataNode)metadata.getAsTree("javax_imageio_png_1.0").getChildNodes();
            NamedNodeMap attr = 
children.getElementsByTagName("IHDR").item(0).getAttributes();
            String bitDepth = attr.getNamedItem("bitDepth").getNodeValue();
            String interlaceMethod = 
attr.getNamedItem("interlaceMethod").getNodeValue();
            String colorType = attr.getNamedItem("colorType").getNodeValue();
            
                System.out.println("bitDepth=" + bitDepth);
                System.out.println("interlaceMethod=" + interlaceMethod);
                System.out.println("colorType=" + colorType);

                System.out.println("== ANY TRUE BOOLEAN RESULTS IN REJECTION 
==");

                System.out.println("!bitDepth.equals(\"8\") ? " + 
!bitDepth.equals("8"));
                System.out.println("!interlaceMethod.equals(\"none\") ? " + 
!interlaceMethod.equals("none"));
                System.out.println("(colorType.equals(\"RGBAlpha\") && penalty 
>= 0) ? " + (colorType.equals("RGBAlpha") && penalty >= 0));
                System.out.println("(colorType.equals(\"GrayAlpha\") && penalty 
>= 0) ? " + (colorType.equals("GrayAlpha") && penalty >= 0));

            children = 
(IIOMetadataNode)metadata.getAsTree("javax_imageio_1.0").getChildNodes();
            Node numChannels = 
children.getElementsByTagName("NumChannels").item(0);
            String numChannelsStr = 
numChannels.getAttributes().getNamedItem("value").getNodeValue();

                System.out.println("numChannels=" + numChannelsStr);
                System.out.println("(\"4\".equals(numChannelsStr) && 
\"Palette\".equals(colorType) && penalty >= 0) ? " + 
("4".equals(numChannelsStr) && "Palette".equals(colorType) && penalty >= 0));
        }
    }   
}
{code}

output


{noformat}
MIME TYPE = image/png ? true
ADDITIONAL PENALTIES IS NULL
PENALTY = 0
bitDepth=8
interlaceMethod=none
colorType=Grayscale
== ANY TRUE BOOLEAN RESULTS IN REJECTION ==
!bitDepth.equals("8") ? false
!interlaceMethod.equals("none") ? false
(colorType.equals("RGBAlpha") && penalty >= 0) ? false
(colorType.equals("GrayAlpha") && penalty >= 0) ? false
numChannels=1
("4".equals(numChannelsStr) && "Palette".equals(colorType) && penalty >= 0) ? 
false
{noformat}


> Some PNGs are rendered incorrectly (Regression 2.7 -> 2.8)
> ----------------------------------------------------------
>
>                 Key: XGC-134
>                 URL: https://issues.apache.org/jira/browse/XGC-134
>             Project: XMLGraphicsCommons
>          Issue Type: Bug
>          Components: general
>    Affects Versions: 2.8
>         Environment: Java 17.0.5 (Adoptium Temurin) on Windows x64.
>            Reporter: mt
>            Priority: Critical
>         Attachments: broken.txt, fixed.txt, fop_broken.png, 
> xgc_2.7_correct-1.png, xgc_2.8_wrong-1.png
>
>
> After upgrading our application from FOP 2.7 to FOP 2.8 we noticed that some 
> PNG files are not rendered correctly in the PDF. While I initially thought 
> this was a problem in FOP, I can reproduce this with FOP 2.7 + XGC 2.8, so I 
> guess it must be an issue in XGC 2.8 .
> Unfortunately I can't share the exact PNG file because it contains the logo 
> of one our customers. When I try to modify the PNG in any way, I can't 
> reproduce it anymore. I also couldn't find another PNG to reproduce this with.
> Basically the PNG is rendered 3 times horizontally and a black bar appears 
> below the 3 images. I attached a comparison between XGC 2.7 and XGC 2.8 . 
> These are (obviously modified) screenshots of the PDF generated by FOP.
> There were hardly any changes between XGC 2.7 and 2.8. Looks like this may be 
> related to XGC-132 ?
> This is with Java 17.0.5 (Adoptium Temurin) on Windows x64.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to