1 // Simple 'detarkinizer'. Turn tarkin stream into a series of .pgm files
3 // Usage: nikrat [filename]
5 // $Id: tarkinplay.c,v 1.1 2001/02/13 01:06:24 giles Exp $
7 // $Log: tarkinplay.c,v $
8 // Revision 1.1 2001/02/13 01:06:24 giles
20 // Function declarations
22 void dumptofile(char *fn
, char *data
, tarkindata
*td
);
23 void make_palette(SDL_Surface
*screen
);
25 int main(int argc
, char **argv
)
28 unsigned char ln
[256], *data
, *dp
, *wksp
;
29 int a
, d
, fd
, dims
[3];
42 if (!(fi
= fopen(argv
[1], "r"))) {
43 sprintf(ln
, "Can't open %s", argv
[1]);
50 sscanf(ln
, "%d %d %d", &td
.x_dim
, &td
.y_dim
, &td
.z_dim
);
51 for (a
= 0, d
= 1; d
< td
.x_dim
; a
++, d
<<= 1);
55 for (a
= 0, d
= 1; d
< td
.y_dim
; a
++, d
<<= 1);
59 for (a
= 0, d
= 1; d
< td
.z_dim
; a
++, d
<<= 1);
63 td
.sz
= td
.x_dim
* td
.y_dim
* td
.z_dim
;
64 td
.sz_workspace
= td
.x_workspace
* td
.y_workspace
* td
.z_workspace
;
67 // Prepare bitstream for unpacking
71 fd
= open(argv
[1], O_RDONLY
);
72 if ((data
= mmap(0, len
, PROT_READ
, MAP_SHARED
, fd
, 0)) == (void*)-1) {
74 perror("Can't mmap file");
77 for (dp
= data
; *dp
!= '\n' && lensub
; dp
++, lensub
--);
80 _oggpack_readinit(&o
, dp
, lensub
);
86 dims
[0] = td
.x_workspace
; dims
[1] = td
.y_workspace
; dims
[2] = td
.z_workspace
;
87 dwt(td
.vectors
, dims
, 3, -1);
89 for (a
= 0; a
< td
.sz_workspace
; a
++) {
90 if (td
.vectors
[a
] < 0.0)
92 if (td
.vectors
[a
] > 255.0)
93 td
.vectors
[a
] = 255.0;
97 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
) < 0) {
98 printf("Unable to init SDL: %s\n", SDL_GetError());
103 screen
= SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE
);
105 printf("Unable to set 320x240 video: %s\n", SDL_GetError());
109 SDL_WM_SetCaption("tarkinplay v0.1beta", NULL
);
111 make_palette(screen
);
114 while (!SDL_QuitRequested()) {
115 printf("Showing frame #%i...\n", i
);
117 if (SDL_MUSTLOCK(screen
)) {
118 SDL_LockSurface(screen
);
121 image
= (char *)malloc(td
.x_dim
* td
.y_dim
);
123 for (y
= 0; y
< td
.y_dim
; y
++)
124 for (x
= 0; x
< td
.x_dim
; x
++)
125 image
[x
+ y
* td
.x_dim
] = td
.vectors
[x
+ y
* td
.x_workspace
+ i
* td
.x_workspace
* td
.y_workspace
];
127 memcpy(screen
->pixels
, image
, 320*240);
131 if (SDL_MUSTLOCK(screen
)) {
132 SDL_UnlockSurface(screen
);
135 SDL_UpdateRect(screen
, 0, 0, 320, 240);
152 fprintf(stderr
, "Usage:\ntarkinplay [filename]\n\n[filename] - Filename with compressed Tarkin stream\n");
156 void make_palette(SDL_Surface
*screen
)
162 ncolors
= screen
->format
->palette
->ncolors
;
163 palette
= (SDL_Color
*)malloc(ncolors
* sizeof(SDL_Color
));
164 for (i
= 0; i
< ncolors
; i
++) {
169 SDL_SetColors(screen
, palette
, 0, ncolors
);