Repository navigation
Description
Why
ISO 32000-2, 7.4.8, says DCTDecode data has one, three or four colour components and holds baseline JPEG or the progressive extension (ISO 32000-1 allows two components as well). Table 87 says that when a JPXDecode image has a ColorSpace, the colour specification inside the JPEG 2000 data is ignored. ISO 32000-1 and 32000-2 8.9.3 say the number of colour components is inferred from the colour space in the image dictionary, so a DCT stream of 2 or 5 components under /DeviceRGB gives a reader 3. 7.4.9 (the ColorSpace bullet) says the colour channels of the JPEG 2000 data shall match the colour space's components, and that the writer shall keep the samples consistent with that colour space.
JpegImageLoader.Load maps the frame's component count with 1 => DeviceGray, 4 => DeviceCmyk, _ => DeviceRgb, and reads any start-of-frame marker. JpxImageLoader does the same in FallbackFromComponents and EnumCsForComponents, and always writes /ColorSpace.
Measured on origin/main b2791ba, each input saved through LayoutImage.FromBytes with no claim (the tests are Iso32000_2_7_4_8_Pins... and Iso32000_2_7_4_9_Pins... in ConformanceAuditG4Tests):
| Input | Written |
|---|---|
| JPEG frame header with 2 components | /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode, body unchanged |
| JPEG frame header with 5 components | the same |
| JPEG with SOF3 (lossless) or SOF9 (arithmetic) | /Filter /DCTDecode, body unchanged |
| bare JPEG 2000 codestream with 2 channels | /ColorSpace /DeviceRGB, and a JP2 whose ihdr says 2 channels and whose colr says enumerated sRGB (16); under PDF/A-2b veraPDF fails the file on 6.2.8.3-1 |
| JP2 file whose colr is enumerated sYCC (18), 3 channels | /ColorSpace /DeviceRGB, so a reader ignores the colr and reads YCC samples as RGB |
veraPDF 1.30.4 passes the other rows under PDF/A-2b (it has no rule for the JPEG frame, and none for the colr box against ColorSpace). Progressive JPEG (SOF2) is accepted correctly, and a 4-channel JP2 whose colr is sRGB keeps DeviceRGB because the loader reads the enumerated space first.
Sweep: image XObjects are written in VellumPdf.Kernel (Images/*, PdfDocument) and read by VellumPdf.Layout and VellumPdf.Reader; git grep -lE "ImageLoader|PdfImageXObject" src outside Kernel/Images finds PdfDocument.cs, four Layout files and the Reader's decoder. Barcodes, Cli, Signing, Conformance and Fonts.Standard14 write no image. Within the Kernel the PNG, BMP, GIF and TIFF loaders choose the colour space from the format's own fields (colour type, photometric), not from a default arm, so the two loaders above are the whole class.
Proposal
- JPEG: refuse a frame header with a component count other than 1, 3 or 4, and a start-of-frame of SOF3, SOF5 to SOF7 or SOF9 to SOF15, with
InvalidDataException. Keep SOF0, SOF1 and SOF2. - JPEG 2000: write
/ColorSpaceonly when the colr box names sRGB, greyscale or CMYK and the channel count matches (or when it is a bare codestream with 1, 3 or 4 channels); otherwise leave it out so the colr box decides, and refuse a bare codestream whose channel count is not 1, 3 or 4. What PDF/A-2 6.2.8.3 needs of the colr box whenColorSpaceis absent needs a check against the ISO 19005-2 text first. - Document each refusal on the loader, and add the "Do not pass" paragraph naming 3.0 where a kept input changes output.
Acceptance
Iso32000_2_7_4_8_ADctImageOfAnotherComponentCountIsNotWrittenAsDeviceRgb,Iso32000_2_7_4_8_AJpegOfAFrameTypeTheFilterDoesNotDecodeIsNotWrittenAsDctDecodeandIso32000_2_7_4_9_AJp2ColourSpecificationThatIsNotADeviceSpaceIsNotOverriddenByADeviceNamelose their skip and pass; the threePinstests are rewritten.- Baseline, progressive, 1, 3 and 4 component JPEGs and the sRGB, grey and CMYK JP2 files write the same bytes as before.
Activity
Tim81 commentedon Nov 29, 2026
The ground in the Why section above is corrected: 8.9.5.1 speaks of entries inconsistent with each other or with the current colour space, not with the data; the binding clauses are 8.9.3, 7.4.9 and Table 89 (DCTDecode always delivers 8-bit samples).
Three inputs the issue does not list (measured at 8d1f6a2,
LayoutImage.FromBytes)/BitsPerComponent 8 /ColorSpace /DeviceRGB /Filter /DCTDecode: the loader never reads the precision byte/ColorSpace /DeviceGray, file passed through/BitsPerComponent 8 /ColorSpace /DeviceRGB, file passed throughThe last two are PDF/A-2b files that veraPDF rejects: like the bare-codestream row, they are invalid under the claim the file makes.
The proposal's JPEG 2000 bullet refuses only "a bare codestream whose channel count is not 1, 3 or 4"; it does not cover a JP2
file with 2 channels or a bpcc box, which keep their bytes and the claim.
Also,
TiffImageLoadersends a Compression 7 strip toJpegImageLoader.Load(TiffImageLoader.cs, theCompressionJpegNewStylebranch), so the Sweep sentence "the PNG, BMP, GIF and TIFF loaders choose the colour space from theformat's own fields" is not true of that path. The fix in
JpegImageLoadercovers it, because the path delegates.Proposal additions
frame type checks.
jp2h has a bpcc box.
Acceptance additions
test: answer the review of the graphics audit (#763, #764, #768, #769)
Tim81 commentedon Nov 29, 2026
Two more points for the fix, from the audit's second review.
CIEJab (enumerated colour space 19). ISO 32000-2 7.4.9 says a JPEG 2000 image within a PDF file shall have one of the baseline JPX colour spaces excluding CIEJab, CMYK (12), or at least one ICC profile valid within PDF. A JP2 file whose only colour specification is CIEJab is written today as
/ColorSpace /DeviceRGB, which reads Jab samples as RGB. LeavingColorSpaceout, as the proposal does for a colour specification that is not a device space, would still put a CIEJab-only image in the file, and under PDF/A-2b veraPDF then fails 6.2.8.3-4. Neither output is valid, so a CIEJab-only JP2 file is refused (InvalidDataException); one that also carries a valid ICC profile keeps it, withColorSpaceleft out.Bit depths per channel (bpcc). The case to fix is a JP2 file whose channels have different depths (a
bpccbox with, for example, 7, 7 and 3 bits), written today as/BitsPerComponent 8 /ColorSpace /DeviceRGBand passed through; veraPDF fails it on 6.2.8.3-5 under PDF/A-2b. The acceptance tests should assert the clause's outcome (the file is refused, or the image is written so that its dictionary and data agree and veraPDF accepts the PDF/A-2b file), not one mechanism, so either fix shape can satisfy them.Tim81 commentedon Nov 29, 2026
The tests that pin and accept this issue were renamed during the audit's review rounds; the acceptance section above names earlier ones. Current names, all in
ConformanceAuditG4Tests(tests/VellumPdf.Kernel.Tests/ConformanceAuditG4Tests.*.cs, PR #765). A pin passes today and is rewritten by the fix; an accept test is skipped now and loses its skip with the fix; a keep test passes before and after.Pins:
Iso32000_2_7_4_8_PinsTodayAJpegOfAnotherComponentCountIsWrittenAsDeviceRgb(2 and 5 components)Iso32000_2_7_4_8_PinsTodayAFrameTypeOtherThanBaselineOrProgressiveIsWrittenAsDctDecode(SOF3, SOF9)Iso32000_1_Table89_PinsTodayAJpegOfTwelveBitPrecisionIsWrittenAsEightBitDct(SOF1, precision 12)Iso32000_2_7_4_9_PinsTodayAJp2WithASyccColourSpecificationIsWrittenAsDeviceRgbIso32000_2_7_4_9_PinsTodayABareCodestreamOfTwoChannelsGetsAnSrgbColourSpecification(also asserts veraPDF 6.2.8.3-1 under PDF/A-2b)Iso19005_2_6_2_8_3_PinsTodayAJp2FileOfTwoChannelsIsPassedThroughAndFailsVeraPdfIso19005_2_6_2_8_3_PinsTodayAJp2FileWithChannelsOfDifferentDepthsIsPassedThroughAndFailsVeraPdf(bpcc 07 07 03, veraPDF 6.2.8.3-5)Iso32000_2_7_4_9_PinsTodayAJp2WithACieJabColourSpecificationIsWrittenAsDeviceRgbAndVeraPdfDoesNotLook(colr 19 kept, veraPDF passes)Accept (skipped):
Iso32000_2_7_4_8_ADctImageOfAnotherComponentCountIsRefused(InvalidDataException)Iso32000_2_7_4_8_AJpegOfAFrameTypeTheFilterDoesNotDecodeIsNotWrittenAsDctDecode(InvalidDataException)Iso32000_1_Table89_AJpegOfAPrecisionOtherThanEightIsRefused(InvalidDataException)Iso32000_2_7_4_9_AJp2ColourSpecificationThatIsNotADeviceSpaceIsNotOverriddenByADeviceName(refusal, or ColorSpace absent)Iso19005_2_6_2_8_3_ABareCodestreamOfTwoChannelsIsRefusedOrWrittenWithoutAVeraPdfFailureIso19005_2_6_2_8_3_AJp2FileOfTwoChannelsIsRefusedOrWrittenWithoutAVeraPdfFailureIso19005_2_6_2_8_3_AJp2FileWithChannelsOfDifferentDepthsIsRefusedOrWrittenWithoutAVeraPdfFailureIso32000_2_7_4_9_AJp2FileWhoseOnlyColourSpecificationIsCieJabIsRefusedOrBackedByAnIccProfile(refusal, or an ICC colr with ColorSpace absent)The three JPEG 2000 "RefusedOrWritten..." tests accept a refusal (
InvalidDataException) or a PDF/A-2b file with no ColorSpace entry that veraPDF passes.Keep:
Iso32000_2_7_4_8_AProgressiveJpegIsAcceptedBecauseTheFilterDecodesIt,Iso32000_1_7_4_8_AJpegPassesThroughAsDctDecodeWithTheColourSpaceItsFrameHeaderImplies,Iso19005_2_6_2_8_3_AJpxImageIsAJp2FileWithOneColourSpecificationOfAnAllowedMethod,Iso32000_2_7_4_9_TheJpxCodestreamIsTheSourceByteForByte,Iso19005_2_6_2_8_TheOutputOfEveryLoaderThatNeedsNoCmykIntentPassesVeraPdfAndQpdf.test: pin graphics and image output to its ISO clauses (#765)
fix(images): write a JP2 device name only for a channel count it fits
docs(conformance): mark the image gaps #763, #764, #768 and #770 fixed