cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

palette.h (5673B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#ifndef GUAC_TERMINAL_PALETTE_H
     21#define GUAC_TERMINAL_PALETTE_H
     22
     23/**
     24 * Constants, structures, and function definitions related to the terminal color pallate.
     25 *
     26 * @file palette.h
     27 */
     28
     29
     30#include <stdint.h>
     31
     32/**
     33 * The pseudo-index of the color set as the the default foreground color for
     34 * the terminal. Regardless of what changes are made to the palette, this index
     35 * will always return the current default foreground color.
     36 */
     37#define GUAC_TERMINAL_COLOR_FOREGROUND -2
     38
     39/**
     40 * The pseudo-index of the color set as the the default background color for
     41 * the terminal. Regardless of what changes are made to the palette, this index
     42 * will always return the current default background color.
     43 */
     44#define GUAC_TERMINAL_COLOR_BACKGROUND -3
     45
     46/**
     47 * The index of black within the terminal color palette.
     48 */
     49#define GUAC_TERMINAL_COLOR_BLACK 0
     50
     51/**
     52 * The index of low-intensity red within the terminal color palette.
     53 */
     54#define GUAC_TERMINAL_COLOR_DARK_RED 1
     55
     56/**
     57 * The index of low-intensity green within the terminal color palette.
     58 */
     59#define GUAC_TERMINAL_COLOR_DARK_GREEN 2
     60
     61/**
     62 * The index of brown within the terminal color palette.
     63 */
     64#define GUAC_TERMINAL_COLOR_BROWN 3
     65
     66/**
     67 * The index of low-intensity blue within the terminal color palette.
     68 */
     69#define GUAC_TERMINAL_COLOR_DARK_BLUE 4
     70
     71/**
     72 * The index of low-intensity magenta (purple) within the terminal color
     73 * palette.
     74 */
     75#define GUAC_TERMINAL_COLOR_PURPLE 5
     76
     77/**
     78 * The index of low-intensity cyan (teal) within the terminal color palette.
     79 */
     80#define GUAC_TERMINAL_COLOR_TEAL 6
     81
     82/**
     83 * The index of low-intensity white (gray) within the terminal color palette.
     84 */
     85#define GUAC_TERMINAL_COLOR_GRAY 7
     86
     87/**
     88 * The index of bright black (dark gray) within the terminal color palette.
     89 */
     90#define GUAC_TERMINAL_COLOR_DARK_GRAY 8
     91
     92/**
     93 * The index of bright red within the terminal color palette.
     94 */
     95#define GUAC_TERMINAL_COLOR_RED 9
     96
     97/**
     98 * The index of bright green within the terminal color palette.
     99 */
    100#define GUAC_TERMINAL_COLOR_GREEN 10
    101
    102/**
    103 * The index of bright brown (yellow) within the terminal color palette.
    104 */
    105#define GUAC_TERMINAL_COLOR_YELLOW 11
    106
    107/**
    108 * The index of bright blue within the terminal color palette.
    109 */
    110#define GUAC_TERMINAL_COLOR_BLUE 12
    111
    112/**
    113 * The index of bright magenta within the terminal color palette.
    114 */
    115#define GUAC_TERMINAL_COLOR_MAGENTA 13
    116
    117/**
    118 * The index of bright cyan within the terminal color palette.
    119 */
    120#define GUAC_TERMINAL_COLOR_CYAN 14
    121
    122/**
    123 * The index of bright white within the terminal color palette.
    124 */
    125#define GUAC_TERMINAL_COLOR_WHITE 15
    126
    127/**
    128 * The index of the first low-intensity color in the 16-color portion of the
    129 * palette.
    130 */
    131#define GUAC_TERMINAL_FIRST_DARK 0
    132
    133/**
    134 * The index of the last low-intensity color in the 16-color portion of the
    135 * palette.
    136 */
    137#define GUAC_TERMINAL_LAST_DARK 7
    138
    139/**
    140 * The index of the first high-intensity color in the 16-color portion of the
    141 * palette.
    142 */
    143#define GUAC_TERMINAL_FIRST_INTENSE 8
    144
    145/**
    146 * The index of the last high-intensity color in the 16-color portion of the
    147 * palette.
    148 */
    149#define GUAC_TERMINAL_LAST_INTENSE 15
    150
    151/**
    152 * The distance between the palette indices of the dark colors (0 through 7)
    153 * and the bright colors (8 - 15) in the 16-color portion of the palette.
    154 */
    155#define GUAC_TERMINAL_INTENSE_OFFSET 8
    156
    157/**
    158 * An RGB color, where each component ranges from 0 to 255.
    159 */
    160typedef struct guac_terminal_color {
    161
    162    /**
    163     * The index of this color within the terminal palette, or -1 if the color
    164     * does not exist within the terminal palette.
    165     */
    166    int palette_index;
    167
    168    /**
    169     * The red component of this color.
    170     */
    171    uint8_t red;
    172
    173    /**
    174     * The green component of this color.
    175     */
    176    uint8_t green;
    177
    178    /**
    179     * The blue component of this color.
    180     */
    181    uint8_t blue;
    182
    183} guac_terminal_color;
    184
    185/**
    186 * Compares two colors, returning a negative value if the first color is less
    187 * than the second, a positive value if the first color is greater than the
    188 * second, and zero if the colors are identical. Only the color components are
    189 * compared (not the palette index). The red component is considered the
    190 * highest order component, followed by green, followed by blue.
    191 *
    192 * @param a
    193 *     The first color to compare.
    194 *
    195 * @param b
    196 *     The second color to compare.
    197 *
    198 * @return
    199 *    A negative value if the first color is less than the second, a positive
    200 *    value if the first color is greater than the second, and zero if the
    201 *    colors are identical.
    202 */
    203int guac_terminal_colorcmp(const guac_terminal_color* a,
    204        const guac_terminal_color* b);
    205
    206/**
    207 * The initial state of the terminal color palette. The color palette used by
    208 * the terminal may modified after the terminal is created through console
    209 * codes.
    210 */
    211extern const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256];
    212
    213#endif
    214