📄 fblin16.c
字号:
/*
* Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
*
* 16bpp Linear Video Driver for Microwindows
*
* Inspired from Ben Pfaff's BOGL <pfaffben@debian.org>
*/
/*#define NDEBUG*/
#include <assert.h>
#include <stdlib.h>
/* We want to do string copying fast, so inline assembly if possible */
#ifndef __OPTIMIZE__
#define __OPTIMIZE__
#endif
#include <string.h>
#include "device.h"
#include "fb.h"
#define USE_DRAWAREA 0 /* =1 to implement temp removed DrawArea code*/
#define USE_16BIT_ACCESS 0 /* =1 to force 16 bit display access*/
#if USE_16BIT_ACCESS
#define memcpy(d,s,nbytes) memcpy16(d,s,(nbytes)>>1)
#define memmove(d,s,nbytes) memcpy16(d,s,(nbytes)>>1)
static void
memcpy16(unsigned short *dst, unsigned short *src, int nwords)
{
while (--nwords >= 0)
*dst++ = *src++;
}
#endif
/* Calc linelen and mmap size, return 0 on fail*/
static int
linear16_init(PSD psd)
{
if (!psd->size) {
psd->size = psd->yres * psd->linelen;
/* convert linelen from byte to pixel len for bpp 16, 24, 32*/
psd->linelen /= 2;
}
return 1;
}
/* Set pixel at x, y, to pixelval c*/
static void
linear16_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
{
ADDR16 addr = psd->addr;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y >= 0 && y < psd->yres);
assert (c < psd->ncolors);
DRAWON;
if(gr_mode == MWMODE_COPY)
addr[x + y * psd->linelen] = c;
else
applyOp(gr_mode, c, &addr[x + y * psd->linelen], ADDR16);
DRAWOFF;
}
/* Read pixel at x, y*/
static MWPIXELVAL
linear16_readpixel(PSD psd, MWCOORD x, MWCOORD y)
{
ADDR16 addr = psd->addr;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y >= 0 && y < psd->yres);
return addr[x + y * psd->linelen];
}
/* Draw horizontal line from x1,y to x2,y including final point*/
static void
linear16_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
{
ADDR16 addr = psd->addr;
assert (addr != 0);
assert (x1 >= 0 && x1 < psd->xres);
assert (x2 >= 0 && x2 < psd->xres);
assert (x2 >= x1);
assert (y >= 0 && y < psd->yres);
assert (c < psd->ncolors);
DRAWON;
addr += x1 + y * psd->linelen;
if(gr_mode == MWMODE_COPY) {
/* FIXME: memsetw(dst, c, x2-x1+1)*/
while(x1++ <= x2)
*addr++ = c;
} else {
while (x1++ <= x2) {
applyOp(gr_mode, c, addr, ADDR16);
++addr;
}
}
DRAWOFF;
}
/* Draw a vertical line from x,y1 to x,y2 including final point*/
static void
linear16_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
{
ADDR16 addr = psd->addr;
int linelen = psd->linelen;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y1 >= 0 && y1 < psd->yres);
assert (y2 >= 0 && y2 < psd->yres);
assert (y2 >= y1);
assert (c < psd->ncolors);
DRAWON;
addr += x + y1 * linelen;
if(gr_mode == MWMODE_COPY) {
while(y1++ <= y2) {
*addr = c;
addr += linelen;
}
} else {
while (y1++ <= y2) {
applyOp(gr_mode, c, addr, ADDR16);
addr += linelen;
}
}
DRAWOFF;
}
/* srccopy bitblt*/
static void
linear16_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
{
ADDR16 dst = dstpsd->addr;
ADDR16 src = srcpsd->addr;
int i;
int dlinelen = dstpsd->linelen;
int slinelen = srcpsd->linelen;
#if ALPHABLEND
unsigned int alpha;
#endif
assert (dst != 0);
assert (dstx >= 0 && dstx < dstpsd->xres);
assert (dsty >= 0 && dsty < dstpsd->yres);
assert (w > 0);
assert (h > 0);
assert (src != 0);
assert (srcx >= 0 && srcx < srcpsd->xres);
assert (srcy >= 0 && srcy < srcpsd->yres);
assert (dstx+w <= dstpsd->xres);
assert (dsty+h <= dstpsd->yres);
assert (srcx+w <= srcpsd->xres);
assert (srcy+h <= srcpsd->yres);
DRAWON;
dst += dstx + dsty * dlinelen;
src += srcx + srcy * slinelen;
#if ALPHABLEND
if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
goto stdblit;
alpha = op & 0xff;
if (dstpsd->pixtype == MWPF_TRUECOLOR565) {
while(--h >= 0) {
for(i=0; i<w; ++i) {
unsigned int s = *src++;
unsigned int d = *dst;
unsigned int t = d & 0xf800;
unsigned int m1, m2, m3;
m1 = (((((s & 0xf800) - t)*alpha)>>8) & 0xf800) + t;
t = d & 0x07e0;
m2 = (((((s & 0x07e0) - t)*alpha)>>8) & 0x07e0) + t;
t = d & 0x001f;
m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
*dst++ = m1 | m2 | m3;
}
dst += dlinelen - w;
src += slinelen - w;
}
} else {
/* 5/5/5 format*/
while(--h >= 0) {
for(i=0; i<w; ++i) {
unsigned int s = *src++;
unsigned int d = *dst;
unsigned int t = d & 0x7c00;
unsigned int m1, m2, m3;
m1 = (((((s & 0x7c00) - t)*alpha)>>8) & 0x7c00) + t;
t = d & 0x03e0;
m2 = (((((s & 0x03e0) - t)*alpha)>>8) & 0x03e0) + t;
t = d & 0x001f;
m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
*dst++ = m1 | m2 | m3;
}
dst += dlinelen - w;
src += slinelen - w;
}
}
DRAWOFF;
return;
stdblit:
#endif
if (op == MWROP_COPY) {
/* copy from bottom up if dst in src rectangle*/
/* memmove is used to handle x case*/
if (srcy < dsty) {
src += (h-1) * slinelen;
dst += (h-1) * dlinelen;
slinelen *= -1;
dlinelen *= -1;
}
while (--h >= 0) {
/* a _fast_ memcpy is a _must_ in this routine*/
memmove(dst, src, w<<1);
dst += dlinelen;
src += slinelen;
}
} else {
while (--h >= 0) {
for (i=0; i<w; i++) {
applyOp(MWROP_TO_MODE(op), *src, dst, ADDR16);
++src;
++dst;
}
dst += dlinelen - w;
src += slinelen - w;
}
}
DRAWOFF;
}
/* VERY experimental globals for debugging stretchblit off-by-some bug*/
extern int g_row_inc, g_col_inc;
/* srccopy stretchblt*/
static void
linear16_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,
MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, MWCOORD srcw,
MWCOORD srch, long op)
{
ADDR16 dst;
ADDR16 src;
int dlinelen = dstpsd->linelen;
int slinelen = srcpsd->linelen;
int i, ymax;
int row_pos, row_inc;
int col_pos, col_inc;
unsigned short pixel = 0;
assert (dstpsd->addr != 0);
assert (dstx >= 0 && dstx < dstpsd->xres);
assert (dsty >= 0 && dsty < dstpsd->yres);
assert (dstw > 0);
assert (dsth > 0);
assert (srcpsd->addr != 0);
assert (srcx >= 0 && srcx < srcpsd->xres);
assert (srcy >= 0 && srcy < srcpsd->yres);
assert (srcw > 0);
assert (srch > 0);
assert (dstx+dstw <= dstpsd->xres);
assert (dsty+dsth <= dstpsd->yres);
assert (srcx+srcw <= srcpsd->xres);
assert (srcy+srch <= srcpsd->yres);
DRAWON;
row_pos = 0x10000;
if (g_row_inc) row_inc = g_row_inc; else
row_inc = (srch << 16) / dsth;
/* stretch blit using integer ratio between src/dst height/width*/
for (ymax = dsty+dsth; dsty<ymax; ++dsty) {
/* find source y position*/
while (row_pos >= 0x10000L) {
++srcy;
row_pos -= 0x10000L;
}
dst = (ADDR16)dstpsd->addr + dstx + dsty*dlinelen;
src = (ADDR16)srcpsd->addr + srcx + (srcy-1)*slinelen;
/* copy a row of pixels*/
col_pos = 0x10000;
if (g_col_inc) col_inc = g_col_inc; else
col_inc = (srcw << 16) / dstw;
for (i=0; i<dstw; ++i) {
/* get source x pixel*/
while (col_pos >= 0x10000L) {
pixel = *src++;
col_pos -= 0x10000L;
}
*dst++ = pixel;
col_pos += col_inc;
}
row_pos += row_inc;
}
DRAWOFF;
}
#if USE_DRAWAREA
/* temporarily removed DrawArea entry point code*/
static void init_alpha_lookup(unsigned short **low, unsigned short **high)
{
unsigned short a, x, *lo, *hi;
unsigned short r, g, b;
unsigned short idx;
lo = *low = malloc(32*256*2);
hi = *high = malloc(32*256*2);
if ( hi == 0 || lo == 0 )
exit(17);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -