From: malaterre Date: Fri, 11 Feb 2005 20:04:07 +0000 (+0000) Subject: ENH: Adding new option in CMake: GDCM_FORCE_BIGENDIAN_EMULATION. You are now able... X-Git-Tag: Version1.0.bp~14 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=37fd1bd483d69af97351da7ccbd9ed7912fbaa75;p=gdcm.git ENH: Adding new option in CMake: GDCM_FORCE_BIGENDIAN_EMULATION. You are now able to change this option in cmake to turn your little endian machine into a big endian one. This is extremly alpha for now, but should allow much easier debugging...hopefully --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1493505a..1475af9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,6 @@ PROJECT(GDCM) CMAKE_MINIMUM_REQUIRED(VERSION 2.0) -#MESSAGE("MATHIEU: ${CMAKE_VERSION_RELEASE}") -#MESSAGE("MATHIEU: ${CMAKE_VERSION}") -#MESSAGE("MATHIEU: ${CMAKE_CACHE_RELEASE_VERSION}") -#IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 2.0) -# IF(${CMAKE_CACHE_RELEASE_VERSION} EQUAL "patch 5") -# MESSAGE("MAHTIEU FOO") -# ENDIF(${CMAKE_CACHE_RELEASE_VERSION} EQUAL "patch 5") -#ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 2.0) - - #----------------------------------------------------------------------------- # GDCM version number, usefull for packaging and doxygen doc: SET(GDCM_MAJOR_VERSION 0) @@ -152,6 +142,10 @@ CHECK_INCLUDE_FILE_CONCAT("netinet/in.h" CMAKE_HAVE_NETINET_IN_H) CHECK_INCLUDE_FILE_CONCAT("net/if_dl.h" CMAKE_HAVE_NET_IF_DL_H) CHECK_INCLUDE_FILE_CONCAT("net/if_arp.h" CMAKE_HAVE_NET_IF_ARP_H) +#----------------------------------------------------------------------------- +# Force Big Endian emulation on little endian: +OPTION(GDCM_FORCE_BIGENDIAN_EMULATION "Force Big Endian Emulation." OFF) + CONFIGURE_FILE(${GDCM_SOURCE_DIR}/gdcmConfigure.h.in ${GDCM_BINARY_DIR}/gdcmConfigure.h @ONLY IMMEDIATE) diff --git a/gdcmConfigure.h.in b/gdcmConfigure.h.in index 0737e4a3..81641613 100644 --- a/gdcmConfigure.h.in +++ b/gdcmConfigure.h.in @@ -51,6 +51,7 @@ #cmakedefine CMAKE_HAVE_NET_IF_ARP_H #cmakedefine HAVE_SA_LEN +#cmakedefine GDCM_FORCE_BIGENDIAN_EMULATION /*--------------------------------------------------------------------------*/ /* GDCM Versioning */ diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index 70a27780..0e677a49 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2005/02/11 19:00:39 $ - Version: $Revision: 1.70 $ + Date: $Date: 2005/02/11 20:04:07 $ + Version: $Revision: 1.71 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -81,7 +81,7 @@ void BinEntry::WriteContent(std::ofstream *fp, FileType filetype) /// to write image with Big Endian Transfert Syntax, /// and we are working on Little Endian Processor -#ifdef GDCM_WORDS_BIGENDIAN +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) /// \todo FIXME Right now, we only care of Pixels element /// we should deal with *all* the BinEntries /// well not really since we are not interpreting values read... diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index f1fb5ed6..3cf3b8bc 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/02/11 19:19:05 $ - Version: $Revision: 1.228 $ + Date: $Date: 2005/02/11 20:04:08 $ + Version: $Revision: 1.229 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,15 +32,6 @@ #include #include -// For nthos: -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) - #include -#endif - -#ifdef CMAKE_HAVE_NETINET_IN_H - #include -#endif - namespace gdcm { //----------------------------------------------------------------------------- @@ -1728,9 +1719,7 @@ bool Document::CheckSwap() // First, compare HostByteOrder and NetworkByteOrder in order to // determine if we shall need to swap bytes (i.e. the Endian type). - - uint32_t x = 4; // x : for ntohs - bool net2host = (x == ntohs(x));// true when HostByteOrder is the same as NetworkByteOrder + bool net2host = Util::IsCurrentProcessorBigEndian(); // The easiest case is the one of a 'true' DICOM header, we just have // to look for the string "DICM" inside the file preamble. diff --git a/src/gdcmJpeg.cxx b/src/gdcmJpeg.cxx index da85bd4b..3d11de65 100644 --- a/src/gdcmJpeg.cxx +++ b/src/gdcmJpeg.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmJpeg.cxx,v $ Language: C++ - Date: $Date: 2005/02/11 19:00:39 $ - Version: $Revision: 1.47 $ + Date: $Date: 2005/02/11 20:04:08 $ + Version: $Revision: 1.48 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -337,7 +337,7 @@ bool JPEGFragment::ReadJPEGFile (std::ifstream *fp, void *image_buffer, int &sta return true; } // The ijg has no notion of big endian, therefore always swap the jpeg stream -#if defined(GDCM_WORDS_BIGENDIAN) && (CMAKE_BITS_IN_JSAMPLE != 8) +#if (defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)) && (CMAKE_BITS_IN_JSAMPLE != 8) uint16_t *buffer16 = (uint16_t*)*buffer; uint16_t *pimage16 = (uint16_t*)pImage; for(unsigned int i=0;i -std::ostream &binary_write(std::ostream &os, const T &val) -{ - return os.write(reinterpret_cast(&val), sizeof val); -} - /** * \brief binary_write binary_write * @param os ostream to write to @@ -827,7 +816,7 @@ std::ostream &binary_write(std::ostream &os, const T &val) */ std::ostream &binary_write(std::ostream &os, const uint16_t &val) { -#ifdef GDCM_WORDS_BIGENDIAN +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) uint16_t swap; swap = ((( val << 8 ) & 0xff00 ) | (( val >> 8 ) & 0x00ff ) ); return os.write(reinterpret_cast(&swap), 2); @@ -843,7 +832,7 @@ std::ostream &binary_write(std::ostream &os, const uint16_t &val) */ std::ostream &binary_write(std::ostream &os, const uint32_t &val) { -#ifdef GDCM_WORDS_BIGENDIAN +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) uint32_t swap; swap = ( ((val<<24) & 0xff000000) | ((val<<8) & 0x00ff0000) | ((val>>8) & 0x0000ff00) | ((val>>24) & 0x000000ff) ); @@ -894,7 +883,7 @@ std::ostream &binary_write(std::ostream &os, const uint16_t *val, size_t len) // This is tricky since we are writting two bytes buffer. Be carefull with little endian // vs big endian. Also this other trick is to allocate a small (efficient) buffer that store // intermidiate result before writting it. -#ifdef GDCM_WORDS_BIGENDIAN +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) const int BUFFER_SIZE = 4096; uint16_t *buffer = new uint16_t[BUFFER_SIZE/2]; uint16_t *binArea16 = (uint16_t*)val; diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 86cee144..8e7ac623 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.h,v $ Language: C++ - Date: $Date: 2005/02/11 19:00:39 $ - Version: $Revision: 1.54 $ + Date: $Date: 2005/02/11 20:04:08 $ + Version: $Revision: 1.55 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -71,8 +71,6 @@ private: static const std::string GDCM_UID; }; -template -GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const T &val); GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val); GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val); GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);