[Libreoffice-commits] core.git: sdext/source

Vort vvort at yandex.ru
Tue Apr 22 09:08:25 PDT 2014


 sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx |   73 +++++++++++++++++-
 1 file changed, 69 insertions(+), 4 deletions(-)

New commits:
commit f61cdf6fa8c3ceb5435fadbe469fa55883c8b31f
Author: Vort <vvort at yandex.ru>
Date:   Tue Apr 22 10:59:37 2014 +0300

    fdo#71217 PDF Import: Fix importing of JPEG images
    
    Change-Id: Ic0902a3f9340d2d05be05d13d98f168879b4c3e3
    Reviewed-on: https://gerrit.libreoffice.org/9120
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
index cf601b9..c5b9aa1 100644
--- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
@@ -143,20 +143,85 @@ void writeBinaryBuffer( const OutputBuffer& rBuffer )
     fflush(g_binary_out);
 }
 
+bool ExtractJpegData(Stream* str, OutputBuffer& outBuf)
+{
+    int bytesToMarker = 0;
+    int bytesToLen = -1;
+    bool collectBytes = false;
+    int startOfScan = 0;
+    int b2 = -1;
+    int b1 = -1;
+    for (; ; )
+    {
+        b2 = b1;
+        b1 = str->getChar();
+
+        if (b1 == -1)
+            return false;
+
+        if (collectBytes)
+        {
+            outBuf.push_back((Output_t)b1);
+
+            bytesToMarker--;
+            bytesToLen--;
+        }
+
+        if (bytesToMarker == 0)
+        {
+            if (startOfScan == 1)
+            {
+                bytesToMarker = -1;
+                startOfScan = 2;
+            }
+            else if (b2 == 0xFF)
+            {
+                if (b1 == 0xD8)
+                {
+                    collectBytes = true;
+                    bytesToMarker = 2;
+
+                    outBuf.push_back((Output_t)0xFF);
+                    outBuf.push_back((Output_t)0xD8);
+                }
+                else
+                {
+                    bytesToLen = 2;
+                }
+                if (b1 == 0xDA)
+                {
+                    startOfScan = 1;
+                }
+            }
+            else if (collectBytes)
+            {
+                return false;
+            }
+        }
+
+        if (bytesToLen == 0)
+        {
+            bytesToMarker = b2 * 256 + b1;
+        }
+
+        if (startOfScan == 2)
+            if ((b2 == 0xFF) && (b1 == 0xD9))
+                return true;
+    }
+}
+
 void writeJpeg_( OutputBuffer& o_rOutputBuf, Stream* str, bool bWithLinefeed )
 {
     // dump JPEG file as-is
 #if POPPLER_CHECK_VERSION(0, 17, 3)
-    str = str->getBaseStream();
+    str = str->getNextStream();
 #else
     str = ((DCTStream *)str)->getRawStream();
 #endif
     str->reset();
 
-    int c;
     o_rOutputBuf.clear();
-    while((c=str->getChar()) != EOF)
-        o_rOutputBuf.push_back(static_cast<char>(c));
+    ExtractJpegData(str, o_rOutputBuf);
 
     printf( " JPEG %d", (int)o_rOutputBuf.size() );
     if( bWithLinefeed )


More information about the Libreoffice-commits mailing list