Commit Diff


commit - 11ecff401f57af01ad1d2e62a5fd7e9791c9240b
commit + 6a46c04128ffe0e1ac573b5da443a3731d9f5c68
blob - 8f4fa53f554e3cdf6b23ec64ab81eb273c836ff2
blob + 3ad9f675d5dc205c0c078e8a5a1f8906a9ec81e4
--- pdf.c
+++ pdf.c
@@ -858,6 +858,7 @@ HParser *p_objdef;
 HParser *p_a85string;
 HParser *p_ahexstream;
 HParser *p_rldstring;
+HParser *p_dct;
 HParser *p_ws;
 HParser *p_wel;
 HParser *p_elemr;
@@ -886,6 +887,84 @@ init_runlengthdecode_parser(struct Env *aux)
 }
 
 void
+init_dct_parser(struct Env *aux)
+{
+	H_RULE(jpgmagic, h_ch('\xFF'));
+	H_RULE(app0_marker, h_ch('\xE0'));
+	H_RULE(app0_length, h_int16());
+
+	H_RULE(app0_magic, LIT("JFIF"));
+	H_RULE(app0_vmajor, h_uint8());
+	H_RULE(app0_vminor, h_uint8());
+	H_RULE(app0_densityunits, h_uint8());	// XXX enum, 0 1 2
+	H_RULE(app0_densityx, h_uint16());
+	H_RULE(app0_densityy, h_uint16());
+	H_RULE(app0_thumbnailx, h_uint8());
+	H_RULE(app0_thumbnaily, h_uint8());
+
+	H_RULE(app0_rgb, h_repeat_n(h_uint8(), 3));
+	H_RULE(app0_rgb_n, h_many(app0_rgb));
+
+	H_RULE(app0, SEQ(jpgmagic, app0_marker, app0_length, app0_magic, app0_vmajor, app0_vminor, app0_densityunits,
+			app0_densityx, app0_densityy, app0_thumbnailx, app0_thumbnaily, app0_rgb_n));
+
+	H_RULE(app1_marker, h_ch('\xE1'));
+	H_RULE(app1_zero, h_ch('\0'));
+	H_RULE(app1_exifdata, h_many(h_uint8()));
+	H_RULE(app1, SEQ(jpgmagic, app1_marker, app1_zero, app1_exifdata));
+
+	H_RULE(sof0_marker, h_ch('\xC0'));
+	/* Bits per sample */
+	H_RULE(sof0_bps, h_uint8());
+	H_RULE(sof0_imgheight, h_uint16());
+	H_RULE(sof0_imgwidth, h_uint16());
+	H_RULE(sof0_numcomponents, h_uint8()); // XXX multiply by 3 in action
+	H_RULE(sof0_componentid, h_uint8()); // enum: y cb cr i q
+	H_RULE(sof0_samplingfactors, h_uint8());
+	/* Quantization table ID */
+	H_RULE(sof0_qtableid, h_uint8());
+	H_RULE(sof0_component, SEQ(sof0_componentid, sof0_samplingfactors, sof0_qtableid));
+
+	/* Rule for the component itself */
+	H_RULE(sof0_component_lv, h_length_value(sof0_numcomponents, sof0_component));
+
+	H_RULE(sof0, SEQ(jpgmagic, sof0_marker, sof0_bps, sof0_imgheight, sof0_imgwidth, sof0_component_lv));
+
+
+	H_RULE(soimarker, h_ch('\xD8'));
+
+	/* start of scan marker segment */
+	H_RULE(sosmarker, h_ch('\xDA'));
+
+	/* length-value array of components begins here */
+	H_RULE(sos_numcomponents, h_uint8());
+
+	/* Rules for component's fields */
+	H_RULE(sos_componentid, h_uint8());
+	H_RULE(sos_huffmantable, h_uint8());
+
+	/* Rule for the component itself */
+	H_RULE(sos_component, SEQ(sos_componentid, sos_huffmantable));
+
+	H_RULE(sos_component_lv, h_length_value(sos_numcomponents, sos_component));
+
+	H_RULE(sos_startspectral, h_uint8());
+	H_RULE(sos_endspectral, h_uint8());
+	H_RULE(sos_approxbitpos, h_uint8());
+
+	/* Final SOS segment parser */
+	H_RULE(sos, SEQ(jpgmagic, sosmarker, sos_component_lv, sos_startspectral, sos_endspectral, sos_approxbitpos));
+
+	// XXX rest of the markers
+
+	// XXX for now this is to prevent unused variable errors when compiling
+	//H_ARULE(dct, SEQ(jpgmagic, app0, sos));
+	H_RULE(dct, SEQ(jpgmagic, app0, sos, soimarker, sof0, app1));
+
+	p_dct = dct;
+}
+
+void
 init_parser(struct Env *aux)
 {
 	TT_HParseResult = h_allocate_token_new("HParseResult", NULL, pp_parseresult);
@@ -1855,6 +1934,16 @@ ASCII85Decode(const Dict *parms, HBytes b, HParser *p)
 }
 
 /*
+ * DCTDecode is, the filter that decodes images encoding
+ * accorded to "Baseline" JPEG (as referred to in the standard)
+ */
+HParseResult*
+DCTDecode(const Dict *parms, HBytes b, HParser *p)
+{
+	return NULL;
+}
+
+/*
  * decode the bytes in 'b' according to metadata in the stream dictionary 'd'
  * and parse the result with 'p'.
  */