?? vid_next.m
字號:
[vid_window_i setTitle: "Bitmap Quake Console"];
//
// allocate memory for the back and translation buffers
//
vid.rowbytes = vid.width;
rowbytesnative = vid.width * pixbytesnative;
AllocBuffers (true);
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
}
/*
=================
UpdateFramebuffer
=================
*/
void UpdateFramebuffer (vrect_t *vrect)
{
byte *psourcebase;
byte *pdestbase;
int scale;
psourcebase = vid.buffer + vrect->x + vrect->y * vid.rowbytes;
if (vid_display == disp_bitmap)
scale = 1; // let NS do the scaling
else
scale = vid_scale;
pdestbase = buffernative + scale *
(vrect->x * pixbytesnative + vrect->y * rowbytesnative);
//
// translate from ideal to native (except 8 bpp direct) and copy to screen
//
if (pixbytesnative == 1)
Update8_1 (psourcebase, pdestbase, vrect->width, vrect->height,
rowbytesnative);
else if (pixbytesnative == 2)
Update16_1 (psourcebase, (unsigned short *)pdestbase, vrect->width, vrect->height,
rowbytesnative);
else
Update32_1 (psourcebase, (unsigned *)pdestbase, vrect->width, vrect->height,
rowbytesnative);
}
/*
=================
UpdateBitmap
=================
*/
void UpdateBitmap (void)
{
unsigned char *planes[5];
NXRect bounds;
int bpp, spp, bps, bpr, colorspace;
//
// flush the screen with an image call
//
if (pixbytesnative == 1)
{
bps = 8;
spp = 1;
bpp = 8;
bpr = vid.width;
colorspace = NX_OneIsWhiteColorSpace;
planes[0] = vid.buffer;
}
else if (pixbytesnative == 2)
{
bps = 4;
spp = 3;
bpp = 16;
bpr = vid.width * 2;
colorspace = NX_RGBColorSpace;
planes[0] = buffernative;
}
else
{
bps = 8;
spp = 3;
bpp = 32;
bpr = vid.width * 4;
colorspace = NX_RGBColorSpace;
planes[0] = buffernative;
}
[vid_view_i getBounds: &bounds];
[vid_view_i lockFocus];
NXDrawBitmap(
&bounds,
vid.width,
vid.height,
bps,
spp,
bpp,
bpr,
NO,
NO,
colorspace,
planes
);
[vid_view_i unlockFocus];
NXPing ();
}
/*
==========================================================================
TRANSLATION TABLE BUILDING
==========================================================================
*/
int redramp[] = {0, 19, 59, 113, 178, 255, 300};
int greenramp[] = {0, 11, 34, 66, 104, 149, 199, 255, 300};
int blueramp[] = {0, 28, 84, 161, 255, 300};
int greyramp[] = { 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204,
221, 238, 255, 300};
byte greytable[256];
byte redtable[256];
byte greentable[256];
byte bluetable[256];
void FillTable (byte *table, int *ramp, int base)
{
int i, j, o;
o = 0;
for (i=0 ; i<16 && o < 256; i++)
{
j = ramp[i];
for ( ; o<=j ; o++)
table[o] = base + i;
}
}
void InitNS8Bit (void)
{
FillTable (greytable, greyramp, 240);
FillTable (redtable, redramp, 0);
FillTable (greentable, greenramp, 0);
FillTable (bluetable, blueramp, 0);
}
byte ns8trans[256] = // FIXME: dynamically calc this so palettes work
{
0,241,242,243,244,244,245,246,247,248,249,250,251,252,253,254,
45,241,241,242,91,91,91,96,96,136,136,136,141,141,141,141,
241,46,242,243,243,97,97,97,245,246,143,143,143,143,148,148,
0,5,45,45,50,50,90,90,95,95,95,95,95,140,140,141,
0,40,40,40,40,80,80,80,80,80,120,120,120,120,120,120,
45,50,50,90,90,95,95,135,135,135,136,141,141,181,181,181,
45,90,91,91,131,131,136,136,136,176,181,181,186,226,231,236,
45,45,91,91,96,96,136,136,137,142,182,182,187,188,188,233,
188,249,248,247,246,137,137,137,244,243,243,91,242,241,241,45,
183,183,183,247,137,137,137,137,137,244,91,91,91,241,241,45,
252,251,188,188,248,248,142,142,142,244,244,243,91,242,241,45,
247,247,246,246,245,245,244,244,243,243,242,242,51,241,241,5,
236,231,231,191,186,185,185,140,140,135,135,95,90,90,45,45,
4,49,49,53,53,93,93,93,93,92,92,92,243,242,46,241,
239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,
239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,182
};
/*
===================
Table8
===================
*/
void Table8 (void)
{
byte *pal;
int r,g,b,v;
int i;
byte *table;
pal = vid_palette;
table = (byte *)pcolormap[0];
for (i=0 ; i<256 ; i++)
{
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// use the grey ramp if all indexes are close
if (r-g < 16 && r-g > -16 && r-b < 16 && r-b > -16)
{
v = (r+g+b)/3;
*table++ = greytable[v];
continue;
}
r = redtable[r];
g = greentable[g];
b = bluetable[b];
// otherwise use the color cube
*table++ = r*(8*5) + g*5 + b;
}
}
/*
===================
Table24
===================
*/
void Table24 (void)
{
byte *pal;
int r,g,b,v;
int i;
unsigned *table;
//
// 8 8 8 encoding
//
pal = vid_palette;
table = (unsigned *)pcolormap[0];
for (i=0 ; i<256 ; i++)
{
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
v = (r<<16) + (g<<8) + b;
*table++ = v;
}
}
/*
===================
Table24Swap
===================
*/
void Table24Swap (void)
{
byte *pal;
int r,g,b,v;
int i;
unsigned *table;
//
// 8 8 8 encoding
//
pal = vid_palette;
table = (unsigned *)pcolormap[0];
for (i=0 ; i<256 ; i++)
{
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
v = (r<<24) + (g<<16) + (b<<8) /*+ 255*/;
v = NXSwapBigLongToHost (v);
*table++ = v;
}
}
/*
===================
Table15
===================
*/
void Table15 (void)
{
byte *pal;
int r,g,b,v;
int i, k;
unsigned char *palette;
unsigned short *table;
int dadj;
int ditheradjust[4] = {(1 << 9) * 3 / 8,
(1 << 9) * 5 / 8,
(1 << 9) * 7 / 8,
(1 << 9) * 1 / 8};
palette = vid_palette;
table = (unsigned short *)pcolormap;
//
// 5 5 5 encoding
//
for (k=0 ; k<4 ; k++)
{
dadj = ditheradjust[k];
pal = vid_palette;
for (i=0 ; i<256 ; i++)
{
// shift 6 bits to get back to 0-255, & 3 more for 5 bit color
// FIXME: scale intensity levels properly
r = (pal[0] + dadj) >> 3;
g = (pal[1] + dadj) >> 3;
b = (pal[2] + dadj) >> 3;
pal += 3;
v = (r<<10) + (g<<5) + b;
*table++ = v;
}
}
}
/*
===================
Table12
===================
*/
void Table12 (void)
{
byte *pal;
int r,g,b,v;
int i, k;
unsigned short *table;
int dadj;
static int ditheradjust[4] = {(1 << 9) * 3 / 8,
(1 << 9) * 5 / 8,
(1 << 9) * 7 / 8,
(1 << 9) * 1 / 8};
table = (unsigned short *)pcolormap;
//
// 4 4 4 encoding
//
for (k=0 ; k<4 ; k++)
{
dadj = ditheradjust[k];
pal = vid_palette;
for (i=0 ; i<256 ; i++)
{
// shift 5 bits to get back to 0-255, & 4 more for 4 bit color
// FIXME: scale intensity levels properly
r = (pal[0] + dadj) >> 4;
g = (pal[1] + dadj) >> 4;
b = (pal[2] + dadj) >> 4;
pal += 3;
v = ((r<<12) + (g<<8) + (b<<4) /*+ 15*/);
*table++ = v;
}
}
}
/*
===================
Table12Swap
===================
*/
void Table12Swap (void)
{
byte *pal;
int r,g,b,v;
int i, k;
unsigned short *table;
int dadj;
static int ditheradjust[4] = {(1 << 9) * 3 / 8,
(1 << 9) * 5 / 8,
(1 << 9) * 7 / 8,
(1 << 9) * 1 / 8};
table = (unsigned short *)pcolormap;
//
// 4 4 4 encoding
//
for (k=0 ; k<4 ; k++)
{
dadj = ditheradjust[k];
pal = vid_palette;
for (i=0 ; i<256 ; i++)
{
// shift 5 bits to get back to 0-255, & 4 more for 4 bit color
// FIXME: scale intensity levels properly
r = (pal[0] + dadj) >> 4;
g = (pal[1] + dadj) >> 4;
b = (pal[2] + dadj) >> 4;
pal += 3;
v = ((r<<12) + (g<<8) + (b<<4) /*+ 15*/);
v = NXSwapBigShortToHost (v);
*table++ = v;
}
}
}
/*
==========================================================================
GENERIC IMAGING FUNCTIONS
==========================================================================
*/
/*
===================
Update8_1
===================
*/
void Update8_1 (pixel_t *src, byte *dest, int width, int height,
int destrowbytes)
{
int x,y;
unsigned rowdelta, srcdelta;
unsigned xcount;
byte *pdest;
int xwidth;
pdest = dest;
xcount = width >> 3;
srcdelta = vid.width - width;
xwidth = width - (xcount << 3);
if (xwidth)
Sys_Error ("Width not multiple of 8");
if ((vid_display == disp_framebuffer) && (vid_scale == 2))
{
int nextrow = destrowbytes;
rowdelta = destrowbytes - (width << 1) + destrowbytes;
if (dither)
{
unsigned short *psrc;
psrc = (unsigned short *)src;
for (y = height ; y ; y--)
{
for (x = xcount ; x ;x--)
{
unsigned temp;
temp = psrc[0];
pdest[0] = ((byte *)pcolormap[0])[temp];
pdest[1] = ((byte *)pcolormap[1])[temp];
pdest[nextrow] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 1] = ((byte *)pcolormap[3])[temp];
temp = psrc[1];
pdest[2] = ((byte *)pcolormap[0])[temp];
pdest[3] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 2] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 3] = ((byte *)pcolormap[3])[temp];
temp = psrc[2];
pdest[4] = ((byte *)pcolormap[0])[temp];
pdest[5] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 4] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 5] = ((byte *)pcolormap[3])[temp];
temp = psrc[3];
pdest[6] = ((byte *)pcolormap[0])[temp];
pdest[7] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 6] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 7] = ((byte *)pcolormap[3])[temp];
temp = psrc[4];
pdest[8] = ((byte *)pcolormap[0])[temp];
pdest[9] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 8] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 9] = ((byte *)pcolormap[3])[temp];
temp = psrc[5];
pdest[10] = ((byte *)pcolormap[0])[temp];
pdest[11] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 10] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 11] = ((byte *)pcolormap[3])[temp];
temp = psrc[6];
pdest[12] = ((byte *)pcolormap[0])[temp];
pdest[13] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 12] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 13] = ((byte *)pcolormap[3])[temp];
temp = psrc[7];
pdest[14] = ((byte *)pcolormap[0])[temp];
pdest[15] = ((byte *)pcolormap[1])[temp];
pdest[nextrow + 14] = ((byte *)pcolormap[2])[temp];
pdest[nextrow + 15] = ((byte *)pcolormap[3])[temp];
pdest += 16; psrc += 8;
}
psrc += srcdelta;
pdest += rowdelta;
}
}
else
{
byte *psrc;
psrc = (byte *)src;
for (y = height ; y ; y--)
{
for (x = xcount ; x ;x--)
{
pdest[0] = pdest[1] = pdest[nextrow] =
pdest[nextrow + 1] = ((byte *)pcolormap[0])[psrc[0]];
pdest[2] = pdest[3] = pdest[nextrow + 2] =
pdest[nextrow + 3] = ((byte *)pcolormap[0])[psrc[1]];
pdest[4] = pdest[5] = pdest[nextrow + 4] =
pdest[nextrow + 5] = ((byte *)pcolormap[0])[psrc[2]];
pdest[6] = pdest[7] = pdest[nextrow + 6] =
pdest[nextrow + 7] = ((byte *)pcolormap[0])[psrc[3]];
pdest[8] = pdest[9] = pdest[nextrow + 8] =
pdest[nextrow + 9] = ((byte *)pcolormap[0])[psrc[4]];
pdest[10] = pdest[11] = pdest[nextrow + 10] =
pdest[nextrow + 11] = ((byte *)pcolormap[0])[psrc[5]];
pdest[12] = pdest[13] = pdest[nextrow + 12] =
pdest[nextrow + 13] = ((byte *)pcolormap[0])[psrc[6]];
pdest[14] = pdest[15] = pdest[nextrow + 14] =
pdest[nextrow + 15] = ((byte *)pcolormap[0])[psrc[7]];
pdest += 16; psrc += 8;
}
psrc += srcdelta;
pdest += rowdelta;
}
}
}
else
{
rowdelta = destrowbytes - width;
if (dither)
{
unsigned short *psrc;
psrc = (unsigned short *)src;
for (y = height ; y>0 ; y -= 2)
{
for (x = xcount ; x ;x--)
{
pdest[0] = ((byte *)pcolormap[0])[psrc[0]];
pdest[1] = ((byte *)pcolormap[1])[psrc[1]];
pdest[2] = ((byte *)pcolormap[0])[psrc[2]];
pdest[3] = ((byte *)pcolormap[1])[psrc[3]];
pdest[4] = ((byte *)pcolormap[0])[psrc[4]];
pdest[5] = ((byte *)pcolormap[1])[psrc[5]];
pdest[6] = ((byte *)pcolormap[0])[psrc[6]];
pdest[7] = ((byte *)pcolormap[1])[psrc[7]];
pdest += 8; psrc += 8;
}
psrc += srcdelta;
pdest += rowdelta;
for (x = xcount ; x ;x--)
{
pdest[0] = ((byte *)pcolormap[2])[psrc[0]];
pdest[1] = ((byte *)pcolormap[3])[psrc[1]];
pdest[2] = ((byte *)pcolormap[2])[psrc[2]];
pdest[3] = ((byte *)pcolormap[3])[psrc[3]];
pdest[4] = ((byte *)pcolormap[2])[psrc[4]];
pdest[5] = ((byte *)pcolormap[3])[psrc[5]];
pdest[6] = ((byte *)pcolormap[2])[psrc[6]];
pdest[7] = ((byte *)pcolormap[3])[psrc[7]];
pdest += 8; psrc += 8;
}
psrc += srcdelta;
pdest += rowdelta;
}
}
else
{
byte *psrc;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -