-
Notifications
You must be signed in to change notification settings - Fork 0
/
rd.c
204 lines (167 loc) · 5.13 KB
/
rd.c
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* ScummC
* Copyright (C) 2004-2006 Alban Bedel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/**
* @file rd.c
* @brief Experiment playground, currently dump SCUMM files.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "scc_fd.h"
#include "scc_util.h"
#include "scc_cost.h"
#include "scc_codec.h"
#include "scc.h"
int scc_image_2_rgb(uint8_t* dst,int dst_stride,
uint8_t* src, int src_stride,
int width,int height,
scc_pal_t* pal) {
int r,c;
for(r = 0 ; r < height ; r++) {
for(c = 0 ; c < width ; c++) {
dst[3*c+0] = pal->r[src[c]];
dst[3*c+1] = pal->g[src[c]];
dst[3*c+2] = pal->b[src[c]];
}
src += src_stride;
dst += dst_stride;
}
return 1;
}
int main(int argc,char** argv) {
scc_fd_t* fd2,*fd = new_scc_fd("TENTACLE.000",O_RDONLY,0x69);
scc_res_idx_t* idx;
scc_res_t* res;
int len;
scc_lfl_t* lfl;
if(!fd) {
printf("Failed to open index :((\n");
return -1;
}
idx = scc_read_res_idx(fd);
//for(i = 0 ; i < d->size ; i++)
// printf("%d ==> ROOM %d: %d\n",i,d->room_no[i],d->room_off[i]);
//return 0;
// fd2 = new_scc_fd("dump.000",O_WRONLY|O_CREAT,0x69);
// scc_write_res_idx(fd2,idx);
// return 0;
fd2 = new_scc_fd("TENTACLE.001",O_RDONLY,0x69);
res = scc_parse_res(fd2,idx);
scc_dump_res(res);
return 0;
scc_fd_close(fd2);
fd2 = new_scc_fd("copy.001",O_WRONLY|O_CREAT,0x69);
scc_write_lecf(fd2,res);
return 0;
for(lfl = res->lfl ; lfl ; lfl = lfl->next) {
scc_room_t* r = &lfl->room;
uint8_t* img8 = calloc(r->width,r->height+5);
uint8_t* img24 = malloc(r->width*r->height*3);
int w,i;
uint8_t* smap;
uint32_t smap_len;
if(r->rmim->num_z_buf < 1) continue;
printf("ROOM %d has %d zbuf\n",r->idx,r->rmim->num_z_buf);
for(i = 1 ; i <= r->rmim->num_z_buf ; i++) {
scc_decode_zbuf(img8,r->width/8,
r->width,r->height,
r->rmim->z_buf[i],
r->rmim->z_buf_size[i],0);
smap_len = scc_code_zbuf(img8,r->width/8,
r->width,r->height,
&smap);
if(smap_len != r->rmim->z_buf_size[i]) printf("ZMAP size mismatch %d != %d !!!\n",smap_len,r->rmim->z_buf_size[i]);
if(!smap) { printf("Failed to code ???\n"); continue; }
scc_decode_zbuf(img24,r->width/8,
r->width,r->height,
smap,
smap_len,0);
free(smap);
for(w = 0 ; w < r->width/8*r->height ; w++) {
if(img24[w] != img8[w]) {
printf("Mismatch at 0x%x/0x%x : 0x%x 0x%x\n",
i,r->width/8*r->height,img24[w],img8[w]);
printf("Ref data: %0x %0x %0x %0x\n",img8[w-1],img8[w],img8[w+1],img8[w+230]);
printf("Our data: %0x %0x %0x %0x\n",img24[w-1],img24[w],img24[w+1],img24[w+2]);
break;
}
}
}
#if 0
scc_code_image(img8,r->width,
r->width,r->height,r->transp,
&smap,&smap_len);
scc_decode_image(img24,r->width,
r->width,r->height,
smap,
smap_len,-1);
for(i = 0 ; i < r->width*r->height ; i++) {
if(img24[i] != img8[i]) {
printf("Mismatch at 0x%x/0x%x : 0x%x 0x%x\n",
i,r->width*r->height,img24[i],img8[i]);
printf("Ref data: %0x %0x %0x %0x\n",img8[i-1],img8[i],img8[i+1],img8[i+230]);
printf("Our data: %0x %0x %0x %0x\n",img24[i-1],img24[i],img24[i+1],img24[i+2]);
break;
}
}
scc_image_2_rgb(img24,r->width*3,img8,r->width,
r->width,r->height,
r->pals);
sprintf(name,"rmim.%3.3d-%dx%d.raw",r->idx,r->width,r->height);
fd2 = new_scc_fd(name,O_WRONLY|O_CREAT,0);
while(c < r->width*r->height*3) {
w = scc_fd_write(fd2,img24+c,r->width*r->height*3-c);
if(c < 0) {
printf("Write error\n");
return -1;
}
c += w;
}
for(ob = r->obim ; ob ; ob = ob->next) {
for(im = ob->img ; im ; im = im->next) {
printf("Parsing images of %d: %d\n",ob->idx,im->idx);
img8 = realloc(img8,ob->width*ob->height);
scc_decode_image(img8,ob->width,
ob->width,ob->height,
im->smap,
im->smap_size,-1);
}
printf("\n");
}
#endif
free(img8);
free(img24);
}
return 0;
res = scc_open_res_file(fd2,idx);
scc_dump_res(res);
return 0;
len = scc_res_find(res,MKID('S','C','R','P'),55);
if(len < 0) {
fprintf(stderr,"Failed to find script 55 (0x%x)\n",MKID('D','S','C','R'));
} else {
fprintf(stderr,"Script 55: %d bytes\n",len);
}
return 0;
}