API Documentation
Loading...
Searching...
No Matches
ImageFactory.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: ImageFactory
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
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>
39namespace NDEVR
40{
41 class RLock;
42 class FileFormat;
43
44 /**--------------------------------------------------------------------------------------------------
45 \brief Defines a DataStream for Image reading or writing
46 **/
60
61 /**--------------------------------------------------------------------------------------------------
62 \brief Can be used to add functionality to the ImageFactory
63 **/
65 {
66 virtual bool readFromFormat(ImageDataStream& data) = 0;
67 virtual bool writeToFormat(ImageDataStream& data) = 0;
68 virtual Buffer<String> supportedFormats() const = 0;
69 };
70
71 /**--------------------------------------------------------------------------------------------------
72 \brief The core class for reading/writing and storing images in an optimized way
73 **/
75 {
76 public:
79 void addImageFile(const String& image_id, const File& file, bool clear_other);
80 void addImageUncompressed(const String& image_id, const Buffer<uint01>& uncompressed, bool clear_other);
81 void addImageUncompressed(const String& image_id, const Buffer<uint01>& uncompressed, const Vector<2, uint04>& size, bool clear_other);
82 void addImageCompressed(const String& image_id, const String& extension, const Buffer<uint01>& compressed, bool clear_other);
83 void addImageCompressed(const String& image_id, const Buffer<uint01>& compressed, bool clear_other);
84 void readFromFile(const String& image_id);
85 void readFromFile(const String& image_id, String format_extension);
86 void writeToFile(const String& image_id, const File& file);
87 static void WriteToFile(const uint01* data, Vector<2, uint04> size, uint04 px_size, const File& file, fltp08 write_quality = 1.0);
88 void readFromCompressed(const String& image_id);
89 Time modifiedTime(const String& image_id) const;
90 void convertDirectory(const File& directory, const String& from_ext, const String& to_ext);
91 bool hasImage(const String& image_id);
92 void copyImage(const String& image_id_destination, const String& image_id_source);
93 const Buffer<uint01>& getUncompressed(const String& image_id);
94 const Buffer<uint01>& getCompressed(const String& image_id, const String& default_extension = ".png");
95 const Buffer<uint01>& getCompressedInFormat(const String& image_id, const String& default_extension);
96 const File& getFile(const String& image_id);
97 void convertColorTheme(const Buffer<std::pair<LABColor, LABColor>, uint04, ObjectAllocator<true>>& color, String& image, bool preserve_brightness, bool preserve_alpha);
98 String optimizedWriteFileName(const String& image_id, const Buffer<String>& optional_extenstions = Buffer<String>());
99 bool hasTransparency(const String& image_id);
100 const Vector<2, uint04>& getSize(const String& image_id);
103 bool canRead(const File& file);
104 void setWriteQuality(fltp08 quality);
106 static void ReadJPG(const uint01* input, uint04 input_length, uint01* buffer, bool has_alpha, uint04 dst_line_span, const Vector<2, uint04>& offset);
107 void readFromBMP(const String& image_id);
108 protected:
117 fltp08 m_write_quality = 1.0;
118 };
119 /**--------------------------------------------------------------------------------------------------
120 \brief A container for Images managed by the ImageFactory. Provides convenience access functions without
121 actually allocating memory outside of the factory.
122 **/
124 {
125 public:
126 ImageData(const String& id, ImageFactory& image_factory);
127 ImageData(const ImageData& data);
128 ImageData(ImageData&& data) noexcept;
130 [[nodiscard]] const File& file() const;
131 [[nodiscard]] const Buffer<uint01>& getUncompressed() const;
132 [[nodiscard]] const Buffer<uint01>& getCompressed(const String& default_image_format) const;
133 [[nodiscard]] const Vector<2, uint04>& size() const;
134 [[nodiscard]] Time modifiedTime() const;
135 [[nodiscard]] String compressionFormat() const;
136 protected:
139 };
140}
141
142
143
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Data that describes a particular file format and how to use the format with the program....
Definition FileFormat.h:43
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
A container for Images managed by the ImageFactory. Provides convenience access functions without act...
Definition ImageFactory.h:124
const Vector< 2, uint04 > & size() const
const Buffer< uint01 > & getUncompressed() const
String compressionFormat() const
const String m_id
Definition ImageFactory.h:138
ImageData(ImageData &&data) noexcept
const File & file() const
ImageData(const String &id, ImageFactory &image_factory)
Time modifiedTime() const
const Buffer< uint01 > & getCompressed(const String &default_image_format) const
ImageFactory & m_image_factory
Definition ImageFactory.h:137
ImageData(const ImageData &data)
The core class for reading/writing and storing images in an optimized way.
Definition ImageFactory.h:75
void copyImage(const String &image_id_destination, const String &image_id_source)
static void WriteToFile(const uint01 *data, Vector< 2, uint04 > size, uint04 px_size, const File &file, fltp08 write_quality=1.0)
const Buffer< uint01 > & getCompressed(const String &image_id, const String &default_extension=".png")
void readFromFile(const String &image_id)
Dictionary< String, File > m_image_files
Definition ImageFactory.h:114
Dictionary< String, Buffer< uint01 > > m_image_decompressed_data
Definition ImageFactory.h:111
static ImageFactory & DefaultFactory()
bool canRead(const File &file)
void addImageUncompressed(const String &image_id, const Buffer< uint01 > &uncompressed, const Vector< 2, uint04 > &size, bool clear_other)
const Vector< 2, uint04 > & getSize(const String &image_id)
Dictionary< String, Time > m_image_modified_time
Definition ImageFactory.h:109
void convertColorTheme(const Buffer< std::pair< LABColor, LABColor >, uint04, ObjectAllocator< true > > &color, String &image, bool preserve_brightness, bool preserve_alpha)
void convertDirectory(const File &directory, const String &from_ext, const String &to_ext)
Dictionary< String, Vector< 2, uint04 > > m_image_size
Definition ImageFactory.h:110
Dictionary< String, String > m_image_compression_format
Definition ImageFactory.h:113
Dictionary< String, ImageFormatHandler * > m_format_handlers
Definition ImageFactory.h:116
void addImageCompressed(const String &image_id, const Buffer< uint01 > &compressed, bool clear_other)
void writeToFile(const String &image_id, const File &file)
void readFromCompressed(const String &image_id)
bool hasImage(const String &image_id)
Time modifiedTime(const String &image_id) const
const File & getFile(const String &image_id)
virtual void getSupportedFormats(Buffer< FileFormat, uint04, ObjectAllocator< false > > &formats) const
bool hasTransparency(const String &image_id)
void addImageUncompressed(const String &image_id, const Buffer< uint01 > &uncompressed, bool clear_other)
void setWriteQuality(fltp08 quality)
void addImageCompressed(const String &image_id, const String &extension, const Buffer< uint01 > &compressed, bool clear_other)
Dictionary< String, Buffer< uint01 > > m_image_compressed_data
Definition ImageFactory.h:112
String optimizedWriteFileName(const String &image_id, const Buffer< String > &optional_extenstions=Buffer< String >())
void readFromBMP(const String &image_id)
void readFromFile(const String &image_id, String format_extension)
String compressionFormat(const String &image_id)
void addImageFile(const String &image_id, const File &file, bool clear_other)
const Buffer< uint01 > & getUncompressed(const String &image_id)
Dictionary< String, bool > m_has_transparency
Definition ImageFactory.h:115
static void ReadJPG(const uint01 *input, uint04 input_length, uint01 *buffer, bool has_alpha, uint04 dst_line_span, const Vector< 2, uint04 > &offset)
const Buffer< uint01 > & getCompressedInFormat(const String &image_id, const String &default_extension)
Can be used to add functionality to the ImageFactory.
Definition ImageFactory.h:65
Definition MemoryManager.h:261
Used to lock a particular variable for reading. Any number of readers can be created when no write lo...
Definition RWLock.h:91
The core String class for the NDEVR API.
Definition String.h:69
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Used to lock a particular variable for writing. Only one write lock can be created when no read locks...
Definition RWLock.h:115
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines a DataStream for Image reading or writing.
Definition ImageFactory.h:48
uint01 * compressed_data
Definition ImageFactory.h:51
Vector< 2, uint04 > image_size
Definition ImageFactory.h:56
fltp08 quality
Definition ImageFactory.h:57
File file
Definition ImageFactory.h:49
uint01 * bitmap_data
Definition ImageFactory.h:53
Vector< 2, uint04 > bitmap_offset
Definition ImageFactory.h:55
bool has_alpha
Definition ImageFactory.h:58
uint04 bitmap_line_span
Definition ImageFactory.h:54
uint04 compressed_length
Definition ImageFactory.h:52
String format
Definition ImageFactory.h:50