Mercurial > hg > dmlib
annotate tests/encbr1test.c @ 2051:c67d863384a5
Changes to the BR1 encoder test.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 03 Dec 2018 19:02:29 +0200 |
parents | 210a0041081b |
children | d5ea82da40ab |
rev | line source |
---|---|
2039
210a0041081b
Fix MinGW build of encbr1test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2024
diff
changeset
|
1 #include "dmtool.h" |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 #include "dmlib.h" |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 #include "dmres.h" |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
4 #include "dmmutex.h" |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
7 #define BR_DEBUG 1 |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 //#define BR_WRITE |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 enum |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 { |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 DMODE_LIT, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 DMODE_RLE, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 }; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
17 #if BR_DEBUG == 1 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
18 static int mcount = 0; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
19 static int moffs = 0; |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
21 static void mprintbyte(const Uint8 data) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
22 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
23 if (mcount == 0) printf("%04x | ", moffs); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
24 printf("%02x ", data); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
25 if (mcount++ >= 15) { printf("\n"); mcount = 0; } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
26 moffs++; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
27 } |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 #endif |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
30 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
31 BOOL dmIFFEncodeByteRun1LIT(DMResource *fp, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
32 const Uint8 *buf, const size_t offs, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
33 const size_t count) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
34 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
35 if (count <= 0) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
36 return TRUE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
37 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
38 Uint8 tmp = count - 1; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
39 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
40 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
41 printf("L: %02x ", tmp); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
42 for (size_t n = 0; n < count; n++) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
43 printf("%02x ", buf[offs + n]); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
44 printf("[%" DM_PRIu_SIZE_T "]\n", count); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
45 #elif BR_DEBUG == 1 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
46 mprintbyte(tmp); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
47 for (size_t n = 0; n < count; n++) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
48 mprintbyte(buf[offs + n]); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
49 #endif |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
51 #ifdef BR_WRITE |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
52 if (!dmf_write_byte(fp, tmp) || |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
53 !dmf_write_str(fp, buf + offs, count)) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
54 return FALSE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
55 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
56 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
57 return TRUE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
58 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
59 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
60 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
61 BOOL dmIFFEncodeByteRun1RLE(DMResource *fp, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
62 const Uint8 *buf, const size_t offs, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
63 const size_t count) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
64 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
65 if (count <= 0) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
66 return TRUE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
67 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
68 Uint8 tmp = ((Uint8) count - 2) ^ 0xff; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
69 Uint8 data = buf[offs]; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
70 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
71 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
72 printf("R: %02x %02x [%" DM_PRIu_SIZE_T "]\n", tmp, data, count); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
73 #elif BR_DEBUG == 1 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
74 mprintbyte(tmp); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
75 mprintbyte(data); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
76 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
77 #ifdef BR_WRITE |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
78 if (!dmf_write_byte(fp, tmp) || |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
79 !dmf_write_byte(fp, data)) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
80 return FALSE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
81 #endif |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 return TRUE; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 } |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 BOOL dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen) |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 { |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 int prev = -1, mode = DMODE_LIT; |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
90 size_t offs, l_offs, r_offs; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
91 BOOL ret = TRUE; |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
93 #if BR_DEBUG == 1 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
94 mcount = 0; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
95 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
96 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
97 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++) |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 { |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 Uint8 data = buf[offs]; |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
100 BOOL flush = FALSE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
101 int pmode = mode; |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 if (data == prev) |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 { |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
105 if (mode == DMODE_LIT && |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
106 offs - r_offs >= 2) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
107 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
108 ret = dmIFFEncodeByteRun1LIT(fp, buf, l_offs, r_offs - l_offs); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
109 mode = DMODE_RLE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
110 } |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 } |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 else |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 { |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
114 if (mode != DMODE_LIT) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
115 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
116 ret = dmIFFEncodeByteRun1RLE(fp, buf, r_offs, offs - r_offs); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
117 mode = DMODE_LIT; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
118 l_offs = offs; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
119 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
120 r_offs = offs; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
121 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
122 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
123 if (!ret) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
124 goto out; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
125 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
126 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
127 printf("%04" DM_PRIx_SIZE_T ": %02x | r_count=%" DM_PRIu_SIZE_T ", l_count=%" DM_PRIu_SIZE_T ", mode=%s | [%04" DM_PRIx_SIZE_T ", %04" DM_PRIx_SIZE_T "]", |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
128 offs, data, offs - r_offs, offs - l_offs, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
129 mode == DMODE_RLE ? "RLE" : "LIT", |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
130 r_offs, l_offs); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
131 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
132 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
133 // NOTE! RLE max is 128, checked against DP2e |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
134 // Not sure about LIT max yet |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
135 if ((pmode == DMODE_RLE && offs - r_offs >= 128) || |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
136 (pmode == DMODE_LIT && offs - l_offs >= 128)) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
137 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
138 flush = TRUE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
139 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
140 printf(" <LEN FLUSH>"); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
141 #endif |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 } |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
144 // Check for last byte of input |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
145 if (offs == bufLen - 1) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
146 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
147 offs++; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
148 flush = TRUE; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
149 pmode = mode; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
150 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
151 printf(" <FINAL FLUSH>"); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
152 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
153 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
154 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
155 #if BR_DEBUG == 2 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
156 printf("\n"); |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 #endif |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
159 if (flush) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
160 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
161 if (pmode == DMODE_RLE) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
162 ret = dmIFFEncodeByteRun1RLE(fp, buf, r_offs, offs - r_offs); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
163 else |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
164 ret = dmIFFEncodeByteRun1LIT(fp, buf, l_offs, offs - l_offs); |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
166 r_offs = l_offs = offs; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
167 mode = DMODE_LIT; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
168 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
169 if (!ret) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
170 goto out; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
171 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
172 |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 prev = data; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 } |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
176 out: |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
177 return ret; |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 } |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 int main(int argc, char *argv[]) |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 { |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
184 DMResource *fp = NULL; |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 (void) argc; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 (void) argv; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
188 #ifdef BR_WRITE |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
189 dmf_open_stdio_stream(stderr, &fp); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
190 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
191 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
192 static const Uint8 test[] = |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 { |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
196 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
197 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
198 |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 1, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
207 2, 2, 3, 4, 5, 5, 5, 6, |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
214 1, 3, |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
216 0, 0, 0, 1, |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 }; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
2051
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
219 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
220 int cnt = 0; |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
221 for (size_t xc = 0; xc < sizeof(test); xc++) |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
222 { |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
223 if (cnt == 0) printf("%04x | ", xc); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
224 printf("%02x ", *(test + xc)); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
225 if (cnt++ >= 15) { printf("\n"); cnt = 0; } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
226 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
227 printf("\n\n"); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
228 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
229 dmIFFEncodeByteRun1Row(fp, test, sizeof(test)); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
230 printf("\n--\n"); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
231 } |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
232 |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
233 #ifdef BR_WRITE |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
234 dmf_close(fp); |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
235 #endif |
c67d863384a5
Changes to the BR1 encoder test.
Matti Hamalainen <ccr@tnsp.org>
parents:
2039
diff
changeset
|
236 |
2024
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 return 0; |
f41bc7203a16
Add a test program for BR1 compression.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 } |