extracttexture.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "common.h"
  2. #include "devil1tex.h"
  3. void extracttextures(const char *filedata,
  4. unsigned int filesize,
  5. const char *filename) {
  6. struct TexturePack *p = NULL;
  7. struct Texture *t = NULL;
  8. struct TextureBatchDescriptor *d = NULL;
  9. char * fmt = NULL;
  10. if (!(DEVIL1TEX.getheader(&p, filedata)) || filesize == 0) {
  11. return;
  12. }
  13. fmt = (char*)malloc(strlen(filename) + 3 + 4);
  14. unsigned int i;
  15. unsigned int j;
  16. unsigned int id = 0;
  17. for (i = 0; i < p -> batchNumber; i++) {
  18. DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
  19. t = (struct Texture*)
  20. malloc(sizeof(struct Texture) * (d -> texNumber));
  21. DEVIL1TEX.gettextures(t, i, filedata, filesize);
  22. for (j = 0; j < d -> texNumber; j++) {
  23. sprintf(fmt, "%s_%d.dds", filename, id);
  24. write(fmt, (char*)t[j].data, d -> textureSize);
  25. id++;
  26. }
  27. free(t);
  28. }
  29. free(fmt);
  30. return;
  31. }
  32. int main(int argc, char ** argv) {
  33. char *f = argv[1];
  34. unsigned int bufsize = 0;
  35. char *buffer = loadfile(f, &bufsize);
  36. extracttextures(buffer, bufsize, f);
  37. free(buffer);
  38. return 0;
  39. }