Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Color Extraction Developer Insights
#3
(01-28-2024, 06:51 AM)DSMan195276 Wrote: The functions alpha/red/green/blue work the same way as what you're doing and will be equivalent in speed. The only minor difference is that your `AND` for the alpha value is unnecessary as all the values you're `AND`ing away will be shifted away by the `_SHR(a, 24)`, so because of that `_ALPHA32()` only does a shift.

That said, them having equivalent speed is only true if you're inlining that logic everywhere you use it. If you plan to put the logic into a QB64 `FUNCTION`then there is overhead to calling QB64 functions that the built-in functions do not have. In absolute time it could easily be 100x slower simply because the `FUNCTION` would do so little actual work.

I would also note that the type's of the variables matter for this question. Your code only works if the types are unsigned, because `_ShR` will do 64-bit sign extension if the original value is a signed negative. In contrast, the QB64 functions will work correctly regardless of the signed/unsigned nature of the original value (really this only matters for the `_Alpha32()`, since the other colors are always positive values after the `AND`).
Excellent, thank you for the quick feedback. I'll use the statements then since they are already as fast as can be and as a bonus handle types better than I was.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
RE: Color Extraction Developer Insights - by TerryRitchie - 01-28-2024, 07:08 AM



Users browsing this thread: 2 Guest(s)