branch port r494666

svn path=/trunk/playground/graphics/oKular/kpdf/; revision=494667
remotes/origin/okular3-playground
Albert Astals Cid 20 years ago
parent 6cf12beee4
commit 85aa75c5b2
  1. 29
      generators/xpdf/xpdf/xpdf/DCTStream.cc

@ -14,19 +14,25 @@ static void str_init_source(j_decompress_ptr /*cinfo*/)
static boolean str_fill_input_buffer(j_decompress_ptr cinfo) static boolean str_fill_input_buffer(j_decompress_ptr cinfo)
{ {
int c;
struct str_src_mgr * src = (struct str_src_mgr *)cinfo->src; struct str_src_mgr * src = (struct str_src_mgr *)cinfo->src;
if (src->index == 0) { if (src->index == 0) {
src->buffer = 0xFF; c = 0xFF;
src->index++; src->index++;
} }
else if (src->index == 1) { else if (src->index == 1) {
src->buffer = 0xD8; c = 0xD8;
src->index++; src->index++;
} }
else src->buffer = src->str->getChar(); else c = src->str->getChar();
src->pub.next_input_byte = &src->buffer; if (c != EOF)
src->pub.bytes_in_buffer = 1; {
return TRUE; src->buffer = c;
src->pub.next_input_byte = &src->buffer;
src->pub.bytes_in_buffer = 1;
return TRUE;
}
else return FALSE;
} }
static void str_skip_input_data(j_decompress_ptr cinfo, long num_bytes) static void str_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
@ -73,6 +79,7 @@ void DCTStream::reset() {
int row_stride; int row_stride;
str->reset(); str->reset();
// JPEG data has to start with 0xFF 0xD8 // JPEG data has to start with 0xFF 0xD8
// but some pdf like the one on // but some pdf like the one on
// https://bugs.freedesktop.org/show_bug.cgi?id=3299 // https://bugs.freedesktop.org/show_bug.cgi?id=3299
@ -80,18 +87,17 @@ void DCTStream::reset() {
// the start marker... // the start marker...
bool startFound = false; bool startFound = false;
int c = 0, c2 = 0; int c = 0, c2 = 0;
int n = 0;
while (!startFound) while (!startFound)
{ {
if (!c) if (!c)
{ {
c = str->getChar(); c = str->getChar();
if (c != 0xFF) c = 0; if (c == -1)
if (c == -1)
{ {
error(-1, "Could not find start of jpeg data"); error(-1, "Could not find start of jpeg data");
exit(1); exit(1);
} }
if (c != 0xFF) c = 0;
} }
else else
{ {
@ -103,7 +109,6 @@ void DCTStream::reset() {
} }
else startFound = true; else startFound = true;
} }
n++;
} }
jpeg_read_header(&cinfo, TRUE); jpeg_read_header(&cinfo, TRUE);
@ -118,7 +123,9 @@ int DCTStream::getChar() {
if (x == 0) { if (x == 0) {
if (cinfo.output_scanline < cinfo.output_height) if (cinfo.output_scanline < cinfo.output_height)
jpeg_read_scanlines(&cinfo, row_buffer, 1); {
if (!jpeg_read_scanlines(&cinfo, row_buffer, 1)) return EOF;
}
else return EOF; else return EOF;
} }
c = row_buffer[0][x]; c = row_buffer[0][x];

Loading…
Cancel
Save