From 1132cfc95d8754abb40bfaf51fa79419de4c11f5 Mon Sep 17 00:00:00 2001 From: BobLD Date: Mon, 6 Feb 2023 19:40:04 +0000 Subject: [PATCH] Update with comments @EliotJones, rename Bitmap(s) to Jbig2Bitmap(s) and replace System.Drawing.rectangle by Jbig2Rectangle and update NOTICE with JBig2 --- NOTICES.txt | 10 ++++- .../Filters/Jbig2/BitmapTest.cs | 14 +++--- .../Filters/Jbig2/ChecksumTest.cs | 10 ++--- .../Filters/Jbig2/GenericRegionTest.cs | 2 +- .../Filters/Jbig2/HalftoneRegionTest.cs | 2 +- .../Filters/Jbig2/MMRDecompressorTest.cs | 4 +- .../Filters/Jbig2/PatternDictionaryTest.cs | 2 +- .../Jbig2/RegionSegmentInformationTest.cs | 4 +- .../Filters/Jbig2DecodeFilterTests.cs | 2 +- .../Files/README_SAMPLE_DATA_LICENSING.txt | 21 --------- .../Images/Files/sampledata.jb2 | Bin 860 -> 0 bytes .../Images/Files/sampledata_page1.jb2 | Bin 400 -> 0 bytes .../Files/sampledata_page1.jb2-decoded.bin | Bin 448 -> 0 bytes .../Images/Files/sampledata_page1.jb2.png | Bin 893 -> 0 bytes .../Images/Files/sampledata_page2.jb2 | Bin 330 -> 0 bytes .../Images/Files/sampledata_page3.jb2 | Bin 215 -> 0 bytes .../Images/PngFromPdfImageFactoryTests.cs | 2 +- .../Filters/Jbig2/ArithmeticDecoder.cs | 2 +- .../Filters/Jbig2/ArithmeticIntegerDecoder.cs | 2 +- src/UglyToad.PdfPig/Filters/Jbig2/CX.cs | 2 +- .../Filters/Jbig2/EncodedTable.cs | 2 +- .../Filters/Jbig2/EndOfStripe.cs | 2 +- .../Filters/Jbig2/FixedSizeTable.cs | 2 +- .../Filters/Jbig2/GenericRefinementRegion.cs | 18 ++++---- .../Filters/Jbig2/GenericRegion.cs | 10 ++--- .../Filters/Jbig2/HalftoneRegion.cs | 28 ++++++------ .../Filters/Jbig2/HuffmanTable.cs | 2 +- .../{IDictionary.cs => IJbigDictionary.cs} | 6 +-- src/UglyToad.PdfPig/Filters/Jbig2/IRegion.cs | 4 +- .../Filters/Jbig2/ImageInputStream.cs | 2 +- .../Filters/Jbig2/IntegerMaxValueException.cs | 2 +- .../Filters/Jbig2/InternalNode.cs | 2 +- .../Jbig2/{Bitmap.cs => Jbig2Bitmap.cs} | 4 +- .../Jbig2/{Bitmaps.cs => Jbig2Bitmaps.cs} | 24 +++++----- .../Filters/Jbig2/Jbig2Document.cs | 2 +- .../Filters/Jbig2/Jbig2Globals.cs | 2 +- .../Filters/Jbig2/Jbig2Page.cs | 20 ++++----- .../Filters/Jbig2/Jbig2Rectangle.cs | 40 +++++++++++++++++ .../Filters/Jbig2/MMRConstants.cs | 2 +- .../Filters/Jbig2/MMRDecompressor.cs | 8 ++-- .../Filters/Jbig2/OutOfBandNode.cs | 2 +- .../Filters/Jbig2/PageInformation.cs | 2 +- .../Filters/Jbig2/PatternDictionary.cs | 21 +++++---- src/UglyToad.PdfPig/Filters/Jbig2/Profiles.cs | 2 +- .../Filters/Jbig2/RegionSegmentInformation.cs | 2 +- .../Filters/Jbig2/SegmentHeader.cs | 2 +- .../Filters/Jbig2/StandardTables.cs | 2 +- .../Filters/Jbig2/SubInputStream.cs | 2 +- .../Filters/Jbig2/SymbolDictionary.cs | 41 +++++++++--------- src/UglyToad.PdfPig/Filters/Jbig2/Table.cs | 2 +- .../Filters/Jbig2/TextRegion.cs | 24 +++++----- src/UglyToad.PdfPig/Filters/Jbig2/Utils.cs | 9 ++-- .../Filters/Jbig2/ValueNode.cs | 9 ++-- .../XObjects/XObjectFactory.cs | 10 ++--- 54 files changed, 208 insertions(+), 183 deletions(-) delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/README_SAMPLE_DATA_LICENSING.txt delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata.jb2 delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2 delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2-decoded.bin delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2.png delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page2.jb2 delete mode 100644 src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page3.jb2 rename src/UglyToad.PdfPig/Filters/Jbig2/{IDictionary.cs => IJbigDictionary.cs} (73%) rename src/UglyToad.PdfPig/Filters/Jbig2/{Bitmap.cs => Jbig2Bitmap.cs} (98%) rename src/UglyToad.PdfPig/Filters/Jbig2/{Bitmaps.cs => Jbig2Bitmaps.cs} (91%) create mode 100644 src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Rectangle.cs diff --git a/NOTICES.txt b/NOTICES.txt index b31cbe75..6f4b7a7f 100644 --- a/NOTICES.txt +++ b/NOTICES.txt @@ -10,4 +10,12 @@ Includes the Adobe Glyph List Copyright 1997, 1998, 2002, 2007, 2010 Adobe Systems Incorporated. Includes the Zapf Dingbats Glyph List -Copyright 2002, 2010 Adobe Systems Incorporated. \ No newline at end of file +Copyright 2002, 2010 Adobe Systems Incorporated. + +------------------------------------------------------------------ + +Apache JBig2 ImageIO Plugin +Copyright 2017 The Apache Software Foundation + +Based on source code originally developed in the JBig2 project. +Copyright (C) 1995-2017 levigo holding GmbH \ No newline at end of file diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/BitmapTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/BitmapTest.cs index aa483f43..72c8153c 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/BitmapTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/BitmapTest.cs @@ -9,7 +9,7 @@ [Fact] public void GetPixelAndSetPixelTest() { - var bitmap = new Bitmap(37, 49); + var bitmap = new Jbig2Bitmap(37, 49); Assert.Equal(0, bitmap.GetPixel(3, 19)); bitmap.SetPixel(3, 19, (byte)1); @@ -20,7 +20,7 @@ [Fact] public void GetByteAndSetByteTest() { - var bitmap = new Bitmap(16, 16); + var bitmap = new Jbig2Bitmap(16, 16); byte value = (byte)4; bitmap.SetByte(0, value); @@ -33,7 +33,7 @@ [Fact] public void GetByteThrowsExceptionTest() { - var bitmap = new Bitmap(16, 16); + var bitmap = new Jbig2Bitmap(16, 16); Action action = () => bitmap.GetByte(32); @@ -43,7 +43,7 @@ [Fact] public void SetByteThrowsExceptionTest() { - var bitmap = new Bitmap(16, 16); + var bitmap = new Jbig2Bitmap(16, 16); Action action = () => bitmap.SetByte(32, (byte)0); @@ -53,7 +53,7 @@ [Fact] public void GetByteAsIntegerTest() { - var bitmap = new Bitmap(16, 16); + var bitmap = new Jbig2Bitmap(16, 16); var byteValue = (byte)4; int integerValue = byteValue; @@ -69,7 +69,7 @@ public void GetHeightTest() { int height = 16; - var bitmap = new Bitmap(1, height); + var bitmap = new Jbig2Bitmap(1, height); Assert.Equal(height, bitmap.Height); } @@ -78,7 +78,7 @@ public void GetWidthTest() { int width = 16; - var bitmap = new Bitmap(width, 1); + var bitmap = new Jbig2Bitmap(width, 1); Assert.Equal(width, bitmap.Width); } diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/ChecksumTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/ChecksumTest.cs index 5ba4ab28..f6ebb01e 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/ChecksumTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/ChecksumTest.cs @@ -46,10 +46,10 @@ new[] { "005.jb2", "712610586-1224021396100112-102-77-1177851" }, new[] { "006.jb2", "-8719-116-83-83-35-3425-64-528667602154-25" }, new[] { "007.jb2", "6171-125-109-20-128-71925295955793-127-41-122" }, - new[] { "sampledata.jb2", "104-68-555325117-4757-48527676-9775-8432" }, - new[] { "sampledata_page1.jb2", "104-68-555325117-4757-48527676-9775-8432" }, - new[] { "sampledata_page2.jb2", "104-68-555325117-4757-48527676-9775-8432" }, - new[] { "sampledata_page3.jb2", "-7825-56-41-30-19-719536-3678580-61-2586" }, + //new[] { "sampledata.jb2", "104-68-555325117-4757-48527676-9775-8432" }, + //new[] { "sampledata_page1.jb2", "104-68-555325117-4757-48527676-9775-8432" }, + //new[] { "sampledata_page2.jb2", "104-68-555325117-4757-48527676-9775-8432" }, + //new[] { "sampledata_page3.jb2", "-7825-56-41-30-19-719536-3678580-61-2586" }, new[] { "20123110001.jb2", "60-96-101-2458-3335024-5468-5-11068-78-80" }, new[] { "20123110002.jb2", "-28-921048181-117-48-96126-110-9-2865611113" }, new[] { "20123110003.jb2", "-3942-239351-28-56-729169-5839122-439231" }, @@ -71,7 +71,7 @@ var iis = new ImageInputStream(ImageHelpers.LoadFileBytes(filename)); var doc = new Jbig2Document(iis); - Bitmap b = doc.GetPage(1).GetBitmap(); + Jbig2Bitmap b = doc.GetPage(1).GetBitmap(); byte[] digest = Hash(b.GetByteArray()); var stringBuilder = new StringBuilder(); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/GenericRegionTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/GenericRegionTest.cs index b56160db..ff4a1f85 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/GenericRegionTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/GenericRegionTest.cs @@ -6,7 +6,7 @@ public class GenericRegionTest { - [Fact] + [Fact(Skip = "File removed")] public void ParseHeaderTest() { var iis = new ImageInputStream(ImageHelpers.LoadFileBytes("sampledata.jb2")); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/HalftoneRegionTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/HalftoneRegionTest.cs index aa4ba7a3..212614ae 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/HalftoneRegionTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/HalftoneRegionTest.cs @@ -6,7 +6,7 @@ public class HalftoneRegionTest { - [Fact] + [Fact(Skip = "File removed")] public void ParseHeaderTest() { var iis = new ImageInputStream(ImageHelpers.LoadFileBytes("sampledata.jb2")); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/MMRDecompressorTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/MMRDecompressorTest.cs index d701f96b..9f239fbd 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/MMRDecompressorTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/MMRDecompressorTest.cs @@ -6,7 +6,7 @@ public class MMRDecompressorTest { - [Fact] + [Fact(Skip = "File removed")] public void MmrDecodingTest() { var expected = new byte[] @@ -20,7 +20,7 @@ // Sixth Segment (number 5) var sis = new SubInputStream(iis, 252, 38); var mmrd = new MMRDecompressor(16 * 4, 4, sis); - Bitmap b = mmrd.Uncompress(); + Jbig2Bitmap b = mmrd.Uncompress(); byte[] actual = b.GetByteArray(); Assert.Equal(expected, actual); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/PatternDictionaryTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/PatternDictionaryTest.cs index 717fe942..7870dff1 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/PatternDictionaryTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/PatternDictionaryTest.cs @@ -6,7 +6,7 @@ public class PatternDictionaryTest { - [Fact] + [Fact(Skip = "File removed")] public void ParseHeaderTest() { var iis = new ImageInputStream(ImageHelpers.LoadFileBytes("sampledata.jb2")); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/RegionSegmentInformationTest.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/RegionSegmentInformationTest.cs index f68bb784..8cbbd824 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2/RegionSegmentInformationTest.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2/RegionSegmentInformationTest.cs @@ -5,8 +5,8 @@ using Xunit; public class RegionSegmentInformationTest - { - [Fact] + { + [Fact(Skip = "File removed")] public void ParseHeaderTest() { var iis = new ImageInputStream(ImageHelpers.LoadFileBytes("sampledata.jb2")); diff --git a/src/UglyToad.PdfPig.Tests/Filters/Jbig2DecodeFilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/Jbig2DecodeFilterTests.cs index 9b8e16ca..acd3c867 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Jbig2DecodeFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Jbig2DecodeFilterTests.cs @@ -8,7 +8,7 @@ namespace UglyToad.PdfPig.Tests.Filters { public class Jbig2DecodeFilterTests { - [Fact] + [Fact(Skip = "File removed")] public void CanDecodeJbig2CompressedImageData_WithoutGlobalSegments() { var encodedImageBytes = ImageHelpers.LoadFileBytes("sampledata_page1.jb2"); diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/README_SAMPLE_DATA_LICENSING.txt b/src/UglyToad.PdfPig.Tests/Images/Files/README_SAMPLE_DATA_LICENSING.txt deleted file mode 100644 index a4f8b5f6..00000000 --- a/src/UglyToad.PdfPig.Tests/Images/Files/README_SAMPLE_DATA_LICENSING.txt +++ /dev/null @@ -1,21 +0,0 @@ -============================================================================ -The files sampledata_pageN.jb2 and sampledata.jb are included subject to the -following terms: -============================================================================ - - The compliance checking files provided with this package contain - information which has been extracted from Recommendation ITU-T T.88 - "Information technology – Lossy/lossless coding of bi-level images" - (2000/02) of the International Telecommunication Union (“ITU Information”), - as found in http://www.itu.int/rec/T-REC-T.88-200002-I/en. - - The extraction and use of ITU Information has been made under license - from International Telecommunication Union (“ITU”), which owns all property - rights (including intellectual property rights) to Recommendation ITU-T - T.88 (2000/02). This ITU Information is made available to everyone for free - and may be used for non-commercial purposes; for any other use please - contact ITU at sales@itu.int. The sole responsibility for extracting the - ITU Information and the responsibility for any errors or deficiencies in - the package lies exclusively with the PdfPig project. ITU is not - involved in the development of the package or the extraction and use of - ITU Information contained therein. diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/sampledata.jb2 b/src/UglyToad.PdfPig.Tests/Images/Files/sampledata.jb2 deleted file mode 100644 index bf2faf85befe2f21112b234a63885ddf0d9c910c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 860 zcmbR41F)npkO|^i z05KSVH8LvsQkdt02F0rcVb`yDKrFPRUqa7 zViq7~WZ>as5CAe*89^j6;BjE*C~&+06k<^a8?OUongKD02I=KyU{qUBcy9TBOz`6a zP@Yu)>^5CS7LaOwg^MkT60VtRhVE_z71_m7A%gMk9l9lFQVEPZF z!6EGbyhnjg_V{^5!6TdU|E~cGbFn)xaDwFIffy}#LGESk&5IIpXa%d~RtKA+3=~EU zOb+J%fB!T6`}dFK-P`uxr?tVVc?7`r%dkPha6(~r?#$(@JZnEa^^m`lu_w=AH&_|3 zxB?Hzemfvm0AfUtfkZKato?M8T-p+m*EU|Fzs_9yyfNSB?f&Ka!6xw;f}ID{#lUX> zPNSfZf%yp}3=KH}2rUK;8Bl~V`akc@kQULm2b(0wpeO)J;|d&1OyCp(WP|uj{x7dz zop5-o+VbDIA~PUrh1eAYL2@8_Q0!vp5dsRatc>aYa=3O{md4Yvez4)fhS2=Oz#w7_ HQ~?A4N`kCK diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2 b/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2 deleted file mode 100644 index 722240c91e6c586fb56bfda9d5b184cfb8800bc5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 400 zcmbR4>m1CWvbR#9#o? z&cwh7V#t8iFacRiPtX2fsC>{O(D9d(7lfkp3S(4|Y4x|Vt|C@?8M dn5wd6QkU1HkV%)kG_^b(SiqskZU{Du0RYIjRxbbm diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2-decoded.bin b/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2-decoded.bin deleted file mode 100644 index 9d1d5c2d430388dfa9cb5ecc4735331472a7079f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 448 zcmYk2u?>ST6htkA1Vtog1{aCDXtNnFy|W%Vd+6e+5s#T3 nbn#vsx_Iu`LuW!~Lgzc6i|^{8i{J0S$ZRgQ?m1rbRPEds6H|mh diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2.png b/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page1.jb2.png deleted file mode 100644 index ebb7b4388a3a71e92414496920ba90271b8c2d07..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 893 zcmV-@1A_dCP)fxd5xPF za0vSDvIOd_I7e57=G5H$C!}yOfb)*C+Zpj&7s!JL6~-lZTlgzbaPt?~SReTR-npxM zHmn3Q3(#wqC5U%KIl@ld00;4EW&!pGE1Y10y;T)abh{tC?;l`!G$ykur`}H70L^(dvjF?aF~i3J`-+*!HX&4kb!4b35sk#5 zbg|2{>avRJHS1_+f;6m%*Bo)KL~Qdg>oxUM-QoS9HFdVy%8*Er3@ZI1W}x_IT=$pvf_wiWwIYvdfc?iPC*D0VSm z9sfQo53eisB(`)}Md{507)+E&BRIW)XNS=)TW}njd_Ky-N5km_qVsr~38j-YaPtCo z4_~s6oHu6O`faxcXu_*?d{iqD8-9wbY`<{^3URSJFmQs@$pf(}5OV-A3lK9h z@PL@Cy?IeW4y|Cd-0EQal!3x#K&%7AAeGz<9L)d!{%894?;p#%x9z`AYlBtu2!QRE zVPgR);-65MojY^+D$m+aPd()CWbDav*bP?3E3Uu;vfmDf6@XX;hy{R{AM9d~6F7kw m3_#|zpKg*%TO#t>#!K|qnQNan=KH+ezkEN~BtAp1^B4e63qKP8 diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page3.jb2 b/src/UglyToad.PdfPig.Tests/Images/Files/sampledata_page3.jb2 deleted file mode 100644 index 2b281b0d45c5aab1b3c3e53ad0f285cedecd92f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 215 zcmbR4l3yf;HyMBo1Z8lZ?EgQ5UPRDpwu=|2bn*~~!94J3R)}3e5Tq7l4~kt3JwiYsmX$HxUk=w!%hGsS)( /// This class represents the arithmetic decoder, described in ISO/IEC 14492:2001 in E.3 /// - internal class ArithmeticDecoder + internal sealed class ArithmeticDecoder { private static readonly int[][] QE = new[]{ new []{ 0x5601, 01, 01, 1 }, new []{ 0x3401, 02, 06, 0 }, new []{ 0x1801, 03, 09, 0 }, diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/ArithmeticIntegerDecoder.cs b/src/UglyToad.PdfPig/Filters/Jbig2/ArithmeticIntegerDecoder.cs index f9e87bd3..f142c4a3 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/ArithmeticIntegerDecoder.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/ArithmeticIntegerDecoder.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents the arithmetic integer decoder, described in ISO/IEC 14492:2001 (Annex A). /// - internal class ArithmeticIntegerDecoder + internal sealed class ArithmeticIntegerDecoder { private readonly ArithmeticDecoder decoder; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/CX.cs b/src/UglyToad.PdfPig/Filters/Jbig2/CX.cs index b8aa1b35..b8557a77 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/CX.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/CX.cs @@ -4,7 +4,7 @@ /// CX represents the context used by arithmetic decoding and arithmetic integer decoding. It selects the probability /// estimate and statistics used during decoding procedure. /// - internal class CX + internal sealed class CX { private readonly byte[] cx; private readonly byte[] mps; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/EncodedTable.cs b/src/UglyToad.PdfPig/Filters/Jbig2/EncodedTable.cs index ce80928d..4de73c46 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/EncodedTable.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/EncodedTable.cs @@ -5,7 +5,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents a encoded huffman table. /// - internal class EncodedTable : HuffmanTable + internal sealed class EncodedTable : HuffmanTable { private readonly Table table; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/EndOfStripe.cs b/src/UglyToad.PdfPig/Filters/Jbig2/EndOfStripe.cs index fac389a9..f13df7af 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/EndOfStripe.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/EndOfStripe.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This segment flags an end of stripe (see JBIG2 ISO standard, 7.4.9). /// - internal class EndOfStripe : ISegmentData + internal sealed class EndOfStripe : ISegmentData { private SubInputStream subInputStream; private int lineNumber; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/FixedSizeTable.cs b/src/UglyToad.PdfPig/Filters/Jbig2/FixedSizeTable.cs index cd67d501..1eb73b97 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/FixedSizeTable.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/FixedSizeTable.cs @@ -5,7 +5,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents a fixed size huffman table. /// - internal class FixedSizeTable : HuffmanTable + internal sealed class FixedSizeTable : HuffmanTable { public FixedSizeTable(List runCodeTable) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/GenericRefinementRegion.cs b/src/UglyToad.PdfPig/Filters/Jbig2/GenericRefinementRegion.cs index 030ec447..053e5d78 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/GenericRefinementRegion.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/GenericRefinementRegion.cs @@ -6,7 +6,7 @@ /// This class represents a generic refinement region and implements the procedure described in JBIG2 ISO standard, 6.3 /// and 7.4.7. /// - internal class GenericRefinementRegion : IRegion + internal sealed class GenericRefinementRegion : IRegion { public abstract class Template { @@ -63,10 +63,10 @@ private short[] grAtY; // Decoded data as pixel values (use row stride/width to wrap line) - private Bitmap regionBitmap; + private Jbig2Bitmap regionBitmap; // Variables for decoding - private Bitmap referenceBitmap; + private Jbig2Bitmap referenceBitmap; private int referenceDX; private int referenceDY; @@ -147,11 +147,11 @@ /// /// Decode using a template and arithmetic coding, as described in 6.3.5.6 /// - /// The decoded . + /// The decoded . /// if an underlying IO operation fails /// if a segment header value is invalid /// if the maximum value limit of an integer is exceeded - public Bitmap GetRegionBitmap() + public Jbig2Bitmap GetRegionBitmap() { if (null == regionBitmap) { @@ -175,7 +175,7 @@ } // 6.3.5.6 - 2) - regionBitmap = new Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); + regionBitmap = new Jbig2Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); if (templateID == 0) { @@ -221,7 +221,7 @@ return arithDecoder.Decode(cx); } - private Bitmap GetGrReference() + private Jbig2Bitmap GetGrReference() { SegmentHeader[] segments = segmentHeader.GetRtSegments(); IRegion region = (IRegion)segments[0].GetSegmentData(); @@ -824,7 +824,7 @@ return context; } - private static byte GetPixel(Bitmap b, int x, int y) + private static byte GetPixel(Jbig2Bitmap b, int x, int y) { if (x < 0 || x >= b.Width) { @@ -848,7 +848,7 @@ internal void SetParameters(CX cx, ArithmeticDecoder arithmeticDecoder, short grTemplate, int regionWidth, int regionHeight, - Bitmap grReference, int grReferenceDX, int grReferenceDY, + Jbig2Bitmap grReference, int grReferenceDX, int grReferenceDY, bool isTPGRon, short[] grAtX, short[] grAtY) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/GenericRegion.cs b/src/UglyToad.PdfPig/Filters/Jbig2/GenericRegion.cs index 0e3dc0e2..26dfe865 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/GenericRegion.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/GenericRegion.cs @@ -5,7 +5,7 @@ /// Parsing is done as described in 7.4.5. /// Decoding procedure is done as described in 6.2.5.7 and 7.4.6.4. /// - internal class GenericRegion : IRegion + internal sealed class GenericRegion : IRegion { private SubInputStream subInputStream; private long dataHeaderOffset = 0; @@ -28,7 +28,7 @@ private bool @override; // Decoded data as pixel values (use row stride/width to wrap line) - private Bitmap regionBitmap; + private Jbig2Bitmap regionBitmap; private ArithmeticDecoder arithDecoder; private CX cx; @@ -123,8 +123,8 @@ /// /// The procedure is described in 6.2.5.7, page 17. /// - /// The decoded . - public Bitmap GetRegionBitmap() + /// The decoded . + public Jbig2Bitmap GetRegionBitmap() { if (null == regionBitmap) { @@ -160,7 +160,7 @@ } // 6.2.5.7 - 2) - regionBitmap = new Bitmap(RegionInfo.BitmapWidth, + regionBitmap = new Jbig2Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); int paddedWidth = (regionBitmap.Width + 7) & -8; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/HalftoneRegion.cs b/src/UglyToad.PdfPig/Filters/Jbig2/HalftoneRegion.cs index 6a596ca3..f125f87e 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/HalftoneRegion.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/HalftoneRegion.cs @@ -8,7 +8,7 @@ /// This class represents the data of segment type "Halftone region". Parsing is described in 7.4.5, page 67. Decoding /// procedure in 6.6.5 and 7.4.5.2. /// - internal class HalftoneRegion : IRegion + internal sealed class HalftoneRegion : IRegion { private SubInputStream subInputStream; private SegmentHeader segmentHeader; @@ -18,10 +18,10 @@ private long dataLength; // Decoded data - private Bitmap halftoneRegionBitmap; + private Jbig2Bitmap halftoneRegionBitmap; // Previously decoded data from other regions or dictionaries, stored to use as patterns in this region. - private List patterns; + private List patterns; // Region segment information field, 7.4.1 public RegionSegmentInformation RegionInfo { get; private set; } @@ -114,14 +114,14 @@ /// /// The procedure is described in JBIG2 ISO standard, 6.6.5. /// - /// The decoded - public Bitmap GetRegionBitmap() + /// The decoded + public Jbig2Bitmap GetRegionBitmap() { if (null == halftoneRegionBitmap) { // 6.6.5, page 40 // 1) - halftoneRegionBitmap = new Bitmap(RegionInfo.BitmapWidth, + halftoneRegionBitmap = new Jbig2Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); if (patterns == null) @@ -176,16 +176,16 @@ y = ComputeY(m, n); // ii) - Bitmap patternBitmap = patterns[grayScaleValues[m][n]]; - Bitmaps.Blit(patternBitmap, halftoneRegionBitmap, (x + HGridX), (y + HGridY), + Jbig2Bitmap patternBitmap = patterns[grayScaleValues[m][n]]; + Jbig2Bitmaps.Blit(patternBitmap, halftoneRegionBitmap, (x + HGridX), (y + HGridY), HCombinationOperator); } } } - private List GetPatterns() + private List GetPatterns() { - var patterns = new List(); + var patterns = new List(); foreach (SegmentHeader s in segmentHeader.GetRtSegments()) { @@ -229,7 +229,7 @@ gbAtY[3] = -2; } - var grayScalePlanes = new Bitmap[bitsPerValue]; + var grayScalePlanes = new Jbig2Bitmap[bitsPerValue]; // 1) var genericRegion = new GenericRegion(subInputStream); @@ -255,7 +255,7 @@ return ComputeGrayScaleValues(grayScalePlanes, bitsPerValue); } - private Bitmap[] CombineGrayScalePlanes(Bitmap[] grayScalePlanes, int j) + private Jbig2Bitmap[] CombineGrayScalePlanes(Jbig2Bitmap[] grayScalePlanes, int j) { int byteIndex = 0; for (int y = 0; y < grayScalePlanes[j].Height; y++) @@ -267,13 +267,13 @@ byte oldValue = grayScalePlanes[j].GetByte(byteIndex); grayScalePlanes[j].SetByte(byteIndex++, - Bitmaps.CombineBytes(oldValue, newValue, CombinationOperator.XOR)); + Jbig2Bitmaps.CombineBytes(oldValue, newValue, CombinationOperator.XOR)); } } return grayScalePlanes; } - private int[][] ComputeGrayScaleValues(Bitmap[] grayScalePlanes, int bitsPerValue) + private int[][] ComputeGrayScaleValues(Jbig2Bitmap[] grayScalePlanes, int bitsPerValue) { // Gray-scale decoding procedure, page 98 int[][] grayScaleValues = new int[HGridHeight][]; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/HuffmanTable.cs b/src/UglyToad.PdfPig/Filters/Jbig2/HuffmanTable.cs index b7d920a7..3c108668 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/HuffmanTable.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/HuffmanTable.cs @@ -33,7 +33,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 public override sealed string ToString() { - return (Value != -1 ? ValueNode.bitPattern(Value, PrefixLength) : "?") + "/" + return (Value != -1 ? ValueNode.BitPattern(Value, PrefixLength) : "?") + "/" + PrefixLength + "/" + RangeLength + "/" + RangeLow; } } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/IDictionary.cs b/src/UglyToad.PdfPig/Filters/Jbig2/IJbigDictionary.cs similarity index 73% rename from src/UglyToad.PdfPig/Filters/Jbig2/IDictionary.cs rename to src/UglyToad.PdfPig/Filters/Jbig2/IJbigDictionary.cs index 787f2c83..367d066f 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/IDictionary.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/IJbigDictionary.cs @@ -5,15 +5,15 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// Interface for all JBIG2 dictionaries segments. /// - internal interface IDictionary : ISegmentData + internal interface IJbigDictionary : ISegmentData { /// /// Decodes a dictionary segment and returns the result. /// - /// A list of s as a result of the decoding process of dictionary segments. + /// A list of s as a result of the decoding process of dictionary segments. /// if the segment header value is invalid. /// if the maximum value limit of an integer is exceeded. /// if an underlying IO operation fails. - List GetDictionary(); + List GetDictionary(); } } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/IRegion.cs b/src/UglyToad.PdfPig/Filters/Jbig2/IRegion.cs index 870a7cdf..a2a5c00c 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/IRegion.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/IRegion.cs @@ -13,10 +13,10 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// Decodes and returns a regions content. /// - /// The decoded region as . + /// The decoded region as . /// if the segment header value is invalid. /// if the maximum value limit of an integer is exceeded. /// if an underlying IO operation fails. - Bitmap GetRegionBitmap(); + Jbig2Bitmap GetRegionBitmap(); } } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/ImageInputStream.cs b/src/UglyToad.PdfPig/Filters/Jbig2/ImageInputStream.cs index d0c29d92..8d88915f 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/ImageInputStream.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/ImageInputStream.cs @@ -3,7 +3,7 @@ using System; using System.IO; - internal class ImageInputStream : AbstractImageInputStream + internal sealed class ImageInputStream : AbstractImageInputStream { private readonly Stream inner; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/IntegerMaxValueException.cs b/src/UglyToad.PdfPig/Filters/Jbig2/IntegerMaxValueException.cs index 9ae69777..c57237b3 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/IntegerMaxValueException.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/IntegerMaxValueException.cs @@ -5,7 +5,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// Can be used if the maximum value limit of an integer is exceeded. /// - internal class IntegerMaxValueException : Jbig2Exception + internal sealed class IntegerMaxValueException : Jbig2Exception { public IntegerMaxValueException() { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/InternalNode.cs b/src/UglyToad.PdfPig/Filters/Jbig2/InternalNode.cs index 3b28aadc..a4bd84e4 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/InternalNode.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/InternalNode.cs @@ -7,7 +7,7 @@ /// /// This class represents an internal node of a Huffman tree. It contains two child nodes. /// - internal class InternalNode : Node + internal sealed class InternalNode : Node { private readonly int depth; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Bitmap.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmap.cs similarity index 98% rename from src/UglyToad.PdfPig/Filters/Jbig2/Bitmap.cs rename to src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmap.cs index 76526b11..8d4bb3ee 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Bitmap.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmap.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents a bi-level image that is organized like a bitmap. /// - internal class Bitmap + internal sealed class Jbig2Bitmap { // 8 pixels per byte, 0 for white, 1 for black private readonly byte[] bitmap; @@ -31,7 +31,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// /// - public Bitmap(int width, int height) + public Jbig2Bitmap(int width, int height) { Height = height; Width = width; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Bitmaps.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmaps.cs similarity index 91% rename from src/UglyToad.PdfPig/Filters/Jbig2/Bitmaps.cs rename to src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmaps.cs index 97c002fd..69522d3e 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Bitmaps.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Bitmaps.cs @@ -1,19 +1,18 @@ namespace UglyToad.PdfPig.Filters.Jbig2 { using System; - using System.Drawing; - internal static class Bitmaps + internal static class Jbig2Bitmaps { /// /// Returns the specified rectangle area of the bitmap. /// - /// A that specifies the requested image section. + /// A that specifies the requested image section. /// src the given bitmap - /// A that represents the requested image section. - public static Bitmap Extract(Rectangle roi, Bitmap src) + /// A that represents the requested image section. + public static Jbig2Bitmap Extract(Jbig2Rectangle roi, Jbig2Bitmap src) { - var dst = new Bitmap(roi.Width, roi.Height); + var dst = new Jbig2Bitmap(roi.Width, roi.Height); int upShift = roi.X & 0x07; int downShift = 8 - upShift; @@ -24,7 +23,8 @@ namespace UglyToad.PdfPig.Filters.Jbig2 int srcLineEndIdx = src.GetByteIndex(roi.X + roi.Width - 1, roi.Y); bool usePadding = dst.RowStride == srcLineEndIdx + 1 - srcLineStartIdx; - for (int y = roi.Y; y < roi.GetMaxY(); y++) + int maxY = roi.GetMaxY(); + for (int y = roi.Y; y < maxY; y++) { int srcIdx = srcLineStartIdx; int dstIdx = dstLineStartIdx; @@ -104,7 +104,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// The x coordinate where the upper left corner of the bitmap to blit should be positioned. /// The y coordinate where the upper left corner of the bitmap to blit should be positioned. /// The combination operator for combining two pixels. - public static void Blit(Bitmap src, Bitmap dst, int x, int y, CombinationOperator combinationOperator) + public static void Blit(Jbig2Bitmap src, Jbig2Bitmap dst, int x, int y, CombinationOperator combinationOperator) { int startLine = 0; int srcStartIdx = 0; @@ -163,7 +163,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 } } - private static void CopyLine(Bitmap src, Bitmap dst, int sourceUpShift, int sourceDownShift, + private static void CopyLine(Jbig2Bitmap src, Jbig2Bitmap dst, int sourceUpShift, int sourceDownShift, int padding, int firstSourceByteOfLine, int lastSourceByteOfLine, bool usePadding, int sourceOffset, int targetOffset) { @@ -210,7 +210,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 return (byte)(value >> padding << padding); } - private static void BlitUnshifted(Bitmap src, Bitmap dst, int startLine, int lastLine, + private static void BlitUnshifted(Jbig2Bitmap src, Jbig2Bitmap dst, int startLine, int lastLine, int dstStartIdx, int srcStartIdx, int srcEndIdx, CombinationOperator op) { @@ -229,7 +229,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 } } - private static void BlitSpecialShifted(Bitmap src, Bitmap dst, int startLine, int lastLine, + private static void BlitSpecialShifted(Jbig2Bitmap src, Jbig2Bitmap dst, int startLine, int lastLine, int dstStartIdx, int srcStartIdx, int srcEndIdx, int toShift, int shiftVal1, int shiftVal2, CombinationOperator op) { @@ -258,7 +258,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 } } - private static void BlitShifted(Bitmap src, Bitmap dst, int startLine, int lastLine, + private static void BlitShifted(Jbig2Bitmap src, Jbig2Bitmap dst, int startLine, int lastLine, int dstStartIdx, int srcStartIdx, int srcEndIdx, int toShift, int shiftVal1, int shiftVal2, CombinationOperator op, int padding) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Document.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Document.cs index f9b37ba3..d48b5c0a 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Document.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Document.cs @@ -7,7 +7,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents the document structure with its pages and global segments. /// - internal class Jbig2Document : IDisposable + internal sealed class Jbig2Document : IDisposable { // ID string in file header, see ISO/IEC 14492:2001, D.4.1 private static readonly int[] FILE_HEADER_ID = { 0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A }; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Globals.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Globals.cs index bd24dad3..76abb8f4 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Globals.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Globals.cs @@ -8,7 +8,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// This segments will be decoded on demand and all results are stored in the document object and can be retrieved from /// there. /// - internal class Jbig2Globals + internal sealed class Jbig2Globals { // This map contains all segments, that are not associated with a page. The key is the segment number. private readonly Dictionary globalSegments = new Dictionary(); diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Page.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Page.cs index 828c637f..e61d2113 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Page.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Page.cs @@ -6,7 +6,7 @@ /// /// This class represents a JBIG2 page. /// - internal class Jbig2Page + internal sealed class Jbig2Page { // This list contains all segments of this page, sorted by segment number in ascending order. private readonly SortedDictionary segments = new SortedDictionary(); @@ -15,7 +15,7 @@ private readonly int pageNumber; // The page bitmap that represents the page buffer - private Bitmap pageBitmap; + private Jbig2Bitmap pageBitmap; private int finalHeight; private int finalWidth; @@ -74,7 +74,7 @@ /// The result of decoding a page /// /// - public Bitmap GetBitmap() + public Jbig2Bitmap GetBitmap() { if (null == pageBitmap) { @@ -84,7 +84,7 @@ } /// - /// This method composes the bitmaps of segments to a page and stores the page as a . + /// This method composes the bitmaps of segments to a page and stores the page as a . /// /// /// @@ -115,7 +115,7 @@ private void CreateNormalPage(PageInformation pageInformation) { - pageBitmap = new Bitmap(pageInformation.BitmapWidth, pageInformation.BitmapHeight); + pageBitmap = new Jbig2Bitmap(pageInformation.BitmapWidth, pageInformation.BitmapHeight); // Page 79, 3) // If default pixel value is not 0, byte will be filled with 0xff @@ -139,7 +139,7 @@ case 43: // Immediate lossless generic refinement region IRegion r = (IRegion)s.GetSegmentData(); - Bitmap regionBitmap = r.GetRegionBitmap(); + Jbig2Bitmap regionBitmap = r.GetRegionBitmap(); if (FitsPage(pageInformation, regionBitmap)) { @@ -150,7 +150,7 @@ RegionSegmentInformation regionInfo = r.RegionInfo; CombinationOperator op = GetCombinationOperator(pageInformation, regionInfo.CombinationOperator); - Bitmaps.Blit(regionBitmap, pageBitmap, regionInfo.X, + Jbig2Bitmaps.Blit(regionBitmap, pageBitmap, regionInfo.X, regionInfo.Y, op); } @@ -164,7 +164,7 @@ /// the region's bitmap as the page's bitmap. Otherwise we have to blit the smaller region's bitmap into the page's /// bitmap. /// - private bool FitsPage(PageInformation pageInformation, Bitmap regionBitmap) + private bool FitsPage(PageInformation pageInformation, Jbig2Bitmap regionBitmap) { return CountRegions() == 1 && pageInformation.DefaultPixelValue == 0 && pageInformation.BitmapWidth == regionBitmap.Width @@ -175,7 +175,7 @@ { List pageStripes = CollectPageStripes(); - pageBitmap = new Bitmap(pageInformation.BitmapWidth, finalHeight); + pageBitmap = new Jbig2Bitmap(pageInformation.BitmapWidth, finalHeight); int startLine = 0; foreach (ISegmentData sd in pageStripes) @@ -190,7 +190,7 @@ RegionSegmentInformation regionInfo = r.RegionInfo; CombinationOperator op = GetCombinationOperator(pageInformation, regionInfo.CombinationOperator); - Bitmaps.Blit(r.GetRegionBitmap(), pageBitmap, regionInfo.X, startLine, + Jbig2Bitmaps.Blit(r.GetRegionBitmap(), pageBitmap, regionInfo.X, startLine, op); } } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Rectangle.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Rectangle.cs new file mode 100644 index 00000000..526f2c70 --- /dev/null +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Jbig2Rectangle.cs @@ -0,0 +1,40 @@ +namespace UglyToad.PdfPig.Filters.Jbig2 +{ + internal readonly struct Jbig2Rectangle + { + /// + /// The x-coordinate of the upper-left corner of the rectangle. + /// + public int X { get; } + + /// + /// The y-coordinate of the upper-left corner of the rectangle. + /// + public int Y { get; } + + /// + /// The width of the rectangle. + /// + public int Width { get; } + + /// + /// The height of the rectangle. + /// + public int Height { get; } + + /// + /// Create a new . + /// + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. + public Jbig2Rectangle(int x, int y, int width, int height) + { + X = x; + Y = y; + Width = width; + Height = height; + } + } +} diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/MMRConstants.cs b/src/UglyToad.PdfPig/Filters/Jbig2/MMRConstants.cs index 6c65fdc4..b3a2c5b8 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/MMRConstants.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/MMRConstants.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// Constants for MMR (de)compression. /// - internal class MMRConstants + internal static class MMRConstants { public const int COMP_FAXG3 = 0; public const int COMP_FAXG4 = 1; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/MMRDecompressor.cs b/src/UglyToad.PdfPig/Filters/Jbig2/MMRDecompressor.cs index 4342d399..1ef168d1 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/MMRDecompressor.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/MMRDecompressor.cs @@ -8,7 +8,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// A decompressor for MMR compression. /// - internal class MMRDecompressor + internal sealed class MMRDecompressor { private readonly int width; private readonly int height; @@ -490,9 +490,9 @@ namespace UglyToad.PdfPig.Filters.Jbig2 InitTables(); } - public Bitmap Uncompress() + public Jbig2Bitmap Uncompress() { - Bitmap result = new Bitmap(width, height); + Jbig2Bitmap result = new Jbig2Bitmap(width, height); int[] currentOffsets = new int[width + 5]; int[] referenceOffsets = new int[width + 5]; @@ -545,7 +545,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 } } - private void FillBitmap(Bitmap result, int line, int[] currentOffsets, int count) + private void FillBitmap(Jbig2Bitmap result, int line, int[] currentOffsets, int count) { int x = 0; int targetByte = result.GetByteIndex(0, line); diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/OutOfBandNode.cs b/src/UglyToad.PdfPig/Filters/Jbig2/OutOfBandNode.cs index f33a3ca3..f676f71f 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/OutOfBandNode.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/OutOfBandNode.cs @@ -5,7 +5,7 @@ /// /// Represents a out of band node in a Huffman tree. /// - internal class OutOfBandNode : Node + internal sealed class OutOfBandNode : Node { public OutOfBandNode(Code c) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/PageInformation.cs b/src/UglyToad.PdfPig/Filters/Jbig2/PageInformation.cs index 94ddaaa4..f8f72e5b 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/PageInformation.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/PageInformation.cs @@ -3,7 +3,7 @@ /// /// This class represents the segment type "Page information", 7.4.8 (page 73). /// - internal class PageInformation : ISegmentData + internal sealed class PageInformation : ISegmentData { private SubInputStream subInputStream; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/PatternDictionary.cs b/src/UglyToad.PdfPig/Filters/Jbig2/PatternDictionary.cs index da8af296..b529dd18 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/PatternDictionary.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/PatternDictionary.cs @@ -1,12 +1,11 @@ namespace UglyToad.PdfPig.Filters.Jbig2 { using System.Collections.Generic; - using System.Drawing; /// /// This class represents the segment type "Pattern dictionary", 7.4.4. /// - internal class PatternDictionary : IDictionary + internal sealed class PatternDictionary : IJbigDictionary { private SubInputStream subInputStream; @@ -20,7 +19,7 @@ private short[] gbAtY = null; // Decoded bitmaps, stored to be used by segments, that refer to it - private List patterns; + private List patterns; // Pattern dictionary flags, 7.4.4.1.1 public bool IsMMREncoded { get; private set; } @@ -99,11 +98,11 @@ /// /// This method decodes a pattern dictionary segment and returns an array of - /// s. Each is a pattern. + /// s. Each is a pattern. /// The procedure is described in 6.7.5 (page 43). /// - /// An array of s as result of the decoding procedure. - public List GetDictionary() + /// An array of s as result of the decoding procedure. + public List GetDictionary() { if (null == patterns) { @@ -117,7 +116,7 @@ genericRegion.SetParameters(IsMMREncoded, dataOffset, dataLength, HdpHeight, (GrayMax + 1) * HdpWidth, HdTemplate, false, false, gbAtX, gbAtY); - Bitmap collectiveBitmap = genericRegion.GetRegionBitmap(); + Jbig2Bitmap collectiveBitmap = genericRegion.GetRegionBitmap(); // 4) ExtractPatterns(collectiveBitmap); @@ -126,18 +125,18 @@ return patterns; } - private void ExtractPatterns(Bitmap collectiveBitmap) + private void ExtractPatterns(Jbig2Bitmap collectiveBitmap) { // 3) int gray = 0; - patterns = new List(GrayMax + 1); + patterns = new List(GrayMax + 1); // 4) while (gray <= GrayMax) { // 4) a) Retrieve a pattern bitmap by extracting it out of the collective bitmap - Rectangle roi = new Rectangle(HdpWidth * gray, 0, HdpWidth, HdpHeight); - Bitmap patternBitmap = Bitmaps.Extract(roi, collectiveBitmap); + Jbig2Rectangle roi = new Jbig2Rectangle(HdpWidth * gray, 0, HdpWidth, HdpHeight); + Jbig2Bitmap patternBitmap = Jbig2Bitmaps.Extract(roi, collectiveBitmap); patterns.Add(patternBitmap); // 4) b) diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Profiles.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Profiles.cs index d95ae304..842115d7 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Profiles.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Profiles.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class is not implemented yet and empty. Wait for use cases. /// - internal class Profiles : ISegmentData + internal sealed class Profiles : ISegmentData { public void Init(SegmentHeader header, SubInputStream sis) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/RegionSegmentInformation.cs b/src/UglyToad.PdfPig/Filters/Jbig2/RegionSegmentInformation.cs index 30aeda46..1b9cd493 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/RegionSegmentInformation.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/RegionSegmentInformation.cs @@ -4,7 +4,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// This class represents the "Region segment information" field, 7.4.1(page 50). /// Every region segment data starts with this part. /// - internal class RegionSegmentInformation : ISegmentData + internal sealed class RegionSegmentInformation : ISegmentData { private readonly SubInputStream subInputStream; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/SegmentHeader.cs b/src/UglyToad.PdfPig/Filters/Jbig2/SegmentHeader.cs index 2cda8087..f5b248f1 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/SegmentHeader.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/SegmentHeader.cs @@ -7,7 +7,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// The basic class for all JBIG2 segments. /// - internal class SegmentHeader + internal sealed class SegmentHeader { private static readonly Dictionary SEGMENT_TYPE_MAP = new Dictionary { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/StandardTables.cs b/src/UglyToad.PdfPig/Filters/Jbig2/StandardTables.cs index 9f609815..1f724b33 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/StandardTables.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/StandardTables.cs @@ -2,7 +2,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 { using System.Collections.Generic; - internal class StandardTables + internal static class StandardTables { class StandardTable : HuffmanTable { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/SubInputStream.cs b/src/UglyToad.PdfPig/Filters/Jbig2/SubInputStream.cs index b73917d7..6769eea3 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/SubInputStream.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/SubInputStream.cs @@ -7,7 +7,7 @@ /// Read accesses to the wrapped stream are synchronized, so that users of this stream need to deal with synchronization /// against other users of the same instance, but not against other users of the wrapped stream. /// - internal class SubInputStream : AbstractImageInputStream + internal sealed class SubInputStream : AbstractImageInputStream { private readonly IImageInputStream wrappedStream; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/SymbolDictionary.cs b/src/UglyToad.PdfPig/Filters/Jbig2/SymbolDictionary.cs index 59933d66..841fa18b 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/SymbolDictionary.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/SymbolDictionary.cs @@ -2,13 +2,12 @@ { using System; using System.Collections.Generic; - using System.Drawing; /// /// This class represents the data of segment type "Symbol dictionary". Parsing is described in /// 7.4.2.1.1 - 7.4.1.1.5 and decoding procedure is described in 6.5. /// - internal class SymbolDictionary : IDictionary + internal sealed class SymbolDictionary : IJbigDictionary { private SubInputStream subInputStream; @@ -41,9 +40,9 @@ // Further parameters private SegmentHeader segmentHeader; private int amountOfImportedSymbolss; - private List importSymbols; + private List importSymbols; private int amountOfDecodedSymbols; - private Bitmap[] newSymbols; + private Jbig2Bitmap[] newSymbols; // User-supplied tables private HuffmanTable dhTable; @@ -52,8 +51,8 @@ private HuffmanTable aggInstTable; // Return value of that segment - private List exportSymbols; - private List sbSymbols; + private List exportSymbols; + private List sbSymbols; private ArithmeticDecoder arithmeticDecoder; private ArithmeticIntegerDecoder iDecoder; @@ -230,7 +229,7 @@ } else { - importSymbols = new List(); + importSymbols = new List(); } } @@ -309,7 +308,7 @@ /// 6.5.5 Decoding the symbol dictionary. /// /// List of decoded symbol bitmaps. - public List GetDictionary() + public List GetDictionary() { if (null == exportSymbols) { @@ -324,7 +323,7 @@ } // 6.5.5 1) - newSymbols = new Bitmap[amountOfNewSymbols]; + newSymbols = new Jbig2Bitmap[amountOfNewSymbols]; // 6.5.5 2) int[] newSymbolsWidths = null; @@ -408,7 +407,7 @@ subInputStream.SkipBits(); - Bitmap heightClassCollectiveBitmap = + Jbig2Bitmap heightClassCollectiveBitmap = DecodeHeightClassCollectiveBitmap(bmSize, heightClassHeight, totalWidth); subInputStream.SkipBits(); @@ -479,7 +478,7 @@ } } - private void DecodeHeightClassBitmap(Bitmap heightClassCollectiveBitmap, + private void DecodeHeightClassBitmap(Jbig2Bitmap heightClassCollectiveBitmap, int heightClassFirstSymbol, int heightClassHeight, int[] newSymbolsWidths) { @@ -492,8 +491,8 @@ startColumn += newSymbolsWidths[j]; } - var roi = new Rectangle(startColumn, 0, newSymbolsWidths[i], heightClassHeight); - var symbolBitmap = Bitmaps.Extract(roi, heightClassCollectiveBitmap); + var roi = new Jbig2Rectangle(startColumn, 0, newSymbolsWidths[i], heightClassHeight); + var symbolBitmap = Jbig2Bitmaps.Extract(roi, heightClassCollectiveBitmap); newSymbols[i] = symbolBitmap; sbSymbols.Add(symbolBitmap); } @@ -619,7 +618,7 @@ // 6) SetSymbolsArray(); - Bitmap ibo = sbSymbols[id]; + Jbig2Bitmap ibo = sbSymbols[id]; DecodeNewSymbols(symbolWidth, heightClassHeight, ibo, rdx, rdy); // 7) @@ -630,7 +629,7 @@ } } - private void DecodeNewSymbols(int symWidth, int hcHeight, Bitmap ibo, int rdx, int rdy) + private void DecodeNewSymbols(int symWidth, int hcHeight, Jbig2Bitmap ibo, int rdx, int rdy) { if (genericRefinementRegion == null) { @@ -670,7 +669,7 @@ private void AddSymbol(IRegion region) { - Bitmap symbol = region.GetRegionBitmap(); + Jbig2Bitmap symbol = region.GetRegionBitmap(); newSymbols[amountOfDecodedSymbols] = symbol; sbSymbols.Add(symbol); } @@ -747,12 +746,12 @@ return 0; } - private Bitmap DecodeHeightClassCollectiveBitmap(long bmSize, + private Jbig2Bitmap DecodeHeightClassCollectiveBitmap(long bmSize, int heightClassHeight, int totalWidth) { if (bmSize == 0) { - Bitmap heightClassCollectiveBitmap = new Bitmap(totalWidth, heightClassHeight); + Jbig2Bitmap heightClassCollectiveBitmap = new Jbig2Bitmap(totalWidth, heightClassHeight); for (int i = 0; i < heightClassCollectiveBitmap.GetByteArray().Length; i++) { @@ -777,7 +776,7 @@ private void SetExportedSymbols(int[] toExportFlags) { - exportSymbols = new List(amountOfExportSymbolss); + exportSymbols = new List(amountOfExportSymbolss); for (int i = 0; i < amountOfImportedSymbolss + amountOfNewSymbols; i++) { @@ -881,7 +880,7 @@ if (sbSymbols == null) { - sbSymbols = new List(); + sbSymbols = new List(); sbSymbols.AddRange(importSymbols); } } @@ -891,7 +890,7 @@ /// private void RetrieveImportSymbols() { - importSymbols = new List(); + importSymbols = new List(); foreach (SegmentHeader referredToSegmentHeader in segmentHeader.GetRtSegments()) { if (referredToSegmentHeader.SegmentType == 0) diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Table.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Table.cs index 420e02a2..c4afe1a2 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Table.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Table.cs @@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Filters.Jbig2 /// /// This class represents a "Table" segment. It handles custom tables, see Annex B. /// - internal class Table : ISegmentData + internal sealed class Table : ISegmentData { private SubInputStream subInputStream; diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/TextRegion.cs b/src/UglyToad.PdfPig/Filters/Jbig2/TextRegion.cs index 2d792e82..e8ba6b8d 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/TextRegion.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/TextRegion.cs @@ -8,7 +8,7 @@ /// /// This class represented the segment type "Text region", 7.4.3, page 56. /// - internal class TextRegion : IRegion + internal sealed class TextRegion : IRegion { private SubInputStream subInputStream; @@ -45,8 +45,8 @@ private int sbStrips; private int amountOfSymbols; - private Bitmap regionBitmap; - private List symbols = new List(); + private Jbig2Bitmap regionBitmap; + private List symbols = new List(); private ArithmeticDecoder arithmeticDecoder; private ArithmeticIntegerDecoder integerDecoder; @@ -283,7 +283,7 @@ } } - public Bitmap GetRegionBitmap() + public Jbig2Bitmap GetRegionBitmap() { if (!isHuffmanEncoded) { @@ -363,7 +363,7 @@ private void CreateRegionBitmap() { // 6.4.5 - regionBitmap = new Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); + regionBitmap = new Jbig2Bitmap(RegionInfo.BitmapWidth, RegionInfo.BitmapHeight); // 1) if (defaultPixel != 0) @@ -472,7 +472,7 @@ // 3 c) v) long r = DecodeRI(); // 6.4.11 - Bitmap ib = DecodeIb(r, id); + Jbig2Bitmap ib = DecodeIb(r, id); // vi) Blit(ib, t); @@ -609,9 +609,9 @@ return 0; } - private Bitmap DecodeIb(long r, long id) + private Jbig2Bitmap DecodeIb(long r, long id) { - Bitmap ib; + Jbig2Bitmap ib; if (r == 0) { @@ -635,7 +635,7 @@ } // 6) - Bitmap ibo = symbols[(int)id]; + Jbig2Bitmap ibo = symbols[(int)id]; int wo = ibo.Width; int ho = ibo.Height; @@ -904,7 +904,7 @@ } - private void Blit(Bitmap ib, long t) + private void Blit(Jbig2Bitmap ib, long t) { if (isTransposed == 0 && (referenceCorner == 2 || referenceCorner == 3)) { @@ -946,7 +946,7 @@ } } - Bitmaps.Blit(ib, regionBitmap, (int)s, (int)t, combinationOperator); + Jbig2Bitmaps.Blit(ib, regionBitmap, (int)s, (int)t, combinationOperator); // x) if (isTransposed == 0 && (referenceCorner == 0 || referenceCorner == 1)) @@ -1105,7 +1105,7 @@ short sbCombinationOperator, short transposed, short refCorner, short sbdsOffset, short sbHuffFS, short sbHuffDS, short sbHuffDT, short sbHuffRDWidth, short sbHuffRDHeight, short sbHuffRDX, short sbHuffRDY, short sbHuffRSize, - short sbrTemplate, short[] sbrATX, short[] sbrATY, List sbSyms, + short sbrTemplate, short[] sbrATX, short[] sbrATY, List sbSyms, int sbSymCodeLen) { diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/Utils.cs b/src/UglyToad.PdfPig/Filters/Jbig2/Utils.cs index b500476d..82d44d2c 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/Utils.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/Utils.cs @@ -1,7 +1,6 @@ namespace UglyToad.PdfPig.Filters.Jbig2 { using System; - using System.Drawing; internal static class Utils { @@ -10,22 +9,22 @@ namespace UglyToad.PdfPig.Filters.Jbig2 return (int)Math.Pow(2, Convert.ToString(number, 2).Length - 1); } - public static int GetMinY(this Rectangle r) + public static int GetMinY(this Jbig2Rectangle r) { return r.Y; } - public static int GetMaxY(this Rectangle r) + public static int GetMaxY(this Jbig2Rectangle r) { return r.Y + r.Height; } - public static int GetMaxX(this Rectangle r) + public static int GetMaxX(this Jbig2Rectangle r) { return r.X + r.Width; } - public static int GetMinX(this Rectangle r) + public static int GetMinX(this Jbig2Rectangle r) { return r.X; } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2/ValueNode.cs b/src/UglyToad.PdfPig/Filters/Jbig2/ValueNode.cs index d3c6a9a9..b9e0dff8 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2/ValueNode.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2/ValueNode.cs @@ -1,12 +1,11 @@ namespace UglyToad.PdfPig.Filters.Jbig2 { - using System; using static HuffmanTable; /// /// Represents a value node in a Huffman tree. It is a leaf of a tree. /// - internal class ValueNode : Node + internal sealed class ValueNode : Node { private readonly int rangeLength; private readonly int rangeLow; @@ -33,13 +32,15 @@ } } - internal static string bitPattern(int v, int len) + internal static string BitPattern(int v, int len) { var result = new char[len]; for (int i = 1; i <= len; i++) + { result[i - 1] = (v >> (len - i) & 1) != 0 ? '1' : '0'; + } - return new String(result); + return new string(result); } } } diff --git a/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs b/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs index 722f21ae..e3b350d8 100644 --- a/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs +++ b/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs @@ -33,8 +33,8 @@ var bounds = xObject.AppliedTransformation.Transform(new PdfRectangle(new PdfPoint(0, 0), new PdfPoint(1, 1))); - var width = dictionary.Get(NameToken.Width).Int; - var height = dictionary.Get(NameToken.Height).Int; + var width = dictionary.Get(NameToken.Width, pdfScanner).Int; + var height = dictionary.Get(NameToken.Height, pdfScanner).Int; var isImageMask = dictionary.TryGet(NameToken.ImageMask, out BooleanToken isMaskToken) && isMaskToken.Data; @@ -65,11 +65,11 @@ } var interpolate = dictionary.TryGet(NameToken.Interpolate, out BooleanToken interpolateToken) - && interpolateToken.Data; - + && interpolateToken.Data; + var supportsFilters = true; - + var filters = filterProvider.GetFilters(dictionary, pdfScanner); foreach (var filter in filters) {