Skip to content

Add standard macros to handle common operations #760

Description

@pierrejoye

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:

  1. Centralized implementation and add them to the CS
  2. testable, we can add tests with an include "../src/gd_intern.h" and run tests across various compilers and architectures
  3. Various implementations like filters, 2D transformations, etc will be predictable and have uniform channel rounding

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?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions