|
1 |
| -/** |
| 1 | +/** |
2 | 2 | * Copyright L. Spiro 2024
|
3 | 3 | *
|
4 | 4 | * Written by: Shawn (L. Spiro) Wilcoxen
|
@@ -109,6 +109,21 @@ namespace sl2 {
|
109 | 109 | FIMULTIBITMAP * pbBitmap;
|
110 | 110 | };
|
111 | 111 |
|
| 112 | + /** Wraps FreeImage_OpenMultiBitmapFromHandle(). */ |
| 113 | + struct SL2_FREEIMAGE_OPEN_MULTI_BIPMAP_FROM_HANDLE { |
| 114 | + SL2_FREEIMAGE_OPEN_MULTI_BIPMAP_FROM_HANDLE( FREE_IMAGE_FORMAT _fiF, FreeImageIO * _pfiIo, fi_handle _hHandle, int _iFlags FI_DEFAULT( 0 ) ) : |
| 115 | + pbBitmap( ::FreeImage_OpenMultiBitmapFromHandle( _fiF, _pfiIo, _hHandle, _iFlags ) ) { |
| 116 | + } |
| 117 | + ~SL2_FREEIMAGE_OPEN_MULTI_BIPMAP_FROM_HANDLE() { |
| 118 | + ::FreeImage_CloseMultiBitmap( pbBitmap ); |
| 119 | + pbBitmap = nullptr; |
| 120 | + } |
| 121 | + |
| 122 | + |
| 123 | + // == Members. |
| 124 | + FIMULTIBITMAP * pbBitmap; |
| 125 | + }; |
| 126 | + |
112 | 127 | /** Wraps FreeImage_Allocate(). */
|
113 | 128 | struct SL2_FREEIMAGE_ALLOCATE {
|
114 | 129 | SL2_FREEIMAGE_ALLOCATE( int _iWidth, int _iHeight, int _iBpp, unsigned _uRedMask FI_DEFAULT(0), unsigned _uGreenMask FI_DEFAULT(0), unsigned _uBlueMask FI_DEFAULT(0) ) :
|
@@ -806,7 +821,53 @@ namespace sl2 {
|
806 | 821 | static double ApplyKernel( double * _pdImage, uint32_t _ui32X, uint32_t _ui32Y, uint32_t _ui32W, uint32_t _ui32H, uint32_t _ui32D, const CKernel &_kKernel,
|
807 | 822 | SL2_TEXTURE_ADDRESSING _taAddressW, SL2_TEXTURE_ADDRESSING _taAddressH, double _dBorder );
|
808 | 823 |
|
809 |
| - |
| 824 | + /** |
| 825 | + * FreeImage read handler. |
| 826 | + * |
| 827 | + * \param _pvBuffer Pointer to the array where the read objects are stored. |
| 828 | + * \param _uSize Size of each object in bytes. |
| 829 | + * \param _uCount The number of the objects to be read. |
| 830 | + * \param _hHandle The stream to read. |
| 831 | + * \return Number of objects read successfully, which may be less than _uCount if an error or end-of-file condition occurs. If _uSize or _uCount is zero, fread returns zero and performs no other action. |
| 832 | + **/ |
| 833 | + static unsigned DLL_CALLCONV FI_Read( void * _pvBuffer, unsigned _uSize, unsigned _uCount, fi_handle _hHandle ) { |
| 834 | + return static_cast<unsigned>(::fread( _pvBuffer, _uSize, _uCount, reinterpret_cast<FILE *>(_hHandle))); |
| 835 | + } |
| 836 | + |
| 837 | + /** |
| 838 | + * FreeImage write handler. |
| 839 | + * |
| 840 | + * \param _pvBuffer Pointer to the first object in the array to be written. |
| 841 | + * \param _uSize Size of each object. |
| 842 | + * \param _uCount The number of the objects to be written. |
| 843 | + * \param _hHandle Pointer to the output stream. |
| 844 | + * \return The number of objects written successfully, which may be less than _uCount if an error occurs. If _uSize or _uCount is zero, fwrite returns zero and performs no other action. |
| 845 | + **/ |
| 846 | + static unsigned DLL_CALLCONV FI_Write( void * _pvBuffer, unsigned _uSize, unsigned _uCount, fi_handle _hHandle ) { |
| 847 | + return static_cast<unsigned>(::fwrite( _pvBuffer, _uSize, _uCount, reinterpret_cast<FILE *>(_hHandle))); |
| 848 | + } |
| 849 | + |
| 850 | + /** |
| 851 | + * Sets the file position indicator for the file stream stream to the value pointed to by _uOffset. |
| 852 | + * |
| 853 | + * \param _hHandle File stream to modify |
| 854 | + * \param _uOffset Number of characters to shift the position relative to origin. |
| 855 | + * \param _uOrigin Position to which offset is added. It can have one of the following values: SEEK_SET, SEEK_CUR, SEEK_END. |
| 856 | + * \return 0 upon success, nonzero value otherwise. |
| 857 | + **/ |
| 858 | + static int DLL_CALLCONV FI_Seek( fi_handle _hHandle, long _uOffset, int _uOrigin ) { |
| 859 | + return static_cast<int>(::fseek( reinterpret_cast<FILE *>(_hHandle), _uOffset, _uOrigin)); |
| 860 | + } |
| 861 | + |
| 862 | + /** |
| 863 | + * Returns the file position indicator for the file stream _hHandle. |
| 864 | + * |
| 865 | + * \param _hHandle File stream to examine. |
| 866 | + * \return File position indicator on success or -1L if failure occurs. |
| 867 | + **/ |
| 868 | + static long DLL_CALLCONV FI_Tell( fi_handle _hHandle ) { |
| 869 | + return static_cast<long>(::ftell( reinterpret_cast<FILE *>(_hHandle) )); |
| 870 | + } |
810 | 871 |
|
811 | 872 |
|
812 | 873 | protected :
|
@@ -935,6 +996,16 @@ namespace sl2 {
|
935 | 996 | **/
|
936 | 997 | void BakeGamma( uint8_t * _pui8Buffer, double _dGamma, uint32_t _ui32Width, uint32_t _ui32Height, uint32_t _ui32Depth, CFormat::SL2_TRANSFER_FUNCS _ptfGamma );
|
937 | 998 |
|
| 999 | + /** |
| 1000 | + * Clamps the given texture between the high and low values. |
| 1001 | + * |
| 1002 | + * \param _pdBuffer The pointer to the RGBA64F buffer to clamp. |
| 1003 | + * \param _sTotal The number of texels in the given buffer. |
| 1004 | + * \param _dLow The low clamp value. |
| 1005 | + * \param _dHigh The high clamp value. |
| 1006 | + **/ |
| 1007 | + static bool Clamp( double * _pdBuffer, size_t _sTotal, double _dLow = 0.0, double _dHigh = 1.0 ); |
| 1008 | + |
938 | 1009 | /**
|
939 | 1010 | * Applies an ICC colorspace transfer function to a given RGBA64F buffer.
|
940 | 1011 | *
|
|
0 commit comments