| 76 | |
| 77 | template< typename T > |
| 78 | static void ClampTexels( void * texels, u32 n64_width, u32 n64_height, u32 native_width, u32 native_height, u32 native_stride ) |
| 79 | { |
| 80 | #ifdef DAEDALUS_ENABLE_ASSERTS |
| 81 | DAEDALUS_ASSERT( native_stride >= native_width * sizeof( T ), "Native stride isn't big enough" ); |
| 82 | DAEDALUS_ASSERT( n64_width <= native_width, "n64 width greater than native width?" ); |
| 83 | DAEDALUS_ASSERT( n64_height <= native_height, "n64 height greater than native height?" ); |
| 84 | #endif |
| 85 | |
| 86 | T * data = reinterpret_cast< T * >( texels ); |
| 87 | |
| 88 | // |
| 89 | // If any of the rows are short, we need to duplicate the last pixel on the row |
| 90 | // Stick this in an outer predicate incase they match |
| 91 | // |
| 92 | if( native_width > n64_width ) |
| 93 | { |
| 94 | for( u32 y {}; y < n64_height; ++y ) |
| 95 | { |
| 96 | T colour( data[ n64_width - 1 ] ); |
| 97 | |
| 98 | for( u32 x = n64_width; x < native_width; ++x ) |
| 99 | { |
| 100 | data[ x ] = colour; |
| 101 | } |
| 102 | |
| 103 | data = AddByteOffset( data, native_stride ); |
| 104 | } |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | data = AddByteOffset( data, n64_height * native_stride ); |
| 109 | } |
| 110 | |
| 111 | // |
| 112 | // At this point all the rows up to the n64 height have been padded out. |
| 113 | // We need to duplicate the last row for every additional native row. |
| 114 | // |
| 115 | if( native_height > n64_height ) |
| 116 | { |
| 117 | const void * last_row {AddByteOffset( texels, ( n64_height - 1 ) * native_stride )}; |
| 118 | |
| 119 | for( u32 y = n64_height; y < native_height; ++y ) |
| 120 | { |
| 121 | memcpy( data, last_row, native_stride ); |
| 122 | |
| 123 | data = AddByteOffset( data, native_stride ); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | template<> |
| 129 | void ClampTexels< NativePfCI44 >( void * texels, u32 n64_width, u32 n64_height, u32 native_width, u32 native_height, u32 native_stride ) |
no test coverage detected