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

📄 generic.c

📁 DirectFB-1.0.1可用于linux的嵌入式GUI
💻 C
📖 第 1 页 / 共 5 页
字号:
/*   (c) Copyright 2001-2007  The DirectFB Organization (directfb.org)   (c) Copyright 2000-2004  Convergence (integrated media) GmbH   All rights reserved.   Written by Denis Oliver Kropp <dok@directfb.org>,              Andreas Hundt <andi@fischlustig.de>,              Sven Neumann <neo@directfb.org>,              Ville Syrjälä <syrjala@sci.fi> and              Claudio Ciccani <klan@users.sf.net>.   This library 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 of the License, or (at your option) any later version.   This library 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; if not, write to the   Free Software Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.*/#include <config.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <dfb_types.h>#include <pthread.h>#include <directfb.h>#include <core/core.h>#include <core/coredefs.h>#include <core/coretypes.h>#include <core/gfxcard.h>#include <core/state.h>#include <core/surfacemanager.h>#include <core/palette.h>#include <misc/gfx_util.h>#include <misc/util.h>#include <misc/conf.h>#include <direct/mem.h>#include <direct/memcpy.h>#include <direct/messages.h>#include <direct/util.h>#include <gfx/convert.h>#include <gfx/util.h>#include "generic.h"#include "duffs_device.h"#include "yuvtbl.h"/* lookup tables for 2/3bit to 8bit color conversion */static const u8 lookup3to8[] = { 0x00, 0x24, 0x49, 0x6d, 0x92, 0xb6, 0xdb, 0xff};static const u8 lookup2to8[] = { 0x00, 0x55, 0xaa, 0xff};#define EXPAND_1to8(v)   ((v) ? 0xff : 0x00)#define EXPAND_2to8(v)   (lookup2to8[v])#define EXPAND_3to8(v)   (lookup3to8[v])#define EXPAND_4to8(v)   (((v) << 4) | ((v)     ))#define EXPAND_5to8(v)   (((v) << 3) | ((v) >> 2))#define EXPAND_6to8(v)   (((v) << 2) | ((v) >> 4))#define EXPAND_7to8(v)   (((v) << 1) | ((v) >> 6))static int use_mmx = 0;#ifdef USE_MMXstatic void gInit_MMX();#endif#if SIZEOF_LONG == 8static void gInit_64bit();#endif/* RGB16 */#define RGB_MASK 0xffff#define Cop_OP_Aop_PFI( op ) Cop_##op##_Aop_16#define Bop_PFI_OP_Aop_PFI( op ) Bop_16_##op##_Aop#include "template_colorkey_16.h"/* ARGB1555 / RGB555*/#define RGB_MASK 0x7fff#define Cop_OP_Aop_PFI( op ) Cop_##op##_Aop_15#define Bop_PFI_OP_Aop_PFI( op ) Bop_15_##op##_Aop#include "template_colorkey_16.h"/* ARGB2554 */#define RGB_MASK 0x3fff#define Cop_OP_Aop_PFI( op ) Cop_##op##_Aop_14#define Bop_PFI_OP_Aop_PFI( op ) Bop_14_##op##_Aop#include "template_colorkey_16.h"/* ARGB4444 / RGB444*/#define RGB_MASK 0x0fff#define Cop_OP_Aop_PFI( op ) Cop_##op##_Aop_12#define Bop_PFI_OP_Aop_PFI( op ) Bop_12_##op##_Aop#include "template_colorkey_16.h"/* ARGB/RGB32/AiRGB */#define RGB_MASK 0x00ffffff#define Cop_OP_Aop_PFI( op ) Cop_##op##_Aop_32#define Bop_PFI_OP_Aop_PFI( op ) Bop_32_##op##_Aop#include "template_colorkey_32.h"/* RGB16 */#define EXPAND_Ato8( a ) 0xFF#define EXPAND_Rto8( r ) EXPAND_5to8( r )#define EXPAND_Gto8( g ) EXPAND_6to8( g )#define EXPAND_Bto8( b ) EXPAND_5to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_RGB16( r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_rgb16_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_rgb16#define A_SHIFT 0#define R_SHIFT 11#define G_SHIFT 5#define B_SHIFT 0#define A_MASK 0#define R_MASK 0xf800#define G_MASK 0x07e0#define B_MASK 0x001f#include "template_acc_16.h"/* ARGB1555 */#define EXPAND_Ato8( a ) EXPAND_1to8( a )#define EXPAND_Rto8( r ) EXPAND_5to8( r )#define EXPAND_Gto8( g ) EXPAND_5to8( g )#define EXPAND_Bto8( b ) EXPAND_5to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_ARGB1555( a, r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_argb1555_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_argb1555#define A_SHIFT 15#define R_SHIFT 10#define G_SHIFT 5#define B_SHIFT 0#define A_MASK 0x8000#define R_MASK 0x7c00#define G_MASK 0x03e0#define B_MASK 0x001f#include "template_acc_16.h"/* RGB555 */#define EXPAND_Ato8( a ) 0xFF#define EXPAND_Rto8( r ) EXPAND_5to8( r )#define EXPAND_Gto8( g ) EXPAND_5to8( g )#define EXPAND_Bto8( b ) EXPAND_5to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_RGB555( r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_xrgb1555_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_xrgb1555#define A_SHIFT 0#define R_SHIFT 10#define G_SHIFT 5#define B_SHIFT 0#define A_MASK 0#define R_MASK 0x7c00#define G_MASK 0x03e0#define B_MASK 0x001f#include "template_acc_16.h"/* ARGB2554 */#define EXPAND_Ato8( a ) EXPAND_2to8( a )#define EXPAND_Rto8( r ) EXPAND_5to8( r )#define EXPAND_Gto8( g ) EXPAND_5to8( g )#define EXPAND_Bto8( b ) EXPAND_4to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_ARGB2554( a, r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_argb2554_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_argb2554#define A_SHIFT 14#define R_SHIFT 9#define G_SHIFT 4#define B_SHIFT 0#define A_MASK 0xc000#define R_MASK 0x3e00#define G_MASK 0x01f0#define B_MASK 0x000f#include "template_acc_16.h"/* ARGB4444 */#define EXPAND_Ato8( a ) EXPAND_4to8( a )#define EXPAND_Rto8( r ) EXPAND_4to8( r )#define EXPAND_Gto8( g ) EXPAND_4to8( g )#define EXPAND_Bto8( b ) EXPAND_4to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_ARGB4444( a, r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_argb4444_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_argb4444#define A_SHIFT 12#define R_SHIFT 8#define G_SHIFT 4#define B_SHIFT 0#define A_MASK 0xf000#define R_MASK 0x0f00#define G_MASK 0x00f0#define B_MASK 0x000f#include "template_acc_16.h"/* RGB444 */#define EXPAND_Ato8( a ) 0xFF#define EXPAND_Rto8( r ) EXPAND_4to8( r )#define EXPAND_Gto8( g ) EXPAND_4to8( g )#define EXPAND_Bto8( b ) EXPAND_4to8( b )#define PIXEL_OUT( a, r, g, b ) PIXEL_RGB444( r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_xrgb4444_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_xrgb4444#define A_SHIFT 0#define R_SHIFT 8#define G_SHIFT 4#define B_SHIFT 0#define A_MASK 0#define R_MASK 0x0f00#define G_MASK 0x00f0#define B_MASK 0x000f#include "template_acc_16.h"/* ARGB */#define EXPAND_Ato8( a ) (a)#define EXPAND_Rto8( r ) (r)#define EXPAND_Gto8( g ) (g)#define EXPAND_Bto8( b ) (b)#define PIXEL_OUT( a, r, g, b ) PIXEL_ARGB( a, r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_argb_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_argb#define A_SHIFT 24#define R_SHIFT 16#define G_SHIFT 8#define B_SHIFT 0#define A_MASK 0xff000000#define R_MASK 0x00ff0000#define G_MASK 0x0000ff00#define B_MASK 0x000000ff#include "template_acc_32.h"/* RGB32 */#define EXPAND_Ato8( a ) 0xFF#define EXPAND_Rto8( r ) (r)#define EXPAND_Gto8( g ) (g)#define EXPAND_Bto8( b ) (b)#define PIXEL_OUT( a, r, g, b ) PIXEL_RGB32( r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_rgb32_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_rgb32#define A_SHIFT 0#define R_SHIFT 16#define G_SHIFT 8#define B_SHIFT 0#define A_MASK 0#define R_MASK 0x00ff0000#define G_MASK 0x0000ff00#define B_MASK 0x000000ff#include "template_acc_32.h"/* AiRGB */#define EXPAND_Ato8( a ) ((a) ^ 0xff)#define EXPAND_Rto8( r ) (r)#define EXPAND_Gto8( g ) (g)#define EXPAND_Bto8( b ) (b)#define PIXEL_OUT( a, r, g, b ) PIXEL_AiRGB( a, r, g, b )#define Sop_PFI_OP_Dacc( op ) Sop_airgb_##op##_Dacc#define Sacc_OP_Aop_PFI( op ) Sacc_##op##_Aop_airgb#define A_SHIFT 24#define R_SHIFT 16#define G_SHIFT 8#define B_SHIFT 0#define A_MASK 0xff000000#define R_MASK 0x00ff0000#define G_MASK 0x0000ff00#define B_MASK 0x000000ff#include "template_acc_32.h"/********************************* Cop_to_Aop_PFI *****************************/static void Cop_to_Aop_8( GenefxState *gfxs ){     memset( gfxs->Aop[0], gfxs->Cop, gfxs->length );}static void Cop_to_Aop_16( GenefxState *gfxs ){     int    w;     int    l   = gfxs->length;     u32   *D   = gfxs->Aop[0];     u32    Cop = gfxs->Cop;     u32 DCop = ((Cop << 16) | Cop);     if (((long)D)&2) {         /* align */          u16* tmp = (u16*) D;          --l;          *tmp = Cop;          D = (u32*)(tmp+1);     }     w = (l >> 1);     while (w) {          *D = DCop;          --w;          ++D;     }     if (l & 1)                 /* do the last ential pixel */          *((u16*)D) = (u16)Cop;}static void Cop_to_Aop_18( GenefxState *gfxs ){     int   w = gfxs->length;     u8   *D = gfxs->Aop[0];     u32   Cop = gfxs->Cop;     while (w) {          D[0] = Cop;          D[1] = Cop >> 8;          D[2] = Cop >> 16;          D += 3;          --w;     }}static void Cop_to_Aop_24( GenefxState *gfxs ){     int   w = gfxs->length;     u8   *D = gfxs->Aop[0];     while (w) {          D[0] = gfxs->color.b;          D[1] = gfxs->color.g;          D[2] = gfxs->color.r;          D += 3;          --w;     }}static void Cop_to_Aop_32( GenefxState *gfxs ){     int    w   = gfxs->length;     u32   *D   = gfxs->Aop[0];     u32    Cop = gfxs->Cop;     while (w--)          *D++ = Cop;}static void Cop_to_Aop_yuv422( GenefxState *gfxs ){     int    l;     int    w   = gfxs->length;     u16   *D   = gfxs->Aop[0];     u32    Cop = gfxs->Cop;     if ((long)D & 2) {#ifdef WORDS_BIGENDIAN          *D++ = Cop & 0xffff;#else          *D++ = Cop >> 16;#endif          w--;     }     for (l = w>>1; l--;) {          *((u32*)D) = Cop;          D += 2;     }     if (w & 1) {#ifdef WORDS_BIGENDIAN          *D = Cop >> 16;#else          *D = Cop & 0xffff;#endif     }}static void Cop_to_Aop_i420( GenefxState *gfxs ){     memset( gfxs->Aop[0], gfxs->YCop, gfxs->length );     if (gfxs->AopY & 1) {          memset( gfxs->Aop[1], gfxs->CbCop, gfxs->length>>1 );          memset( gfxs->Aop[2], gfxs->CrCop, gfxs->length>>1 );     }}static void Cop_to_Aop_nv12( GenefxState *gfxs ){     memset( gfxs->Aop[0], gfxs->YCop, gfxs->length );         if (gfxs->dst_format == DSPF_NV16 || gfxs->AopY & 1) {          u16   *D   = gfxs->Aop[1];          int    w   = gfxs->length>>1;          u16    Cop = gfxs->CbCop | (gfxs->CrCop << 8);                    while (w--)               *D++ = Cop;     }}static void Cop_to_Aop_nv21( GenefxState *gfxs ){     memset( gfxs->Aop[0], gfxs->YCop, gfxs->length );         if (gfxs->AopY & 1) {          u16   *D   = gfxs->Aop[1];          int    w   = gfxs->length>>1;          u16    Cop = gfxs->CrCop | (gfxs->CbCop << 8);                    while (w--)               *D++ = Cop;     }}static GenefxFunc Cop_to_Aop_PFI[DFB_NUM_PIXELFORMATS] = {     Cop_to_Aop_16,      /* DSPF_ARGB1555 */     Cop_to_Aop_16,      /* DSPF_RGB16 */     Cop_to_Aop_24,      /* DSPF_RGB24 */     Cop_to_Aop_32,      /* DSPF_RGB32 */     Cop_to_Aop_32,      /* DSPF_ARGB */     Cop_to_Aop_8,       /* DSPF_A8 */     Cop_to_Aop_yuv422,  /* DSPF_YUY2 */     Cop_to_Aop_8,       /* DSPF_RGB332 */     Cop_to_Aop_yuv422,  /* DSPF_UYVY */     Cop_to_Aop_i420,    /* DSPF_I420 */     Cop_to_Aop_i420,    /* DSPF_YV12 */     Cop_to_Aop_8,       /* DSPF_LUT8 */     Cop_to_Aop_8,       /* DSPF_ALUT44 */     Cop_to_Aop_32,      /* DSPF_AiRGB */     NULL,               /* DSPF_A1 */     Cop_to_Aop_nv12,    /* DSPF_NV12 */     Cop_to_Aop_nv12,    /* DSPF_NV16 */     Cop_to_Aop_16,      /* DSPF_ARGB2554 */     Cop_to_Aop_16,      /* DSPF_ARGB4444 */     Cop_to_Aop_nv21,    /* DSPF_NV21 */     Cop_to_Aop_32,      /* DSPF_AYUV */     NULL,               /* DSPF_A4 */     Cop_to_Aop_18,      /* DSPF_ARGB1666 */     Cop_to_Aop_18,      /* DSPF_ARGB6666 */     Cop_to_Aop_18,      /* DSPF_RGB18 */     NULL,               /* DSPF_LUT2 */     Cop_to_Aop_16,      /* DSPF_RGB444 */     Cop_to_Aop_16,      /* DSPF_RGB555 */};/********************************* Cop_toK_Aop_PFI ****************************/static void Cop_toK_Aop_8( GenefxState *gfxs ){     int    w    = gfxs->length;     u8    *D    = gfxs->Aop[0];     u32    Cop  = gfxs->Cop;     u32    Dkey = gfxs->Dkey;     while (w--) {          if (Dkey == *D)               *D = Cop;          D++;     }}static void Cop_toK_Aop_18( GenefxState *gfxs ){     int   w   = gfxs->length;     u8   *D   = gfxs->Aop[0];     u32   Dkey = gfxs->Dkey;     u32   Cop  = gfxs->Cop;     while (w) {        if (Dkey == ((u32)(D[2]<<16 | D[1]<<8 | D[0]) & 0x3FFFF)) {               D[0] = Cop;               D[1] = Cop >> 8;               D[2] = Cop >> 16;        }        D += 3;        --w;

⌨️ 快捷键说明

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