34#include <NDEVR/Dictionary.h>
35#include <NDEVR/String.h>
36#include <NDEVR/LABColor.h>
37#include <NDEVR/File.h>
38#include <NDEVR/RWLock.h>
39#include <NDEVR/UUID.h>
40#include <NDEVR/Pointer.h>
151 virtual void getSupportedFormats(AlocatingAlignedBuffer<FileFormat, 64>& formats,
bool is_read)
const = 0;
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
ImageData(const ImageData &data)
Copy constructor.
ImageReadPointer getUncompressed() const
Retrieves the uncompressed (raw ARGB) pixel data for this image from the factory.
ImageData(ImageData &&data) noexcept
Move constructor.
StringView compressionFormat() const
Returns the compression format extension of this image's compressed data.
ImageReadPointer getCompressed(const String &default_image_format) const
Retrieves the compressed data for this image in the specified format.
Time modifiedTime() const
Returns the last modification time of this image.
ImageData(const StringView &id, ImageFactory &image_factory)
Constructs an ImageData referencing a specific image in the given factory.
const String m_id
The unique string identifier for this image within the factory.
ImageReadPointer size() const
Retrieves the image dimensions without fully decompressing the data.
ImageFactory & m_image_factory
Reference to the owning ImageFactory managing this image's data.
The core class for reading/writing and storing images in an optimized way.
bool canRead(const File &file)
Checks whether any registered handler can read the given file.
static void ReadJPG(const uint01 *input, uint04 input_length, uint01 *buffer, bool has_alpha, uint04 dst_line_span, const Vector< 2, uint04 > &offset)
Decodes JPEG data from a memory buffer into a raw pixel buffer.
Dictionary< String, DynamicPointer< ImageCacheData > > cachedData() const
Returns a copy of the internal cache dictionary mapping image IDs to their cache data.
ImageReadPointer getUncompressed(const StringView &id, bool ensure_valid_transparancy=false)
Retrieves the uncompressed (raw ARGB) pixel data for the cached image.
bool hasImage(const StringView &id) const
Checks whether an image with the given identifier exists in the cache.
Dictionary< UUID, ImageFormatHandler * > m_format_handlers
Instance-level registered format handlers keyed by UUID.
void readFromBMP(ImageCacheData &data)
Reads image data from a BMP-formatted source into the cache data.
virtual void getSupportedFormats(AlocatingAlignedBuffer< FileFormat, 64 > &formats, bool is_read) const
Populates a buffer with all file formats supported by this factory and its handlers.
bool hasTransparency(ImageCacheData &data)
Determines whether the image truly contains transparent pixels (not just an alpha channel).
void addImageUncompressed(const StringView &id, const Buffer< uint01 > &uncompressed, bool clear_other)
Adds an uncompressed (raw ARGB) image to the cache.
ImageReadPointer getCompressed(const StringView &id, StringView default_extension=".png")
Retrieves the compressed data for the cached image in its current or default format.
static void Resize(const Buffer< uint01 > &input, const Vector< 2, uint04 > &in_size, const Vector< 2, uint04 > &out_size, Buffer< uint01 > &output)
Resizes raw pixel data from one resolution to another using bilinear or nearest-neighbor sampling.
void addImageUncompressed(const StringView &id, const Buffer< uint01 > &uncompressed, const Vector< 2, uint04 > &size, bool clear_other)
Adds an uncompressed (raw ARGB) image with explicit dimensions to the cache.
ImageReadPointer getMetaData(const StringView &id)
Retrieves metadata for the cached image, reading it from the source if necessary.
static FileFormat PNGFormat()
Creates and returns a FileFormat descriptor for the PNG image format.
void handleMetaData(ImageCacheData &data)
Reads and processes metadata (e.g., EXIF) from the image data using registered handlers.
bool readFromCompressed(ImageCacheData &data)
Reads image data from the compressed_data buffer in the cache data using registered handlers.
void copyImage(const StringView &id_destination, const StringView &id_source)
Copies cached image data from one identifier to another.
void addFormatHandler(ImageFormatHandler *handler)
Registers a format handler with this ImageFactory instance.
Time modifiedTime(const StringView &id) const
Returns the last modification time of the cached image.
ImageReadPointer getCompressedInFormat(const StringView &id, const Buffer< StringView > &acceptable_formats)
Retrieves the compressed data for the cached image in one of the acceptable formats.
static ImageFactory & DefaultFactory()
Returns the singleton default ImageFactory instance.
ImageReadPointer getSize(const StringView &id)
Retrieves the image dimensions without fully decompressing the image data.
static void AddFormatHandler(ImageFormatHandler *handler)
Registers a format handler with the global static handler registry, available to all ImageFactory ins...
bool determineCompressionFormat(ImageCacheData &data)
Attempts to determine the compression format of the image's compressed data by inspecting its header ...
StringView compressionFormat(const StringView &id)
Returns the compression format extension of the cached image's compressed data.
ImageReadPointer getCompressedInFormat(const StringView &id, const StringView &extension)
Retrieves the compressed data for the cached image, converting to a specific format.
static void RemoveFormatHandler(const UUID &handler)
Removes a format handler from the global static handler registry.
void addImageFile(const StringView &id, const File &file, bool clear_other)
Adds an image to the cache by reading from a file on disk.
void addImageCompressed(const StringView &id, const Buffer< uint01 > &compressed, bool clear_other)
Adds a compressed image to the cache, auto-detecting the compression format.
void addImageCompressed(const StringView &id, const StringView &extension, const Buffer< uint01 > &compressed, const Vector< 2, uint04 > &size, bool clear_other)
Adds a compressed image with a known format extension and explicit dimensions to the cache.
void convertDirectory(const File &directory, const StringView &from_ext, const StringView &to_ext)
Converts all images in a directory from one format to another.
static Dictionary< UUID, ImageFormatHandler * > s_format_handlers
Global static registry of format handlers shared across all ImageFactory instances.
void clearAllImageData(const StringView &id)
Removes all cached data (compressed, decompressed, metadata) for the given image.
ImageWritePointer getEditableData(const StringView &id)
Returns a writable pointer to the image cache data with a write lock acquired.
bool readFromFile(ImageCacheData &data, StringView format_extension=StringView())
Reads image data from the file referenced in the cache data.
ImageReadPointer getReadOnlyData(const StringView &id) const
Returns a read-only pointer to the image cache data with a read lock acquired.
void removeFormatHandler(const UUID &handler)
Removes a previously registered format handler by its UUID.
void addImageCompressed(const StringView &id, const StringView &extension, const Buffer< uint01 > &compressed, bool clear_other)
Adds a compressed image with a known format extension to the cache.
fltp08 m_write_quality
Default write quality for compressed output (0.0 to 1.0).
RWLock m_lock
Read-write lock protecting access to the cache and handler dictionaries.
void setWriteQuality(fltp08 quality)
Sets the quality level used when writing compressed images (e.g., JPEG quality).
void convertColorTheme(const Buffer< std::pair< LABColor, LABColor > > &color, String &image, bool preserve_brightness, bool preserve_alpha)
Remaps the colors of a cached image using LAB color space substitutions.
String optimizedWriteFileName(const StringView &id, const Buffer< String > &optional_extensions=Buffer< String >())
Determines the optimal file name and extension for writing the image to disk.
const Buffer< uint01 > & calculateAndGetDecompressed(ImageCacheData &data)
Ensures the decompressed data is available, decompressing if necessary, and returns it.
void writeToFile(const StringView &id, const File &file)
Writes the cached image to a file on disk.
Dictionary< String, DynamicPointer< ImageCacheData > > m_cached_data
Cache mapping image identifiers to their associated data.
static void WriteToFile(const uint01 *data, Vector< 2, uint04 > size, uint04 px_size, const File &file, fltp08 write_quality=1.0)
Writes raw pixel data to a file on disk in the format determined by the file extension.
Used to lock a particular variable for reading.
A readers-writer lock allowing concurrent reads or exclusive writes.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
Represents a timestamp with utilities for manipulation and conversion.
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A point in N-dimensional space, used primarily for spatial location information.
Used to lock a particular variable for writing.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ file
The source file path associated with this object.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Holds cached image data including compressed and decompressed pixel buffers, file references,...
Vector< 2, uint04 > size
Image dimensions (width, height) in pixels.
Time modified_time
Last modification time of this cache entry.
RWLock lock
Read-write lock for thread-safe access to this cache entry.
ImageCacheData()
Constructs an ImageCacheData and sets modified_time to the current system time.
Buffer< uint01 > compressed_data
In-memory compressed image data (e.g., JPEG, PNG bytes).
ImageCacheData & operator=(const ImageCacheData &data)
Assigns the contents of another ImageCacheData to this one.
ImageMetaData metadata
Metadata associated with this image (location, orientation, etc.).
String compression_format
The file extension or format identifier of the compressed data (e.g., ".png").
bool has_calculated_transparency
Whether transparency has been explicitly determined (vs. assumed).
bool has_transparency
Whether the image contains transparent pixels.
String name
Display name or identifier for this image.
Buffer< uint01 > decompressed_data
Raw decompressed pixel data in ARGB 32-bit format.
File file
File reference for the on-disk image source, if applicable.
A read-only smart pointer to ImageCacheData that acquires a read lock on construction.
ImageReadPointer()
Default constructor.
ImageReadPointer(const DynamicPointer< ImageCacheData > &d)
Constructs a read pointer from a DynamicPointer and acquires a read lock.
A writable smart pointer to ImageCacheData that acquires a write lock on construction.
ImageWritePointer(const DynamicPointer< ImageCacheData > &d)
Constructs a write pointer from a DynamicPointer and acquires a write lock.
ImageWritePointer()
Default constructor.