|
|
That's your mistake! You should have stick to VI!
|
|
|
|
|
If I could, you know I would.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Oh, that's Bad.
|
|
|
|
|
My e-paper display drivers for IoT are now best of class.
I support simulated grayscale for black and white e-paper, and nearest color matching for color e-paper.
The grayscale simulation is done through dithering.
That way you can load JPEGs into the things and they look reasonable.
I don't support color dithering yet because every technique I've tried is far too expensive both in terms of space and time requirements.
Still, no other drivers for IoT that I'm aware of support these features.
This is super cool.
Real programmers use butterflies
|
|
|
|
|
You shouldn't kick s - they have long memories and will kick back. And they are bigger than you!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm reckless like that.
Real programmers use butterflies
|
|
|
|
|
Color is just a pigment of your imagination.
|
|
|
|
|
Cervantes' Don Quixote renamed (reimagined as a warhorse fit for his new identity) the worn-out horse he rode in his knight-errant adventures 'Rocinante' [1] ... today, that name came to mind as i wrestled with the DataGridView control whose endless quirks, and gargantuan [2] smorgasbord of settings, properties, and, events, induce vertigo, or worse ...
Each of the old WinForm controls, back in the neolithic-period wrappers around a COM core, is a little universe of idiosyncrasies only partially connected to its housemates by semantic consistencies.
Perhaps the flip-side of their virtual virtue is that their limitations catalyzed a thriving 3rd. party controls market ? Cue: "Just enough for the City" [^]. And, truth be told, the expensive suites from Telerik, et. al., also have very steep learning curves.
But, try as i might, i never succeeded in imagining myself transformed from code-drudge to knight
Usual disclaimer: cup is half-full.
~
[1] A complex pun [^] ... also the name of the Martian ship in 'The Expanse.' My enthusiasm for the Quixote has been magnified by Edith Grossman's modern translation (see what A.S. Byatt says about that: [^]). fyi: there is an audiobook version of Grossman's translation read by the talented George Guidall: [^].
[2] If you read the story of Gargantua's birth from the ear of Madam Gargamelle [^] ... after you throw-up, you may appreciate the depth of queasiness i imply here.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
BillWoodruff wrote: also the name of the Martian ship in 'The Expanse.'
Not Martian: "Legitimate Salvage"[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
"In the novel series The Expanse and its TV series adaptation, the Rocinante is the new name given to a Martian gunship that becomes the primary setting for much of the series." Wikipedia
my favorite send-up of Wikipedia (scene from 'Jennifer's Body'): [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Now just hold up a second. Of all the folks on CP, Bill is our resident literati (literatus?). Anyway, he's good with words.
If he omits an adverbBillWoodruff should have wrote: also the name of the originally Martian ship in 'The Expanse' we should give him the benefit of the doubt.
Software Zen: delete this;
|
|
|
|
|
If you ever wondered why your nose is located in the middle of your face, it's because it's your scenter.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
|
Is the processor just that slow, or do you think that profiling your code might uncover things that could be sped up to reach an acceptable level?
|
|
|
|
|
It's difficult to profile because it's cross compiled to run on an IoT device, where I don't have access to profiling.
I *can* do it but it involves setting up a lot of test code in order to use GFX from my PC.
Besides, I know where it's taking the time, and there's not much I can do about it.
The source machine is running at between 160MHz and 240MHz and the operation cannot be readily parallelized without using RAM i don't have.
Algorithmically, I've optimized it about as much as I can. The mixing plan for finding two dither colors is like O(log N) which isn't that bad. The problem is I have to do it for 200x200 pixels. And for my color display I have to do it twice per frame because it's a 3 color display organized in two monochrome planes - one white, and one red, and I don't have the RAM to store the frame between rendering the two planes.
On a superscalar PC running at GHz speeds this is no problem, and I *thought* it shouldn't be a problem even for this machine, but I guess I dramatically underestimated the time it takes this algorithm to run.
I actually have two algos. The first one is similar to the one used by photoshop (but different enough that it avoids patent infringement)
The second one is a much faster, simpler algorithm.
Color dithers are apparently not as easy as I thought.
Real programmers use butterflies
|
|
|
|
|
I knew nothing of dithering, so I just read about it. Interesting. Eventually you'll be a numerical analysis weenie.
It also means that what I was going to ask, namely whether you could cache frequently used results, seems to make no sense.
|
|
|
|
|
Yeah. My current plan is to stick with nearest matching color only for color displays. I'm going to try dithering once again on black and white since those algorithms run much faster.
Edit: Black and white dithering is fast fast fast, so I've added support for it to b&w e-paper displays. I don't do it for monochrome displays yet, and I'm not sure I will since they can update in real time and dithering interferes with that, but since you can turn it off maybe I'll add support for it. I only do nearest color matching for color e-ink displays. The color dithering as I said, was just too expensive.
Real programmers use butterflies
modified 18-Jun-21 1:35am.
|
|
|
|
|
Best to begin without morals.
|
|
|
|
|
Well.. look at it this way, the code you took 1 day to write is almost as good as this PhD code the guy spent a few years perfecting!
|
|
|
|
|
I guess you do a bit of rounding then? If you do, it may be that it is possible to improve that by a lot of bit-fiddling …
On x64 I've seen significant performance improvement, between 20% and 300%, for the following:
isnan, isinf, signbit, frexp, min, max, trunc, round, clamp and lerp
I have no idea about how well this will work out for an ARM cpu, but here is the core of my implementation (Sorry about the formatting, paste and encode as HTML doesn't work well for C++ code anymore ):
template <typename T>
struct FractionWidth;
template <>
struct FractionWidth<float>
{
static constexpr UInt32 value = 23;
};
template <>
struct FractionWidth<double>
{
static constexpr UInt32 value = 52;
};
template <typename T>
struct ExponentWidth;
template <>
struct ExponentWidth<float>
{
static constexpr UInt32 value = 8;
};
template <>
struct ExponentWidth<double>
{
static constexpr UInt32 value = 11;
};
template <typename T>
struct ExponenBias;
template <>
struct ExponenBias<float>
{
static constexpr UInt32 value = _FBIAS;
};
template <>
struct ExponenBias<double>
{
static constexpr UInt32 value = _DBIAS;
};
template <typename T>
struct InfinityUnsignedValue;
template <>
struct InfinityUnsignedValue<float>
{
static constexpr UInt32 value = 0X7F800000UL;
};
template <>
struct InfinityUnsignedValue<double>
{
static constexpr UInt64 value = 0x7FF0000000000000ULL;
};
template <typename T>
struct NegativeInfinityUnsignedValue;
template <>
struct NegativeInfinityUnsignedValue<float>
{
static constexpr UInt32 value = 0xFF800000UL;
};
template <>
struct NegativeInfinityUnsignedValue<double>
{
static constexpr UInt64 value = 0xFFF0000000000000ULL;
};
template <typename T>
struct QuietNaNUnsignedValue;
template <>
struct QuietNaNUnsignedValue<float>
{
static constexpr UInt32 value = 0XFFC00001UL;
};
template <>
struct QuietNaNUnsignedValue<double>
{
static constexpr UInt64 value = 0x7FF0000000000001ULL;
};
#pragma pack(push,1)
template<typename T>
struct FloatingPoint
{
using ValueType = std::remove_cvref_t<T>;
using UIntType = MakeUnsigned<ValueType>;
static constexpr Int32 FractionWidth = static_cast<Int32>( Internal::FractionWidth<ValueType>::value );
static constexpr Int32 ExponentWidth = static_cast<Int32>( Internal::ExponentWidth<ValueType>::value );
static constexpr Int32 ExponentBias = ( 1 << ( ExponentWidth - 1 ) ) - 1;
static constexpr Int32 MaxExponentValue = ( 1 << ExponentWidth ) - 1;
static constexpr UIntType MaxExponent = static_cast<UIntType>( MaxExponentValue ) << FractionWidth;
static constexpr UIntType MinSubnormal = UIntType( 1 );
static constexpr UIntType MaxSubnormal = ( UIntType( 1 ) << FractionWidth ) - 1;
static constexpr UIntType MinNormal = ( UIntType( 1 ) << FractionWidth );
static constexpr UIntType MaxNormal = ( ( UIntType( MaxExponentValue ) - 1 ) << FractionWidth ) | MaxSubnormal;
static constexpr UIntType FractionMask = FractionMask<ValueType, UIntType>;
static constexpr UIntType ExponentMask = ExponentMask<ValueType, UIntType>;
static constexpr UIntType SignMask = ~( FractionMask | ExponentMask );
static constexpr UIntType InfinityValue = InfinityUnsignedValue<ValueType>::value;
static constexpr UIntType NegativeInfinityValue = NegativeInfinityUnsignedValue<ValueType>::value;
static constexpr UIntType QuietNaNValue = QuietNaNUnsignedValue<ValueType>::value;
static constexpr UIntType ZeroValue = static_cast<UIntType>( 0 );
static constexpr UIntType NegativeZeroValue = SignMask;
UIntType value_;
constexpr FloatingPoint( ) noexcept
: value_( std::bit_cast<UIntType>( static_cast<ValueType>( 0.0 ) ) )
{
}
constexpr explicit FloatingPoint( ValueType value ) noexcept
: value_( std::bit_cast<UIntType>( value ) )
{
}
constexpr explicit FloatingPoint( UIntType value, bool ) noexcept
: value_( value )
{
}
constexpr explicit FloatingPoint( UIntType fraction, Int32 exponent, bool sign) noexcept
: value_( (fraction & FractionMask ) |
(( static_cast<UIntType>( exponent ) << FractionWidth ) & ExponentMask) |
( sign? SignMask : 0 ) )
{
}
constexpr FloatingPoint& operator = ( ValueType value ) noexcept
{
value_ = std::bit_cast<UIntType>( value );
return *this;
}
constexpr bool Sign( ) const noexcept
{
return ( value_ & SignMask ) != 0;
}
constexpr void SetSign( bool value = true ) noexcept
{
if ( value )
{
value_ |= SignMask;
}
else
{
value_ &= ~SignMask;
}
}
constexpr Int32 Exponent( ) const noexcept
{
return static_cast<Int32>( ( value_ & ExponentMask ) >> FractionWidth ) - ExponentBias;
}
private:
constexpr void SetExponent( UIntType value ) noexcept
{
value_ = ( value << FractionWidth ) & ExponentMask;
}
public:
constexpr UIntType Fraction( ) const noexcept
{
return value_ & FractionMask;
}
private:
constexpr void SetFraction( UIntType value ) noexcept
{
value_ = value & FractionMask;
}
public:
constexpr bool IsZero( ) const noexcept
{
return (value_ & ( ExponentMask | FractionMask )) == 0;
}
constexpr bool IsInf( ) const noexcept
{
return ( value_ & FractionMask ) == 0 && ( ( value_ & ExponentMask ) == MaxExponent );
}
constexpr bool IsNaN( ) const noexcept
{
return ( ( value_ & ExponentMask ) == MaxExponent ) && ( ( value_ & FractionMask ) != 0 );
}
constexpr bool IsInfOrNaN( ) const noexcept
{
return ( value_ & ExponentMask ) == MaxExponent;
}
static constexpr ValueType MakeNaN( UIntType value ) noexcept
{
UIntType result;
result = MaxExponent | (value & FractionMask);
return std::bit_cast<ValueType>( result );
}
constexpr ValueType AsFloatingPoint( ) const noexcept
{
return std::bit_cast<ValueType>( value_ );
}
constexpr UIntType AsUnsigned( ) const noexcept
{
return value_;
}
static constexpr FloatingPoint Zero( ) noexcept
{
return FloatingPoint( );
}
static constexpr FloatingPoint NegZero( ) noexcept
{
FloatingPoint result;
result.value_ = SignMask;
return result;
}
static constexpr FloatingPoint Inf( ) noexcept
{
FloatingPoint result;
result.value_ = MaxExponent;
return result;
}
static constexpr FloatingPoint NegInf( ) noexcept
{
FloatingPoint result;
result.value_ = MaxExponent | SignMask;
return result;
}
constexpr ValueType Trunc( ) const noexcept
{
if ( IsInfOrNaN( ) )
{
return std::bit_cast<ValueType>(value_);
}
Int32 exponent = Exponent( );
if ( exponent >= static_cast<Int32>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent <= -1 )
{
return Sign() ? static_cast<ValueType>( -0.0 ) : static_cast<ValueType>( 0.0 );
}
Int32 trimSize = FractionWidth - exponent;
UIntType result = (value_ & (SignMask | ExponentMask)) | (( (value_ & FractionMask) >> trimSize ) << trimSize);
return std::bit_cast<ValueType>( result );
}
constexpr ValueType Ceil( ) const noexcept
{
if ( IsInfOrNaN( ) || IsZero( ) )
{
return std::bit_cast<ValueType>( value_ );
}
Int32 exponent = Exponent( );
if ( exponent >= static_cast<Int32>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent <= -1 )
{
return Sign() ? ValueType( -0.0 ) : ValueType( 1.0 );
}
Int32 trimSize = FractionWidth - exponent;
UIntType result = ( value_ & ( SignMask | ExponentMask ) ) | ( ( ( value_ & FractionMask ) >> trimSize ) << trimSize );
if ( result == value_ )
{
return std::bit_cast<ValueType>( value_ );
}
return Sign( ) ? std::bit_cast<ValueType>( result ) : std::bit_cast<ValueType>( result ) + static_cast<ValueType>( 1.0 );
}
constexpr ValueType Floor( ) const noexcept
{
if ( Sign() )
{
FloatingPoint tmp( value_ & ( ExponentMask | FractionMask ), true );
return -tmp.Ceil( );
}
else
{
return Trunc( );
}
}
constexpr ValueType Round( ) const noexcept
{
if ( IsInfOrNaN( ) || IsZero( ) )
{
return std::bit_cast<ValueType>(value_);
}
int exponent = Exponent( );
if ( exponent >= static_cast<int>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent == -1 )
{
bool isNegative = Sign( );
if ( isNegative )
{
return static_cast<ValueType>( -1.0 );
}
else
{
return static_cast<ValueType>( 1.0 );
}
}
if ( exponent <= -2 )
{
bool isNegative = Sign( );
if ( isNegative )
{
return static_cast<ValueType>( -0.0 );
}
else
{
return static_cast<ValueType>( 0.0 );
}
}
UInt32 trimSize = FractionWidth - exponent;
bool middleBitSet = (value_ & FractionMask) & ( UIntType( 1 ) << ( trimSize - 1 ) );
UIntType result = ( value_ & ( SignMask | ExponentMask ) ) | ( ( ( value_ & FractionMask ) >> trimSize ) << trimSize );
if ( result == value_ )
{
return std::bit_cast<ValueType>( value_ );
}
if ( !middleBitSet )
{
return std::bit_cast<ValueType>( result );
}
else
{
bool isNegative = Sign( );
return isNegative ?
std::bit_cast<ValueType>( result ) - static_cast<ValueType>( 1.0 ) :
std::bit_cast<ValueType>( result ) + static_cast<ValueType>( 1.0 );
}
}
};
#pragma pack(pop)
Espen Harlinn
Senior Architect - Ulriken Consulting AS
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
modified 21-Jun-21 19:41pm.
|
|
|
|
|
If it was closer to performing like I need I'd twiddle with optimizations like this, but this sort of improvement isn't going to change the code from taking minutes to taking seconds, and that's what I need.
I've basically abandoned color dithering for this project.
Real programmers use butterflies
|
|
|
|
|
You made me curious. It looks like this worked. There were a couple quirk texts in your paste I had to eliminate, but the main thing was using Notepad++ to convert it to ANSI before pasting here. Weird - it took a bit of work, like 5 mins puttering...
For my own code, I do a two-step process. First paste as HTML and encode, then copy everything, delete it, and repaste as C++.
template <typename T>
struct FractionWidth;
template <>
struct FractionWidth<float>
{
static constexpr UInt32 value = 23;
};
template <>
struct FractionWidth<double>
{
static constexpr UInt32 value = 52;
};
template <typename T>
struct ExponentWidth;
template <>
struct ExponentWidth<float>
{
static constexpr UInt32 value = 8;
};
template <>
struct ExponentWidth<double>
{
static constexpr UInt32 value = 11;
};
template <typename T>
struct ExponenBias;
template <>
struct ExponenBias<float>
{
static constexpr UInt32 value = _FBIAS;
};
template <>
struct ExponenBias<double>
{
static constexpr UInt32 value = _DBIAS;
};
template <typename T>
struct InfinityUnsignedValue;
template <>
struct InfinityUnsignedValue<float>
{
static constexpr UInt32 value = 0X7F800000UL;
};
template <>
struct InfinityUnsignedValue<double>
{
static constexpr UInt64 value = 0x7FF0000000000000ULL;
};
template <typename T>
struct NegativeInfinityUnsignedValue;
template <>
struct NegativeInfinityUnsignedValue<float>
{
static constexpr UInt32 value = 0xFF800000UL;
};
template <>
struct NegativeInfinityUnsignedValue<double>
{
static constexpr UInt64 value = 0xFFF0000000000000ULL;
};
template <typename T>
struct QuietNaNUnsignedValue;
template <>
struct QuietNaNUnsignedValue<float>
{
static constexpr UInt32 value = 0XFFC00001UL;
};
template <>
struct QuietNaNUnsignedValue<double>
{
static constexpr UInt64 value = 0x7FF0000000000001ULL;
};
pragma pack(push,1);
template<typename T>
struct FloatingPoint
{
using ValueType = std::remove_cvref_t<T>;
using UIntType = MakeUnsigned<ValueType>;
<pre>
static constexpr Int32 FractionWidth = static_cast<Int32>( Internal::FractionWidth<ValueType>::value );
static constexpr Int32 ExponentWidth = static_cast<Int32>( Internal::ExponentWidth<ValueType>::value );
static constexpr Int32 ExponentBias = ( 1 << ( ExponentWidth - 1 ) ) - 1;
static constexpr Int32 MaxExponentValue = ( 1 << ExponentWidth ) - 1;
static constexpr UIntType MaxExponent = static_cast<UIntType>( MaxExponentValue ) << FractionWidth;
static constexpr UIntType MinSubnormal = UIntType( 1 );
static constexpr UIntType MaxSubnormal = ( UIntType( 1 ) << FractionWidth ) - 1;
static constexpr UIntType MinNormal = ( UIntType( 1 ) << FractionWidth );
static constexpr UIntType MaxNormal = ( ( UIntType( MaxExponentValue ) - 1 ) << FractionWidth ) | MaxSubnormal;
static constexpr UIntType FractionMask = FractionMask<ValueType, UIntType>;
static constexpr UIntType ExponentMask = ExponentMask<ValueType, UIntType>;
static constexpr UIntType SignMask = ~( FractionMask | ExponentMask );
static constexpr UIntType InfinityValue = InfinityUnsignedValue<ValueType>::value;
static constexpr UIntType NegativeInfinityValue = NegativeInfinityUnsignedValue<ValueType>::value;
static constexpr UIntType QuietNaNValue = QuietNaNUnsignedValue<ValueType>::value;
static constexpr UIntType ZeroValue = static_cast<UIntType>( 0 );
static constexpr UIntType NegativeZeroValue = SignMask;
UIntType value_;
constexpr FloatingPoint( ) noexcept
: value_( std::bit_cast<UIntType>( static_cast<ValueType>( 0.0 ) ) )
{
}
constexpr explicit FloatingPoint( ValueType value ) noexcept
: value_( std::bit_cast<UIntType>( value ) )
{
}
constexpr explicit FloatingPoint( UIntType value, bool ) noexcept
: value_( value )
{
}
constexpr explicit FloatingPoint( UIntType fraction, Int32 exponent, bool sign) noexcept
: value_( (fraction & FractionMask ) |
(( static_cast<UIntType>( exponent ) << FractionWidth ) & ExponentMask) |
( sign? SignMask : 0 ) )
{
}
constexpr FloatingPoint& operator = ( ValueType value ) noexcept
{
value_ = std::bit_cast<UIntType>( value );
return *this;
}
constexpr bool Sign( ) const noexcept
{
return ( value_ & SignMask ) != 0;
}
constexpr void SetSign( bool value = true ) noexcept
{
if ( value )
{
value_ |= SignMask;
}
else
{
value_ &= ~SignMask;
}
}
constexpr Int32 Exponent( ) const noexcept
{
return static_cast<Int32>( ( value_ & ExponentMask ) >> FractionWidth ) - ExponentBias;
}
private:
constexpr void SetExponent( UIntType value ) noexcept
{
value_ = ( value << FractionWidth ) & ExponentMask;
}
public:
constexpr UIntType Fraction( ) const noexcept
{
return value_ & FractionMask;
}
private:
constexpr void SetFraction( UIntType value ) noexcept
{
value_ = value & FractionMask;
}
public:
constexpr bool IsZero( ) const noexcept
{
return (value_ & ( ExponentMask | FractionMask )) == 0;
}
constexpr bool IsInf( ) const noexcept
{
return ( value_ & FractionMask ) == 0 && ( ( value_ & ExponentMask ) == MaxExponent );
}
constexpr bool IsNaN( ) const noexcept
{
return ( ( value_ & ExponentMask ) == MaxExponent ) && ( ( value_ & FractionMask ) != 0 );
}
constexpr bool IsInfOrNaN( ) const noexcept
{
return ( value_ & ExponentMask ) == MaxExponent;
}
static constexpr ValueType MakeNaN( UIntType value ) noexcept
{
UIntType result;
result = MaxExponent | (value & FractionMask);
return std::bit_cast<ValueType>( result );
}
constexpr ValueType AsFloatingPoint( ) const noexcept
{
return std::bit_cast<ValueType>( value_ );
}
constexpr UIntType AsUnsigned( ) const noexcept
{
return value_;
}
static constexpr FloatingPoint Zero( ) noexcept
{
return FloatingPoint( );
}
static constexpr FloatingPoint NegZero( ) noexcept
{
FloatingPoint result;
result.value_ = SignMask;
return result;
}
static constexpr FloatingPoint Inf( ) noexcept
{
FloatingPoint result;
result.value_ = MaxExponent;
return result;
}
static constexpr FloatingPoint NegInf( ) noexcept
{
FloatingPoint result;
result.value_ = MaxExponent | SignMask;
return result;
}
constexpr ValueType Trunc( ) const noexcept
{
if ( IsInfOrNaN( ) )
{
return std::bit_cast<ValueType>(value_);
}
Int32 exponent = Exponent( );
if ( exponent >= static_cast<Int32>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent <= -1 )
{
return Sign() ? static_cast<ValueType>( -0.0 ) : static_cast<ValueType>( 0.0 );
}
Int32 trimSize = FractionWidth - exponent;
UIntType result = (value_ & (SignMask | ExponentMask)) | (( (value_ & FractionMask) >> trimSize ) << trimSize);
return std::bit_cast<ValueType>( result );
}
constexpr ValueType Ceil( ) const noexcept
{
if ( IsInfOrNaN( ) || IsZero( ) )
{
return std::bit_cast<ValueType>( value_ );
}
Int32 exponent = Exponent( );
if ( exponent >= static_cast<Int32>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent <= -1 )
{
return Sign() ? ValueType( -0.0 ) : ValueType( 1.0 );
}
Int32 trimSize = FractionWidth - exponent;
UIntType result = ( value_ & ( SignMask | ExponentMask ) ) | ( ( ( value_ & FractionMask ) >> trimSize ) << trimSize );
if ( result == value_ )
{
return std::bit_cast<ValueType>( value_ );
}
return Sign( ) ? std::bit_cast<ValueType>( result ) : std::bit_cast<ValueType>( result ) + static_cast<ValueType>( 1.0 );
}
constexpr ValueType Floor( ) const noexcept
{
if ( Sign() )
{
FloatingPoint tmp( value_ & ( ExponentMask | FractionMask ), true );
return -tmp.Ceil( );
}
else
{
return Trunc( );
}
}
constexpr ValueType Round( ) const noexcept
{
if ( IsInfOrNaN( ) || IsZero( ) )
{
return std::bit_cast<ValueType>(value_);
}
int exponent = Exponent( );
if ( exponent >= static_cast<int>( FractionWidth ) )
{
return std::bit_cast<ValueType>( value_ );
}
if ( exponent == -1 )
{
bool isNegative = Sign( );
if ( isNegative )
{
return static_cast<ValueType>( -1.0 );
}
else
{
return static_cast<ValueType>( 1.0 );
}
}
if ( exponent <= -2 )
{
bool isNegative = Sign( );
if ( isNegative )
{
return static_cast<ValueType>( -0.0 );
}
else
{
return static_cast<ValueType>( 0.0 );
}
}
UInt32 trimSize = FractionWidth - exponent;
bool middleBitSet = (value_ & FractionMask) & ( UIntType( 1 ) << ( trimSize - 1 ) );
UIntType result = ( value_ & ( SignMask | ExponentMask ) ) | ( ( ( value_ & FractionMask ) >> trimSize ) << trimSize );
if ( result == value_ )
{
return std::bit_cast<ValueType>( value_ );
}
if ( !middleBitSet )
{
return std::bit_cast<ValueType>( result );
}
else
{
bool isNegative = Sign( );
return isNegative ?
std::bit_cast<ValueType>( result ) - static_cast<ValueType>( 1.0 ) :
std::bit_cast<ValueType>( result ) + static_cast<ValueType>( 1.0 );
}
}
};
pragma pack(pop)
|
|
|
|
|
I am surprised it is that bad. I thought something like the ESP32 at 240Mhz would do a Floyd-Steinberg reasonable well, at least keeping up with the 680x0's and 86x86's I used to run Floyd-Steinberg on 25 odd years ago. I know it is a different architecture, but it is also a 200Mhz speed advantage. But maybe it was just a lot slower than I recall it - back then we where amazed it displayed something at all. I am quite sure it never took a minute though - but if it was ½ or 20 seconds who knows.
I wonder if it is memory access or something slowing it down.
Takes ages to develop these kind of things though. As soon as it displays something, you loose the next couple of hours looking at it before moving on.
|
|
|
|
|
I can't do floyd steinberg because of the memory requirements.
I do a similar style as Thomas Knoll's adobe photoshop grid dithering method for my "slow" dithering, and an optimized Yliluoma algorithm for my "fast" dithering. Both are far too slow.
Real programmers use butterflies
|
|
|
|
|