⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fblin32alpha.c

📁 the embedded GUI for SamSung s3c2410 cpu based board.is microwindows0.90
💻 C
📖 第 1 页 / 共 3 页
字号:
				register int d;				a = (int) (unsigned char)					src8[MWI_BYTE_OFFSET_ALPHA];				if (a == 255) {					dst8[0] = src8[0];					dst8[1] = src8[1];					dst8[2] = src8[2];					dst8[MWI_BYTE_OFFSET_ALPHA] = a;				} else if (a != 0) {					s = (int) (unsigned char)						src8[MWI_BYTE_OFFSET_R];					d = (int) (unsigned char)						dst8[MWI_BYTE_OFFSET_R];					dst8[MWI_BYTE_OFFSET_R] =						(unsigned						 char) ((((s - d) * a) >> 8) +							d);					s = (int) (unsigned char)						src8[MWI_BYTE_OFFSET_G];					d = (int) (unsigned char)						dst8[MWI_BYTE_OFFSET_G];					dst8[MWI_BYTE_OFFSET_G] =						(unsigned						 char) ((((s - d) * a) >> 8) +							d);					s = (int) (unsigned char)						src8[MWI_BYTE_OFFSET_B];					d = (int) (unsigned char)						dst8[MWI_BYTE_OFFSET_B];					dst8[MWI_BYTE_OFFSET_B] =						(unsigned						 char) ((((s - d) * a) >> 8) +							d);					d = (int) (unsigned char)						dst8[MWI_BYTE_OFFSET_ALPHA];					dst8[MWI_BYTE_OFFSET_ALPHA] =						(a + ((d * (256 - a)) >> 8));				}				src8 += 4;				dst8 += 4;			}			dst8 += (dlinelen - w) * 4;			src8 += (slinelen - w) * 4;		}	} else {		/* FIXME: Implement other alpha blend modes */	}	DRAWOFF;}/* srccopy stretchblt*/static voidlinear32a_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,		      MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy,		      MWCOORD srcw, MWCOORD srch, long op){	ADDR32 dst;	ADDR32 src;	int dlinelen = dstpsd->linelen;	int slinelen = srcpsd->linelen;	int i, ymax;	int row_pos, row_inc;	int col_pos, col_inc;	unsigned long 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;	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 = (ADDR32) dstpsd->addr + dstx + dsty * dlinelen;		src = (ADDR32) srcpsd->addr + srcx + (srcy - 1) * slinelen;		/* copy a row of pixels */		col_pos = 0x10000;		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;}/* * This stretchblit code was originally written for the TriMedia * VLIW CPU.  Therefore it uses RESTRICT pointers, and the special * one-assembler-opcode pseudo-functions SIGN and ABS. * * (The 'restrict' extension is in C99, so for a C99 compiler you * could "#define RESTRICT restrict" or put * "CFLAGS += -DRESTRICT=restrict" in the makefile). * * Compatibility definitions: */#ifndef RESTRICT#define RESTRICT#endif#ifndef SIGN#define SIGN(x) (((x) > 0) ? 1 : (((x) == 0) ? 0 : -1))#endif#ifndef ABS#define ABS(x) (((x) >= 0) ? (x) : -(x))#endif/* Blit a 32-bit image. * Can stretch the image by any X and/or Y scale factor. * Can flip the image in the X and/or Y axis. * * This is the faster version with no per-pixel multiply and a single * decision tree for the inner loop, by Jon.  Based on Alex's original * all-integer version. * * Paramaters: * srf              - Dest surface * dest_x_start * dest_y_start    - Top left corner of dest rectangle * width, height   - Size in dest co-ordinates. * x_denominator   - Denominator for source X value fractions.  Note that *                   this must be even, and all the numerators must also be *                   even, so we can easily divide by 2. * y_denominator   - Denominator for source Y value fractions.  Note that *                   this must be even, and all the numerators must also be *                   even, so we can easily divide by 2. * src_x_fraction  - * src_y_fraction  - Point in source that corresponds to the top left corner *                   of the pixel (dest_x_start, dest_y_start).  This is a *                   fraction - to get a float, divide by y_denominator. * x_step_fraction - X step in src for an "x++" step in dest.  May be negative *                   (for a flip).  Expressed as a fraction - divide it by *                   x_denominator for a float. * y_step_fraction - Y step in src for a  "y++" step in dest.  May be negative *                   (for a flip).  Expressed as a fraction - divide it by *                   y_denominator for a float. * image           - Source image. * op              - Raster operation, currently ignored. */static voidlinear32a_stretchblitex(PSD dstpsd,			PSD srcpsd,			MWCOORD dest_x_start,			MWCOORD dest_y_start,			MWCOORD width,			MWCOORD height,			int x_denominator,			int y_denominator,			int src_x_fraction,			int src_y_fraction,			int x_step_fraction, int y_step_fraction, long op){	/* Pointer to the current pixel in the source image */	unsigned long *RESTRICT src_ptr;	/* Pointer to x=xs1 on the next line in the source image */	unsigned long *RESTRICT next_src_ptr;	/* Pointer to the current pixel in the dest image */	unsigned long *RESTRICT dest_ptr;	/* Pointer to x=xd1 on the next line in the dest image */	unsigned long *next_dest_ptr;	/* Keep track of error in the source co-ordinates */	int x_error;	int y_error;	/* 1-unit steps "forward" through the source image, as steps in the image	 * byte array.	 */	int src_x_step_one;	int src_y_step_one;	/* normal steps "forward" through the source image, as steps in the image	 * byte array.	 */	int src_x_step_normal;	int src_y_step_normal;	/* 1-unit steps "forward" through the source image, as steps in the image	 * byte array.	 */	int x_error_step_normal;	int y_error_step_normal;	/* Countdown to the end of the destination image */	int x_count;	int y_count;	/* Start position in source, in whole pixels */	int src_x_start;	int src_y_start;	/* Error values for start X position in source */	int x_error_start;	/* 1-unit step down dest, in bytes. */	int dest_y_step;	/*DPRINTF("Nano-X: linear32_stretchflipblit( dest=(%d,%d) %dx%d )\n",	   dest_x_start, dest_y_start, width, height); */	/* We add half a dest pixel here so we're sampling from the middle of	 * the dest pixel, not the top left corner.	 */	src_x_fraction += (x_step_fraction >> 1);	src_y_fraction += (y_step_fraction >> 1);	/* Seperate the whole part from the fractions.	 *	 * Also, We need to do lots of comparisons to see if error values are	 * >= x_denominator.  So subtract an extra x_denominator for speed - then	 * we can just check if it's >= 0.	 */	src_x_start = src_x_fraction / x_denominator;	src_y_start = src_y_fraction / y_denominator;	x_error_start = src_x_fraction - (src_x_start + 1) * x_denominator;	y_error = src_y_fraction - (src_y_start + 1) * y_denominator;	/* precalculate various deltas */	src_x_step_normal = x_step_fraction / x_denominator;	src_x_step_one = SIGN(x_step_fraction);	x_error_step_normal =		ABS(x_step_fraction) - ABS(src_x_step_normal) * x_denominator;	src_y_step_normal = y_step_fraction / y_denominator;	src_y_step_one = SIGN(y_step_fraction) * srcpsd->linelen;	y_error_step_normal =		ABS(y_step_fraction) - ABS(src_y_step_normal) * y_denominator;	src_y_step_normal *= srcpsd->linelen;	/* DPRINTF("ov_stretch_image8: X: One step=%d, err-=%d; normal step=%d, err+=%d\n                   Y: One step=%d, err-=%d; normal step=%d, err+=%d\n",	   src_x_step_one, x_denominator, src_x_step_normal, x_error_step_normal,	   src_y_step_one, y_denominator, src_y_step_normal, y_error_step_normal);	 */	/* Pointer to the first source pixel */	next_src_ptr =		((unsigned long *) srcpsd->addr) +		src_y_start * srcpsd->linelen + src_x_start;	/* Cache the width of a scanline in dest */	dest_y_step = dstpsd->linelen;	/* Pointer to the first dest pixel */	next_dest_ptr =		((unsigned long *) dstpsd->addr) +		(dest_y_start * dest_y_step) + dest_x_start;	/*	 * Note: The MWROP_SRC and MWROP_XOR_FGBG cases below are simple	 * expansions of the default case.  They can be removed without	 * significant speed penalty if you need to reduce code size.	 *	 * The SRC_OVER case cannot be removed (since applyOp doesn't	 * handle it correctly).	 *	 * The MWROP_CLEAR case could be removed.  But it is a large	 * speed increase for a small quantity of code.	 *	 * FIXME Porter-Duff rules other than SRC_OVER not handled!!	 */	switch (op & MWROP_EXTENSION) {	case MWROP_SRC:		/* Benchmarking shows that this while loop is faster than the equivalent		 * for loop: for(y_count=0; y_count<height; y_count++) { ... }		 */		y_count = height;		while (y_count-- > 0) {			src_ptr = next_src_ptr;			dest_ptr = next_dest_ptr;			x_error = x_error_start;			x_count = width;			while (x_count-- > 0) {				*dest_ptr++ = *src_ptr;				src_ptr += src_x_step_normal;				x_error += x_error_step_normal;				if (x_error >= 0) {					src_ptr += src_x_step_one;					x_error -= x_denominator;				}			}			next_dest_ptr += dest_y_step;			next_src_ptr += src_y_step_normal;			y_error += y_error_step_normal;			if (y_error >= 0) {				next_src_ptr += src_y_step_one;				y_error -= y_denominator;			}		}		break;	case MWROP_SRC_OVER:		/* Benchmarking shows that this while loop is faster than the equivalent		 * for loop: for(y_count=0; y_count<height; y_count++) { ... }		 */		y_count = height;		while (y_count-- > 0) {			src_ptr = next_src_ptr;			dest_ptr = next_dest_ptr;			x_error = x_error_start;			x_count = width;			while (x_count-- > 0) {				int c;				int a;				int s;				register int d;				int orig;				int result;				c = *src_ptr;				a = (c >> 24) & 0xFF;				if (a == 255) {					*dest_ptr = c;				} else if (a != 0) {					orig = *dest_ptr;					d = (orig >> 24) & 0xFF;					result = ((d + a -						   ((d * a) >> 8)) << 24);					s = ((c >> 16) & 0xFF);					d = (orig >> 16) & 0xFF;					result |=						(((((s - d) * a) >> 8) +						  d) << 16);					s = ((c >> 8) & 0xFF);					d = (orig >> 8) & 0xFF;					result |=						(((((s - d) * a) >> 8) +						  d) << 8);					s = (c & 0xFF);					d = orig & 0xFF;					result |= ((((s - d) * a) >> 8) + d);					*dest_ptr = result;				}				dest_ptr++;				src_ptr += src_x_step_normal;				x_error += x_error_step_normal;				if (x_error >= 0) {					src_ptr += src_x_step_one;					x_error -= x_denominator;				}			}			next_dest_ptr += dest_y_step;			next_src_ptr += src_y_step_normal;			y_error += y_error_step_normal;			if (y_error >= 0) {				next_src_ptr += src_y_step_one;				y_error -= y_denominator;			}		}		break;	case MWROP_XOR_FGBG:		y_count = height;		while (y_count-- > 0) {			src_ptr = next_src_ptr;			dest_ptr = next_dest_ptr;			x_error = x_error_start;			x_count = width;			while (x_count-- > 0) {				*dest_ptr++ ^= *src_ptr ^ gr_background;				src_ptr += src_x_step_normal;				x_error += x_error_step_normal;				if (x_error >= 0) {					src_ptr += src_x_step_one;					x_error -= x_denominator;				}			}			next_dest_ptr += dest_y_step;			next_src_ptr += src_y_step_normal;			y_error += y_error_step_normal;			if (y_error >= 0) {				next_src_ptr += src_y_step_one;				y_error -= y_denominator;			}		}		break;	case MWROP_CLEAR:		y_count = height;		while (y_count-- > 0) {			dest_ptr = next_dest_ptr;			x_count = width;			while (x_count-- > 0) {				*dest_ptr++ = 0;			}			next_dest_ptr += dest_y_step;		}		break;	default:		y_count = height;		while (y_count-- > 0) {			src_ptr = next_src_ptr;			dest_ptr = next_dest_ptr;			x_error = x_error_start;			x_count = width;			while (x_count-- > 0) {				applyOp(MWROP_TO_MODE(op), *src_ptr, dest_ptr,					ADDR32);				dest_ptr++;				src_ptr += src_x_step_normal;				x_error += x_error_step_normal;				if (x_error >= 0) {					src_ptr += src_x_step_one;					x_error -= x_denominator;				}			}			next_dest_ptr += dest_y_step;			next_src_ptr += src_y_step_normal;			y_error += y_error_step_normal;			if (y_error >= 0) {				next_src_ptr += src_y_step_one;				y_error -= y_denominator;			}		}		break;	}}#if MW_FEATURE_PSDOP_BITMAP_BYTES_LSB_FIRST/* psd->DrawArea operation PSDOP_BITMAP_BYTES_LSB_FIRST which * takes a pixmap, each line is byte aligned, and copies it * to the screen using fg_color and bg_color to replace a 1 * and 0 in the pixmap.  This pixmap is ordered the wrong * way around; it has the leftmost pixel (on the screen) in * LSB (Bit 0) of the bytes. * * The reason why this non-intuitive bit ordering is used is * to match the bit ordering used in the T1lib font rendering * library. * * Variables used in the gc: *       dstx, dsty, dsth, dstw   Destination rectangle *       srcx, srcy               Source rectangle *       src_linelen              Linesize in bytes of source *       pixels                   Pixmap data *       fg_color                 Color of a '1' bit *       bg_color                 Color of a '0' bit *       gr_usebg                 If set, bg_color is used.  If zero, *                                then '0' bits are transparent. */static voidlinear32a_drawarea_bitmap_bytes_lsb_first(PSD psd, driver_gc_t * gc){/* * The difference between the MSB_FIRST and LSB_FIRST variants of * this function is simply the definition of these three #defines. * * MWI_IS_BIT_BEFORE_OR_EQUAL(A,B) returns true if bit A is before *     (i.e. to the left of) bit B. * MWI_ADVANCE_BIT(X) advances X on to the next bit to the right, *     and stores the result back in X. * MWI_BIT_NO(N), where 0<=n<=7, gives the Nth bit, where 0 is the *     leftmost bit and 7 is the rightmost bit.  This is a constant *     iff N is a constant. */#define MWI_IS_BIT_BEFORE_OR_EQUAL(a,b) ((a) <= (b))#define MWI_ADVANCE_BIT(target) ((target) <<= 1)#define MWI_BIT_NO(n) (0x01 << (n))/* * Two convenience defines - these are the same for MSB_FIRST and * LSB_FIRST. */#define MWI_FIRST_BIT MWI_BIT_NO(0)#define MWI_LAST_BIT  MWI_BIT_NO(7)	unsigned char prefix_first_bit;	unsigned char postfix_first_bit = MWI_FIRST_BIT;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -