lib3ddevil1/demo/extracttexture.c

44 lines
1.2 KiB
C
Raw Permalink Normal View History

2018-04-18 12:17:08 +05:30
#include "common.h"
#include "devil1tex.h"
2018-04-18 12:17:08 +05:30
2018-04-18 12:49:05 +05:30
void extracttextures(const char *filedata,
2018-04-18 12:17:08 +05:30
unsigned int filesize,
const char *filename) {
struct TexturePack *p = NULL;
struct Texture *t = NULL;
struct TextureBatchDescriptor *d = NULL;
char * fmt = NULL;
if (!(DEVIL1TEX.getheader(&p, filedata)) || filesize == 0) {
2018-04-18 12:17:08 +05:30
return;
}
fmt = (char*)malloc(strlen(filename) + 3 + 4);
unsigned int i;
unsigned int j;
unsigned int id = 0;
for (i = 0; i < p -> batchNumber; i++) {
DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
t = (struct Texture*)
malloc(sizeof(struct Texture) * (d -> texNumber));
DEVIL1TEX.gettextures(t, i, filedata, filesize);
for (j = 0; j < d -> texNumber; j++) {
sprintf(fmt, "%s_%d.dds", filename, id);
write(fmt, (char*)t[j].data, d -> textureSize);
2018-04-18 12:17:08 +05:30
id++;
}
free(t);
}
free(fmt);
return;
}
int main(int argc, char ** argv) {
char *f = argv[1];
unsigned int bufsize = 0;
char *buffer = loadfile(f, &bufsize);
2018-04-18 12:49:05 +05:30
extracttextures(buffer, bufsize, f);
2018-04-18 12:17:08 +05:30
free(buffer);
return 0;
}