Stored Draft color integer is different from the default?

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Stored Draft color integer is different from the default?

Post by Roy_043 »

While working on the Draft_AnnotationStyleEditor code I notice that Draft stores a different color integer from the default. Is this a deliberate choice?

Code: Select all

Example:
RGB = (11, 12, 13)

Draft format:
1095401999616
Hex:
??RRGGBBAA
ff0b0c0d00

Default format:
185339391
Hex:
??RRGGBBAA
000b0c0dff
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Stored Draft color integer is different from the default?

Post by yorik »

I don't understand exactly what you mean... the size of the integer you mean? AFAICR it varies, for ex. 255 is a valid color integer.
In any case I think it's meant to be saved in the same format as in the FreeCAD parameters, if it's different it's probably a mistake.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Stored Draft color integer is different from the default?

Post by Roy_043 »

The color integers contain four relevant bytes. Qt stores the Alpha value in the highest of those bytes (ARGB), whereas FreeCAD stores the Alpha value in the lowest byte (RGBA):

With the given RGB list (11, 12, 13) Qt returns this int:
ff0b0c0d
And FreeCAD would stored the value as:
0b0c0dff

In the Draft code the Qt int is simply shifted 8 bits to the left which results in:
ff0b0c0d00
This means that the RGB bytes are in the correct position, but the int has a different value from what is used in other parts of FreeCAD.

2 functions to convert from ARGB to RGBA and vice versa:

Code: Select all

def argb_to_rgba(color):
    """Change byte order of a 4 byte color int from ARGB (Qt) to RGBA."""
    return ((color & 0xFFFFFF) << 8) + (color >> 24)


def rgba_to_argb(color):
    """Change byte order of a 4 byte color int from RGBA to ARGB (Qt)."""
    return (color >> 8) + ((color & 0xFF) << 24)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Stored Draft color integer is different from the default?

Post by yorik »

Roy_043 wrote: Wed Nov 16, 2022 2:31 pm Qt stores the Alpha value in the highest of those bytes (ARGB), whereas FreeCAD stores the Alpha value in the lowest byte (RGBA)
Hmm indeed it's possible that I forgot that bit...
Post Reply