-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add standard macros to handle common operations #760
Comments
centralizing helpers in gd_intern.h sgtm i think changing "cast_uint8" to "_u8" doesn't really lose clarity ? |
That should be ok. I tend to prefer self documentation about what it accepts and returns. I don't mind either one. :) I did not create a task for it but I would like to enforce usage of stdint types as well. |
Yes, that sounds good to me either. We should not forget about Lines 95 to 120 in 0f9dd96
Maybe we should drop that altogether, or at least use int64_t instead of long on 64bit (for LLP64). |
We have the same operations across the sources, sometimes using the same method, sometimes not. As it may not be an issue for some, it creates disparities and inconsistencies, especially if it comes to channels calculations. Many times we don't follow standards (or lack of), like differences between integer casting on intel or arm, or various other architectures.
We have a few macros or functions already, however I would like to use gd_intern.h to implement the most common ones and unify their usages everywhere as well as enforce their usage for all new codes.
It has three main advantages:
The 1st ones I had in mind are:
gd intern
clamp255
clamp127
clamp(input, min, max)
double
roundd
roundd_cast_uint8
roundd_cast_uint16
roundd_cast_uint32
roundd_cast_uint64
roundd
roundupd_cast_uint8
roundupd_cast_uint16
roundupd_cast_uint32
roundupd_cast_uint64
floord
floord_cast_uint8
floord_cast_uint16
floord_cast_uint32
floord_cast_uint64
float
roundf
roundf_cast_uint8
roundf_cast_uint16
roundf_cast_uint32
roundf_cast_uint64
roundupf
roundupf_cast_uint8
roundupf_cast_uint16
roundupf_cast_uint32
roundupf_cast_uint64
floorf
floorf_cast_uint8
floorf_cast_uint16
floorf_cast_uint32
floorf_cast_uint64
We could add as well the same but taking an uint32_t argb, the uint32_t 31 bit color, or both the quadlet and triplet (r,g,b)/(a,r,g,b).
And indeed, the same for the fixed point (bith fp32 and fp64). However we need to unify the FP APIs as well. And use the same implementations everywhere.
What do you think?
The text was updated successfully, but these errors were encountered: