Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.

LibLapin's logo

LibLapin

Color





This module contains symbolic constants, data types and macros to help you handling colors in your program.


The vector module header is lapin/color.h.

k
typedef enum e_bunny_rgb
{
     R‌E‌D_CMP,
     G‌R‌E‌E‌N_CMP,
     B‌L‌U‌E_CMP,
     A‌L‌P‌H‌A_CMP

} t‌_‌b‌u‌n‌n‌y‌_‌r‌g‌b;

Description

     The t‌_‌b‌u‌n‌n‌y‌_‌r‌g‌b enumeration is useful to access in a char array containing a color each color component one by one.
In the associated type t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌l‌o‌r, fields are also following this order.

Symbols




INDEX

k
typedef union u_bunny_color
{
     uint32_t full;
     uint8_t argb[4];
     int8_t mod[4];

} t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌l‌o‌r;

Description

     The t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌l‌o‌r union is 4 bytes length and contains a color. This color, thanks to its attributes, can be accessed in several ways, matching several usage.


Symbols

  • uint32_t full:
         This attribute offer the first obvious usage of t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌l‌o‌r. It is to use it as an integer. With this attribute, you can simply move the full color easily. One drawback is that you cannot make efficient math on it.
  • uint8_t argb[4]
         This array of 4 bytes store the same color as full, but allows you to access each color component separately. Used with the t‌_‌b‌u‌n‌n‌y‌_‌r‌g‌b symbolic constant A‌L‌P‌H‌A_CMP, R‌E‌D_CMP, G‌R‌E‌E‌N_CMP and B‌L‌U‌E_CMP, you can access readably the field you need.
    Thanks to this field, you can make efficient math on colors, but you cannot do all kind of operations because of the nature of unsigned integers. This field is cool to store colors, but not color offset because of this.
  • int8_t mod[4]:
         This array of 4 bytes do not really store a color. It stores a color offset. It can be, for example, added to a color, or subtract, with care about overflow, of course.

    You may find it quite limited because of its integer nature and this is right. It may be inefficient: if it is, make your own 4 float array.



INDEX

Description

This macro render a fully transparent black.
Note that drawing it will not, in context that handle opacity, draw anything. To make this color effective, it must be set or draw in a context that ignore opacity.


INDEX

Description

This macro render a fully opaque black.


INDEX

Macro R‌E‌D

Description

This macro render a fully opaque red.


INDEX

Description

This macro render a fully opaque green.


INDEX

Description

This macro render a fully opaque blue.


INDEX

Description

This macro render a fully opaque purple.


INDEX

Description

This macro render a fully opaque teal.


INDEX

Description

This macro render a fully opaque yellow.


INDEX

Description

This macro render a fully opaque white.


INDEX

Description

This macro render a fully opaque quite sad pink.


INDEX

Description

This macro render my favorite fully opaque fun and shiny pink.


INDEX

Macro unsigned int T‌O‌_‌A‌L‌P‌H‌A (unsigned char color_component)

Description

This macro transform the sent color component to a valid opacity value that could be added or binary ORed to a full 4 byte color. Example:

unsigned int color = B‌L‌A‌C‌K;

color |= T‌O‌_‌A‌L‌P‌H‌A(128); // The color is now half transparent.

Parameters

  • unsigned char color_component:
         The color component that will be turned into a 4 byte color format.

Return value

  • This function return a 4 byte color format version of the send 1 byte color component.


INDEX

Macro unsigned int T‌O‌_‌R‌E‌D (unsigned char color_component)

Description

This macro transform the sent color component to a valid component value that could be added or binary ORed to a full 4 byte color. Example:

unsigned int color = B‌L‌A‌C‌K;

color |= T‌O‌_‌R‌E‌D(128); // The color is now draw red

Parameters

  • unsigned char color_component:
         The color component that will be turned into a 4 byte color format.

Return value

  • This function return a 4 byte color format version of the send 1 byte color component.


INDEX

Macro unsigned int T‌O‌_‌G‌R‌E‌E‌N (unsigned char color_component)

Description

This macro transform the sent color component to a valid component value that could be added or binary OGreen to a full 4 byte color. Example:

unsigned int color = B‌L‌A‌C‌K;

color |= T‌O‌_‌G‌R‌E‌E‌N(128); // The color is now draw green

Parameters

  • unsigned char color_component:
         The color component that will be turned into a 4 byte color format.

Return value

  • This function return a 4 byte color format version of the send 1 byte color component.


INDEX

Macro unsigned int T‌O‌_‌B‌L‌U‌E (unsigned char color_component)

Description

This macro transform the sent color component to a valid component value that could be added or binary OBlue to a full 4 byte color. Example:

unsigned int color = B‌L‌A‌C‌K;

color |= T‌O‌_‌B‌L‌U‌E(128); // The color is now draw blue

Parameters

  • unsigned char color_component:
         The color component that will be turned into a 4 byte color format.

Return value

  • This function return a 4 byte color format version of the send 1 byte color component.


INDEX

Macro unsigned int G‌E‌T‌_‌C‌O‌L‌O‌R (unsigned int color)

Description

This macro extract the color part of the sent 4 byte color. For example, sending an half transparent purple will return a transparent purple: only the three bytes composing the red, green and blue are returned. The fourth byte containing the opacity is erased and set to 0.

Parameters

  • unsigned int color:
         A 4 byte color that will be partially erased to remove its opacity component.

Return value

  • This function return a 4 byte color format version of the send color without its opacity byte.


INDEX

Macro unsigned int A‌L‌P‌H‌A (unsigned char opacity, unsigned int color)

Description

This macro is pretty useful. It takes two parameters: an opacity and a color and generate a new color of the sent one with the sent opacity.

Parameters

  • unsigned char opacity:
         The opacity of the color that will be generated.
  • unsigned int color:
         The color that will be used to generate a new one with the sent opacity.

Return value

  • This function return a 4 byte color of the sent color mixed with the sent opacity.


INDEX

Macro unsigned int C‌O‌L‌O‌R ( unsigned char opacity, unsigned char red, unsigned char green, unsigned char blue );

Description

This macro build a 4 byte color from 4 1 byte color components.

Parameters

  • unsigned char opacity:
         The opacity of the generated color.
  • unsigned char red:
         The red part of the generated color.
  • unsigned char green:
         The green part of the generated color.
  • unsigned char blue:
         The blue part of the generated color.

Return value

  • This function returns a 4 byte color, mixing all the sent components.


INDEX

Macro unsigned int A‌L‌P‌H‌A‌_‌G‌R‌A‌Y ( unsigned char opacity, unsigned char gray );

Description

This macro build a 4 byte color of gray color and with sent opacity.

Parameters

  • unsigned char opacity:
         The opacity of the generated color.
  • unsigned char gray:
         The red, green and blue part of the generated color.

Return value

  • This function returns a 4 byte color, mixing all the sent components.


INDEX

Macro unsigned int A‌L‌P‌H‌A‌_‌G‌R‌A‌Y ( unsigned char gray );

Description

This macro build a 4 byte color of fully opaque gray color.

Parameters

  • unsigned char gray:
         The red, green and blue part of the generated color.

Return value

  • This function returns an opaque 4 byte color, mixing all the sent components.


INDEX