Warcraft III resources & community, 2003–2006 · archived

CreateColorInteger

not rated
Submitted by PepparVariable Change0 downloads
Creates a color integer (as opposed to a color string e.g. "ff00aabb".) Color integers can be created at compile-time by using the 0x-prefix. They have the format: 0xAABBGGRR where AA is alpha, BB is blue, GG is green and RR is red in hexadecimal pairs.

Color integers aren't necessary, but they are fast in comparision to color strings. Especially when retrieving a color of a color string, the color integer is many times faster.

The ColorIntegerGet-function retrieves one of the four different colors of a color integer.

Source

function CreateColorInteger takes integer red, integer green, integer blue, integer alpha returns integer
    return red + green * 0x100 + blue * 0x10000 + alpha * 0x1000000
endfunction

function ColorIntegerGetRed takes integer i returns integer
    if i < 0 then
        return ModuloInteger(i + 0x80000000, 0x100)
    endif
    return ModuloInteger(i, 0x100)
endfunction
function ColorIntegerGetGreen takes integer i returns integer
    if i < 0 then
        return ModuloInteger((i + 0x80000000) / 0x100, 0x100)
    endif
    return ModuloInteger(i / 0x100, 0x100)
endfunction
function ColorIntegerGetBlue takes integer i returns integer
    if i < 0 then
        return ModuloInteger((i + 0x80000000) / 0x10000, 0x100)
    endif
    return ModuloInteger(i / 0x10000, 0x100)
endfunction
function ColorIntegerGetAlpha takes integer i returns integer
    if i < 0 then
        return (i + 0x80000000) / 0x1000000 + 0x80
    endif
    return i / 0x1000000
endfunction

Comments

0

No comments.