26 #ifndef NVNEURAL_CPUIMAGE_H 
   27 #define NVNEURAL_CPUIMAGE_H 
   34 #include <stb/stb_image.h> 
   35 #include <stb/stb_image_write.h> 
   94     virtual NeuralResult fromFill(std::size_t height, std::size_t width, std::size_t channels, std::uint8_t fillValue) noexcept = 0;
 
  111     nvneural::refobj::Implements<nvneural::IFileImage>,
 
  112     nvneural::refobj::Implements<nvneural::IImage>>
 
  132     std::size_t 
height() 
const noexcept 
override;
 
  134     std::size_t 
width() 
const noexcept 
override;
 
  136     std::size_t 
channels() 
const noexcept 
override;
 
  138     std::size_t 
elements() 
const noexcept 
override;
 
  140     std::uint8_t* 
data() noexcept 
override;
 
  142     const std::uint8_t* 
data() 
const noexcept 
override;
 
  145     static const std::uint8_t FillValue = 0u;
 
  147     std::unique_ptr<std::uint8_t[], decltype(&stbi_image_free)> m_data{
nullptr, stbi_image_free};
 
  148     std::size_t m_height = 0;
 
  149     std::size_t m_width = 0;
 
  150     std::size_t m_channels = 0;
 
  154     NeuralResult addChannelPadding(std::size_t extraChannels) noexcept;
 
Common helper classes and template function implementations.
 
Fundamental NvNeural data types are declared here.
 
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
 
Defines file I/O operations for IImage objects.
Definition: CpuImage.h:70
 
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: CpuImage.h:73
 
virtual NeuralResult loadFromDescriptors(const std::vector< ImageDescriptor > &descriptors) noexcept=0
Loads an image from a chained set of descriptors.
 
virtual NeuralResult fromFill(std::size_t height, std::size_t width, std::size_t channels, std::uint8_t fillValue) noexcept=0
Loads an image by tiling a fill value.
 
virtual NeuralResult fromRandomValues(std::size_t height, std::size_t width, std::size_t channels) noexcept=0
Loads an image by generating normally distributed noise in the range [0, 255].
 
virtual NeuralResult loadFromFile(const std::string &filename) noexcept=0
Loads an image from a single bitmap file.
 
virtual NeuralResult saveToFile(const std::string &filename) noexcept=0
Saves the resulting image as a file.
 
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:343
 
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:349
 
Standard implementation for IFileImage.
Definition: CpuImage.h:113
 
NeuralResult loadFromDescriptors(const std::vector< ImageDescriptor > &descriptors) noexcept
Loads an image from a chained set of descriptors.
Definition: CpuImage.cpp:57
 
NeuralResult fromFill(std::size_t height, std::size_t width, std::size_t channels, std::uint8_t fillValue) noexcept
Loads an image by tiling a fill value.
Definition: CpuImage.cpp:267
 
NeuralResult saveToFile(const std::string &filename) noexcept
Saves the resulting image as a file.
Definition: CpuImage.cpp:279
 
NeuralResult fromRandomValues(std::size_t height, std::size_t width, std::size_t channels) noexcept
Loads an image by generating normally distributed noise in the range [0, 255].
Definition: CpuImage.cpp:252
 
std::size_t height() const noexcept
Returns the height of the image in pixels.
Definition: CpuImage.cpp:393
 
NeuralResult loadFromFile(const std::string &filename) noexcept
Loads an image from a single bitmap file.
Definition: CpuImage.cpp:52
 
std::size_t width() const noexcept
Returns the width of the image in pixels.
Definition: CpuImage.cpp:398
 
NeuralResult resize(std::size_t height, std::size_t width, std::size_t channels) noexcept
Clears the image and reserves storage.
Definition: CpuImage.cpp:97
 
std::size_t channels() const noexcept
Returns the number of color channels in the image.
Definition: CpuImage.cpp:403
 
std::uint8_t * data() noexcept
Returns a pointer to the raw pixel data in HWC layout.
Definition: CpuImage.cpp:413
 
std::size_t elements() const noexcept
Returns the number of data elements in the image.
Definition: CpuImage.cpp:408
 
Defines one image component to load into a tensor.
Definition: CpuImage.h:46
 
std::size_t channels
Number of channels to take from the image.
Definition: CpuImage.h:52
 
ImageDescriptor(std::string filename_, std::size_t channels_)
Constructs an ImageDescriptor with filename and channel count.
Definition: CpuImage.h:57
 
static const std::size_t DefaultChannels
Use the channel count from the image file.
Definition: CpuImage.h:47
 
std::string filename
Filename of an image.
Definition: CpuImage.h:50
 
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336