Commit 951a7236 authored by Sylvain Thery's avatar Sylvain Thery

MAJ img3DIO texture et text3D,

modification apps_cmake
parent 74a258a0
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
project(geometryAssertD) project(testing_debug)
SET(CMAKE_BUILD_TYPE Debug) SET(CMAKE_BUILD_TYPE Debug)
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/include
...@@ -12,11 +11,15 @@ include_directories( ...@@ -12,11 +11,15 @@ include_directories(
) )
# define libs path IF(WIN32)
link_directories( link_directories(
${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/$(ConfigurationName)
${CGoGN_ROOT_DIR}/lib/Release ${CGoGN_ROOT_DIR}/lib/Release )
) ELSE(WIN32)
link_directories(
${CGoGN_ROOT_DIR}/lib/Debug
${CGoGN_ROOT_DIR}/lib/Release )
ENDIF(WIN32)
#define exec to compile #define exec to compile
......
Principe des applications dans CGoGN_Apps
Faire un repertoire CGoGN_Apps ou on veut. Y mettre des sous répertoires
contenant chacun une application/
Le CMakeLists.txt a la racine de l'application doit commencer par
cmake_minimum_required(VERSION 2.8)
PROJECT(NOM_DE_L_APPLICATION)
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../../CGoGN)
INCLUDE(${CGoGN_ROOT_DIR}/build/apps_cmake.txt)
Le ../../CGoGN correspond au chemin relatif vers votre version de CGoGN
(ici placée au même niveau que CGoGN_Apps)
Si vous voulez faire des sous répertoires release et debug:
add_subdirectory(${CMAKE_SOURCE_DIR}/Release Release)
IF (NOT WIN32)
add_subdirectory(${CMAKE_SOURCE_DIR}/Debug Debug)
ENDIF (NOT WIN32)
Le CMakeLists (Release par exemple) doit ensuite contenir
SET(CMAKE_BUILD_TYPE Release)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release/)
include_directories(
${CGoGN_ROOT_DIR}/include # for CGoGN
${COMMON_INCLUDES} # for thirdparty & system
${CMAKE_CURRENT_SOURCE_DIR} # for application
${CMAKE_CURRENT_BINARY_DIR} # for qt (ui,moc,etc.) if necessary
)
add_executable( mon_exec ${CMAKE_SOURCE_DIR}/mon_source.cpp)
target_link_libraries( mon_exec ${CGoGN_LIBS_R} ${COMMON_LIBS})
Pour le compiler le plus propre est de faire un repertoire build,
d'aller à l'interieur et de faire ccmake .. (j'ai bien ecrit "..")
ccmake (ou un equivalent type cmake-gui) permet de mettre à jour les variables,
ici WITH_QT, WITH_ASSIMP, WITH_NUMERICAL, WITH_ZINRI.
Ceci ajoutera automatiquement tout ce qu'il faut aux variables COMMON_INCLUDES
et COMMON_LIBS.
On peut aussi utiliser cmake avec l'option -D (moins pratique).
# A mettre juste apres la definition de CGoGN_ROOT_DIR a la racine du CGoGN_Apps # A mettre juste apres la definition de CGoGN_ROOT_DIR a la racine du CGoGN_Apps
# include(${CGoGN_ROOT_DIR}/build/apps_cmake.txt) # include(${CGoGN_ROOT_DIR}/build/apps_cmake.txt)
SET(CMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH} ${CGoGN_ROOT_DIR}/cmake_modules/") SET(CMAKE_MODULE_PATH ${CGoGN_ROOT_DIR}/cmake_modules/)
SET ( WITH_ASSIMP ON CACHE BOOL "need Assimp") SET ( WITH_ASSIMP ON CACHE BOOL "need Assimp")
...@@ -30,7 +30,7 @@ ENDIF (DEFINED ASSERTON) ...@@ -30,7 +30,7 @@ ENDIF (DEFINED ASSERTON)
add_definitions(-DSHADERPATH="${CGoGN_ROOT_DIR}/lib/Shaders/") add_definitions(-DSHADERPATH="${CGoGN_ROOT_DIR}/lib/Shaders/")
# define includes of external libs # define includes of external libs
SET(CGoGN_EXT_INCLUDES SET(COMMON_INCLUDES
${CGoGN_ROOT_DIR}/ThirdParty/glm ${CGoGN_ROOT_DIR}/ThirdParty/glm
${OPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS}
...@@ -50,13 +50,13 @@ SET (COMMON_LIBS ...@@ -50,13 +50,13 @@ SET (COMMON_LIBS
#optionnal libs #optionnal libs
IF (WITH_ASSIMP) IF (WITH_ASSIMP)
add_definitions(-DWITH_ASSIMP) add_definitions(-DWITH_ASSIMP)
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ThirdParty/Assimp/include) SET (COMMON_INCLUDES ${COMMON_INCLUDES} ThirdParty/Assimp/include)
SET (COMMON_LIBS ${COMMON_LIBS} assimp) SET (COMMON_LIBS ${COMMON_LIBS} assimp)
ENDIF (WITH_ASSIMP) ENDIF (WITH_ASSIMP)
IF (WITH_ZINRI) IF (WITH_ZINRI)
add_definitions(-DWITH_ZINRI) add_definitions(-DWITH_ZINRI)
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Zinri) SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Zinri)
SET (COMMON_LIBS ${COMMON_LIBS} Zinri) SET (COMMON_LIBS ${COMMON_LIBS} Zinri)
ENDIF (WITH_ZINRI) ENDIF (WITH_ZINRI)
...@@ -66,16 +66,20 @@ IF (WITH_QT) ...@@ -66,16 +66,20 @@ IF (WITH_QT)
SET(QT_USE_QTOPENGL TRUE) SET(QT_USE_QTOPENGL TRUE)
INCLUDE(${QT_USE_FILE}) INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS}) ADD_DEFINITIONS(${QT_DEFINITIONS})
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${QT_INCLUDE_DIR}) SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${QT_INCLUDE_DIR})
SET (CGoGN_EXT_LIBS ${CGoGN_EXT_LIBS} ${QT_LIBRARIES}) SET (COMMON_LIBS ${COMMON_LIBS} ${QT_LIBRARIES})
ENDIF (WITH_QT) ENDIF (WITH_QT)
IF (WITH_NUMERICAL) IF (WITH_NUMERICAL)
add_definitions(-DWITH_NUMERICAL) add_definitions(-DWITH_NUMERICAL)
SET (NUMERICAL_INCLUDES ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig) # SET (NUMERICAL_INCLUDES ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig)
SET (NUMERICAL_LIBS f2c blas numerical lapack) # SET (NUMERICAL_LIBS f2c blas numerical lapack)
SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig)
SET (COMMON_LIBS ${COMMON_LIBS} f2c blas numerical lapack)
ENDIF (WITH_NUMERICAL) ENDIF (WITH_NUMERICAL)
# qq definition specifiques pour mac # qq definition specifiques pour mac
IF(APPLE) IF(APPLE)
# attention a changer pour chercher la bonne version automatiquement # attention a changer pour chercher la bonne version automatiquement
...@@ -85,20 +89,15 @@ IF(APPLE) ...@@ -85,20 +89,15 @@ IF(APPLE)
SET(CMAKE_OSX_ARCHITECTURES x86_64) SET(CMAKE_OSX_ARCHITECTURES x86_64)
ENDIF(APPLE) ENDIF(APPLE)
# qq definition specifiques pour windows
IF(WIN32) IF(WIN32)
add_subdirectory(Release)
add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps)
set(CMAKE_PREFIX_PATH ${CGoGN_ROOT_DIR}/windows_dependencies CACHE STRING "path to dependencies") set(CMAKE_PREFIX_PATH ${CGoGN_ROOT_DIR}/windows_dependencies CACHE STRING "path to dependencies")
set(CMAKE_CONFIGURATION_TYPES Release Debug) set(CMAKE_CONFIGURATION_TYPES Release Debug)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Only Release or Debug" FORCE) set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Only Release or Debug" FORCE)
ELSE(WIN32) ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_subdirectory(Release)
add_subdirectory(Debug)
add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps)
ENDIF(WIN32) ENDIF(WIN32)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
SET(CGoGN_LIBS_D topologyD algoD containerD utilsD) SET(CGoGN_LIBS_D topologyD algoD containerD utilsD)
......
...@@ -180,7 +180,6 @@ void Image<DataType>::loadVox(char *filename) ...@@ -180,7 +180,6 @@ void Image<DataType>::loadVox(char *filename)
template< typename DataType > template< typename DataType >
bool Image<DataType>::loadPNG3D(const char* filename) bool Image<DataType>::loadPNG3D(const char* filename)
{ {
CGoGN::Utils::Img3D_IO::initIO();
int tag; int tag;
//en fonction de DataType utiliser la bonne fonction de chargement, //en fonction de DataType utiliser la bonne fonction de chargement,
......
...@@ -32,7 +32,7 @@ namespace CGoGN ...@@ -32,7 +32,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
#ifdef WITH_QT
namespace Img3D_IO namespace Img3D_IO
{ {
/** /**
...@@ -40,13 +40,7 @@ namespace Img3D_IO ...@@ -40,13 +40,7 @@ namespace Img3D_IO
*/ */
enum TYPEIMG {BOOL8=1, VAL8, RGB8, VAL16, VALFLOAT}; enum TYPEIMG {BOOL8=1, VAL8, RGB8, VAL16, VALFLOAT};
#ifdef PORTED_TO_QIMAGE
/**
* Initialization of IO
* Necessary before any other call
*/
void initIO();
/** /**
* Load bool image (0/255) * Load bool image (0/255)
...@@ -113,7 +107,7 @@ namespace Img3D_IO ...@@ -113,7 +107,7 @@ namespace Img3D_IO
/** /**
* Load 16 bits value image * Load RGB 8 bits image
* Warning: the allocated data image contain w supplemntary bytes which store information * Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident * @param filename evident
* @param w width of image (reference out) * @param w width of image (reference out)
...@@ -125,11 +119,11 @@ namespace Img3D_IO ...@@ -125,11 +119,11 @@ namespace Img3D_IO
* @param tag image tag (reference out) * @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function) * @return a pointer on the image data (that have been allocated by function)
*/ */
// unsigned short* loadVal_16(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag); unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
/** /**
* Save 16bits val image * Save RGB 8 bits image
* Warning: the saved image contain w supplemntary bytes which store informations * Warning: the saved image contain 3w supplemntary bytes which store informations
* Warning: origin of image is lower left * Warning: origin of image is lower left
* @param filename evident * @param filename evident
* @param data a pointer on the image data * @param data a pointer on the image data
...@@ -141,10 +135,9 @@ namespace Img3D_IO ...@@ -141,10 +135,9 @@ namespace Img3D_IO
* @param vz voxel size z * @param vz voxel size z
* @param tag image tag * @param tag image tag
*/ */
// void saveVal_16(const std::string& filename, unsigned short* data, int w, int h, int d, float vx, float vy, float vz, int tag); void saveRGB(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag);
/** /**
* Load float value image * Load 16 bits value image
* Warning: the allocated data image contain w supplemntary bytes which store information * Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident * @param filename evident
* @param w width of image (reference out) * @param w width of image (reference out)
...@@ -156,10 +149,10 @@ namespace Img3D_IO ...@@ -156,10 +149,10 @@ namespace Img3D_IO
* @param tag image tag (reference out) * @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function) * @return a pointer on the image data (that have been allocated by function)
*/ */
// float* loadVal_float(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id); // unsigned short* loadVal_16(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag);
/** /**
* Save float val image * Save 16bits val image
* Warning: the saved image contain w supplemntary bytes which store informations * Warning: the saved image contain w supplemntary bytes which store informations
* Warning: origin of image is lower left * Warning: origin of image is lower left
* @param filename evident * @param filename evident
...@@ -172,11 +165,10 @@ namespace Img3D_IO ...@@ -172,11 +165,10 @@ namespace Img3D_IO
* @param vz voxel size z * @param vz voxel size z
* @param tag image tag * @param tag image tag
*/ */
// void saveVal_float(const std::string& filename, float* data, int w, int h, int d, float vx, float vy, float vz, int tag); // void saveVal_16(const std::string& filename, unsigned short* data, int w, int h, int d, float vx, float vy, float vz, int tag);
/** /**
* Load RGB 8 bits image * Load float value image
* Warning: the allocated data image contain w supplemntary bytes which store information * Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident * @param filename evident
* @param w width of image (reference out) * @param w width of image (reference out)
...@@ -188,11 +180,11 @@ namespace Img3D_IO ...@@ -188,11 +180,11 @@ namespace Img3D_IO
* @param tag image tag (reference out) * @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function) * @return a pointer on the image data (that have been allocated by function)
*/ */
unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id); // float* loadVal_float(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
/** /**
* Save RGB 8 bits image * Save float val image
* Warning: the saved image contain 3w supplemntary bytes which store informations * Warning: the saved image contain w supplemntary bytes which store informations
* Warning: origin of image is lower left * Warning: origin of image is lower left
* @param filename evident * @param filename evident
* @param data a pointer on the image data * @param data a pointer on the image data
...@@ -204,10 +196,13 @@ namespace Img3D_IO ...@@ -204,10 +196,13 @@ namespace Img3D_IO
* @param vz voxel size z * @param vz voxel size z
* @param tag image tag * @param tag image tag
*/ */
void saveRGB(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag); // void saveVal_float(const std::string& filename, float* data, int w, int h, int d, float vx, float vy, float vz, int tag);
#endif
} //namespace } //namespace
#endif
} //namespace } //namespace
} //namespace } //namespace
......
...@@ -197,13 +197,10 @@ public: ...@@ -197,13 +197,10 @@ public:
typedef Geom::Vector<DIM,unsigned int> COORD; typedef Geom::Vector<DIM,unsigned int> COORD;
protected: protected:
/// id of image for DevIL
QImage* m_qimg;
template <typename TYPEDOUBLE> template <typename TYPEDOUBLE>
TYPE applyFilterOneTexel(const Filter<DIM>& filter, const COORD& t) const; TYPE applyFilterOneTexel(const Filter<DIM>& filter, const COORD& t) const;
/// swap two texel in dim 1 image /// swap two texel in dim 1 image
void swapTexels(unsigned int x0, unsigned int x1); void swapTexels(unsigned int x0, unsigned int x1);
...@@ -225,21 +222,24 @@ public: ...@@ -225,21 +222,24 @@ public:
/// destructor /// destructor
~Image(); ~Image();
/**
* swap two images
*/
virtual void swap(Image<DIM,TYPE>& img);
/**
* Load from memory ptr,
* a copy if performed (ptr could be destructed just after calling
* @param ptr a pointer on memory source image (allocation must be coherent with other parameters)
* @param w width of image
* @param h heighy of image
* @param bpp byte per pixel of image
*/
bool load(const unsigned char *ptr, unsigned int w, unsigned int h, unsigned int bpp)
#ifdef WITH_QT
/// load from file /// load from file
bool load(const std::string& filename); bool load(const std::string& filename);
/// load from file with conversion (template type is type pixel image-
template <typename TYPE2 >
bool load(const std::string& filename, void (*convertFunc)(const TYPE2&, const TYPE&));
/// load from file /// load from file
void save(const std::string& filename); void save(const std::string& filename);
#endif
/** /**
* crop image * crop image
......
...@@ -256,15 +256,13 @@ void ImageData<DIM,TYPE>::convert(ImageData<DIM,TYPE2>& output, TYPE2 (*convertF ...@@ -256,15 +256,13 @@ void ImageData<DIM,TYPE>::convert(ImageData<DIM,TYPE2>& output, TYPE2 (*convertF
// implementation class Image // implementation class Image
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::Image(): Image<DIM,TYPE>::Image()
m_qimg(NULL)
{ {
} }
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::Image(const COORD& size): Image<DIM,TYPE>::Image(const COORD& size):
ImageData<DIM,TYPE>(size), ImageData<DIM,TYPE>(size)
m_qimg(NULL)
{ {
} }
...@@ -272,12 +270,11 @@ m_qimg(NULL) ...@@ -272,12 +270,11 @@ m_qimg(NULL)
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::~Image() Image<DIM,TYPE>::~Image()
{ {
if (this->m_qimg != NULL) delete[] m_data_ptr;
delete this->m_qimg;
m_qimg = NULL;
this->m_data_ptr = NULL; this->m_data_ptr = NULL;
} }
/*
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img) void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img)
{ {
...@@ -290,69 +287,41 @@ void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img) ...@@ -290,69 +287,41 @@ void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img)
ImageData<DIM,TYPE>::swap(img); ImageData<DIM,TYPE>::swap(img);
} }
*/
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
bool Image<DIM,TYPE>::load(const std::string& filename) bool Image<DIM,TYPE>::load(const unsigned char *ptr, unsigned int w, unsigned int h, unsigned int bpp)
{ {
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension); CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
QImage* ptr = new QImage(filename.c_str());
if (ptr == NULL)
{
delete ptr;
return false;
}
// get the info of images
unsigned int bpp = ptr->depth() / 8;
// compatible TYPE // compatible TYPE
if (bpp < sizeof(TYPE)) if (bpp != sizeof(TYPE))
{ {
CGoGNout << "Image::load incompatible type: bbp="<<bpp<< CGoGNendl; CGoGNout << "Image::load incompatible type: bbp=" << bpp << CGoGNendl;
CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl; CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl;
delete ptr; delete ptr;
return false; return false;
} }
// destroy old data // destroy old data
if (this->m_qimg != NULL) if (this->m_data_ptr != NULL)
delete this->m_qimg;
else if (this->m_data_ptr != NULL)
delete[] this->m_data_ptr; delete[] this->m_data_ptr;
if (bpp > sizeof(TYPE)) this->m_data_ptr = new T[sizeof(TYPE)*w*h];
{ memcpy(this->m_data_ptr, img.bits(), sizeof(TYPE)*w*h);
if (sizeof(TYPE) == 3) this->m_size[0] = w;
{ this->m_size[1] = h;
QImage img = ptr->convertToFormat(QImage::Format_RGB888);
this->m_qimg = new QImage(img);
}
else if (sizeof(TYPE) == 1)
{
QImage img = ptr->convertToFormat(QImage::Format_Indexed8);
this->m_qimg = new QImage(img);
}
delete ptr;
}
else
this->m_qimg = ptr;
this->m_size[0] = this->m_qimg->width();
this->m_size[1] = m_qimg->height();
this->m_data_ptr = reinterpret_cast<TYPE*>(m_qimg->bits());
this->computeSub(); this->computeSub();
return true; return true;
} }
#ifdef WITH_QT
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
template <typename TYPE2 > bool Image<DIM,TYPE>::load(const std::string& filename)
bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(const TYPE2&, const TYPE&))
{ {
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension); CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
...@@ -360,7 +329,7 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons ...@@ -360,7 +329,7 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
if (ptr == NULL) if (ptr == NULL)
{ {
delete ptr; CGoGNout << "Impossible to load "<< filename << std::endl;
return false; return false;
} }
...@@ -368,18 +337,16 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons ...@@ -368,18 +337,16 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
unsigned int bpp = ptr->depth() / 8; unsigned int bpp = ptr->depth() / 8;
// compatible TYPE // compatible TYPE
if (bpp != sizeof(TYPE)) if (bpp < sizeof(TYPE))
{ {
CGoGNout << "Image::load incompatible type: bbp="<<bpp<< CGoGNendl; CGoGNout << "Image::load incompatible type: bbp=" << bpp << CGoGNendl;
CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl; CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl;
delete ptr; delete ptr;
return false; return false;
} }
// destroy old data // destroy old data
if (this->m_qimg != NULL) if (this->m_data_ptr != NULL)
delete this->m_qimg;
else if (this->m_data_ptr != NULL)
delete[] this->m_data_ptr; delete[] this->m_data_ptr;
if (bpp > sizeof(TYPE)) if (bpp > sizeof(TYPE))
...@@ -387,34 +354,27 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons ...@@ -387,34 +354,27 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
if (sizeof(TYPE) == 3) if (sizeof(TYPE) == 3)
{ {
QImage img = ptr->convertToFormat(QImage::Format_RGB888); QImage img = ptr->convertToFormat(QImage::Format_RGB888);
this->m_qimg = new QImage(img); this->m_data_ptr = new T[3*img.width()*img.height()];
memcpy(this->m_data_ptr, img.bits(), 3*img.width()*img.height());
} }
else if (sizeof(TYPE) == 1) else if (sizeof(TYPE) == 1)
{ {
QImage img = ptr->convertToFormat(QImage::Format_Indexed8); QImage img = ptr->convertToFormat(QImage::Format_Indexed8);
this->m_qimg = new QImage(img); this->m_data_ptr = new T[img.width()*img.height()];
memcpy(this->m_data_ptr, img.bits(), img.width()*img.height());
} }
delete ptr; }
} else
else {
this->m_qimg = ptr; this->m_data_ptr = new T[ptr->width()*ptr->height()];
memcpy(this->m_data_ptr, ptr->bits(), ptr->width()*ptr->height());
}
this->m_size[0] = this->m_qimg->width();
this->m_size[1] = m_qimg->height();
this->m_size[0] = ptr->width();
this->m_size[1] = ptr->height();
this->computeSub(); this->computeSub();
this->m_data_ptr = new TYPE[this->m_sizeSub[1]]; delete ptr;
TYPE2 *ptrSrc = reinterpret_cast<TYPE2*>(ptr->bits());
TYPE* ptrDst = this->m_data_ptr;
for (unsigned int i = 0; i < this->m_sizeSub[1]; ++i)
(*convertFunc)(*ptrSrc++, *ptrDst++);
delete this->m_qimg;
this->m_qimg=NULL;
return true; return true;
} }
...@@ -424,24 +384,7 @@ void Image<DIM,TYPE>::save(const std::string& filename) ...@@ -424,24 +384,7 @@ void Image<DIM,TYPE>::save(const std::string& filename)
{ {
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension); CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
if (this->m_qimg != NULL) if (this->m_data_ptr != NULL)
{
switch(sizeof(TYPE))
{
case 1:
this->m_qimg->save(QString(filename), QImage::Format_Indexed8);
break;
case 3:
this->m_qimg->save(QString(filename), QImage::Format_RGB888);
break;
case 4:
this->m_qimg->save(QString(filename), QImage::Format_ARGB32);
break;
default:
break;
}
}
else if (this->m_data_ptr != NULL)
{ {
switch(sizeof(TYPE)) switch(sizeof(TYPE))
{ {
...@@ -468,7 +411,7 @@ void Image<DIM,TYPE>::save(const std::string& filename) ...@@ -468,7 +411,7 @@ void Image<DIM,TYPE>::save(const std::string& filename)
} }
} }
} }
#endif
template < unsigned int DIM, typename TYPE > template < unsigned int DIM, typename TYPE >
......
...@@ -34,14 +34,9 @@ namespace CGoGN ...@@ -34,14 +34,9 @@ namespace CGoGN
namespace Utils namespace Utils
{