summaryrefslogtreecommitdiff
path: root/sdext
diff options
context:
space:
mode:
authorVort <vvort@yandex.ru>2014-04-22 10:59:37 +0300
committerCaolán McNamara <caolanm@redhat.com>2014-04-22 16:08:01 +0000
commitf61cdf6fa8c3ceb5435fadbe469fa55883c8b31f (patch)
tree14ab5f797308ed3c865913b129090d0a0b34f722 /sdext
parent613699ebaf97e77c77e7bf2e90100be56299b550 (diff)
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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sdext')
-rw-r--r--sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx73
1 files changed, 69 insertions, 4 deletions
diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
index cf601b9fb4f5..c5b9aa11bf9a 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 )