// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "PixelFormat.h" /// /// Utility for writing and reading from different pixels formats within a single code path. /// API_STRUCT(NoDefault) struct FLAXENGINE_API PixelFormatSampler { DECLARE_SCRIPTING_TYPE_MINIMAL(PixelFormatSampler); typedef Float4 (*ReadPixel)(const void* data); typedef void (*WritePixel)(void* data, const Float4& value); public: // Element format. PixelFormat Format; // Element size in bytes. int32 PixelSize; // Read data function. ReadPixel Read; // Write data function. WritePixel Write; public: /// /// Stores the color into the specified texture data (uses no interpolation). /// /// The data pointer for the texture slice (1D or 2D image). /// The X texture coordinates (normalized to range 0-width). /// The Y texture coordinates (normalized to range 0-height). /// The row pitch (in bytes). The offset between each image rows. /// The color to store (linear). void Store(void* data, int32 x, int32 y, int32 rowPitch, const Color& color) const; /// /// Samples the specified linear data (uses no interpolation). /// /// The data pointer for the data slice (linear buffer or 1D image). /// Index of the element. /// The sampled value. Float4 Sample(const void* data, int32 x) const; /// /// Samples the specified texture data (uses no interpolation). /// /// The data pointer for the texture slice (1D or 2D image). /// The texture coordinates (normalized to range 0-1). /// The size of the input texture (in pixels). /// The row pitch (in bytes). The offset between each image rows. /// The sampled color (linear). Color SamplePoint(const void* data, const Float2& uv, const Int2& size, int32 rowPitch) const; /// /// Samples the specified texture data (uses no interpolation). /// /// The data pointer for the texture slice (1D or 2D image). /// The X texture coordinates (normalized to range 0-width). /// The Y texture coordinates (normalized to range 0-height). /// The row pitch (in bytes). The offset between each image rows. /// The sampled color (linear). Color SamplePoint(const void* data, int32 x, int32 y, int32 rowPitch) const; /// /// Samples the specified texture data (uses linear interpolation). /// /// The data pointer for the texture slice (1D or 2D image). /// The texture coordinates (normalized to range 0-1). /// The size of the input texture (in pixels). /// The row pitch (in bytes). The offset between each image rows. /// The sampled color (linear). Color SampleLinear(const void* data, const Float2& uv, const Int2& size, int32 rowPitch) const; public: /// /// Tries to get a sampler tool for the specified format to read pixels. /// /// The format. /// The pointer to the sampler object or null when cannot sample the given format. static const PixelFormatSampler* Get(PixelFormat format); };