mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2025-05-31 14:11:42 +05:30
Added revised functions for handling texture files
This commit is contained in:
36
test/main.c
36
test/main.c
@@ -91,7 +91,6 @@ bool unpackpld (const char *filedata,
|
||||
}
|
||||
|
||||
void write(const char *filename,
|
||||
unsigned int id,
|
||||
const char* t,
|
||||
unsigned int size) {
|
||||
if (filename == NULL) {
|
||||
@@ -132,7 +131,7 @@ void unpacktextures(const char *filedata,
|
||||
for (i = 0; i < texturecount; i++) {
|
||||
texsize = descripts[i/(tp -> batchNumber)] -> textureSize;
|
||||
sprintf(fmt, "%s_%d.dds", filename, i);
|
||||
write(fmt, i, filedata + tloc[i], texsize);
|
||||
write(fmt, filedata + tloc[i], texsize);
|
||||
}
|
||||
free(fmt);
|
||||
free(tloc);
|
||||
@@ -140,12 +139,43 @@ void unpacktextures(const char *filedata,
|
||||
free(batches);
|
||||
}
|
||||
|
||||
void exporttextures(const char *filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
struct TexturePack *p = NULL;
|
||||
struct Texture *t = NULL;
|
||||
struct TextureBatchDescriptor *d = NULL;
|
||||
char * fmt = NULL;
|
||||
if (filename == NULL || filesize == 0) {
|
||||
return;
|
||||
}
|
||||
p = (struct TexturePack*)filedata;
|
||||
fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int id = 0;
|
||||
for (i = 0; i < p -> batchNumber; i++) {
|
||||
gettexdescriptor(&d, i, filedata, filesize);
|
||||
t = (struct Texture*)
|
||||
malloc(sizeof(struct Texture) * (d -> texNumber));
|
||||
unpacktexbatch(t, i, filedata, filesize);
|
||||
for (j = 0; j < d -> texNumber; j++) {
|
||||
sprintf(fmt, "%s_%d.dds", filename, id);
|
||||
write(fmt, t[j].data, d -> textureSize);
|
||||
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);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
unpacktextures(buffer, bufsize, f);
|
||||
exporttextures(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user