-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpartial_decode.txt
87 lines (72 loc) · 2.47 KB
/
partial_decode.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Here's the header data blob:
554e 4952 4153 5400-0000 0001 1801 0004
0000 0001 0000 0000-0000 13ec 0000 19c8
0000 0258 0000 0000-0000 0000 ff80 c780
01
// raster data starts here -- BYTE ALIGNED
7f ffff ff7f ffff-ff7f ffff ff7f ffff
// file header (12 bytes)
554e 4952 4153 5400 = "UNIRAST\0"
0000 0001 = 1 page
// page header (32 bytes)
18 = 24bpp
01 = color space 1 (values 1-6 mean different things)
00 = duplex mode (no)
04 = quality 4
0000 0001 = unknown
0000 0000 = unknown
0000 13ec = 5100 = page width
0000 19c8 = 6600 = page height
0000 0258 = 600 = dots per inch
0000 0000 = unknown
0000 0000 = unknown
Another one, for a 17-page file (which reported 0 pages up front, supposedly)
554e 4952 4153 5400-0000 0011 1801 0004
0000 0001 0000 0000-0000 13ec 0000 19c8
0000 0258 0000 0000-0000 0000 ff80 9b80
017f ffff ff7f ffff-ff7f ffff ff7f ffff
554e 4952 4153 5400 = "UNIRAST\0"
0000 0011 = 17 pages
// page header (32 bytes)
0: 18 = bits per pixel
1: 01 = color space
2: 00 = duplex mode
3: 04 = print quality
4: 0000 0001
8: 0000 0000
C: 0000 13ec = 5100 = page width
10: 0000 19c8 = 6600 = page height
14: 0000 0258 = 600 = resolution
18: 0000 0000
1C: 0000 0000
// raster data
20: ff = line repeat code -- how many times this line repeats. Unsigned byte.
21: 80 = PackBits code (see below)
22: 9b = line repeat code
23: 80 = PackBits code
24: 01 = line repeat code
etc...
UNIRAST PackBits Algorithm:
===========================
This is sort of an inverted version of the TIFF PackBits algorithm.
Code is a signed byte, with three interpretations:
switch ( code )
{
case -128: // 0x80
FillRestOfLineWithFillByte();
break;
case 0..127: // copy single pixel and repeat it n+1 times
int n = ((int)code)+1;
uint8_t pixel[pixel_size];
ReadData(&pixel, pixel_size);
while ( n-- > 0 )
{
AddPixelToLine( pixel );
}
break;
case -128..-1: // copy the following (-n)+1 pixels verbatim
int n = (-(int)code)+1;
ReadData(linePtr, n * pixel_size);
break;
}
In TIFF, the 0x80 byte is a NOP used for padding, and the -128..-1 and 0..127 cases are the other way around. I saw some weird results when I tried that...