Changeset 293


Ignore:
Timestamp:
Dec 31, 2003, 2:20:18 PM (19 years ago)
Author:
Sam Hocevar
Message:
  • test/optipal.c: + Optimised S-Lang palette generator.
  • src/graphics: + Removed the S-Lang palette generator and replaced it with the tables

generated by optipal.

Location:
libcaca/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/graphics.c

    r286 r293  
    7575
    7676#if defined(USE_SLANG)
    77 static int slang_assoc[16*16];
     77/* Tables generated by test/optipal.c */
     78const static int slang_palette[2*16*16] =
     79{
     80     1,  0,   2,  0,   3,  0,   4,  0,   5,  0,   6,  0,   7,  0,   8,  0,
     81     9,  0,  10,  0,  11,  0,  12,  0,  13,  0,  14,  0,  15,  0,   0,  8,
     82     8,  7,   7,  8,  15,  7,   7, 15,  15,  9,   9, 15,   1,  9,   9,  1,
     83     7,  9,   9,  7,   8,  1,   1,  8,   0,  1,  15, 10,  10, 15,   2, 10,
     84    10,  2,   7, 10,  10,  7,   8,  2,   2,  8,   0,  2,  15, 11,  11, 15,
     85     3, 11,  11,  3,   7, 11,  11,  7,   8,  3,   3,  8,   0,  3,  15, 12,
     86    12, 15,   4, 12,  12,  4,   7, 12,  12,  7,   8,  4,   4,  8,   0,  4,
     87    15, 13,  13, 15,   5, 13,  13,  5,   7, 13,  13,  7,   8,  5,   5,  8,
     88     0,  5,  15, 14,  14, 15,   6, 14,  14,  6,   7, 14,  14,  7,   8,  6,
     89     6,  8,   0,  6,   4,  6,   6,  4,  12, 14,  14, 12,   6,  2,   2,  6,
     90    14, 10,  10, 14,   2,  3,   3,  2,  10, 11,  11, 10,   3,  1,   1,  3,
     91    11,  9,   9, 11,   1,  5,   5,  1,   9, 13,  13,  9,   5,  4,   4,  5,
     92    13, 12,  12, 13,   4, 14,   6, 12,  12,  6,  14,  4,   6, 10,   2, 14,
     93    14,  2,  10,  6,   2, 11,   3, 10,  10,  3,  11,  2,   3,  9,   1, 11,
     94    11,  1,   9,  3,   1, 13,   5,  9,   9,  5,  13,  1,   5, 12,   4, 13,
     95    13,  4,  12,  5,   0,  7,   0, 15,  15,  8,   8, 15,  15,  1,   7,  1,
     96     1,  6,   2,  5,   3,  4,   4,  3,   5,  2,   6,  1,   0,  0,   1,  1,
     97     9,  6,  10,  5,  11,  4,  12,  3,  13,  2,  14,  1,   2,  2,   3,  3,
     98     4,  4,   5,  5,   6,  6,   7,  7,  14,  9,   1, 15,   8,  9,   8,  8,
     99     9,  9,   1,  7,   0,  9,   9,  8,   6,  9,  13, 10,   2, 15,   8, 10,
     100     7,  2,  15,  2,   2,  7,   0, 10,  10,  8,   5, 10,  12, 11,   3, 15,
     101     8, 11,   7,  3,  15,  3,   3,  7,   0, 11,  11,  8,   4, 11,  11, 12,
     102     4, 15,   8, 12,   7,  4,  15,  4,   4,  7,   0, 12,  12,  8,   3, 12,
     103    10, 13,   5, 15,   8, 13,   7,  5,  15,  5,   5,  7,   0, 13,  13,  8,
     104     2, 13,   9, 14,   6, 15,   8, 14,   7,  6,  15,  6,   6,  7,   0, 14,
     105    14,  8,   1, 14,   5,  6,   2,  4,  13, 14,  10, 12,   4,  2,   3,  6,
     106    12, 10,  11, 14,   6,  3,   1,  2,  14, 11,   9, 10,   2,  1,   5,  3,
     107    10,  9,  13, 11,   3,  5,   4,  1,  11, 13,  12,  9,   1,  4,   6,  5,
     108     9, 12,  14, 13,   5, 14,   2, 12,  13,  6,  10,  4,   4, 10,   3, 14,
     109    12,  2,  11,  6,   6, 11,   1, 10,  14,  3,   9,  2,   2,  9,   5, 11,
     110    10,  1,  13,  3,   3, 13,   4,  9,  11,  5,  12,  1,   1, 12,   6, 13,
     111     9,  4,  14,  5,  10, 10,  11, 11,  12, 12,  13, 13,  14, 14,  15, 15,
     112};
     113
     114const static int slang_assoc[16*16] =
     115{
     116    134, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
     117    28, 135, 214, 86, 219, 91, 133, 127, 26, 23, 240, 112, 245, 117, 141, 126,
     118    37, 211, 142, 83, 206, 132, 78, 160, 35, 237, 32, 109, 232, 140, 104, 161,
     119    46, 87, 82, 143, 131, 215, 210, 169, 44, 113, 108, 41, 139, 241, 236, 170,
     120    55, 222, 203, 130, 144, 94, 75, 178, 53, 248, 229, 138, 50, 120, 101, 179,
     121    64, 90, 129, 218, 95, 145, 223, 187, 62, 116, 137, 244, 121, 59, 249, 188,
     122    73, 128, 79, 207, 74, 202, 146, 196, 71, 136, 105, 233, 100, 228, 68, 197,
     123    122, 153, 162, 171, 180, 189, 198, 147, 16, 25, 34, 43, 52, 61, 70, 18,
     124    15, 27, 36, 45, 54, 63, 72, 17, 151, 155, 164, 173, 182, 191, 200, 124,
     125    154, 22, 238, 110, 243, 115, 156, 24, 150, 152, 216, 88, 221, 93, 148, 20,
     126    163, 235, 31, 107, 230, 165, 102, 33, 159, 213, 250, 85, 208, 157, 80, 29,
     127    172, 111, 106, 40, 174, 239, 234, 42, 168, 89, 84, 251, 166, 217, 212, 38,
     128    181, 246, 227, 183, 49, 118, 99, 51, 177, 224, 205, 175, 252, 96, 77, 47,
     129    190, 114, 192, 242, 119, 58, 247, 60, 186, 92, 184, 220, 97, 253, 225, 56,
     130    199, 201, 103, 231, 98, 226, 67, 69, 195, 193, 81, 209, 76, 204, 254, 65,
     131    123, 149, 158, 167, 176, 185, 194, 19, 125, 21, 30, 39, 48, 57, 66, 255,
     132};
    78133#endif
    79134
     
    874929        }
    875930#else
    876     int i, cur = 0;
    877 
    878     /* 6 colours in hue order */
    879     static const enum caca_color hue_list[] =
    880     {
    881         CACA_COLOR_RED,
    882         CACA_COLOR_BROWN,
    883         CACA_COLOR_GREEN,
    884         CACA_COLOR_CYAN,
    885         CACA_COLOR_BLUE,
    886         CACA_COLOR_MAGENTA
    887     };
    888 
    889 #define SETPAIR(_fg, _bg, _n) \
    890     do \
    891     { \
    892         int fg = _fg, bg = _bg, n = _n; \
    893         SLtt_set_color(n, NULL, slang_colors[fg], slang_colors[bg]); \
    894         slang_assoc[fg + 16 * bg] = n; \
    895     } \
    896     while(0);
    897 
    898     /*
    899      * XXX: See the NOTES file for what follows
    900      */
    901 
    902     /* black background colour pairs that are needed for the old renderer */
    903     for(i = 1; i < 16; i++)
    904         SETPAIR(i, CACA_COLOR_BLACK, cur++);
    905 
    906     /* gray combinations used for grayscale dithering */
    907     SETPAIR(CACA_COLOR_BLACK, CACA_COLOR_DARKGRAY, cur++);
    908     SETPAIR(CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY, cur++);
    909     SETPAIR(CACA_COLOR_LIGHTGRAY, CACA_COLOR_DARKGRAY, cur++);
    910     SETPAIR(CACA_COLOR_WHITE, CACA_COLOR_LIGHTGRAY, cur++);
    911     SETPAIR(CACA_COLOR_LIGHTGRAY, CACA_COLOR_WHITE, cur++);
    912 
    913     /* white/light, light/dark, lightgray/light, darkgray/dark, dark/black
    914      * combinations often used for saturation/value dithering (the two
    915      * other possible combinations, lightgray/dark and darkgray/light, are
    916      * not considered here) */
    917     for(i = 1; i < 7; i++)
    918     {
    919         SETPAIR(CACA_COLOR_WHITE, i + 8, cur++);
    920         SETPAIR(i + 8, CACA_COLOR_WHITE, cur++);
    921         SETPAIR(i, i + 8, cur++);
    922         SETPAIR(i + 8, i, cur++);
    923         SETPAIR(CACA_COLOR_LIGHTGRAY, i + 8, cur++);
    924         SETPAIR(i + 8, CACA_COLOR_LIGHTGRAY, cur++);
    925         SETPAIR(CACA_COLOR_DARKGRAY, i, cur++);
    926         SETPAIR(i, CACA_COLOR_DARKGRAY, cur++);
    927         SETPAIR(CACA_COLOR_BLACK, i, cur++);
    928     }
    929 
    930     /* next colour combinations for hue dithering (magenta/blue, blue/green
    931      * and so on) */
    932     for(i = 0; i < 6; i++)
    933     {
    934         SETPAIR(hue_list[i], hue_list[(i + 1) % 6], cur++);
    935         SETPAIR(hue_list[(i + 1) % 6], hue_list[i], cur++);
    936         SETPAIR(hue_list[i] + 8, hue_list[(i + 1) % 6] + 8, cur++);
    937         SETPAIR(hue_list[(i + 1) % 6] + 8, hue_list[i] + 8, cur++);
    938     }
    939 
    940     /* next colour combinations for hue/value dithering (blue/lightgreen,
    941      * green/lightblue and so on) */
    942     for(i = 0; i < 6; i++)
    943     {
    944         SETPAIR(hue_list[i], hue_list[(i + 1) % 6] + 8, cur++);
    945         SETPAIR(hue_list[(i + 1) % 6], hue_list[i] + 8, cur++);
    946         SETPAIR(hue_list[i] + 8, hue_list[(i + 1) % 6], cur++);
    947         SETPAIR(hue_list[(i + 1) % 6] + 8, hue_list[i], cur++);
    948     }
    949 
    950     /* black on light gray, black on white, white on dark gray, dark gray
    951      * on white, white on blue, light gray on blue (chosen arbitrarily) */
    952     SETPAIR(CACA_COLOR_BLACK, CACA_COLOR_LIGHTGRAY, cur++);
    953     SETPAIR(CACA_COLOR_BLACK, CACA_COLOR_WHITE, cur++);
    954     SETPAIR(CACA_COLOR_WHITE, CACA_COLOR_DARKGRAY, cur++);
    955     SETPAIR(CACA_COLOR_DARKGRAY, CACA_COLOR_WHITE, cur++);
    956     SETPAIR(CACA_COLOR_WHITE, CACA_COLOR_BLUE, cur++);
    957     SETPAIR(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLUE, cur++);
    958 
    959     /*
    960      * Now the possibly emulated pairs
    961      */
    962 
    963     /* light gray on dark colour: emulate with light colour on dark colour
    964      * white on dark colour: emulate with light gray on light colour
    965      * black on light colour: emulate with dark gray on dark colour
    966      * dark gray on light colour: emulate with dark colour on light colour
    967      * light colour on dark gray: emulate with dark colour on dark gray
    968      * dark colour on light gray: emulate with light colour on light gray
    969      * dark colour on white: emulate with light colour on white */
    970     for(i = 1; i < 7; i++)
    971     {
    972         if(i != CACA_COLOR_BLUE)
    973         {
    974             SETPAIR(CACA_COLOR_LIGHTGRAY, i, 128 +
    975                     slang_assoc[i + 8 + 16 * i]);
    976             SETPAIR(CACA_COLOR_WHITE, i, 128 +
    977                     slang_assoc[CACA_COLOR_LIGHTGRAY + 16 * (i + 8)]);
    978         }
    979         SETPAIR(CACA_COLOR_BLACK, i + 8,
    980                 128 + slang_assoc[CACA_COLOR_DARKGRAY + 16 * i]);
    981         SETPAIR(CACA_COLOR_DARKGRAY, i + 8,
    982                 128 + slang_assoc[i + 16 * (i + 8)]);
    983         SETPAIR(i + 8, CACA_COLOR_DARKGRAY,
    984                 128 + slang_assoc[i + 16 * CACA_COLOR_DARKGRAY]);
    985         SETPAIR(i, CACA_COLOR_LIGHTGRAY,
    986                 128 + slang_assoc[i + 8 + 16 * CACA_COLOR_LIGHTGRAY]);
    987         SETPAIR(i, CACA_COLOR_WHITE,
    988                 128 + slang_assoc[i + 8 + 16 * CACA_COLOR_WHITE]);
    989     }
    990 
    991     /* 120 degree hue pairs can be emulated as well; for instance blue on
    992      * red can be emulated using magenta on red, and blue on green using
    993      * cyan on green */
    994     for(i = 0; i < 6; i++)
    995     {
    996         SETPAIR(hue_list[(i + 2) % 6], hue_list[i],
    997             128 + slang_assoc[hue_list[(i + 1) % 6] + 16 * hue_list[i]]);
    998         SETPAIR(hue_list[(i + 2) % 6] + 8, hue_list[i] + 8,
    999             128 + slang_assoc[hue_list[(i + 1) % 6] + 16 * hue_list[i] + 136]);
    1000         SETPAIR(hue_list[(i + 2) % 6] + 8, hue_list[i],
    1001             128 + slang_assoc[hue_list[(i + 1) % 6] + 16 * hue_list[i] + 8]);
    1002         SETPAIR(hue_list[(i + 2) % 6], hue_list[i] + 8,
    1003             128 + slang_assoc[hue_list[(i + 1) % 6] + 16 * hue_list[i] + 128]);
    1004 
    1005         SETPAIR(hue_list[(i + 4) % 6], hue_list[i],
    1006             128 + slang_assoc[hue_list[(i + 5) % 6] + 16 * hue_list[i]]);
    1007         SETPAIR(hue_list[(i + 4) % 6] + 8, hue_list[i] + 8,
    1008             128 + slang_assoc[hue_list[(i + 5) % 6] + 16 * hue_list[i] + 136]);
    1009         SETPAIR(hue_list[(i + 4) % 6] + 8, hue_list[i],
    1010             128 + slang_assoc[hue_list[(i + 5) % 6] + 16 * hue_list[i] + 8]);
    1011         SETPAIR(hue_list[(i + 4) % 6], hue_list[i] + 8,
    1012             128 + slang_assoc[hue_list[(i + 5) % 6] + 16 * hue_list[i] + 128]);
    1013     }
    1014 
    1015     /* dark opposite on dark: emulate with dark opposite on black
    1016      * light opposite on dark: emulate with light opposite on black
    1017      * dark opposite on light: emulate with black on dark
    1018      * light opposite on light: emulate with white on light */
    1019     for(i = 0; i < 6; i++)
    1020     {
    1021         SETPAIR(hue_list[i], hue_list[(i + 3) % 6],
    1022                 128 + slang_assoc[hue_list[i] + 16 * CACA_COLOR_BLACK]);
    1023         SETPAIR(hue_list[i] + 8, hue_list[(i + 3) % 6],
    1024                 128 + slang_assoc[hue_list[i] + 8 + 16 * CACA_COLOR_BLACK]);
    1025         SETPAIR(hue_list[(i + 3) % 6], hue_list[i] + 8,
    1026                 128 + slang_assoc[CACA_COLOR_BLACK + 16 * hue_list[i]]);
    1027         SETPAIR(hue_list[(i + 3) % 6] + 8, hue_list[i] + 8,
    1028                 128 + slang_assoc[CACA_COLOR_WHITE + 16 * (hue_list[i] + 8)]);
    1029     }
     931    int i;
     932
     933    for(i = 0; i < 16 * 16; i++)
     934        SLtt_set_color(i, NULL, slang_colors[slang_palette[i * 2]],
     935                                slang_colors[slang_palette[i * 2 + 1]]);
    1030936#endif
    1031937}
  • libcaca/trunk/test

    • Property svn:ignore
      •  

        old new  
        55dithering.exe
        66dithering
         7optipal.exe
         8optipal
  • libcaca/trunk/test/Makefile.am

    r292 r293  
    33###############################################################################
    44
    5 noinst_PROGRAMS = dithering
     5noinst_PROGRAMS = dithering optipal
    66
    77dithering_SOURCES = dithering.c
     
    99dithering_CPPFLAGS = -I$(top_srcdir)/src
    1010
     11optipal_SOURCES = optipal.c
     12optipal_LDADD = ../src/libcaca.a @CACA_LIBS@
     13optipal_CPPFLAGS = -I$(top_srcdir)/src
     14
Note: See TracChangeset for help on using the changeset viewer.