Merge branch 'master' of https://git.teknik.io/scuti/lib3ddevil1 into h/pldnoheap

This commit is contained in:
_
2018-04-06 15:04:34 -07:00
4 changed files with 221 additions and 3 deletions

View File

@@ -1,9 +1,11 @@
#include "devil1pld.h"
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "devil1pld.h"
#include "devil1tex.h"
bool writedata(const char *basename,
unsigned int id,
const char *data,
@@ -98,11 +100,60 @@ bool unpackpld(const char *filedata,
}
}
void write(const char *filename,
const char* 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 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);
// unpackpld(buffer, bufsize, f);
exporttextures(buffer, bufsize, f);
free(buffer);
return 0;
}