[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50334] trunk/blender/source/blender: add endian switch functions to replace macros SWITCH_INT/LONG/SHORT, with BLI_endian_switch_int32/int64/float/double...

Campbell Barton ideasman42 at gmail.com
Mon Sep 3 09:37:39 CEST 2012


Revision: 50334
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50334
Author:   campbellbarton
Date:     2012-09-03 07:37:38 +0000 (Mon, 03 Sep 2012)
Log Message:
-----------
add endian switch functions to replace macros SWITCH_INT/LONG/SHORT, with BLI_endian_switch_int32/int64/float/double...

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/customdata_file.c
    trunk/blender/source/blender/blenkernel/intern/idprop.c
    trunk/blender/source/blender/blenlib/BLI_utildefines.h
    trunk/blender/source/blender/blenlib/CMakeLists.txt
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/versioning_250.c
    trunk/blender/source/blender/blenloader/intern/versioning_legacy.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/imbuf/intern/indexer.c
    trunk/blender/source/blender/imbuf/intern/thumbs_blend.c
    trunk/blender/source/blender/makesdna/DNA_sdna_types.h

Added Paths:
-----------
    trunk/blender/source/blender/blenlib/BLI_endian_switch.h
    trunk/blender/source/blender/blenlib/BLI_endian_switch_inline.h
    trunk/blender/source/blender/blenlib/intern/endian_switch.c

Modified: trunk/blender/source/blender/blenkernel/intern/customdata_file.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata_file.c	2012-09-03 05:36:47 UTC (rev 50333)
+++ trunk/blender/source/blender/blenkernel/intern/customdata_file.c	2012-09-03 07:37:38 UTC (rev 50334)
@@ -32,6 +32,7 @@
 #include "BLI_fileops.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
+#include "BLI_endian_switch.h"
 
 #include "BKE_customdata_file.h"
 #include "BKE_global.h"
@@ -165,9 +166,9 @@
 	header->endian = cdf_endian();
 
 	if (cdf->switchendian) {
-		SWITCH_INT(header->type);
-		SWITCH_INT(header->totlayer);
-		SWITCH_INT(header->structbytes);
+		BLI_endian_switch_int32(&header->type);
+		BLI_endian_switch_int32(&header->totlayer);
+		BLI_endian_switch_int32(&header->structbytes);
 	}
 
 	if (!ELEM(header->type, CDF_TYPE_IMAGE, CDF_TYPE_MESH))
@@ -185,10 +186,10 @@
 			return 0;
 
 		if (cdf->switchendian) {
-			SWITCH_INT(image->width);
-			SWITCH_INT(image->height);
-			SWITCH_INT(image->tile_size);
-			SWITCH_INT(image->structbytes);
+			BLI_endian_switch_int32(&image->width);
+			BLI_endian_switch_int32(&image->height);
+			BLI_endian_switch_int32(&image->tile_size);
+			BLI_endian_switch_int32(&image->structbytes);
 		}
 
 		offset += image->structbytes;
@@ -200,7 +201,7 @@
 			return 0;
 
 		if (cdf->switchendian)
-			SWITCH_INT(mesh->structbytes);
+			BLI_endian_switch_int32(&mesh->structbytes);
 
 		offset += mesh->structbytes;
 		mesh->structbytes = sizeof(CDataFileMeshHeader);
@@ -219,10 +220,10 @@
 			return 0;
 
 		if (cdf->switchendian) {
-			SWITCH_INT(layer->type);
-			SWITCH_INT(layer->datatype);
-			SWITCH_INT64(layer->datasize);
-			SWITCH_INT(layer->structbytes);
+			BLI_endian_switch_int32(&layer->type);
+			BLI_endian_switch_int32(&layer->datatype);
+			BLI_endian_switch_uint64(&layer->datasize);
+			BLI_endian_switch_int32(&layer->structbytes);
 		}
 
 		if (layer->datatype != CDF_DATA_FLOAT)
@@ -329,7 +330,7 @@
 		fdata = data;
 
 		for (a = 0; a < size / sizeof(float); a++) {
-			SWITCH_INT(fdata[a]);
+			BLI_endian_switch_float(&fdata[a]);
 		}
 	}
 

Modified: trunk/blender/source/blender/blenkernel/intern/idprop.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/idprop.c	2012-09-03 05:36:47 UTC (rev 50333)
+++ trunk/blender/source/blender/blenkernel/intern/idprop.c	2012-09-03 07:37:38 UTC (rev 50334)
@@ -293,18 +293,6 @@
 	return newp;
 }
 
-/*taken from readfile.c*/
-#define SWITCH_LONGINT(a) { \
-		char s_i, *p_i; \
-		p_i = (char *)& (a);  \
-		s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \
-		s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \
-		s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \
-		s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \
-	} (void)0
-
-
-
 /* ---------- String Type ------------ */
 IDProperty *IDP_NewString(const char *st, const char *name, int maxlen)
 {

Added: trunk/blender/source/blender/blenlib/BLI_endian_switch.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_endian_switch.h	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/BLI_endian_switch.h	2012-09-03 07:37:38 UTC (rev 50334)
@@ -0,0 +1,33 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_ENDIAN_SWITCH_H__
+#define __BLI_ENDIAN_SWITCH_H__
+
+/** \file BLI_endian_switch.h
+ *  \ingroup bli
+ */
+
+#include "BLI_endian_switch_inline.h"
+
+
+#endif  /* __BLI_ENDIAN_SWITCH_H__ */


Property changes on: trunk/blender/source/blender/blenlib/BLI_endian_switch.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/blender/source/blender/blenlib/BLI_endian_switch_inline.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_endian_switch_inline.h	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/BLI_endian_switch_inline.h	2012-09-03 07:37:38 UTC (rev 50334)
@@ -0,0 +1,116 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* only include from header */
+#ifndef __BLI_ENDIAN_SWITCH_H__
+#  error "this file isnt to be directly included"
+#endif
+
+#ifndef __BLI_ENDIAN_SWITCH_INLINE_H__
+#define __BLI_ENDIAN_SWITCH_INLINE_H__
+
+/** \file blender/blenlib/BLI_endian_switch_inline.h
+ *  \ingroup bli
+ */
+
+
+BLI_INLINE void BLI_endian_switch_int16(short *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i    = p_i[0];
+	p_i[0] = p_i[1];
+	p_i[1] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i    = p_i[0];
+	p_i[0] = p_i[1];
+	p_i[1] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_int32(int *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_float(float *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_int64(int64_t *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i;
+	s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i;
+	s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i;
+	s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i;
+	s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i;
+}
+
+BLI_INLINE void BLI_endian_switch_double(double *val)
+{
+	char *p_i = (char *)val;
+	char s_i;
+
+	s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i;
+	s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i;
+	s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i;
+	s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i;
+}
+
+#endif  /* __BLI_ENDIAN_SWITCH_INLINE_H__ */


Property changes on: trunk/blender/source/blender/blenlib/BLI_endian_switch_inline.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/blender/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_utildefines.h	2012-09-03 05:36:47 UTC (rev 50333)
+++ trunk/blender/source/blender/blenlib/BLI_utildefines.h	2012-09-03 07:37:38 UTC (rev 50334)
@@ -225,30 +225,6 @@
 		(item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot))       \
 	)
 
-/* This one rotates the bytes in an int64, int (32) and short (16) */
-#define SWITCH_INT64(a) {                                                     \
-		char s_i, *p_i;                                                       \
-		p_i = (char *)&(a);                                                   \
-		s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i;                          \
-		s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i;                          \
-		s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i;                          \
-		s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i;                          \
-	} (void)0
-
-#define SWITCH_INT(a) {                                                       \
-		char s_i, *p_i;                                                       \
-		p_i = (char *)&(a);                                                   \
-		s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i;                          \
-		s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i;                          \
-	} (void)0
-
-#define SWITCH_SHORT(a) {                                                     \
-		char s_i, *p_i;                                                       \
-		p_i = (char *)&(a);                                                   \
-		s_i = p_i[0]; p_i[0] = p_i[1]; p_i[1] = s_i;                          \
-	} (void)0
-
-
 /* Warning-free macros for storing ints in pointers. Use these _only_
  * for storing an int in a pointer, not a pointer in an int (64bit)! */
 #define SET_INT_IN_POINTER(i)    ((void *)(intptr_t)(i))

Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-09-03 05:36:47 UTC (rev 50333)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-09-03 07:37:38 UTC (rev 50334)
@@ -55,6 +55,7 @@
 	intern/cpu.c
 	intern/dynlib.c
 	intern/edgehash.c
+	intern/endian_switch.c
 	intern/fileops.c
 	intern/fnmatch.c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list