Skip to content

Commit 623d48e

Browse files
committed
Added support for JBIG2
1 parent c9eeadf commit 623d48e

File tree

111 files changed

+6267
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+6267
-13
lines changed

docs/development-resources.md

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ https://koushtav.me/jpeg/tutorial/2017/11/25/lets-write-a-simple-jpeg-library-pa
3838
https://koushtav.me/jpeg/tutorial/c++/decoder/2019/03/02/lets-write-a-simple-jpeg-library-part-2/
3939

4040

41+
## JBIG2
42+
43+
### STDU Viewer
44+
The JBI2 support in image viewers are rare. This is a tool that supports opening JBIG2 files.
45+
46+
http://www.stdutility.com/stduviewer.html
47+
48+
4149
## Fonts
4250

4351
### fontbakery

docs/limitations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ This is a incomplete summary of non-supported features.
66

77
## Image formats
88

9-
The by far most commonly used image formats in PDFs are images encoded with DCTDecode (JPEG) and FlateDecode (PNG alike). Those are supported, with the exception that DCTDecode is only supported for RGB images.
9+
The by far most commonly used image formats in PDFs are images encoded with DCTDecode (JPEG) and FlateDecode (PNG alike). Those are supported, with the exception that DCTDecode is not supported for
10+
progressive CMYK or YCCK images.
1011

1112
The following image formats are not supported:
1213

1314
* JPEG 2000
1415
* Progressive CMYK or YCCK JPEG
15-
* JBIG2
1616

1717
## Color spaces
1818

docs/specifications.md

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ T.6 : Facsimile coding schemes and coding control functions for Group 4 facsimil
5454

5555
https://www.itu.int/rec/T-REC-T.6/en
5656

57+
### JBIG2
58+
ITU-T Rec. T.88 - ISO/IEC 14492 – Lossy/lossless coding of bi-level images
59+
60+
https://www.itu.int/ITU-T/recommendations/rec.aspx?rec=13688&lang=en
61+
5762

5863
## Fonts
5964

src/PdfToSvg/Common/ArrayUtils.cs

+18
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ public static T[] Concat<T>(params T[]?[] arrays)
9393
return result;
9494
}
9595

96+
public static bool StartsWith(byte[] data, int offset, int count, byte[] lookFor)
97+
{
98+
if (lookFor.Length > count)
99+
{
100+
return false;
101+
}
102+
103+
for (var i = 0; i < lookFor.Length; i++)
104+
{
105+
if (data[offset + i] != lookFor[i])
106+
{
107+
return false;
108+
}
109+
}
110+
111+
return true;
112+
}
113+
96114
#if (NET40 || NET45)
97115
private class EmptyArrayHolder<T>
98116
{

src/PdfToSvg/Common/BitReaderUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static string FormatDebugView(ArraySegment<byte> buffer, int byteCursor,
2828

2929
public static string FormatDebugView(ArraySegment<byte> buffer, int byteCursor, int bitCursor, int currentByte)
3030
{
31-
var result = "";
31+
var result = byteCursor + ":" + bitCursor + " ";
3232

3333
string Format(int cursorOffset)
3434
{

src/PdfToSvg/Common/MathUtils.cs

+48
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,53 @@ public static int IntLog2(int value)
115115

116116
return result;
117117
}
118+
119+
public static int IntLog2Ceil(int value)
120+
{
121+
var result = 0;
122+
123+
value--;
124+
125+
while (value > 0)
126+
{
127+
result++;
128+
value >>= 1;
129+
}
130+
131+
return result;
132+
}
133+
134+
public static int FloorDiv(int x, int y)
135+
{
136+
var neg = false;
137+
138+
if (x < 0)
139+
{
140+
neg = true;
141+
x = -x;
142+
}
143+
144+
if (y < 0)
145+
{
146+
neg ^= true;
147+
y = -y;
148+
}
149+
150+
if (neg)
151+
{
152+
x += y - 1;
153+
}
154+
155+
var result = x / y;
156+
157+
if (neg)
158+
{
159+
return -result;
160+
}
161+
else
162+
{
163+
return result;
164+
}
165+
}
118166
}
119167
}

src/PdfToSvg/DocumentModel/Names.cs

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ internal static class Names
192192
public static PdfName LZWDecode { get; } = new PdfName("LZWDecode");
193193
public static PdfName CCITTFaxDecode { get; } = new PdfName("CCITTFaxDecode");
194194
public static PdfName RunLengthDecode { get; } = new PdfName("RunLengthDecode");
195+
public static PdfName JBIG2Decode { get; } = new PdfName("JBIG2Decode");
195196

196197
public static PdfName DecodeParms { get; } = new PdfName("DecodeParms");
197198
public static PdfName EarlyChange { get; } = new PdfName("EarlyChange");
@@ -206,6 +207,7 @@ internal static class Names
206207
public static PdfName BitsPerFlag { get; } = new PdfName("BitsPerFlag");
207208
public static PdfName Colors { get; } = new PdfName("Colors");
208209
public static PdfName Interpolate { get; } = new PdfName("Interpolate");
210+
public static PdfName JBIG2Globals { get; } = new PdfName("JBIG2Globals");
209211

210212
public static PdfName ColorSpace { get; } = new PdfName("ColorSpace");
211213
public static PdfName DeviceGray { get; } = new PdfName("DeviceGray");

src/PdfToSvg/Filters/Filter.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal abstract class Filter
2121
public static Filter FlateDecode { get; } = new FlateDecodeFilter();
2222
public static Filter LzwDecode { get; } = new LzwDecodeFilter();
2323
public static Filter RunLengthDecode { get; } = new RunLengthDecodeFilter();
24-
24+
public static Filter Jbig2Decode { get; } = new DctDecodeFilter();
2525
public static Filter CcittFaxDecode { get; } = new CcittFaxDecodeFilter();
2626

2727
private static readonly Dictionary<PdfName, Filter> filters = new Dictionary<PdfName, Filter>
@@ -41,6 +41,7 @@ internal abstract class Filter
4141
{ AbbreviatedNames.LZW, LzwDecode },
4242
{ Names.RunLengthDecode, RunLengthDecode },
4343
{ AbbreviatedNames.RL, RunLengthDecode },
44+
{ Names.JBIG2Decode, Jbig2Decode },
4445
};
4546

4647
public abstract Stream Decode(Stream encodedStream, PdfDictionary? decodeParms);
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) PdfToSvg.NET contributors.
2+
// https://github.com/dmester/pdftosvg.net
3+
// Licensed under the MIT License.
4+
5+
using PdfToSvg.DocumentModel;
6+
using PdfToSvg.Filters;
7+
using System;
8+
using System.IO;
9+
using System.IO.Compression;
10+
11+
namespace PdfToSvg.Filters
12+
{
13+
internal class Jbig2DecodeFilter : Filter
14+
{
15+
public override Stream Decode(Stream stream, PdfDictionary? decodeParms)
16+
{
17+
throw new NotSupportedException("Jbig2DecodeFilter is only supported for image streams.");
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)