Issue #132 new

History behind 7-bit alpha component?

Nathanael Jones
created an issue

Hi, I'm looking for more information about why the alpha channel is limited to 7 bits. Are/were there platform issues? Is it just for backwards compatibility?

Comments (2)

  1. Toster Cx

    Found this cryptic note in the source:

    /* gd has only 7 bits of alpha channel resolution, and
     * 127 is transparent, 0 opaque. A moment of convenience,
     *  a lifetime of compatibility.
     */
    

    May or may not have something to do with this:

    While most people are used to an 8-bit (0-255) alpha channel, it is actually quite handy that GD's is 7-bit (0- 127). Each pixel is represented by a 32-bit signed integer, with the four 8-bit bytes arranged like this:

    High Byte Low Byte

    {Alpha Channel} {Red} {Green} {Blue}

    For a signed integer, the leftmost bit, or the highest bit, is used to indicate whether the value is negative, thus leaving only 31 bits of actual information. PHP's default integer value is a signed long into which we can store a single GD palette entry. Whether that integer is positive or negative tells us whether antialiasing is enabled for that palette entry.

  2. Log in to comment