mirror of
				https://notabug.org/scuti/lib3ddevil1
				synced 2025-05-31 14:11:42 +05:30 
			
		
		
		
	detour-implementation of texture unpacking
This commit is contained in:
		| @@ -52,7 +52,7 @@ unsigned int gettexturebatch( | ||||
|                      const char*,  | ||||
|                      unsigned int); | ||||
|  | ||||
| void gettextures(struct Texture **, | ||||
| void gettextures(unsigned int*, | ||||
|                      struct TexturePack*, | ||||
|                      struct TextureBatch**, | ||||
|                      struct TextureBatchDescriptor**); | ||||
|   | ||||
| @@ -78,8 +78,8 @@ unsigned int gettexturebatch( | ||||
|     } | ||||
|     return totaltextures; | ||||
| } | ||||
|  | ||||
| void gettextures(struct Texture **t, | ||||
|   | ||||
| void gettextures(unsigned int *t, | ||||
|                      struct TexturePack *tp, | ||||
|                      struct TextureBatch **tb, | ||||
|                      struct TextureBatchDescriptor **bds) { | ||||
| @@ -87,11 +87,11 @@ void gettextures(struct Texture **t, | ||||
|     unsigned int j; | ||||
|     // k is access to index of textures. | ||||
|     unsigned int k = 0; | ||||
|     unsigned int offset = 0; | ||||
|     unsigned int offset = tp -> firstBatchOffset; | ||||
|     for (i = 0; i < tp -> batchNumber; i++) { | ||||
|         for (j = 0; j < bds[i] -> texNumber; j++) { | ||||
|             printf("texture offsets %x\n", offset + tp -> firstBatchOffset); | ||||
|             t[k] = (struct Texture*)tb + offset; | ||||
|             printf("texture offsets %x\n", offset); | ||||
|             t[k]    = offset; | ||||
|             offset += bds[i] -> textureSize; | ||||
|             k++; | ||||
|         } | ||||
|   | ||||
							
								
								
									
										17
									
								
								test/main.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								test/main.c
									
									
									
									
									
								
							| @@ -110,7 +110,7 @@ bool unpackpld (const char *filedata, | ||||
|  | ||||
| void write(const char *filename,  | ||||
|            unsigned int id,  | ||||
|            struct Texture *t,  | ||||
|            const char* t,  | ||||
|            unsigned int size) { | ||||
|     if (filename == NULL) { | ||||
|         return; | ||||
| @@ -120,6 +120,10 @@ void write(const char *filename, | ||||
|     if (out != NULL) { | ||||
|         written = fwrite(t, sizeof(unsigned char), size, out); | ||||
|         fclose(out); | ||||
| /*         unsigned int i; | ||||
|         for (i = 0; i < 10; i++) { | ||||
|             printf("w %u \n", *(t + i)); | ||||
|         } */ | ||||
|         if (written == 0) { | ||||
|             perror("texture write error"); | ||||
|         } | ||||
| @@ -140,10 +144,9 @@ void unpacktextures(const char *filedata, | ||||
|                                                 descripts,  | ||||
|                                                 filedata,  | ||||
|                                                 filesize); | ||||
|     struct Texture **textures = NULL; | ||||
|     textures = (struct Texture**) | ||||
|                     malloc(sizeof(struct Texture**) * texturecount);     | ||||
|     gettextures(textures, tp, batches, descripts); | ||||
|     unsigned int *tloc = (unsigned int*) | ||||
|                             malloc(sizeof(unsigned int) * texturecount); | ||||
|     gettextures(tloc, 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; | ||||
| @@ -151,10 +154,10 @@ void unpacktextures(const char *filedata, | ||||
|     for (i = 0; i < texturecount; i++) { | ||||
|         texsize = descripts[i/(tp -> batchNumber)] -> textureSize; | ||||
|         sprintf(fmt, "test_%d.dds", i); | ||||
|         write(fmt, i, textures[i], texsize); | ||||
|         write(fmt, i, filedata + tloc[i], texsize); | ||||
|     } | ||||
|     free(fmt); | ||||
|     free(textures); | ||||
|     free(tloc); | ||||
|     free(descripts); | ||||
|     free(batches); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user