Skip to content

image/color: NRGBA(64).RGBA() optimization #11793

Open
@pierrre

Description

@pierrre

If alpha is equal to 0xffff, return r,b,g,a.
If alpha is equal to 0, return 0,0,0,0.
Else, multiply by alpha, divide by 0xffff, return r,g,b,a.

New code:

func (c NRGBA) RGBA() (r, g, b, a uint32) {
    a = uint32(c.A)
    a |= a << 8
    if a == 0 {
        return 0, 0, 0, 0
    }
    r = uint32(c.R)
    r |= r << 8
    g = uint32(c.G)
    g |= g << 8
    b = uint32(c.B)
    b |= b << 8
    if a == 0xffff {
        return
    }
    r = r * a / 0xffff
    g = g * a / 0xffff
    b = b * a / 0xffff
    return
}

func (c NRGBA64) RGBA() (r, g, b, a uint32) {
    a = uint32(c.A)
    if a == 0 {
        return 0, 0, 0, 0
    }
    r = uint32(c.R)
    g = uint32(c.G)
    b = uint32(c.B)
    if a == 0xffff {
        return
    }
    r = r * a / 0xffff
    g = g * a / 0xffff
    b = b * a / 0xffff
    return
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions