--- uae/src/gfxutil.c 2018/04/24 16:38:54 1.1.1.2 +++ uae/src/gfxutil.c 2018/04/24 16:39:49 1.1.1.3 @@ -1,8 +1,8 @@ - /* + /* * UAE - The Un*x Amiga Emulator - * + * * Common code needed by all the various graphics systems. - * + * * (c) 1996 Bernd Schmidt, Ed Hanway, Samuel Devulder */ @@ -11,6 +11,7 @@ #include "config.h" #include "options.h" +#include "threaddep/penguin.h" #include "memory.h" #include "custom.h" #include "keyboard.h" @@ -24,7 +25,7 @@ /* * dither matrix */ -static UBYTE dither[4][4] = +static uae_u8 dither[4][4] = { {0,8,2,10}, {12,4,14,6}, @@ -71,9 +72,13 @@ void alloc_colors256(allocfunc_type allo int i,j,k,l,t; xcolnr *map; - + map = (xcolnr *)malloc(sizeof(xcolnr) * maxcol); - + if(!map) { + write_log("Not enough mem for colormap!\n"); + abort(); + } + /* * compute #cols per components */ @@ -90,11 +95,11 @@ void alloc_colors256(allocfunc_type allo */ l=0; for(i = 0; i < nb_cols[RED]; ++i) { - int r = (i * 15 + (nb_cols[RED] - 1)/2) / (nb_cols[RED] - 1); + int r = (i * 15) / (nb_cols[RED] - 1); for(j = 0; j < nb_cols[GRN]; ++j) { - int g = (j * 15 + (nb_cols[GRN] - 1)/2) / (nb_cols[GRN] - 1); - for(k = 0; k < nb_cols[BLU]; ++k) { - int b = (k * 15 + (nb_cols[BLU] - 1)/2) / (nb_cols[BLU] - 1); + int g = (j * 15) / (nb_cols[GRN] - 1); + for(k = 0; k < nb_cols[BLU]; ++k) { + int b = (k * 15) / (nb_cols[BLU] - 1); int result; result = allocfunc(r, g, b, map + l); l++; @@ -111,7 +116,7 @@ void alloc_colors256(allocfunc_type allo int r, d = 8; for(r=0; r<16; ++r) { int cr, g, q; - + k = nb_cols[RED]-1; cr = (r * k) / 15; q = (r * k) % 15; @@ -119,7 +124,7 @@ void alloc_colors256(allocfunc_type allo diffr = abs(cr*k-r); for(g=0; g<16; ++g) { int cg, b; - + k = nb_cols[GRN]-1; cg = (g * k) / 15; q = (g * k) % 15; @@ -145,16 +150,16 @@ void alloc_colors256(allocfunc_type allo lost = 0; won++; for(r = 15; r >= 0; r--) { int cr, g, q; - + for(g = 15; g >= 0; g--) { int cg, b; - + for(b = 15; b >= 0; b--) { int cb, rgb = (r<<8) | (g<<4) | b; if (color_diff[rgb] == maxdiff) { int result; - + if (l >= maxcol) lost++; else { @@ -164,7 +169,7 @@ void alloc_colors256(allocfunc_type allo color_diff[rgb] = 0; } else if (color_diff[rgb] > newmaxdiff) newmaxdiff = color_diff[rgb]; - + } } } @@ -179,14 +184,14 @@ void alloc_colors256(allocfunc_type allo * This dithering process works by letting UAE run internaly in 12bit * mode and doing the dithering on the fly when rendering to the display. * The dithering algorithm is quite fast but uses lot of memory (4*8*2^12 = - * 128Kb). I don't think that is a trouble right now, but when UAE will + * 128Kb). I don't think that is a trouble right now, but when UAE will * emulate AGA and work internaly in 24bit mode, that dithering algorithm * will need 4*8*2^24 = 512Mb. Obviously that fast algorithm will not be - * tractable. However, we could then use an other algorithm, slower, but + * tractable. However, we could then use an other algorithm, slower, but * far more reasonable (I am thinking about the one that is used in DJPEG). */ -UBYTE cidx[4][8*4096]; /* fast, but memory hungry =:-( */ +uae_u8 cidx[4][8*4096]; /* fast, but memory hungry =:-( */ /* * Compute dithering structures @@ -195,11 +200,15 @@ void setup_greydither_maxcol(int maxcol, { int i,j,k,l,t; xcolnr *map; - + for (i = 0; i < 4096; i++) xcolors[i] = i; - + map = (xcolnr *)malloc(sizeof(xcolnr) * maxcol); + if(!map) { + write_log("Not enough mem for colormap!\n"); + abort(); + } /* * set the colormap @@ -207,7 +216,7 @@ void setup_greydither_maxcol(int maxcol, for(i = 0; i < maxcol; ++i) { int c, result; c = (15 * i + (maxcol-1)/2) / (maxcol - 1); - result = allocfunc(c, c, c, map + i); + result = allocfunc(c, c, c, map + i); /* @@@ check for errors */ } @@ -224,18 +233,18 @@ void setup_greydither_maxcol(int maxcol, for(b=0; b<16; ++b) { int rgb = (r<<8) | (g<<4) | b; int c,p,q; - - c = (77 * r + - 151 * g + + + c = (77 * r + + 151 * g + 28 * b) / 15; /* c in 0..256 */ - - k = maxcol-1; + + k = maxcol-1; p = (c * k) / 256; q = (c * k) % 256; 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+4)*4096] = cidx[i][rgb + j*4096] = map[p]; } } @@ -258,12 +267,16 @@ void setup_dither(int bits, allocfunc_ty xcolnr *map; int *redvals, *grnvals, *bluvals; - + map = (xcolnr *)malloc(sizeof(xcolnr) * maxcol); + if(!map) { + write_log("Not enough mem for colormap!\n"); + abort(); + } for (i = 0; i < 4096; i++) xcolors[i] = i; - + /* * compute #cols per components */ @@ -282,19 +295,19 @@ void setup_dither(int bits, allocfunc_ty redvals = (int *)malloc(sizeof(int) * maxcol); grnvals = redvals + nb_cols[RED]; - bluvals = grnvals + nb_cols[BLU]; + bluvals = grnvals + nb_cols[GRN]; /* * set the colormap */ l=0; for(i = 0; i < nb_cols[RED]; ++i) { - int r = (i * 15 + (nb_cols[RED] - 1)/2) / (nb_cols[RED] - 1); + int r = (i * 15) / (nb_cols[RED] - 1); redvals[i] = r; for(j = 0; j < nb_cols[GRN]; ++j) { - int g = (j * 15 + (nb_cols[GRN] - 1)/2) / (nb_cols[GRN] - 1); + int g = (j * 15) / (nb_cols[GRN] - 1); grnvals[j] = g; - for(k = 0; k < nb_cols[BLU]; ++k) { - int b = (k * 15 + (nb_cols[BLU] - 1)/2) / (nb_cols[BLU] - 1); + for(k = 0; k < nb_cols[BLU]; ++k) { + int b = (k * 15) / (nb_cols[BLU] - 1); int result; bluvals[k] = b; result = allocfunc(r, g, b, map + l); @@ -329,7 +342,7 @@ void setup_dither(int bits, allocfunc_ty if(q / k > d / k && rederr <= 0) ++cr; if (cr > k) cr = k; rederr += redvals[cr]-r; - + k = nb_cols[GRN]-1; cg = g * k / 15; q = g * k - 15*cg; @@ -355,7 +368,7 @@ void setup_dither(int bits, allocfunc_ty else if(q /*/ k*/ > d /*/ k*/) ++cr; if (cr > k) cr = k; - + k = nb_cols[GRN]-1; cg = g * k / 15; q = g * k - 15*cg; @@ -381,20 +394,20 @@ void setup_dither(int bits, allocfunc_ty free (map); } -#ifndef X86_ASSEMBLY +#if !defined X86_ASSEMBLY /* * Dither the line. * Make sure you call this only with (len & 3) == 0, or you'll just make * yourself unhappy. */ -void DitherLine(UBYTE *l, UWORD *r4g4b4, int x, int y, WORD len, int bits) +void DitherLine(uae_u8 *l, uae_u16 *r4g4b4, int x, int y, uae_s16 len, int bits) { - UBYTE *dith = cidx[y&3]+(x&3)*4096; - UBYTE d = 0; + uae_u8 *dith = cidx[y&3]+(x&3)*4096; + uae_u8 d = 0; int bitsleft = 8; - - if(bits == 8) { + + if(bits == 8) { while(len>0) { *l++ = dith[0*4096 + *r4g4b4++]; *l++ = dith[1*4096 + *r4g4b4++]; @@ -412,19 +425,19 @@ void DitherLine(UBYTE *l, UWORD *r4g4b4, d |= (v << bitsleft); if (!bitsleft) *l++ = d, bitsleft = 8, d = 0; - + v = dith[1*4096 + *r4g4b4++]; bitsleft -= bits; d |= (v << bitsleft); if (!bitsleft) *l++ = d, bitsleft = 8, d = 0; - + v = dith[2*4096 + *r4g4b4++]; bitsleft -= bits; d |= (v << bitsleft); if (!bitsleft) *l++ = d, bitsleft = 8, d = 0; - + v = dith[3*4096 + *r4g4b4++]; bitsleft -= bits; d |= (v << bitsleft);