mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Implemented texture unpacking - needs testing
This commit is contained in:
parent
d3f6a20bec
commit
1b06741be4
44
test/main.c
44
test/main.c
@ -108,14 +108,31 @@ bool unpackpld (const char *filedata,
|
|||||||
strcat(fmt, "%d.dds");
|
strcat(fmt, "%d.dds");
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
void write(const char *filename,
|
||||||
|
unsigned int id,
|
||||||
|
struct Texture *t,
|
||||||
|
unsigned int size) {
|
||||||
|
if (filename == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned int written = 0;
|
||||||
|
FILE *out = fopen(filename, "wb");
|
||||||
|
if (out != NULL) {
|
||||||
|
written = fwrite(t, sizeof(unsigned char), size, out);
|
||||||
|
fclose(out);
|
||||||
|
if (written == 0) {
|
||||||
|
perror("texture write error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void unpacktextures(const char *filedata,
|
void unpacktextures(const char *filedata,
|
||||||
unsigned int filesize) {
|
unsigned int filesize,
|
||||||
|
const char *filename) {
|
||||||
struct TexturePack *tp = (struct TexturePack*)filedata;
|
struct TexturePack *tp = (struct TexturePack*)filedata;
|
||||||
|
struct TextureBatch **batches = NULL;
|
||||||
struct TextureBatch **batches = NULL;
|
|
||||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
|
||||||
|
|
||||||
struct TextureBatchDescriptor **descripts = NULL;
|
struct TextureBatchDescriptor **descripts = NULL;
|
||||||
|
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
||||||
descripts = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
descripts = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||||
gettbd(descripts, filedata, filesize);
|
gettbd(descripts, filedata, filesize);
|
||||||
// array of pointers - texture data exists in memory in filedata.
|
// array of pointers - texture data exists in memory in filedata.
|
||||||
@ -124,9 +141,19 @@ void unpacktextures(const char *filedata,
|
|||||||
filedata,
|
filedata,
|
||||||
filesize);
|
filesize);
|
||||||
struct Texture **textures = NULL;
|
struct Texture **textures = NULL;
|
||||||
textures = (struct Texture**)malloc(
|
textures = (struct Texture**)
|
||||||
sizeof(struct Texture**) * texturecount);
|
malloc(sizeof(struct Texture**) * texturecount);
|
||||||
gettextures(textures, tp, batches, descripts);
|
gettextures(textures, tp, batches, descripts);
|
||||||
|
// add 3 to buffer for digits, & 4 for file extension
|
||||||
|
char *fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
||||||
|
unsigned int texsize = 0;
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < texturecount; i++) {
|
||||||
|
texsize = descripts[i/(tp -> batchNumber)] -> textureSize;
|
||||||
|
sprintf(fmt, "test_%d.dds", i);
|
||||||
|
write(fmt, i, textures[i], texsize);
|
||||||
|
}
|
||||||
|
free(fmt);
|
||||||
free(textures);
|
free(textures);
|
||||||
free(descripts);
|
free(descripts);
|
||||||
free(batches);
|
free(batches);
|
||||||
@ -137,8 +164,7 @@ int main(int argc, char ** argv) {
|
|||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
// unpackpld(buffer, bufsize, f);
|
// unpackpld(buffer, bufsize, f);
|
||||||
// unpacktextures(buffer, bufsize);
|
unpacktextures(buffer, bufsize, f);
|
||||||
unpacktextures(buffer, bufsize);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user