Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 2522:27271f2afa7c
Clean up the SupeRes decoder a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 15 May 2020 03:23:59 +0300 |
parents | b19535da15e9 |
children | 22d2cfeed831 |
comparison
equal
deleted
inserted
replaced
2521:b19535da15e9 | 2522:27271f2afa7c |
---|---|
107 return DMERR_OK; | 107 return DMERR_OK; |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 static int fmtDecodeSupeRes24_25(DMSupeResCtx *ctx, Uint8 tmp) | |
113 { | |
114 if (tmp == 0x24) | |
115 { | |
116 ctx->dbyte = 0xff; | |
117 } | |
118 else | |
119 { | |
120 if (tmp == 0x25) | |
121 { | |
122 int res; | |
123 if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK) | |
124 return res; | |
125 | |
126 tmp = (0x26 + tmp) & 0xff; | |
127 } | |
128 | |
129 ctx->dbyte = tmp - 0x26; | |
130 } | |
131 | |
132 return DMERR_OK; | |
133 } | |
134 | |
135 | |
112 static int fmtDecodeSupeResByte(DMSupeResCtx *ctx) | 136 static int fmtDecodeSupeResByte(DMSupeResCtx *ctx) |
113 { | 137 { |
114 Uint8 tmp; | 138 Uint8 tmp; |
115 int res; | 139 int res; |
116 | 140 |
121 | 145 |
122 if (tmp == 0x21) | 146 if (tmp == 0x21) |
123 { | 147 { |
124 // ???? | 148 // ???? |
125 ctx->offs = 0xffff; | 149 ctx->offs = 0xffff; |
126 return DMERR_OK; | 150 goto out; |
127 } | |
128 else | |
129 if (tmp == 0x24) | |
130 { | |
131 ctx->dbyte = 0xff; | |
132 return DMERR_OK; | |
133 } | 151 } |
134 else | 152 else |
135 if (tmp == 0x20) | 153 if (tmp == 0x20) |
136 { | 154 { |
137 if ((res = fmtSupeResGetByte(ctx, &tmp, 2)) != DMERR_OK) | 155 if ((res = fmtSupeResGetByte(ctx, &tmp, 2)) != DMERR_OK) |
138 goto out; | 156 goto out; |
139 | 157 |
140 ctx->repcount = tmp - 0x26; | 158 ctx->repcount = tmp - 0x26; |
141 | 159 |
142 if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK) | 160 if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK || |
161 (res = fmtDecodeSupeRes24_25(ctx, tmp)) != DMERR_OK) | |
143 goto out; | 162 goto out; |
144 | |
145 if (tmp == 0x24) | |
146 { | |
147 ctx->dbyte = 0xff; | |
148 } | |
149 else | |
150 { | |
151 if (tmp == 0x25) | |
152 { | |
153 if ((res = fmtSupeResGetByte(ctx, &tmp, 4)) != DMERR_OK) | |
154 goto out; | |
155 | |
156 tmp = (0x26 + tmp) & 0xff; | |
157 } | |
158 | |
159 ctx->dbyte = tmp - 0x26; | |
160 } | |
161 | 163 |
162 for (int cnt = 0; cnt < ctx->repcount; cnt++) | 164 for (int cnt = 0; cnt < ctx->repcount; cnt++) |
163 { | 165 { |
164 ctx->dstBuf[ctx->offs++] = ctx->dbyte; | 166 ctx->dstBuf[ctx->offs++] = ctx->dbyte; |
165 if (ctx->offs >= ctx->end_offs) | 167 if (ctx->offs >= ctx->end_offs) |
173 | 175 |
174 goto out; | 176 goto out; |
175 } | 177 } |
176 else | 178 else |
177 { | 179 { |
178 if (tmp == 0x25) | 180 res = fmtDecodeSupeRes24_25(ctx, tmp); |
179 { | 181 goto out; |
180 if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK) | |
181 goto out; | |
182 | |
183 tmp = (0x26 + tmp) & 0xff; | |
184 } | |
185 | |
186 ctx->dbyte = tmp - 0x26; | |
187 | |
188 return DMERR_OK; | |
189 } | 182 } |
190 | 183 |
191 goto lcont; | 184 goto lcont; |
192 | 185 |
193 out: | 186 out: |
222 DMSupeResCtx ctx; | 215 DMSupeResCtx ctx; |
223 DMGrowBuf tmp; | 216 DMGrowBuf tmp; |
224 int res; | 217 int res; |
225 | 218 |
226 memset(&ctx, 0, sizeof(ctx)); | 219 memset(&ctx, 0, sizeof(ctx)); |
227 ctx.dstSize = 0x4000; | 220 ctx.dstSize = 0x3000; |
228 | 221 |
229 // As we need to modify the offs, etc. but not the data, | 222 // As we need to modify the offs, etc. but not the data, |
230 // we will just make a shallow copy of the DMGrowBuf struct | 223 // we will just make a shallow copy of the DMGrowBuf struct |
231 dmGrowBufConstCopyOffs(&ctx.src, psrc, 4); | 224 dmGrowBufConstCopyOffs(&ctx.src, psrc, 4); |
232 | 225 |