Commit Diff


commit - cd24df616f7e500ccb59ed64cfc36e8f18702fd1
commit + 8ef141df421bafd93b75fefaeb236065afe4ee24
blob - 90fd8c86d9e1362ad5fb717b09ed41bcbdee3c96
blob + a6701a03676e9edef98247fe1b651219e16294c8
--- .gitignore
+++ .gitignore
@@ -6,3 +6,4 @@ pdf
 hammer
 lib
 t/*.pdf
+t/img
blob - b832e23dae132b87644b75263786583b238ce914
blob + efc2064482b109830c2fcb9905c2593d1088f9b5
--- pdf.c
+++ pdf.c
@@ -1882,6 +1882,33 @@ ASCII85Decode(const Dict *parms, HBytes b, HParser *p)
 }
 
 /*
+ * JPEG images
+ */
+static int dumpjpegs = 0; // XXX hackety hack!
+HParseResult*
+DCTDecode(const Dict *parms, HBytes b, HParser *p)
+{
+	// XXX hackety hack just dump it to a file :D
+	if (dumpjpegs > 0) {
+		char name[10];
+		FILE *f;
+		size_t n;
+
+		snprintf(name, sizeof name, "%04d.jpg", dumpjpegs++);
+		if ((f = fopen(name, "w")) == NULL)
+			warn("%s: fopen failed", name);
+		else if ((n = fwrite(b.token, 1, b.len, f) < b.len))
+			warn("%s: fwrite failed (after %zu bytes)", name, n);
+		else {
+			fprintf(stderr, "%s (%zu bytes)\n", name, b.len);
+			fclose(f);
+		}
+	}
+
+	return h_parse(p, b.token, b.len);	// XXX no actual decoding
+}
+
+/*
  * decode the bytes in 'b' according to metadata in the stream dictionary 'd'
  * and parse the result with 'p'.
  */
@@ -1918,6 +1945,8 @@ decode_stream(const Dict *d, HBytes b, HParser *p)
 		filter = RunLengthDecode;
 	else if (bytes_eq(v->bytes, "LZWDecode"))
 		filter = LZWDecode;
+	else if (bytes_eq(v->bytes, "DCTDecode"))	/* JPEG image */
+		filter = DCTDecode;
 	else
 		return NULL;		/* filter not supported */
 
@@ -1994,6 +2023,8 @@ p_stream_data__m(HAllocator *mm__, const Dict *dict)
 	if (bytes_eq(v->bytes, "ObjStm"))
 		return p_objstm__m(mm__, dict);
 #endif
+	if (bytes_eq(v->bytes, "XObject"))
+		return p_epsilon;	// XXX just to get our hooks in
 
 	return NULL;					/* unrecognized type */
 }
@@ -2455,7 +2486,9 @@ main(int argc, char *argv[])
 	//	h_pprintln(stderr, aux.xrefs[i]);
 
 	/* run the main parser */
+	dumpjpegs = 1;	// XXX hackety hack!
 	res = h_parse(p_pdf, input, sz);
+	dumpjpegs = 0;	// XXX hackety hack!
 	if (!res) {
 		fprintf(stderr, "%s: no parse\n", infile);