# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Remotely Modified (Based On HEAD)
+++ Locally Modified (Based On LOCAL)
@@ -45,11 +45,13 @@
     private static final Log LOG = LogFactory.getLog(JPXFilter.class);
 
     /**
-     * Decode JPEG2000 data using Java ImageIO library.
+     * Decode JPEG data using Java ImageIO library.
      *
      * {@inheritDoc}
      *
+     * @throws java.io.IOException
      */
+    @Override
     public void decode(InputStream compressedData, OutputStream result, COSDictionary options, int filterIndex)
             throws IOException
     {
@@ -69,6 +71,23 @@
                 options.setInt(COSName.BITS_PER_COMPONENT, colorModel.getPixelSize() / colorModel.getNumComponents());
                 options.setInt(COSName.HEIGHT, bi.getHeight());
                 options.setInt(COSName.WIDTH, bi.getWidth());
+                
+                //TH PDFBOX-52
+                if (bi.getType() == bi.TYPE_3BYTE_BGR)
+                {
+                    byte[] byteBuffer =((DataBufferByte) dBuf).getData();
+                    for (int i = 0; i < byteBuffer.length; i += 3)
+                    {
+                        //BGR
+                        //to
+                        //RGB
+                        byte tmp0 = byteBuffer[i];
+                        byteBuffer[i] = byteBuffer[i+2];
+                        byteBuffer[i+2] = tmp0;
+                    }
+                    result.write(byteBuffer);
+                }
+                else
                 result.write(((DataBufferByte) dBuf).getData());
             }
             else
@@ -80,7 +99,10 @@
 
     /**
      * {@inheritDoc}
+     * 
+     * @throws java.io.IOException
      */
+    @Override
     public void encode(InputStream rawData, OutputStream result, COSDictionary options, int filterIndex)
             throws IOException
     {
