mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-18 12:16:40 -04:00
animations MGF works
This commit is contained in:
parent
4f9f985918
commit
2be84e406c
10 changed files with 224 additions and 293 deletions
190
libs/mgifmem.c
190
libs/mgifmem.c
|
@ -74,17 +74,30 @@ void mgif_install_proc(MGIF_PROC proc)
|
|||
show_proc=proc;
|
||||
}
|
||||
|
||||
struct mgif_header load_mgif_header(char **mgif) {
|
||||
struct mgif_header r;
|
||||
char *iter = *mgif;
|
||||
memcpy(r.sign, iter, 4); iter+=4;
|
||||
memcpy(r.year, iter, 2); iter+=2;
|
||||
r.eof = *iter++;
|
||||
memcpy(&r.ver, iter, 2); iter+=2;
|
||||
memcpy(&r.frames, iter, 4); iter+=4;
|
||||
memcpy(&r.snd_chans, iter, 2); iter+=2;
|
||||
memcpy(&r.snd_freq, iter, 4); iter+=4;
|
||||
memcpy(r.ampl_table, iter, sizeof(r.ampl_table)); iter+=sizeof(r.ampl_table);
|
||||
iter += 64;
|
||||
*mgif = iter;
|
||||
return r;
|
||||
}
|
||||
|
||||
void *open_mgif(void *mgif) //vraci ukazatel na prvni frame
|
||||
{
|
||||
char *c;
|
||||
struct mgif_header *mgh;
|
||||
char *c = mgif;
|
||||
struct mgif_header mgh = load_mgif_header(&c);
|
||||
|
||||
c=mgif;
|
||||
if (strncmp(c,MGIF,4)) return NULL;
|
||||
mgh=mgif;
|
||||
mgif_frames=mgh->frames;
|
||||
if (strncmp(mgh.sign,MGIF,4)) return NULL;
|
||||
mgif_frames=mgh.frames;
|
||||
cur_frame=0;
|
||||
c+=sizeof(*mgh);
|
||||
init_lzw_compressor(8);
|
||||
if (lzw_buffer==NULL) lzw_buffer=getmem(LZW_BUFFER);
|
||||
return c;
|
||||
|
@ -100,34 +113,22 @@ void close_mgif(void) //dealokuje buffery pro prehravani
|
|||
|
||||
int input_code(void *source,int32_t *bitepos,int bitsize,int mask)
|
||||
{
|
||||
int32_t ofs = *bitepos >> 3;
|
||||
int32_t shf = *bitepos & 0x7;
|
||||
uint8_t *src = source;
|
||||
uint8_t val1 = src[ofs];
|
||||
uint8_t val2 = src[ofs+1];
|
||||
uint16_t val = val1 + val2 * 256;
|
||||
*bitepos+=bitsize;
|
||||
return val >> shf;
|
||||
/*
|
||||
__asm
|
||||
{
|
||||
mov esi,source
|
||||
mov edi,bitepos
|
||||
mov ebx,bitsize
|
||||
mov edx,mask
|
||||
uint8_t *esi = source; // mov esi,source
|
||||
int32_t *edi = bitepos; // mov edi,bitepos
|
||||
int ebx = bitsize; // mov ebx,bitsize
|
||||
int edx = mask; // mov edx,mask
|
||||
|
||||
mov ecx,[edi]
|
||||
mov eax,ecx
|
||||
shr eax,3
|
||||
mov eax,[esi+eax]
|
||||
and cl,7
|
||||
shr eax,cl
|
||||
and eax,edx
|
||||
add [edi],ebx
|
||||
}
|
||||
*/
|
||||
int ecx = *edi; // mov ecx,[edi]
|
||||
int eax = ecx; // mov eax,ecx
|
||||
eax >>=3; // shr eax,3
|
||||
eax = esi[eax] | (esi[eax+1] << 8) | (esi[eax+2] << 16) | (esi[eax+3] << 24);
|
||||
// mov eax,[esi+eax]
|
||||
ecx &= 7; // and cl,7
|
||||
eax >>= ecx; // shr eax,cl
|
||||
eax &= edx; // and eax,edx
|
||||
(*edi) += ebx; // add [edi],ebx
|
||||
return eax;
|
||||
}
|
||||
//#pragma aux input_code parm [esi][edi][ebx][edx]=\ value[eax] modify [ecx];
|
||||
|
||||
|
||||
int de_add_code(int group,int chr,int mask)
|
||||
|
@ -144,10 +145,56 @@ int de_add_code(int group,int chr,int mask)
|
|||
return mask;
|
||||
}
|
||||
|
||||
|
||||
int fast_expand_code(DOUBLE_S *compress_dic, int code,uint8_t **target, uint8_t *old_value)
|
||||
int fast_expand_code(const DOUBLE_S *compress_dic, int code,uint8_t **target, uint8_t *old_value)
|
||||
{
|
||||
|
||||
|
||||
int eax = code; //mov eax,code
|
||||
uint8_t ** edi = target; //mov edi,target
|
||||
//cmp eax,256
|
||||
if (eax < 256) { //jnc expand
|
||||
uint8_t *esi = *edi; //mov esi,[edi]
|
||||
++(*edi); //inc dword ptr [edi]
|
||||
uint8_t bl = (uint8_t)eax; //mov bl,al
|
||||
uint8_t al = bl + *old_value; //add al,old_value
|
||||
*esi = al; // mov [esi],al
|
||||
*old_value = al; // mov old_value,al
|
||||
return bl; // jmp end
|
||||
}
|
||||
|
||||
//expand:
|
||||
const DOUBLE_S *ebx = compress_dic; // mov ebx,compress_dic
|
||||
const DOUBLE_S *ecx = ebx+eax; // lea ecx,[eax*8+ebx]
|
||||
eax = ecx->first; // movzx eax,short ptr [ecx+4] // first
|
||||
*target += eax; // add [edi],eax
|
||||
int save_eax = eax; // push eax
|
||||
uint8_t *esi = *edi; // mov esi,[edi] //esi - target ptr
|
||||
|
||||
do { //eloop:
|
||||
|
||||
eax = ecx->chr; //movzx eax,short ptr [ecx+2] // chr
|
||||
*esi = (uint8_t)(eax); //mov [esi],al
|
||||
--esi; //dec esi
|
||||
eax = ecx->group; //movzx eax,short ptr [ecx] //group
|
||||
ecx = ebx+eax; //lea ecx,[eax*8+ebx]
|
||||
//cmp eax,256
|
||||
} while (eax >= 256 ); //jnc eloop
|
||||
uint8_t bl = (uint8_t)eax; //mov bl,al
|
||||
uint8_t al = bl + *old_value; //add al,old_value
|
||||
*esi = al; //mov [esi],al
|
||||
++(*edi); //inc dword ptr [edi]
|
||||
int ecx2 = save_eax; //pop ecx
|
||||
do { //elp2
|
||||
++esi; //inc esi
|
||||
al = al + *esi; //add al,[esi]
|
||||
*esi = al; //mov [esi],al
|
||||
--ecx2; //dec ecx
|
||||
} while (ecx2 > 0); //jnz elp2
|
||||
*old_value =al; //mov old_value,al
|
||||
return bl; //movzx eax,bl
|
||||
|
||||
// }
|
||||
#if 0
|
||||
uint8_t out;
|
||||
uint8_t w;
|
||||
if (code >= 256) {
|
||||
|
@ -178,10 +225,11 @@ int fast_expand_code(DOUBLE_S *compress_dic, int code,uint8_t **target, uint8_t
|
|||
out = (uint8_t) code;
|
||||
w = out + *old_value;
|
||||
*old_value = w;
|
||||
**target = out;
|
||||
**target = w;
|
||||
(*target)++;
|
||||
}
|
||||
return out;
|
||||
#endif
|
||||
/*
|
||||
_asm
|
||||
{
|
||||
|
@ -228,25 +276,24 @@ end:
|
|||
*/
|
||||
}
|
||||
|
||||
|
||||
void lzw_decode(void *source,char *target)
|
||||
{
|
||||
int32_t bitpos=0;
|
||||
register int code;
|
||||
int code;
|
||||
int old,i;
|
||||
//int group,chr;
|
||||
int old_first;
|
||||
register int mask=0xff;
|
||||
|
||||
uint8_t old_value;
|
||||
|
||||
for(i=0;i<LZW_MAX_CODES;i++) compress_dic[i].first=0;
|
||||
uint8_t *t = (uint8_t *)target;
|
||||
clear:
|
||||
old_value=0;
|
||||
int mask=0xff;
|
||||
nextgroup=free_code;
|
||||
bitsize=init_bitsize;
|
||||
mask=(1<<bitsize)-1;
|
||||
code=input_code(source,&bitpos,bitsize,mask);
|
||||
uint8_t *t = (uint8_t *)target;
|
||||
old_first=fast_expand_code(compress_dic,code,&t,&old_value);
|
||||
old=code;
|
||||
while ((code=input_code(source,&bitpos,bitsize,mask))!=end_code)
|
||||
|
@ -274,14 +321,71 @@ void lzw_decode(void *source,char *target)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct frame_header_t {
|
||||
uint32_t size;
|
||||
uint8_t count;
|
||||
} FRAME_HEADER_T;
|
||||
|
||||
typedef struct chunk_header_t {
|
||||
uint32_t size;
|
||||
uint8_t type;
|
||||
} CHUNK_HEADER_T;
|
||||
|
||||
CHUNK_HEADER_T read_chunk_header(char **iter) {
|
||||
CHUNK_HEADER_T ret;
|
||||
ret.type = *(uint8_t *)(*iter)++;
|
||||
ret.size = *(uint8_t *)(*iter)++;
|
||||
ret.size |= *(uint8_t *)(*iter)++ << 8;
|
||||
ret.size |= *(uint8_t *)(*iter)++ << 16;
|
||||
return ret;
|
||||
}
|
||||
|
||||
FRAME_HEADER_T read_frame_header(char **iter) {
|
||||
FRAME_HEADER_T ret;
|
||||
ret.count = *(uint8_t *)(*iter)++;
|
||||
ret.size = *(uint8_t *)(*iter)++;
|
||||
ret.size |= *(uint8_t *)(*iter)++ << 8;
|
||||
ret.size |= *(uint8_t *)(*iter)++ << 16;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *mgif_play(void *mgif) //dekoduje a zobrazi frame
|
||||
{
|
||||
char *pf,*pc,*ff;
|
||||
int acts,size,act,csize;
|
||||
// int acts,size,act,csize;
|
||||
void *scr_sav;
|
||||
int scr_act=-1;
|
||||
|
||||
|
||||
|
||||
pf=mgif;
|
||||
FRAME_HEADER_T frame_hdr = read_frame_header(&pf);
|
||||
pc = pf;
|
||||
pf += frame_hdr.size;
|
||||
for (uint8_t i = 0; i < frame_hdr.count; ++i) {
|
||||
CHUNK_HEADER_T chunk_hdr = read_chunk_header(&pc);
|
||||
if (chunk_hdr.type == MGIF_LZW || chunk_hdr.type == MGIF_DELTA) {
|
||||
ff=lzw_buffer;
|
||||
lzw_decode(pc,ff);
|
||||
scr_sav=ff;
|
||||
scr_act=chunk_hdr.type;
|
||||
} else if (chunk_hdr.type==MGIF_COPY) {
|
||||
//scr_sav=ff;scr_act=act;
|
||||
//strange code
|
||||
scr_sav = pc;
|
||||
scr_act = chunk_hdr.type;
|
||||
} else {
|
||||
show_proc(chunk_hdr.type,pc,chunk_hdr.size);
|
||||
}
|
||||
pc+=chunk_hdr.size;
|
||||
}
|
||||
if (scr_act!=-1) show_proc(scr_act,scr_sav,0);
|
||||
cur_frame+=1;
|
||||
if (cur_frame==mgif_frames) return NULL;
|
||||
return pf;
|
||||
}
|
||||
/*
|
||||
acts=*pf++;
|
||||
size=(*(int *)pf) & 0xffffff;
|
||||
pf+=3;pc=pf;pf+=size;
|
||||
|
@ -316,7 +420,7 @@ void *mgif_play(void *mgif) //dekoduje a zobrazi frame
|
|||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue