cscg24-guacamole

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

palette.c (9273B)


      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#include "terminal/palette.h"
     21
     22const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256] = {
     23
     24    /* Normal colors */
     25    {0, 0x00, 0x00, 0x00}, /* Black   */
     26    {1, 0x99, 0x3E, 0x3E}, /* Red     */
     27    {2, 0x3E, 0x99, 0x3E}, /* Green   */
     28    {3, 0x99, 0x99, 0x3E}, /* Brown   */
     29    {4, 0x3E, 0x3E, 0x99}, /* Blue    */
     30    {5, 0x99, 0x3E, 0x99}, /* Magenta */
     31    {6, 0x3E, 0x99, 0x99}, /* Cyan    */
     32    {7, 0x99, 0x99, 0x99}, /* White   */
     33
     34    /* Intense colors */
     35    {8,  0x3E, 0x3E, 0x3E}, /* Black   */
     36    {9,  0xFF, 0x67, 0x67}, /* Red     */
     37    {10, 0x67, 0xFF, 0x67}, /* Green   */
     38    {11, 0xFF, 0xFF, 0x67}, /* Brown   */
     39    {12, 0x67, 0x67, 0xFF}, /* Blue    */
     40    {13, 0xFF, 0x67, 0xFF}, /* Magenta */
     41    {14, 0x67, 0xFF, 0xFF}, /* Cyan    */
     42    {15, 0xFF, 0xFF, 0xFF}, /* White   */
     43
     44    /* Remainder of xterm's 256-color palette */
     45    {16,  0x00, 0x00, 0x00},
     46    {17,  0x00, 0x00, 0x5F},
     47    {18,  0x00, 0x00, 0x87},
     48    {19,  0x00, 0x00, 0xAF},
     49    {20,  0x00, 0x00, 0xD7},
     50    {21,  0x00, 0x00, 0xFF},
     51    {22,  0x00, 0x5F, 0x00},
     52    {23,  0x00, 0x5F, 0x5F},
     53    {24,  0x00, 0x5F, 0x87},
     54    {25,  0x00, 0x5F, 0xAF},
     55    {26,  0x00, 0x5F, 0xD7},
     56    {27,  0x00, 0x5F, 0xFF},
     57    {28,  0x00, 0x87, 0x00},
     58    {29,  0x00, 0x87, 0x5F},
     59    {30,  0x00, 0x87, 0x87},
     60    {31,  0x00, 0x87, 0xAF},
     61    {32,  0x00, 0x87, 0xD7},
     62    {33,  0x00, 0x87, 0xFF},
     63    {34,  0x00, 0xAF, 0x00},
     64    {35,  0x00, 0xAF, 0x5F},
     65    {36,  0x00, 0xAF, 0x87},
     66    {37,  0x00, 0xAF, 0xAF},
     67    {38,  0x00, 0xAF, 0xD7},
     68    {39,  0x00, 0xAF, 0xFF},
     69    {40,  0x00, 0xD7, 0x00},
     70    {41,  0x00, 0xD7, 0x5F},
     71    {42,  0x00, 0xD7, 0x87},
     72    {43,  0x00, 0xD7, 0xAF},
     73    {44,  0x00, 0xD7, 0xD7},
     74    {45,  0x00, 0xD7, 0xFF},
     75    {46,  0x00, 0xFF, 0x00},
     76    {47,  0x00, 0xFF, 0x5F},
     77    {48,  0x00, 0xFF, 0x87},
     78    {49,  0x00, 0xFF, 0xAF},
     79    {50,  0x00, 0xFF, 0xD7},
     80    {51,  0x00, 0xFF, 0xFF},
     81    {52,  0x5F, 0x00, 0x00},
     82    {53,  0x5F, 0x00, 0x5F},
     83    {54,  0x5F, 0x00, 0x87},
     84    {55,  0x5F, 0x00, 0xAF},
     85    {56,  0x5F, 0x00, 0xD7},
     86    {57,  0x5F, 0x00, 0xFF},
     87    {58,  0x5F, 0x5F, 0x00},
     88    {59,  0x5F, 0x5F, 0x5F},
     89    {60,  0x5F, 0x5F, 0x87},
     90    {61,  0x5F, 0x5F, 0xAF},
     91    {62,  0x5F, 0x5F, 0xD7},
     92    {63,  0x5F, 0x5F, 0xFF},
     93    {64,  0x5F, 0x87, 0x00},
     94    {65,  0x5F, 0x87, 0x5F},
     95    {66,  0x5F, 0x87, 0x87},
     96    {67,  0x5F, 0x87, 0xAF},
     97    {68,  0x5F, 0x87, 0xD7},
     98    {69,  0x5F, 0x87, 0xFF},
     99    {70,  0x5F, 0xAF, 0x00},
    100    {71,  0x5F, 0xAF, 0x5F},
    101    {72,  0x5F, 0xAF, 0x87},
    102    {73,  0x5F, 0xAF, 0xAF},
    103    {74,  0x5F, 0xAF, 0xD7},
    104    {75,  0x5F, 0xAF, 0xFF},
    105    {76,  0x5F, 0xD7, 0x00},
    106    {77,  0x5F, 0xD7, 0x5F},
    107    {78,  0x5F, 0xD7, 0x87},
    108    {79,  0x5F, 0xD7, 0xAF},
    109    {80,  0x5F, 0xD7, 0xD7},
    110    {81,  0x5F, 0xD7, 0xFF},
    111    {82,  0x5F, 0xFF, 0x00},
    112    {83,  0x5F, 0xFF, 0x5F},
    113    {84,  0x5F, 0xFF, 0x87},
    114    {85,  0x5F, 0xFF, 0xAF},
    115    {86,  0x5F, 0xFF, 0xD7},
    116    {87,  0x5F, 0xFF, 0xFF},
    117    {88,  0x87, 0x00, 0x00},
    118    {89,  0x87, 0x00, 0x5F},
    119    {90,  0x87, 0x00, 0x87},
    120    {91,  0x87, 0x00, 0xAF},
    121    {92,  0x87, 0x00, 0xD7},
    122    {93,  0x87, 0x00, 0xFF},
    123    {94,  0x87, 0x5F, 0x00},
    124    {95,  0x87, 0x5F, 0x5F},
    125    {96,  0x87, 0x5F, 0x87},
    126    {97,  0x87, 0x5F, 0xAF},
    127    {98,  0x87, 0x5F, 0xD7},
    128    {99,  0x87, 0x5F, 0xFF},
    129    {100, 0x87, 0x87, 0x00},
    130    {101, 0x87, 0x87, 0x5F},
    131    {102, 0x87, 0x87, 0x87},
    132    {103, 0x87, 0x87, 0xAF},
    133    {104, 0x87, 0x87, 0xD7},
    134    {105, 0x87, 0x87, 0xFF},
    135    {106, 0x87, 0xAF, 0x00},
    136    {107, 0x87, 0xAF, 0x5F},
    137    {108, 0x87, 0xAF, 0x87},
    138    {109, 0x87, 0xAF, 0xAF},
    139    {110, 0x87, 0xAF, 0xD7},
    140    {111, 0x87, 0xAF, 0xFF},
    141    {112, 0x87, 0xD7, 0x00},
    142    {113, 0x87, 0xD7, 0x5F},
    143    {114, 0x87, 0xD7, 0x87},
    144    {115, 0x87, 0xD7, 0xAF},
    145    {116, 0x87, 0xD7, 0xD7},
    146    {117, 0x87, 0xD7, 0xFF},
    147    {118, 0x87, 0xFF, 0x00},
    148    {119, 0x87, 0xFF, 0x5F},
    149    {120, 0x87, 0xFF, 0x87},
    150    {121, 0x87, 0xFF, 0xAF},
    151    {122, 0x87, 0xFF, 0xD7},
    152    {123, 0x87, 0xFF, 0xFF},
    153    {124, 0xAF, 0x00, 0x00},
    154    {125, 0xAF, 0x00, 0x5F},
    155    {126, 0xAF, 0x00, 0x87},
    156    {127, 0xAF, 0x00, 0xAF},
    157    {128, 0xAF, 0x00, 0xD7},
    158    {129, 0xAF, 0x00, 0xFF},
    159    {130, 0xAF, 0x5F, 0x00},
    160    {131, 0xAF, 0x5F, 0x5F},
    161    {132, 0xAF, 0x5F, 0x87},
    162    {133, 0xAF, 0x5F, 0xAF},
    163    {134, 0xAF, 0x5F, 0xD7},
    164    {135, 0xAF, 0x5F, 0xFF},
    165    {136, 0xAF, 0x87, 0x00},
    166    {137, 0xAF, 0x87, 0x5F},
    167    {138, 0xAF, 0x87, 0x87},
    168    {139, 0xAF, 0x87, 0xAF},
    169    {140, 0xAF, 0x87, 0xD7},
    170    {141, 0xAF, 0x87, 0xFF},
    171    {142, 0xAF, 0xAF, 0x00},
    172    {143, 0xAF, 0xAF, 0x5F},
    173    {144, 0xAF, 0xAF, 0x87},
    174    {145, 0xAF, 0xAF, 0xAF},
    175    {146, 0xAF, 0xAF, 0xD7},
    176    {147, 0xAF, 0xAF, 0xFF},
    177    {148, 0xAF, 0xD7, 0x00},
    178    {149, 0xAF, 0xD7, 0x5F},
    179    {150, 0xAF, 0xD7, 0x87},
    180    {151, 0xAF, 0xD7, 0xAF},
    181    {152, 0xAF, 0xD7, 0xD7},
    182    {153, 0xAF, 0xD7, 0xFF},
    183    {154, 0xAF, 0xFF, 0x00},
    184    {155, 0xAF, 0xFF, 0x5F},
    185    {156, 0xAF, 0xFF, 0x87},
    186    {157, 0xAF, 0xFF, 0xAF},
    187    {158, 0xAF, 0xFF, 0xD7},
    188    {159, 0xAF, 0xFF, 0xFF},
    189    {160, 0xD7, 0x00, 0x00},
    190    {161, 0xD7, 0x00, 0x5F},
    191    {162, 0xD7, 0x00, 0x87},
    192    {163, 0xD7, 0x00, 0xAF},
    193    {164, 0xD7, 0x00, 0xD7},
    194    {165, 0xD7, 0x00, 0xFF},
    195    {166, 0xD7, 0x5F, 0x00},
    196    {167, 0xD7, 0x5F, 0x5F},
    197    {168, 0xD7, 0x5F, 0x87},
    198    {169, 0xD7, 0x5F, 0xAF},
    199    {170, 0xD7, 0x5F, 0xD7},
    200    {171, 0xD7, 0x5F, 0xFF},
    201    {172, 0xD7, 0x87, 0x00},
    202    {173, 0xD7, 0x87, 0x5F},
    203    {174, 0xD7, 0x87, 0x87},
    204    {175, 0xD7, 0x87, 0xAF},
    205    {176, 0xD7, 0x87, 0xD7},
    206    {177, 0xD7, 0x87, 0xFF},
    207    {178, 0xD7, 0xAF, 0x00},
    208    {179, 0xD7, 0xAF, 0x5F},
    209    {180, 0xD7, 0xAF, 0x87},
    210    {181, 0xD7, 0xAF, 0xAF},
    211    {182, 0xD7, 0xAF, 0xD7},
    212    {183, 0xD7, 0xAF, 0xFF},
    213    {184, 0xD7, 0xD7, 0x00},
    214    {185, 0xD7, 0xD7, 0x5F},
    215    {186, 0xD7, 0xD7, 0x87},
    216    {187, 0xD7, 0xD7, 0xAF},
    217    {188, 0xD7, 0xD7, 0xD7},
    218    {189, 0xD7, 0xD7, 0xFF},
    219    {190, 0xD7, 0xFF, 0x00},
    220    {191, 0xD7, 0xFF, 0x5F},
    221    {192, 0xD7, 0xFF, 0x87},
    222    {193, 0xD7, 0xFF, 0xAF},
    223    {194, 0xD7, 0xFF, 0xD7},
    224    {195, 0xD7, 0xFF, 0xFF},
    225    {196, 0xFF, 0x00, 0x00},
    226    {197, 0xFF, 0x00, 0x5F},
    227    {198, 0xFF, 0x00, 0x87},
    228    {199, 0xFF, 0x00, 0xAF},
    229    {200, 0xFF, 0x00, 0xD7},
    230    {201, 0xFF, 0x00, 0xFF},
    231    {202, 0xFF, 0x5F, 0x00},
    232    {203, 0xFF, 0x5F, 0x5F},
    233    {204, 0xFF, 0x5F, 0x87},
    234    {205, 0xFF, 0x5F, 0xAF},
    235    {206, 0xFF, 0x5F, 0xD7},
    236    {207, 0xFF, 0x5F, 0xFF},
    237    {208, 0xFF, 0x87, 0x00},
    238    {209, 0xFF, 0x87, 0x5F},
    239    {210, 0xFF, 0x87, 0x87},
    240    {211, 0xFF, 0x87, 0xAF},
    241    {212, 0xFF, 0x87, 0xD7},
    242    {213, 0xFF, 0x87, 0xFF},
    243    {214, 0xFF, 0xAF, 0x00},
    244    {215, 0xFF, 0xAF, 0x5F},
    245    {216, 0xFF, 0xAF, 0x87},
    246    {217, 0xFF, 0xAF, 0xAF},
    247    {218, 0xFF, 0xAF, 0xD7},
    248    {219, 0xFF, 0xAF, 0xFF},
    249    {220, 0xFF, 0xD7, 0x00},
    250    {221, 0xFF, 0xD7, 0x5F},
    251    {222, 0xFF, 0xD7, 0x87},
    252    {223, 0xFF, 0xD7, 0xAF},
    253    {224, 0xFF, 0xD7, 0xD7},
    254    {225, 0xFF, 0xD7, 0xFF},
    255    {226, 0xFF, 0xFF, 0x00},
    256    {227, 0xFF, 0xFF, 0x5F},
    257    {228, 0xFF, 0xFF, 0x87},
    258    {229, 0xFF, 0xFF, 0xAF},
    259    {230, 0xFF, 0xFF, 0xD7},
    260    {231, 0xFF, 0xFF, 0xFF},
    261    {232, 0x08, 0x08, 0x08},
    262    {233, 0x12, 0x12, 0x12},
    263    {234, 0x1C, 0x1C, 0x1C},
    264    {235, 0x26, 0x26, 0x26},
    265    {236, 0x30, 0x30, 0x30},
    266    {237, 0x3A, 0x3A, 0x3A},
    267    {238, 0x44, 0x44, 0x44},
    268    {239, 0x4E, 0x4E, 0x4E},
    269    {240, 0x58, 0x58, 0x58},
    270    {241, 0x62, 0x62, 0x62},
    271    {242, 0x6C, 0x6C, 0x6C},
    272    {243, 0x76, 0x76, 0x76},
    273    {244, 0x80, 0x80, 0x80},
    274    {245, 0x8A, 0x8A, 0x8A},
    275    {246, 0x94, 0x94, 0x94},
    276    {247, 0x9E, 0x9E, 0x9E},
    277    {248, 0xA8, 0xA8, 0xA8},
    278    {249, 0xB2, 0xB2, 0xB2},
    279    {250, 0xBC, 0xBC, 0xBC},
    280    {251, 0xC6, 0xC6, 0xC6},
    281    {252, 0xD0, 0xD0, 0xD0},
    282    {253, 0xDA, 0xDA, 0xDA},
    283    {254, 0xE4, 0xE4, 0xE4},
    284    {255, 0xEE, 0xEE, 0xEE}
    285
    286};
    287
    288int guac_terminal_colorcmp(const guac_terminal_color* a,
    289        const guac_terminal_color* b) {
    290
    291    /* Compare palette index alone if not unknown */
    292    if (a->palette_index != -1 && b->palette_index != -1)
    293        return a->palette_index - b->palette_index;
    294
    295    /* Consider red component highest order ... */
    296    if (a->red != b->red)
    297        return a->red - b->red;
    298
    299    /* ... followed by green ... */
    300    if (a->green != b->green)
    301        return a->green - b->green;
    302
    303    /* ... followed by blue */
    304    if (a->blue != b->blue)
    305        return a->blue - b->blue;
    306
    307    /* If all components match, colors are equal */
    308    return 0;
    309
    310}
    311