--- uae/src/gfxutil.c 2018/04/24 16:38:39 1.1.1.1 +++ uae/src/gfxutil.c 2018/04/24 16:38:54 1.1.1.2 @@ -13,7 +13,6 @@ #include "options.h" #include "memory.h" #include "custom.h" -#include "newcpu.h" #include "keyboard.h" #include "xwin.h" #include "keybuf.h" @@ -57,13 +56,19 @@ void alloc_colors64k(int rw, int gw, int } static int allocated[4096]; +static int color_diff[4096]; +static int newmaxcol = 0; + +void setup_maxcol(int max) +{ + newmaxcol = max; +} void alloc_colors256(allocfunc_type allocfunc) { int nb_cols[3]; /* r,g,b */ - int maxcol = 256; + int maxcol = newmaxcol == 0 ? 256 : newmaxcol; int i,j,k,l,t; - int diff[4096]; xcolnr *map; @@ -129,9 +134,9 @@ void alloc_colors256(allocfunc_type allo if(q > d && cb < k) ++cb; diffb = abs(cb*k-b); xcolors[rgb] = map[(cr*nb_cols[GRN]+cg)*nb_cols[BLU]+cb]; - diff[rgb] = diffr+diffg+diffb; - if (diff[rgb] > maxdiff) - maxdiff = diff[rgb]; + color_diff[rgb] = diffr+diffg+diffb; + if (color_diff[rgb] > maxdiff) + maxdiff = color_diff[rgb]; } } } @@ -147,7 +152,7 @@ void alloc_colors256(allocfunc_type allo for(b = 15; b >= 0; b--) { int cb, rgb = (r<<8) | (g<<4) | b; - if (diff[rgb] == maxdiff) { + if (color_diff[rgb] == maxdiff) { int result; if (l >= maxcol) @@ -156,9 +161,9 @@ void alloc_colors256(allocfunc_type allo result = allocfunc(r, g, b, xcolors + rgb); l++; } - diff[rgb] = 0; - } else if (diff[rgb] > newmaxdiff) - newmaxdiff = diff[rgb]; + color_diff[rgb] = 0; + } else if (color_diff[rgb] > newmaxdiff) + newmaxdiff = color_diff[rgb]; } } @@ -186,10 +191,9 @@ UBYTE cidx[4][8*4096]; /* fast, but memo /* * Compute dithering structures */ -void setup_greydither(int bits, allocfunc_type allocfunc) +void setup_greydither_maxcol(int maxcol, allocfunc_type allocfunc) { int i,j,k,l,t; - int maxcol = 1 << bits; xcolnr *map; for (i = 0; i < 4096; i++) @@ -228,7 +232,9 @@ void setup_greydither(int bits, allocfun k = maxcol-1; p = (c * k) / 256; q = (c * k) % 256; - if(q / k > d / k && p < k) ++p; + if(q /*/ k*/> d /*/ k*/ && p < k) ++p; +/* sam: ^^^^^^^ */ +/* It seems that produces better output */ cidx[i][rgb + (j+4)*4096] = cidx[i][rgb + j*4096] = map[p]; } @@ -239,6 +245,11 @@ void setup_greydither(int bits, allocfun free (map); } +void setup_greydither(int bits, allocfunc_type allocfunc) +{ + setup_greydither_maxcol(1 << bits, allocfunc); +} + void setup_dither(int bits, allocfunc_type allocfunc) { int nb_cols[3]; /* r,g,b */ @@ -291,7 +302,7 @@ void setup_dither(int bits, allocfunc_ty } } } - fprintf(stderr, "%d color(s) lost\n",maxcol - l); +/* fprintf(stderr, "%d color(s) lost\n",maxcol - l);*/ /* * for each component compute the mapping @@ -342,7 +353,7 @@ void setup_dither(int bits, allocfunc_ty q = r * k - 15*cr; if (cr < 0) cr = 0; else - if(q / k > d / k) ++cr; + if(q /*/ k*/ > d /*/ k*/) ++cr; if (cr > k) cr = k; k = nb_cols[GRN]-1; @@ -350,7 +361,7 @@ void setup_dither(int bits, allocfunc_ty q = g * k - 15*cg; if (cg < 0) cg = 0; else - if (q / k > d / k) ++cg; + if (q /*/ k*/ > d /*/ k*/) ++cg; if (cg > k) cg = k; k = nb_cols[BLU]-1; @@ -358,7 +369,7 @@ void setup_dither(int bits, allocfunc_ty q = b * k - 15*cb; if (cb < 0) cb = 0; else - if (q / k > d / k) ++cb; + if (q /*/ k*/ > d /*/ k*/) ++cb; if (cb > k) cb = k; #endif cidx[i][rgb + (j+4)*4096] = cidx[i][rgb + j*4096] = map[(cr*nb_cols[GRN]+cg)*nb_cols[BLU]+cb]; @@ -377,12 +388,23 @@ void setup_dither(int bits, allocfunc_ty * yourself unhappy. */ -void DitherLine(UBYTE *l, UWORD *r4g4b4, int x, int y, UWORD len, int bits) +void DitherLine(UBYTE *l, UWORD *r4g4b4, int x, int y, WORD len, int bits) { UBYTE *dith = cidx[y&3]+(x&3)*4096; UBYTE d = 0; int bitsleft = 8; + if(bits == 8) { + while(len>0) { + *l++ = dith[0*4096 + *r4g4b4++]; + *l++ = dith[1*4096 + *r4g4b4++]; + *l++ = dith[2*4096 + *r4g4b4++]; + *l++ = dith[3*4096 + *r4g4b4++]; + len -= 4; + } + return; + } + while(len) { int v; v = dith[0*4096 + *r4g4b4++];