about summary refs log tree commit diff
path: root/src/engine/e_datafile.c
diff options
context:
space:
mode:
authorJoel de Vahl <joel@stalverk80.se>2008-10-07 16:06:51 +0000
committerJoel de Vahl <joel@stalverk80.se>2008-10-07 16:06:51 +0000
commitc0fa3003d793b0b42b9f643e9f0fd405c01b57d7 (patch)
treecdf65c93c17d8843c54f0e91b6e585566f634210 /src/engine/e_datafile.c
parent3159f795c17930aeacabbd8166b8f8779906f121 (diff)
downloadzcatch-c0fa3003d793b0b42b9f643e9f0fd405c01b57d7.tar.gz
zcatch-c0fa3003d793b0b42b9f643e9f0fd405c01b57d7.zip
fixed background on ppc
Diffstat (limited to 'src/engine/e_datafile.c')
-rw-r--r--src/engine/e_datafile.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/engine/e_datafile.c b/src/engine/e_datafile.c
index c0376088..49154567 100644
--- a/src/engine/e_datafile.c
+++ b/src/engine/e_datafile.c
@@ -214,13 +214,14 @@ int datafile_get_datasize(DATAFILE *df, int index)
 	return  df->info.data_offsets[index+1]-df->info.data_offsets[index];
 }
 
-void *datafile_get_data(DATAFILE *df, int index)
+static void *datafile_get_data_impl(DATAFILE *df, int index, int swap)
 {
 	/* load it if needed */
 	if(!df->data_ptrs[index])
 	{
 		/* fetch the data size */
 		int datasize = datafile_get_datasize(df, index);
+		int swapsize = datasize;
 		
 		if(df->header.version == 4)
 		{
@@ -239,6 +240,7 @@ void *datafile_get_data(DATAFILE *df, int index)
 			/* decompress the data, TODO: check for errors */
 			s = uncompressed_size;
 			uncompress((Bytef*)df->data_ptrs[index], &s, (Bytef*)temp, datasize);
+			swapsize = s;
 
 			/* clean up the temporary buffers */
 			mem_free(temp);
@@ -251,27 +253,25 @@ void *datafile_get_data(DATAFILE *df, int index)
 			io_seek(df->file, df->data_start_offset+df->info.data_offsets[index], IOSEEK_START);
 			io_read(df->file, df->data_ptrs[index], datasize);
 		}
+
+#if defined(CONF_ARCH_ENDIAN_BIG)
+		if(swap && swapsize)
+			swap_endian(df->data_ptrs[index], sizeof(int), swapsize/sizeof(int));
+#endif
 	}
 	
 	return df->data_ptrs[index];
 }
 
-void *datafile_get_data_swapped(DATAFILE *df, int index)
+void *datafile_get_data(DATAFILE *df, int index)
 {
-	void *ptr = datafile_get_data(df, index);
-	int size = datafile_get_datasize(df, index);
-	(void)size; /* not used on LE machines */
-	
-	if(!ptr)
-		return ptr;
-
-#if defined(CONF_ARCH_ENDIAN_BIG)
-	swap_endian(ptr, sizeof(int), size / sizeof(int));
-#endif
-
-	return ptr;
+	return datafile_get_data_impl(df, index, 0);
 }
 
+void *datafile_get_data_swapped(DATAFILE *df, int index)
+{
+	return datafile_get_data_impl(df, index, 1);
+}
 
 void datafile_unload_data(DATAFILE *df, int index)
 {