diff --git a/library/public/image.h b/library/public/image.h index eeea7e33b7..5324571a09 100644 --- a/library/public/image.h +++ b/library/public/image.h @@ -114,6 +114,11 @@ class F3D_EXPORT image */ ChannelType getChannelType() const; + /** + * Get image channel type size in bytes. + */ + unsigned int getTypeSize() const; + ///@{ @name Buffer Data /** * Set/Get image buffer data. @@ -121,6 +126,9 @@ class F3D_EXPORT image */ image& setData(void* buffer); void* getData() const; +#ifndef F3D_NO_DEPRECATED + F3D_DEPRECATED unsigned char* getData() const; +#endif ///@} /** diff --git a/library/src/image.cxx b/library/src/image.cxx index 8223123b9e..011c8612bb 100644 --- a/library/src/image.cxx +++ b/library/src/image.cxx @@ -178,15 +178,20 @@ image::ChannelType image::getChannelType() const throw read_exception("Unknown channel type"); } +//---------------------------------------------------------------------------- +unsigned int image::getTypeSize() const +{ + return this->Internals->Image->GetScalarSize(); +} + //---------------------------------------------------------------------------- image& image::setData(void* buffer) { unsigned int scalarSize = this->Internals->Image->GetScalarSize(); unsigned int totalSize = this->getWidth() * this->getHeight() * this->getChannelCount() * scalarSize; - unsigned char* internalBuffer = - static_cast(this->Internals->Image->GetScalarPointer()); - std::copy_n(static_cast(buffer), totalSize, internalBuffer); + uint8_t* internalBuffer = static_cast(this->Internals->Image->GetScalarPointer()); + std::copy_n(static_cast(buffer), totalSize, internalBuffer); return *this; } @@ -196,6 +201,14 @@ void* image::getData() const return this->Internals->Image->GetScalarPointer(); } +#ifndef F3D_NO_DEPRECATED +//---------------------------------------------------------------------------- +unsigned char* image::getData() const +{ + return static_cast(this->Internals->Image->GetScalarPointer()); +} +#endif + //---------------------------------------------------------------------------- bool image::compare(const image& reference, double threshold, image& diff, double& error) const { diff --git a/library/testing/TestSDKImage.cxx b/library/testing/TestSDKImage.cxx index 4da27ee305..6d3252d1b6 100644 --- a/library/testing/TestSDKImage.cxx +++ b/library/testing/TestSDKImage.cxx @@ -60,7 +60,13 @@ int TestSDKImage(int argc, char* argv[]) if (shortImg.getChannelType() != f3d::image::ChannelType::SHORT) { - std::cerr << "Cannot read a 16-bits image" << std::endl; + std::cerr << "Cannot read a 16-bits image type" << std::endl; + return EXIT_FAILURE; + } + + if (shortImg.getTypeSize() != 2) + { + std::cerr << "Cannot read a 16-bits image type size" << std::endl; return EXIT_FAILURE; } @@ -73,6 +79,12 @@ int TestSDKImage(int argc, char* argv[]) return EXIT_FAILURE; } + if (shortImg.getTypeSize() != 4) + { + std::cerr << "Cannot read a HDR 32-bits image type size" << std::endl; + return EXIT_FAILURE; + } + #if F3D_MODULE_EXR // check reading EXR f3d::image exrImg(std::string(argv[1]) + "/data/kloofendal_43d_clear_1k.exr");