GrafX2 2.9.3227
The ultimate 256-color painting program
|
Color reduction and color conversion (24b->8b, RGB<->HSL). More...
Data Structures | |
struct | T_Occurrence_table |
Occurence table. More... | |
struct | S_Cluster_CutData |
informations used while median-cutting. More... | |
struct | S_Cluster_PalData |
information used while color reducing More... | |
union | U_Cluster_Data |
struct | T_Cluster |
Color cluster. More... | |
struct | T_Cluster_set |
Cluster set. More... | |
struct | T_Gradient |
Gradient. More... | |
struct | T_Gradient_set |
Typedefs | |
typedef T_Components * | T_Bitmap24B |
typedef byte * | T_Bitmap256 |
Functions | |
void | RGB_to_HSL (int r, int g, int b, byte *h, byte *s, byte *l) |
Convert RGB to HSL. More... | |
void | HSL_to_RGB (byte h, byte s, byte l, byte *r, byte *g, byte *b) |
Convert HSL back to RGB Input and output are all in range 0..255. More... | |
long | Perceptual_lightness (T_Components *color) |
Returns a value that is high when color is near white, and low when it's darker. More... | |
void | OT_init (T_Occurrence_table *t) |
Initialize an occurrence table. More... | |
T_Occurrence_table * | OT_new (int nbb_r, int nbb_g, int nbb_b) |
Allocate an occurrence table for given number of bits. More... | |
void | OT_delete (T_Occurrence_table *t) |
Delete a table and free the memory. More... | |
int | OT_get (T_Occurrence_table *t, byte r, byte g, byte b) |
Get number of occurrences for a given color. More... | |
void | OT_inc (T_Occurrence_table *t, byte r, byte g, byte b) |
Add 1 to the count for a color. More... | |
void | OT_count_occurrences (T_Occurrence_table *t, T_Bitmap24B image, int size) |
Count the use of each color in a 24bit picture and fill in the table. More... | |
void | Cluster_pack (T_Cluster *c, const T_Occurrence_table *const to) |
Pack a cluster, ie compute its {r,v,b}{min,max} values. More... | |
void | Cluster_split (T_Cluster *c, T_Cluster *c1, T_Cluster *c2, int hue, const T_Occurrence_table *const to) |
Split a cluster on its longest axis. More... | |
void | Cluster_compute_hue (T_Cluster *c, T_Occurrence_table *to) |
Compute the mean R, G, B (for palette generation) and H, L (for palette sorting) More... | |
void | CS_Init (T_Cluster_set *cs, T_Occurrence_table *to) |
Setup the first cluster before we start the operations This one covers the full palette range. More... | |
T_Cluster_set * | CS_New (int nbmax, T_Occurrence_table *to) |
Allocate a new cluster set. More... | |
void | CS_Delete (T_Cluster_set *cs) |
Free a cluster set. More... | |
void | CS_Get (T_Cluster_set *cs, T_Cluster **c) |
Pop a cluster from the cluster list. More... | |
int | CS_Set (T_Cluster_set *cs, T_Cluster *c) |
Push a copy of a cluster in the list return -1 in case of error. More... | |
int | CS_Generate (T_Cluster_set *cs, const T_Occurrence_table *const to, CT_Tree *colorTree) |
This is the main median cut algorithm and the function actually called to reduce the palette. More... | |
void | CS_Compute_colors (T_Cluster_set *cs, T_Occurrence_table *to) |
Compute the color associated to each box in the list. More... | |
void | CS_Generate_color_table_and_palette (T_Cluster_set *cs, CT_Tree *tc, T_Components *palette, T_Occurrence_table *to) |
Generates the palette from the clusters, then the conversion table to map (RGB) to a palette index. More... | |
void | GS_Init (T_Gradient_set *ds, T_Cluster_set *cs) |
T_Gradient_set * | GS_New (T_Cluster_set *cs) |
void | GS_Delete (T_Gradient_set *ds) |
void | GS_Generate (T_Gradient_set *ds, T_Cluster_set *cs) |
int | Convert_24b_bitmap_to_256 (T_Bitmap256 dest, T_Bitmap24B source, int width, int height, T_Components *palette) |
Converts a 24 bit picture to 256 color (color reduction) More... | |
Color reduction and color conversion (24b->8b, RGB<->HSL).
This is called op_c because half of the process was originally coded in op_asm, in assembler.
typedef T_Components* T_Bitmap24B |
typedef byte* T_Bitmap256 |
Convert RGB to HSL.
Both input and output are in the 0..255 range to use in the palette screen
Referenced by Button_Palette(), Cluster_compute_hue(), Compute_optimal_menu_colors(), Display_sliders(), Draw_all_palette_sliders(), and Set_HSL().
Convert HSL back to RGB Input and output are all in range 0..255.
Referenced by Button_Palette(), and Set_HSL().
long Perceptual_lightness | ( | T_Components * | color | ) |
Returns a value that is high when color is near white, and low when it's darker.
Used for sorting.
References T_Components::B, T_Components::G, and T_Components::R.
Referenced by Button_Palette().
void OT_init | ( | T_Occurrence_table * | t | ) |
Initialize an occurrence table.
References T_Occurrence_table::rng_b, T_Occurrence_table::rng_g, T_Occurrence_table::rng_r, and T_Occurrence_table::table.
T_Occurrence_table * OT_new | ( | int | nbb_r, |
int | nbb_g, | ||
int | nbb_b | ||
) |
Allocate an occurrence table for given number of bits.
References T_Occurrence_table::dec_b, T_Occurrence_table::dec_g, T_Occurrence_table::dec_r, T_Occurrence_table::nbb_b, T_Occurrence_table::nbb_g, T_Occurrence_table::nbb_r, NULL, T_Occurrence_table::red_b, T_Occurrence_table::red_g, T_Occurrence_table::red_r, T_Occurrence_table::rng_b, T_Occurrence_table::rng_g, T_Occurrence_table::rng_r, and T_Occurrence_table::table.
Referenced by Optimize_palette().
void OT_delete | ( | T_Occurrence_table * | t | ) |
Delete a table and free the memory.
References NULL, and T_Occurrence_table::table.
Referenced by Optimize_palette().
int OT_get | ( | T_Occurrence_table * | t, |
byte | r, | ||
byte | g, | ||
byte | b | ||
) |
Get number of occurrences for a given color.
References T_Occurrence_table::dec_b, T_Occurrence_table::dec_g, T_Occurrence_table::dec_r, and T_Occurrence_table::table.
Referenced by Cluster_compute_hue().
void OT_inc | ( | T_Occurrence_table * | t, |
byte | r, | ||
byte | g, | ||
byte | b | ||
) |
Add 1 to the count for a color.
References T_Occurrence_table::dec_b, T_Occurrence_table::dec_g, T_Occurrence_table::dec_r, T_Occurrence_table::red_b, T_Occurrence_table::red_g, T_Occurrence_table::red_r, and T_Occurrence_table::table.
Referenced by OT_count_occurrences().
void OT_count_occurrences | ( | T_Occurrence_table * | t, |
T_Bitmap24B | image, | ||
int | size | ||
) |
Count the use of each color in a 24bit picture and fill in the table.
References T_Components::B, T_Components::G, OT_inc(), and T_Components::R.
Referenced by Optimize_palette().
void Cluster_pack | ( | T_Cluster * | c, |
const T_Occurrence_table *const | to | ||
) |
Pack a cluster, ie compute its {r,v,b}{min,max} values.
References T_Cluster::bmax, T_Cluster::bmin, U_Cluster_Data::cut, T_Cluster::data, T_Occurrence_table::dec_b, T_Occurrence_table::dec_g, T_Occurrence_table::dec_r, T_Cluster::occurences, S_Cluster_CutData::plus_large, T_Cluster::rmax, T_Cluster::rmin, S_Cluster_CutData::sqdiag, T_Occurrence_table::table, T_Cluster::vmax, T_Cluster::vmin, and S_Cluster_CutData::volume.
Referenced by CS_Generate(), and CS_Init().
void Cluster_split | ( | T_Cluster * | c, |
T_Cluster * | c1, | ||
T_Cluster * | c2, | ||
int | hue, | ||
const T_Occurrence_table *const | to | ||
) |
Split a cluster on its longest axis.
c = source cluster, c1, c2 = output after split the two output clusters have half population (and not half volume)
References T_Cluster::bmax, T_Cluster::Bmax, T_Cluster::bmin, T_Cluster::Bmin, T_Cluster::Gmin, T_Cluster::occurences, T_Cluster::rmax, T_Cluster::Rmax, T_Cluster::rmin, T_Cluster::Rmin, T_Cluster::vmax, T_Cluster::Vmax, and T_Cluster::vmin.
Referenced by CS_Generate().
void Cluster_compute_hue | ( | T_Cluster * | c, |
T_Occurrence_table * | to | ||
) |
Compute the mean R, G, B (for palette generation) and H, L (for palette sorting)
References S_Cluster_PalData::b, T_Cluster::bmin, T_Cluster::data, S_Cluster_PalData::g, S_Cluster_PalData::h, S_Cluster_PalData::l, T_Cluster::occurences, OT_get(), U_Cluster_Data::pal, S_Cluster_PalData::r, T_Occurrence_table::red_b, T_Occurrence_table::red_g, T_Occurrence_table::red_r, RGB_to_HSL(), T_Cluster::rmin, and T_Cluster::vmin.
Referenced by CS_Compute_colors().
void CS_Init | ( | T_Cluster_set * | cs, |
T_Occurrence_table * | to | ||
) |
Setup the first cluster before we start the operations This one covers the full palette range.
References T_Cluster::bmax, T_Cluster::Bmax, T_Cluster::bmin, T_Cluster::Bmin, Cluster_pack(), T_Cluster_set::clusters, T_Cluster::Gmin, T_Cluster_set::nb, T_Cluster::next, NULL, T_Cluster::rmax, T_Cluster::Rmax, T_Cluster::rmin, T_Cluster::Rmin, T_Occurrence_table::rng_b, T_Occurrence_table::rng_g, T_Occurrence_table::rng_r, T_Cluster::vmax, T_Cluster::Vmax, and T_Cluster::vmin.
Referenced by CS_New().
T_Cluster_set * CS_New | ( | int | nbmax, |
T_Occurrence_table * | to | ||
) |
Allocate a new cluster set.
References T_Cluster_set::clusters, CS_Init(), T_Cluster_set::nb_max, NULL, and OT_count_colors().
Referenced by Optimize_palette().
void CS_Delete | ( | T_Cluster_set * | cs | ) |
Free a cluster set.
References T_Cluster_set::clusters, T_Cluster::next, and NULL.
Referenced by Optimize_palette().
void CS_Get | ( | T_Cluster_set * | cs, |
T_Cluster ** | c | ||
) |
Pop a cluster from the cluster list.
References T_Cluster_set::clusters, T_Cluster_set::nb, and T_Cluster::next.
Referenced by CS_Generate().
int CS_Set | ( | T_Cluster_set * | cs, |
T_Cluster * | c | ||
) |
Push a copy of a cluster in the list return -1 in case of error.
References T_Cluster_set::clusters, U_Cluster_Data::cut, T_Cluster::data, T_Cluster_set::nb, T_Cluster::next, NULL, S_Cluster_CutData::sqdiag, and S_Cluster_CutData::volume.
Referenced by CS_Generate().
int CS_Generate | ( | T_Cluster_set * | cs, |
const T_Occurrence_table *const | to, | ||
CT_Tree * | colorTree | ||
) |
This is the main median cut algorithm and the function actually called to reduce the palette.
We get the number of pixels for each collor in the occurrence table and generate the cluster set from it.
References T_Cluster::Bmax, T_Cluster::Bmin, Cluster_pack(), Cluster_split(), CS_Get(), CS_Set(), CT_set_trad(), U_Cluster_Data::cut, T_Cluster::data, T_Cluster::Gmin, T_Cluster_set::nb, T_Cluster_set::nb_max, T_Cluster::occurences, S_Cluster_CutData::plus_large, T_Cluster::Rmax, T_Cluster::Rmin, T_Cluster::Vmax, and S_Cluster_CutData::volume.
Referenced by Optimize_palette().
void CS_Compute_colors | ( | T_Cluster_set * | cs, |
T_Occurrence_table * | to | ||
) |
Compute the color associated to each box in the list.
References Cluster_compute_hue(), T_Cluster_set::clusters, T_Cluster::next, and NULL.
Referenced by Optimize_palette().
void CS_Generate_color_table_and_palette | ( | T_Cluster_set * | cs, |
CT_Tree * | tc, | ||
T_Components * | palette, | ||
T_Occurrence_table * | to | ||
) |
Generates the palette from the clusters, then the conversion table to map (RGB) to a palette index.
References S_Cluster_PalData::b, T_Components::B, T_Cluster::Bmax, T_Cluster::Bmin, T_Cluster_set::clusters, CT_set_trad(), T_Cluster::data, S_Cluster_PalData::g, T_Components::G, T_Cluster::Gmin, T_Cluster_set::nb, T_Cluster::next, U_Cluster_Data::pal, S_Cluster_PalData::r, T_Components::R, T_Cluster::Rmax, T_Cluster::Rmin, and T_Cluster::Vmax.
Referenced by Optimize_palette().
void GS_Init | ( | T_Gradient_set * | ds, |
T_Cluster_set * | cs | ||
) |
References T_Cluster_set::clusters, T_Cluster::data, T_Gradient_set::gradients, S_Cluster_PalData::h, T_Gradient::hue, T_Gradient::max, T_Gradient::min, T_Gradient_set::nb, T_Gradient::nb_colors, and U_Cluster_Data::pal.
Referenced by GS_New().
T_Gradient_set * GS_New | ( | T_Cluster_set * | cs | ) |
References T_Gradient_set::gradients, GS_Init(), T_Cluster_set::nb_max, T_Gradient_set::nb_max, and NULL.
Referenced by Optimize_palette().
void GS_Delete | ( | T_Gradient_set * | ds | ) |
References T_Gradient_set::gradients.
Referenced by Optimize_palette().
void GS_Generate | ( | T_Gradient_set * | ds, |
T_Cluster_set * | cs | ||
) |
int Convert_24b_bitmap_to_256 | ( | T_Bitmap256 | dest, |
T_Bitmap24B | source, | ||
int | width, | ||
int | height, | ||
T_Components * | palette | ||
) |
Converts a 24 bit picture to 256 color (color reduction)
[out] | dest | The converted 8bpp picture |
[in] | source | the 24bpp picture |
[in] | width | the width of the picture |
[in] | height | the height of the picture |
[out] | palette | the palette of the converted 8bpp picture |
References Convert_24b_bitmap_to_256_nearest_neighbor(), CT_delete(), NULL, Optimize_palette(), precision_24b, and Try_Convert_to_256_Without_Loss().
Referenced by Load_image(), and Test_Convert_24b_bitmap_to_256().