GrafX2 2.9.3227
The ultimate 256-color painting program
palette.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "const.h"
#include "struct.h"
#include "global.h"
#include "misc.h"
#include "engine.h"
#include "readline.h"
#include "buttons.h"
#include "pages.h"
#include "help.h"
#include "screen.h"
#include "errors.h"
#include "op_c.h"
#include "windows.h"
#include "input.h"
#include "graph.h"
#include "palette.h"
#include "shade.h"
+ Include dependency graph for palette.c:

Functions

static void Component_unit (int count)
 
void Set_palette_RGB_scale (int scale)
 Choose the number of graduations for RGB components, from 2 to 256. More...
 
int Get_palette_RGB_scale (void)
 
void Set_palette_Gamma (int gamma)
 Configure Gamma correction. More...
 
byte Round_palette_component (byte comp)
 Round a 0-255 RGB component according to the RGB_scale and gamm correction. More...
 
static int Decode_component (int comp)
 Turns a RGB component from 0-(RGB_scale-1) scale to 0-255 and apply reverse. More...
 
int Encode_component (int comp)
 Turns a RGB component from 0-255 to 0-(RGB_scale-1) and apply Gamma correction. More...
 
static int Add_encoded (int comp, int offset)
 Compute the component at a given distance from the current one. More...
 
void Set_HSL (T_Palette start_palette, T_Palette end_palette, byte color, short diff_h, short diff_s, short diff_l)
 
void Set_red (byte color, short new_color, T_Palette palette)
 
void Set_green (byte color, short new_color, T_Palette palette)
 
void Set_blue (byte color, short new_color, T_Palette palette)
 
void Format_component (byte value, char *str)
 
void Spread_colors (short start, short end, T_Palette palette)
 
void Palette_edit_step ()
 Backup before doing one self-complete change. More...
 
void Palette_edit_select_range ()
 Mode for incremental changes. More...
 
void Palette_edit_alter_channel ()
 Perform incremental change in RGB channel of some color(s). More...
 
void Palette_edit_undo_redo ()
 Undo. More...
 
void Update_color_count (short *used_colors, dword *color_usage)
 
void Remap_zone_highlevel (short x1, short y1, short x2, short y2, byte *conversion_table)
 
void Remap_image_highlevel (byte *conversion_table)
 
void Swap (int with_remap, short block_1_start, short block_2_start, short block_size, T_Palette palette, dword *color_usage)
 
void Set_nice_menu_colors (dword *color_usage, int not_picture)
 Adds 4 menu colors in the current palette. More...
 
void Reduce_palette (short *used_colors, int nb_colors_asked, T_Palette palette, dword *color_usage)
 
void Set_palette_slider (T_Scroller_button *slider, word nb_elements, word position, char *value, short x_pos)
 
void Display_sliders (T_Scroller_button *red_slider, T_Scroller_button *green_slider, T_Scroller_button *blue_slider, byte block_is_selected, T_Components *palette)
 
void Draw_all_palette_sliders (T_Scroller_button *red_slider, T_Scroller_button *green_slider, T_Scroller_button *blue_slider, T_Palette palette, byte start, byte end)
 
int Window_Histogram (unsigned char block_start, unsigned char block_end, dword *color_usage)
 
void Print_RGB_or_HSL (byte mode)
 
void Tag_used_colors (byte color, dword color_usage[])
 
void Button_Palette (int btn)
 Open the palette menu and handles everything inside it. More...
 
void Button_Secondary_palette (int btn)
 Open the secondary palette menu and handles it. More...
 
void Set_clipboard_colors (int nb_colors, T_Components *colors)
 Put some colors in the clipboard. More...
 
int Get_clipboard_colors (T_Palette palette, byte start_color)
 Get some RGB colors from clipboard. More...
 
const T_ComponentsFavorite_GUI_color (byte color_index)
 Get the favorite color to use for GUI's black,dark,light or white. More...
 

Variables

static byte Palette_view_is_RGB = 1
 
static float Gamma = 1.0
 
static const int COUNT_X = 138
 
static const int COUNT_Y = 64
 
int RGB_scale = 256
 
int Color_count =256
 
int Color_max =255
 
int Color_halfstep =0
 
T_Componentsbackup_palette
 
T_Componentstemp_palette
 
T_Componentsworking_palette
 
byte Palette_undo_state = 0
 
byte Palette_change_state = 0
 
static const int NUMERIC_R_X = 216
 
static const int NUMERIC_G_X = 243
 
static const int NUMERIC_B_X = 270
 
static const int NUMERIC_Y = 183
 
static const int NUMERIC_BOX_X = 215
 
static const int NUMERIC_BOX_Y = 181
 
static const int NUMERIC_BOX_W = 81
 
static const int NUMERIC_BOX_H = 12
 
int Palette_clipboard_count =0
 
T_Palette Palette_clipboard
 

Function Documentation

◆ Component_unit()

static void Component_unit ( int  count)
static

◆ Set_palette_RGB_scale()

void Set_palette_RGB_scale ( int  scale)

Choose the number of graduations for RGB components, from 2 to 256.

References Component_unit(), and RGB_scale.

Referenced by Analyze_command_line(), Button_Constraint_menu(), and Button_Secondary_palette().

◆ Get_palette_RGB_scale()

int Get_palette_RGB_scale ( void  )

◆ Set_palette_Gamma()

void Set_palette_Gamma ( int  gamma)

Configure Gamma correction.

References Gamma.

Referenced by Analyze_command_line(), and Button_Constraint_menu().

◆ Round_palette_component()

byte Round_palette_component ( byte  comp)

Round a 0-255 RGB component according to the RGB_scale and gamm correction.

Scale a component (R, G or B) according to the current RGB graduations.

The result is also in the 0-255 range.

References Gamma, and RGB_scale.

Referenced by Compute_optimal_menu_colors(), Set_blue(), Set_green(), Set_nice_menu_colors(), Set_palette(), and Set_red().

◆ Decode_component()

static int Decode_component ( int  comp)
static

Turns a RGB component from 0-(RGB_scale-1) scale to 0-255 and apply reverse.

The passed value should come from Round_palette_component(), otherwise the rounding will be "down".

References Color_max, and Gamma.

Referenced by Add_encoded(), Button_Palette(), and Spread_colors().

◆ Encode_component()

int Encode_component ( int  comp)

Turns a RGB component from 0-255 to 0-(RGB_scale-1) and apply Gamma correction.

Turns a RGB component from 0-255 to 0-(RGB_scale-1) with Gamma correction.

References Color_max, and Gamma.

Referenced by Add_encoded(), Display_sliders(), Draw_all_palette_sliders(), Spread_colors(), and Status_print_palette_color().

◆ Add_encoded()

static int Add_encoded ( int  comp,
int  offset 
)
static

Compute the component at a given distance from the current one.

Used by the add/remove and lighten/darken operations.

References Decode_component(), and Encode_component().

Referenced by Button_Palette().

◆ Set_HSL()

void Set_HSL ( T_Palette  start_palette,
T_Palette  end_palette,
byte  color,
short  diff_h,
short  diff_s,
short  diff_l 
)

References HSL_to_RGB(), and RGB_to_HSL().

Referenced by Button_Palette().

◆ Set_red()

void Set_red ( byte  color,
short  new_color,
T_Palette  palette 
)

◆ Set_green()

void Set_green ( byte  color,
short  new_color,
T_Palette  palette 
)

◆ Set_blue()

void Set_blue ( byte  color,
short  new_color,
T_Palette  palette 
)

◆ Format_component()

void Format_component ( byte  value,
char *  str 
)

◆ Spread_colors()

void Spread_colors ( short  start,
short  end,
T_Palette  palette 
)

◆ Palette_edit_step()

void Palette_edit_step ( )

Backup before doing one self-complete change.

References backup_palette, Palette_change_state, Palette_undo_state, and working_palette.

Referenced by Button_Palette().

◆ Palette_edit_select_range()

void Palette_edit_select_range ( )

Mode for incremental changes.

References Palette_change_state.

Referenced by Button_Palette().

◆ Palette_edit_alter_channel()

void Palette_edit_alter_channel ( )

Perform incremental change in RGB channel of some color(s).

References backup_palette, Palette_change_state, temp_palette, and working_palette.

Referenced by Button_Palette().

◆ Palette_edit_undo_redo()

void Palette_edit_undo_redo ( )

◆ Update_color_count()

void Update_color_count ( short *  used_colors,
dword color_usage 
)

◆ Remap_zone_highlevel()

void Remap_zone_highlevel ( short  x1,
short  y1,
short  x2,
short  y2,
byte conversion_table 
)

◆ Remap_image_highlevel()

◆ Swap()

void Swap ( int  with_remap,
short  block_1_start,
short  block_2_start,
short  block_size,
T_Palette  palette,
dword color_usage 
)

◆ Set_nice_menu_colors()

void Set_nice_menu_colors ( dword color_usage,
int  not_picture 
)

Adds 4 menu colors in the current palette.

Parameters
color_usageAn up-to-date color usage table (byte[256]) (read only)
not_picture0 if the caller is the palette screen, 1 if it's a preview in the file selector.

References T_Components::B, Best_color_nonexcluded(), Display_cursor(), Favorite_GUI_color(), T_Components::G, Hide_cursor, Main, T_Document::palette, T_Components::R, Remap_image_highlevel(), Remap_zone_highlevel(), Round_palette_component(), Screen_height, and Screen_width.

Referenced by Button_Palette().

◆ Reduce_palette()

void Reduce_palette ( short *  used_colors,
int  nb_colors_asked,
T_Palette  palette,
dword color_usage 
)

◆ Set_palette_slider()

void Set_palette_slider ( T_Scroller_button slider,
word  nb_elements,
word  position,
char *  value,
short  x_pos 
)

◆ Display_sliders()

◆ Draw_all_palette_sliders()

◆ Window_Histogram()

◆ Print_RGB_or_HSL()

void Print_RGB_or_HSL ( byte  mode)

References MC_Dark, MC_Light, mode, and Print_in_window().

Referenced by Button_Palette().

◆ Tag_used_colors()

void Tag_used_colors ( byte  color,
dword  color_usage[] 
)

◆ Button_Palette()

void Button_Palette ( int  btn)

Open the palette menu and handles everything inside it.

References Add_encoded(), T_Components::B, Back_color, Backup_layers(), backup_palette, T_Dropdown_button::Bottom_up, BUTTON_COLORPICKER, BUTTON_HELP, BUTTON_PALETTE, BUTTON_UNDO, Close_window(), Color_count, Color_max, Component_unit(), Compute_optimal_menu_colors(), Config, CONTEXT_PALETTE, Decode_component(), Display_cursor(), Display_grad_block_in_window(), Display_menu(), Display_sliders(), Draw_all_palette_sliders(), Draw_thingumajig(), Dropdown_activate(), T_Dropdown_button::Dropdown_width, End_of_modification(), T_Dropdown_button::First_item, Fore_color, Format_component(), T_Components::G, Get_clipboard_colors(), Get_color_behind_window(), T_Dropdown_button::Height, Hide_cursor, HSL_to_RGB(), Input_sticky_control, INPUT_TYPE_HEXA, Is_shortcut(), Key, KEY_b, KEY_BACKSPACE, KEY_c, KEY_d, KEY_DELETE, KEY_e, KEY_ESC, KEY_f, KEY_g, KEY_h, KEY_i, KEY_KP_MINUS, KEY_KP_PLUS, KEY_l, KEY_m, KEY_n, KEY_NONE, KEY_RETURN, KEY_s, KEY_t, KEY_u, KEY_w, KEY_x, L1, L2, L3, L4, LAYER_ALL, LAYER_NONE, LEFT_SIDE, Load_picture(), Main, MC_Black, MC_Dark, MC_Light, MC_White, Menu_factor_Y, Menu_Y_before_window, Mouse_K, Mouse_X, Mouse_Y, NULL, Num2str, T_Dropdown_choice::Number, NUMERIC_B_X, NUMERIC_BOX_H, NUMERIC_BOX_W, NUMERIC_BOX_X, NUMERIC_BOX_Y, NUMERIC_G_X, NUMERIC_R_X, NUMERIC_Y, Open_window(), T_Document::palette, Palette_edit_alter_channel(), Palette_edit_select_range(), Palette_edit_step(), Palette_edit_undo_redo(), Palette_view_is_RGB, Perceptual_lightness(), T_Dropdown_button::Pos_X, T_Dropdown_button::Pos_Y, T_Scroller_button::Position, Print_counter(), Print_in_window(), Print_RGB_or_HSL(), Quit_is_required, T_Components::R, Read_pixel, Readline(), Reduce_palette(), Remap_image_highlevel(), Remap_screen_after_menu_colors_change(), Reposition_palette(), Requester_window(), RGB_scale, RGB_to_HSL(), RIGHT_SIDE, T_Config::Safety_colors, Save_picture(), Screen_width, Select_button(), Set_blue(), Set_clipboard_colors(), Set_green(), Set_HSL(), Set_nice_menu_colors(), Set_palette(), Set_red(), SHORTCUT_COPY, SHORTCUT_PASTE, SPECIAL_NEXT_BACKCOLOR, SPECIAL_NEXT_FORECOLOR, SPECIAL_PREVIOUS_BACKCOLOR, SPECIAL_PREVIOUS_FORECOLOR, Spread_colors(), Swap(), SWAP_BYTES, SWAP_DWORDS, Tag_color_range(), Tag_used_colors(), temp_palette, Unselect_button(), Update_color_count(), Update_rect(), Update_window_area, Wait_click_in_palette(), Wait_end_of_click(), Window_attribute2, Window_clicked_button(), Window_display_frame_mono(), Window_draw_normal_bouton(), Window_draw_palette_bouton(), Window_draw_slider(), Window_dropdown_add_item(), Window_dropdown_clear_items(), Window_height, Window_help(), Window_Histogram(), Window_palette_button_list, Window_pos_Y, Window_rectangle(), Window_set_dropdown_button(), Window_set_normal_button(), Window_set_palette_button(), Window_set_repeatable_button(), Window_set_scroller_button(), and working_palette.

Referenced by Button_Select_forecolor().

◆ Button_Secondary_palette()

◆ Set_clipboard_colors()

void Set_clipboard_colors ( int  nb_colors,
T_Components colors 
)

Put some colors in the clipboard.

Parameters
nb_colorsNumber of colors to push
colorsFirst color of the input array

References Palette_clipboard, and Palette_clipboard_count.

Referenced by Button_Palette().

◆ Get_clipboard_colors()

int Get_clipboard_colors ( T_Palette  palette,
byte  start_color 
)

Get some RGB colors from clipboard.

Parameters
paletteTarget palette
start_colorIndex of first color to replace
Returns
Number of colors retrieved (0-256)

References Palette_clipboard, and Palette_clipboard_count.

Referenced by Button_Palette().

◆ Favorite_GUI_color()

const T_Components * Favorite_GUI_color ( byte  color_index)

Get the favorite color to use for GUI's black,dark,light or white.

References T_Components::B, T_Gui_skin::Color, T_Gui_skin::Default_palette, T_Components::G, Gfx, T_Components::R, and RGB_scale.

Referenced by Button_Constraint_menu(), Load_image(), and Set_nice_menu_colors().

Variable Documentation

◆ Palette_view_is_RGB

byte Palette_view_is_RGB = 1
static

◆ Gamma

◆ COUNT_X

const int COUNT_X = 138
static

◆ COUNT_Y

const int COUNT_Y = 64
static

◆ RGB_scale

◆ Color_count

int Color_count =256

◆ Color_max

◆ Color_halfstep

int Color_halfstep =0

Referenced by Component_unit().

◆ backup_palette

◆ temp_palette

◆ working_palette

◆ Palette_undo_state

byte Palette_undo_state = 0

◆ Palette_change_state

◆ NUMERIC_R_X

const int NUMERIC_R_X = 216
static

◆ NUMERIC_G_X

const int NUMERIC_G_X = 243
static

◆ NUMERIC_B_X

const int NUMERIC_B_X = 270
static

◆ NUMERIC_Y

const int NUMERIC_Y = 183
static

◆ NUMERIC_BOX_X

const int NUMERIC_BOX_X = 215
static

Referenced by Button_Palette().

◆ NUMERIC_BOX_Y

const int NUMERIC_BOX_Y = 181
static

Referenced by Button_Palette().

◆ NUMERIC_BOX_W

const int NUMERIC_BOX_W = 81
static

Referenced by Button_Palette().

◆ NUMERIC_BOX_H

const int NUMERIC_BOX_H = 12
static

Referenced by Button_Palette().

◆ Palette_clipboard_count

int Palette_clipboard_count =0

◆ Palette_clipboard

T_Palette Palette_clipboard