Control: tags -1 patch

On Sat, 29 Sep 2018 12:52:24 +0200 Tobias Frost <t...@debian.org>
wrote:
> Hi,
> 
> Looks like #869638 of slic3r-prusa, upstream 
> https://github.com/prusa3d/Slic3r/issues/532
> 
> However, prusa's version has diverged and changed one file to c++,
> so the patch is unfortunatly not directly applicable and needs
porting.

Attached is my try to patch the issue at hand.
I have no big endian machine at hand, but the package
at builds at least.

Note that I did not have to patch stlint.c -- in contrast to the prusa
version it seems already big endian aware, at least when looking at
the commits for https://github.com/slic3r/Slic3r/pull/4143

Adrian: Do you have a possiblity to test?

Cheers,
-- 
tobi
Index: slic3r-1.3.0+dfsg1/xs/src/admesh/stl_io.c
===================================================================
--- slic3r-1.3.0+dfsg1.orig/xs/src/admesh/stl_io.c
+++ slic3r-1.3.0+dfsg1/xs/src/admesh/stl_io.c
@@ -193,6 +193,22 @@ stl_print_neighbors(stl_file *stl, ADMES
   fclose(fp);
 }
 
+/* Test for a little-endian machine */
+#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
+void stl_internal_reverse_quads(char *buf, size_t cnt)
+{
+  for (size_t i = 0; i < cnt; i += 4) {
+      char tmp;
+      tmp = buf[i];
+      buf[i] = buf[i+3];
+      buf[i+3] = tmp;
+      tmp = buf[i+1];
+      buf[i+1] = buf[i+2];
+      buf[i+2] = tmp;
+  }
+}
+#endif
+
 void
 stl_write_binary(stl_file *stl, const ADMESH_CHAR *file, const char *label) {
   FILE      *fp;
@@ -213,9 +229,22 @@ stl_write_binary(stl_file *stl, const AD
   for(i = strlen(label); i < LABEL_SIZE; i++) putc(0, fp);
 
   fseek(fp, LABEL_SIZE, SEEK_SET);
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   fwrite(&stl->stats.number_of_facets, 4, 1, fp);
   for(i = 0; i < stl->stats.number_of_facets; i++)
     fwrite(stl->facet_start + i, SIZEOF_STL_FACET, 1, fp);
+#else
+  char buffer[50];
+  memcpy(buffer, &stl->stats.number_of_facets, 4);
+  stl_internal_reverse_quads(buffer, 4);
+  fwrite(buffer, 4, 1, fp);
+  for (i = 0; i < stl->stats.number_of_facets; ++ i) {
+      memcpy(buffer, stl->facet_start + i, 50);
+      // Convert to little endian.
+      stl_internal_reverse_quads(buffer, 48);
+      fwrite(buffer, SIZEOF_STL_FACET, 1, fp);
+  }
+#endif
   fclose(fp);
 }
 
Index: slic3r-1.3.0+dfsg1/xs/src/admesh/stl.h
===================================================================
--- slic3r-1.3.0+dfsg1.orig/xs/src/admesh/stl.h
+++ slic3r-1.3.0+dfsg1/xs/src/admesh/stl.h
@@ -26,11 +26,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stddef.h>
-#include <boost/detail/endian.hpp>
-
-#ifndef BOOST_LITTLE_ENDIAN
-#error "admesh works correctly on little endian machines only!"
-#endif
 
 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
     #include "windows.h"

Reply via email to