Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Jul 10, 2023
1 parent a27f11f commit 07165d4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions library/public/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,21 @@ 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.
* Its size is expected to be `width * height * channelCount * typeSize`.
*/
image& setData(void* buffer);
void* getData() const;
#ifndef F3D_NO_DEPRECATED
F3D_DEPRECATED unsigned char* getData() const;
#endif
///@}

/**
Expand Down
19 changes: 16 additions & 3 deletions library/src/image.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char*>(this->Internals->Image->GetScalarPointer());
std::copy_n(static_cast<unsigned char*>(buffer), totalSize, internalBuffer);
uint8_t* internalBuffer = static_cast<uint8_t*>(this->Internals->Image->GetScalarPointer());
std::copy_n(static_cast<uint8_t*>(buffer), totalSize, internalBuffer);
return *this;
}

Expand All @@ -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<unsigned char*>(this->Internals->Image->GetScalarPointer());
}
#endif

//----------------------------------------------------------------------------
bool image::compare(const image& reference, double threshold, image& diff, double& error) const
{
Expand Down
14 changes: 13 additions & 1 deletion library/testing/TestSDKImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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");
Expand Down

0 comments on commit 07165d4

Please sign in to comment.