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

📄 surface.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *			GPAC - Multimedia Framework C SDK * *			Copyright (c) Jean Le Feuvre 2000-2005 *					All rights reserved * *  This file is part of GPAC / software 2D rasterizer module * *  GPAC is free software; you can redistribute it and/or modify *  it under the terms of the GNU Lesser General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. *    *  GPAC is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. *    *  You should have received a copy of the GNU Lesser General Public *  License along with this library; see the file COPYING.  If not, write to *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  * * */#include "rast_soft.h"static void get_surface_world_matrix(EVGSurface *_this, GF_Matrix2D *mat){	gf_mx2d_init(*mat);	if (_this->center_coords) {		gf_mx2d_add_scale(mat, FIX_ONE, -FIX_ONE);		gf_mx2d_add_translation(mat, INT2FIX(_this->width / 2), INT2FIX(_this->height / 2));	}}GF_SURFACE evg_surface_new(GF_Raster2D *_dr, Bool center_coords){	EVGSurface *_this;	GF_SAFEALLOC(_this, EVGSurface);	if (_this) {		_this->center_coords = center_coords;		_this->texture_filter = GF_TEXTURE_FILTER_DEFAULT;		_this->ftparams.source = &_this->ftoutline;		_this->ftparams.user = _this;		_this->raster = evg_raster_new();	}	return _this;}void evg_surface_delete(GF_SURFACE _this){	EVGSurface *surf = (EVGSurface *)_this;#ifndef INLINE_POINT_CONVERSION	if (surf->points) free(surf->points);#endif	if (surf->stencil_pix_run) free(surf->stencil_pix_run);	evg_raster_del(surf->raster);	free(surf);}GF_Err evg_surface_set_matrix(GF_SURFACE _this, GF_Matrix2D *mat){	GF_Matrix2D tmp;	EVGSurface *surf = (EVGSurface *)_this;	if (!surf) return GF_BAD_PARAM;	get_surface_world_matrix(surf, &surf->mat);	if (!mat) return GF_OK;	gf_mx2d_init(tmp);	gf_mx2d_add_matrix(&tmp, mat);	gf_mx2d_add_matrix(&tmp, &surf->mat);	gf_mx2d_copy(surf->mat, tmp);	return GF_OK;}GF_Err evg_surface_attach_to_callbacks(GF_SURFACE _this, GF_RasterCallback *callbacks, u32 width, u32 height){	EVGSurface *surf = (EVGSurface *)_this;	if (!surf || !width || !height || !callbacks) return GF_BAD_PARAM;	if (!callbacks->cbk || !callbacks->fill_run_alpha || !callbacks->fill_run_no_alpha) return GF_BAD_PARAM;	surf->width = width;	surf->height = height;	if (surf->stencil_pix_run) free(surf->stencil_pix_run);	surf->stencil_pix_run = (u32 *) malloc(sizeof(u32) * (width+2));	surf->raster_cbk = callbacks->cbk;	surf->raster_fill_run_alpha = callbacks->fill_run_alpha;	surf->raster_fill_run_no_alpha = callbacks->fill_run_no_alpha;	evg_surface_set_matrix(surf, NULL);	return GF_OK;}GF_Err evg_surface_attach_to_buffer(GF_SURFACE _this, char *pixels, u32 width, u32 height, u32 stride, GF_PixelFormat pixelFormat){	u32 BPP;	EVGSurface *surf = (EVGSurface *)_this;	if (!surf || !pixels || (pixelFormat>GF_PIXEL_YUVA)) return GF_BAD_PARAM;	switch (pixelFormat) {#ifdef GF_RGB_444_SUPORT	case GF_PIXEL_RGB_444:#endif#ifdef GF_RGB_555_SUPORT	case GF_PIXEL_RGB_555:#endif	case GF_PIXEL_RGB_565:		BPP = 2;		break;	case GF_PIXEL_BGR_24:	case GF_PIXEL_RGB_24:		BPP = 3;		break;	case GF_PIXEL_RGB_32:	case GF_PIXEL_ARGB:		BPP = 4;		break;	case GF_PIXEL_BGR_32:	default:		return GF_NOT_SUPPORTED;	}	surf->stride = stride;	surf->width = width;	if (surf->stencil_pix_run) free(surf->stencil_pix_run);	surf->stencil_pix_run = (u32 *) malloc(sizeof(u32) * (width+2));	surf->height = height;	surf->pixels = (char*)pixels;	surf->pixelFormat = pixelFormat;	surf->BPP = BPP;	surf->raster_cbk = NULL;	surf->raster_fill_run_alpha = NULL;	surf->raster_fill_run_no_alpha = NULL;	evg_surface_set_matrix(_this, NULL);	return GF_OK;}GF_Err evg_surface_attach_to_texture(GF_SURFACE _this, GF_STENCIL sten){	u32 BPP;	EVGSurface *surf = (EVGSurface *)_this;	EVG_Texture *tx = (EVG_Texture *) sten;;	if (!surf || (tx->type != GF_STENCIL_TEXTURE)) return GF_BAD_PARAM;	switch (tx->pixel_format) {	case GF_PIXEL_GREYSCALE:		BPP = 1;		break;	case GF_PIXEL_ALPHAGREY:#ifdef GF_RGB_444_SUPORT	case GF_PIXEL_RGB_444:#endif#ifdef GF_RGB_555_SUPORT	case GF_PIXEL_RGB_555:#endif	case GF_PIXEL_RGB_565:		BPP = 2;		break;	case GF_PIXEL_BGR_24:	case GF_PIXEL_RGB_24:		BPP = 3;		break;	case GF_PIXEL_RGB_32:	case GF_PIXEL_ARGB:		BPP = 4;		break;	default:		return GF_NOT_SUPPORTED;	}	surf->stride = tx->stride;	if (surf->stencil_pix_run) free(surf->stencil_pix_run);	surf->stencil_pix_run = (u32 *) malloc(sizeof(u32) * (tx->width+2));	surf->width = tx->width;	surf->height = tx->height;	surf->pixels = tx->pixels;	surf->pixelFormat = tx->pixel_format;	surf->BPP = BPP;	surf->raster_cbk = NULL;	surf->raster_fill_run_alpha = NULL;	surf->raster_fill_run_no_alpha = NULL;	evg_surface_set_matrix(surf, NULL);	return GF_OK;}void evg_surface_detach(GF_SURFACE _this){	EVGSurface *surf = (EVGSurface *)_this;	surf->raster_cbk = NULL;	surf->raster_fill_run_alpha = NULL;	surf->raster_fill_run_no_alpha = NULL;}GF_Err evg_surface_clear(GF_SURFACE _this, GF_IRect *rc, u32 color){	GF_IRect clear;	EVGSurface *surf = (EVGSurface *)_this;	if (!surf) return GF_BAD_PARAM;	if (rc) {			s32 _x, _y;		if (surf->center_coords) {			_x = rc->x + surf->width / 2;			_y = surf->height / 2 - rc->y;		} else {			_x = rc->x;			_y = rc->y - rc->height;		}		clear.width = (u32) rc->width;		if (_x>=0) {			clear.x = (u32) _x;		} else {			if ( (s32) clear.width + _x < 0) return GF_BAD_PARAM;			clear.width += _x;			clear.x = 0;		}		clear.height = (u32) rc->height;		if (_y>=0) {			clear.y = _y;		} else {			if ( (s32) clear.height + _y < 0) return GF_BAD_PARAM;			clear.height += _y;			clear.y = 0;		}	} else {		clear.x = clear.y = 0;		clear.width = surf->width;		clear.height = surf->height;	}		if (surf->raster_cbk) {		return evg_surface_clear_user(surf, clear, color);	}	switch (surf->pixelFormat) {	case GF_PIXEL_ARGB:	case GF_PIXEL_RGB_32:		return evg_surface_clear_argb(surf, clear, color);	case GF_PIXEL_BGR_24:		return evg_surface_clear_rgb(surf, clear, color);	case GF_PIXEL_RGB_24:		return evg_surface_clear_bgr(surf, clear, color);	case GF_PIXEL_RGB_565:		return evg_surface_clear_565(surf, clear, color);#ifdef GF_RGB_444_SUPORT	case GF_PIXEL_RGB_444:		return evg_surface_clear_444(surf, clear, color);#endif#ifdef GF_RGB_555_SUPORT	case GF_PIXEL_RGB_555:		return evg_surface_clear_555(surf, clear, color);#endif	default:		return GF_BAD_PARAM;	}}GF_Err evg_surface_set_raster_level(GF_SURFACE _this, GF_RasterLevel RasterSetting){	EVGSurface *surf = (EVGSurface *)_this;	if (!surf) return GF_BAD_PARAM;	switch (RasterSetting) {	case GF_RASTER_HIGH_QUALITY:		surf->AALevel = 1;/*don't draw pixels with 0 alpha...*/		surf->texture_filter = GF_TEXTURE_FILTER_HIGH_QUALITY;		break;	case GF_RASTER_MID:		surf->AALevel = 90;		surf->texture_filter = GF_TEXTURE_FILTER_HIGH_QUALITY;		break;	case GF_RASTER_HIGH_SPEED:	default:		surf->AALevel = 180;		surf->texture_filter = GF_TEXTURE_FILTER_HIGH_SPEED;		break;	}	return GF_OK;}GF_Err evg_surface_set_clipper(GF_SURFACE _this , GF_IRect *rc){	EVGSurface *surf = (EVGSurface *)_this;	if (!surf) return GF_BAD_PARAM;	if (rc) {		surf->clipper = *rc;		surf->useClipper = 1;		/*clipper was given in BIFS like coords, we work with bottom-min for rect, (0,0) top-left of surface*/		if (surf->center_coords) {			surf->clipper.x += surf->width / 2;			surf->clipper.y = surf->height / 2 - rc->y;		} else {			surf->clipper.y -= rc->height;		}		if (surf->clipper.x <=0) {			if (surf->clipper.x + (s32) surf->clipper.width < 0) return GF_BAD_PARAM;			surf->clipper.width += surf->clipper.x;			surf->clipper.x = 0;

⌨️ 快捷键说明

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