Skip to content

Commit

Permalink
Support for wider channel size in f3d::image (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored Jul 10, 2023
1 parent 6e7f96b commit ab3f48d
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 114 deletions.
1 change: 1 addition & 0 deletions .cppcheck.supp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ preprocessorErrorDirective:library/src/engine.cxx
preprocessorErrorDirective:plugins/draco/module/vtkF3DDracoReader.cxx
unknownMacro:library/VTKExtensions/Applicative/vtkF3DObjectFactory.cxx
unusedVariable:*factory.cxx*
constParameter:library/src/image.cxx
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,15 @@ jobs:
-DCMAKE_PREFIX_PATH:PATH=$(pwd)/../dependencies/install/
-DF3D_COVERAGE=ON
-DF3D_MODULE_EXTERNAL_RENDERING=ON
-DF3D_MODULE_EXR=ON
-DF3D_MODULE_RAYTRACING=ON
-DF3D_PLUGINS_STATIC_BUILD=OFF
-DF3D_PLUGIN_BUILD_ALEMBIC=ON
-DF3D_PLUGIN_BUILD_ASSIMP=ON
-DF3D_PLUGIN_BUILD_DRACO=ON
-DF3D_PLUGIN_BUILD_OCCT=ON
-DF3D_STRICT_BUILD=ON
-DF3D_EXCLUDE_DEPRECATED=ON
-DF3D_TESTING_ENABLE_LONG_TIMEOUT_TESTS=ON
- name: Build
Expand Down
1 change: 1 addition & 0 deletions application/F3DConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace F3D
const std::string PluginsInstallDir = "@F3D_PLUGINS_INSTALL_DIR@";
}

// TODO: Use CMake definitions and get rid of these
#cmakedefine01 F3D_MACOS_BUNDLE
#cmakedefine01 F3D_MODULE_RAYTRACING
#cmakedefine01 F3D_MODULE_EXR
Expand Down
1 change: 1 addition & 0 deletions doc/dev/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ needed dependencies, configuring and building.
* Optionally, [Draco](https://google.github.io/draco/) >= 1.5.
* Optionally, [Python](https://www.python.org/) >= 3.6 and [pybind11](https://github.com/pybind/pybind11) >= 2.2.
* Optionally, [Java](https://www.java.com) >= 18.
* Optionally, [OpenEXR](https://openexr.com/en/latest/) >= 3.0.

## VTK compatibility

Expand Down
8 changes: 7 additions & 1 deletion library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ set_target_properties(libf3d PROPERTIES

# Generate export macros for exported public APIs
include(GenerateExportHeader)
option(F3D_EXCLUDE_DEPRECATED "Exclude deprecated functions of the library" OFF)
set(libf3d_no_deprecated)
if(F3D_EXCLUDE_DEPRECATED)
set(libf3d_no_deprecated "DEFINE_NO_DEPRECATED")
endif()
generate_export_header(libf3d
EXPORT_FILE_NAME public/export.h
EXPORT_MACRO_NAME F3D_EXPORT)
BASE_NAME F3D
${libf3d_no_deprecated})

target_include_directories(libf3d
INTERFACE
Expand Down
1 change: 1 addition & 0 deletions library/VTKExtensions/Core/vtkF3DConfigure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
static const std::string F3D_RESERVED_STRING = "f3d_reserved";
static const std::string F3D_EXIT_HOTKEY_SYM = "Escape";

// TODO: Use CMake definitions and get rid of these
#cmakedefine01 F3D_WINDOWS_GUI

#cmakedefine01 F3D_MODULE_EXTERNAL_RENDERING
Expand Down
78 changes: 70 additions & 8 deletions library/public/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ namespace f3d
class F3D_EXPORT image
{
public:
/**
* Enumeration of supported export formats
* =======================================
* PNG: Supports channel size up to 2 bytes
* JPG: Supports channel size of 1 byte
* TIF: Supports channel size up to 4 bytes
* BMP: Supports channel size of 1 byte
*/
enum class SaveFormat : unsigned char
{
PNG,
JPG,
TIF,
BMP
};

/**
* Enumeration of supported channel types
* ======================================
* BYTE: 8-bit integer in range [0,255]
* SHORT: 16-bit integer in range [0,65535]
* FLOAT: 32-bit floating point in range [-inf,+inf]
*/
enum class ChannelType : unsigned char
{
BYTE,
SHORT,
FLOAT
};

/**
* Create an image from file, the following formats are supported:
* PNG, PNM, TIFF, BMP, HDR, JPEG, GESigna, MetaImage, TGA.
Expand All @@ -26,6 +56,13 @@ class F3D_EXPORT image
*/
explicit image(const std::string& path);

/**
* Create an image from a given width, height, and channel count.
* A channel type can also be given. Default is BYTE.
*/
image(unsigned int width, unsigned int height, unsigned int channelCount,
ChannelType type = ChannelType::BYTE);

///@{ @name Constructors
/**
* Default/copy/move constructors/operators.
Expand All @@ -49,27 +86,52 @@ class F3D_EXPORT image
///@{ @name Resolution
/**
* Set/Get image resolution.
*
* \deprecated { setResolution is deprecated, use the appropriate constructor }
*/
unsigned int getWidth() const;
unsigned int getHeight() const;
image& setResolution(unsigned int width, unsigned int height);
#ifndef F3D_NO_DEPRECATED
F3D_DEPRECATED image& setResolution(unsigned int width, unsigned int height);
#endif
///@}

///@{ @name Channel Count
/**
* Set/Get image channel count.
*
* \deprecated { setChannelCount is deprecated, use the appropriate constructor }
*/
unsigned int getChannelCount() const;
image& setChannelCount(unsigned int dim);
#ifndef F3D_NO_DEPRECATED
F3D_DEPRECATED image& setChannelCount(unsigned int dim);
#endif
///@}

/**
* Get image channel type.
* throw an image::read_exception if the type is unknown.
*/
ChannelType getChannelType() const;

/**
* Get image channel type size in bytes.
*/
unsigned int getChannelTypeSize() const;

///@{ @name Buffer Data
/**
* Set/Get image buffer data.
* Its size is expected to be `width * height * channelCount`.
* Its size is expected to be `width * height * channelCount * typeSize`.
*
* \deprecated { setData and getData are deprecated, use setContent and getContent instead }
*/
image& setData(unsigned char* buffer);
unsigned char* getData() const;
image& setContent(void* buffer);
void* getContent() const;
#ifndef F3D_NO_DEPRECATED
F3D_DEPRECATED image& setData(unsigned char* buffer);
F3D_DEPRECATED unsigned char* getData() const;
#endif
///@}

/**
Expand All @@ -86,10 +148,10 @@ class F3D_EXPORT image
bool compare(const image& reference, double threshold, image& diff, double& error) const;

/**
* Save an image to a file in .png format.
* Throw an image::write_exception if image cannot be written.
* Save an image to a file in the specified format.
* Default format is PNG if not specified.
*/
void save(const std::string& path) const;
void save(const std::string& path, SaveFormat format = SaveFormat::PNG) const;

/**
* An exception that can be thrown by the image when there.
Expand Down
Loading

0 comments on commit ab3f48d

Please sign in to comment.