📄 yuv_sw.c
字号:
/*** $Id: yuv_sw.c,v 1.4 2003/09/04 06:02:53 weiym Exp $** ** Port to MiniGUI by Wei Yongming (2001/10/03).** Copyright (C) 2001 ~ 2002 Wei Yongming.** Copyright (C) 2003 Feynman Software.**** SDL - Simple DirectMedia Layer** Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program 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 General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* This is the software implementation of the YUV video overlay support *//* This code was derived from code carrying the following copyright notices: * Copyright (c) 1995 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * Copyright (c) 1995 Erik Corry * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" * BASIS, AND ERIK CORRY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * Portions of this software Copyright (c) 1995 Brown University. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement * is hereby granted, provided that the above copyright notice and the * following two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "common.h"#include "newgal.h"#include "stretch_c.h"#include "yuvfuncs.h"#include "yuv_sw_c.h"/* Function to check the CPU flags */#define MMX_CPU 0x800000#ifdef USE_ASMBLIT#define CPU_Flags() Hermes_X86_CPU()#else#define CPU_Flags() 0L#endif#ifdef USE_ASMBLIT#define X86_ASSEMBLER#define HermesConverterInterface void#define HermesClearInterface void#define STACKCALLtypedef Uint32 int32;#include "HeadX86.h"#endif/* The functions used to manipulate software video overlays */static struct private_yuvhwfuncs sw_yuvfuncs = { GAL_LockYUV_SW, GAL_UnlockYUV_SW, GAL_DisplayYUV_SW, GAL_FreeYUV_SW};/* RGB conversion lookup tables */struct private_yuvhwdata { GAL_Surface *stretch; GAL_Surface *display; Uint8 *pixels; int *colortab; Uint32 *rgb_2_pix; void (*Display1X)(int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ); void (*Display2X)(int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ); /* These are just so we don't have to allocate them separately */ Uint16 pitches[3]; Uint8 *planes[3];};/* The colorspace conversion functions */extern void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod );extern void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod );static void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ){ unsigned short* row1; unsigned short* row2; unsigned char* lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; row1 = (unsigned short*) out; row2 = row1 + cols + mod; lum2 = lum + cols; mod += cols + mod; y = rows / 2; while( y-- ) { x = cols_2; while( x-- ) { register int L; cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; crb_g = 1*768+256 + colortab[ *cr + 1*256 ] + colortab[ *cb + 2*256 ]; cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; ++cr; ++cb; L = *lum++; *row1++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); L = *lum++; *row1++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); /* Now, do second row. */ L = *lum2++; *row2++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); L = *lum2++; *row2++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); } /* * These values are at the start of the next line, (due * to the ++'s above),but they need to be at the start * of the line after that. */ lum += cols; lum2 += cols; row1 += mod; row2 += mod; }}static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ){ unsigned int value; unsigned char* row1; unsigned char* row2; unsigned char* lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; row1 = out; row2 = row1 + cols*3 + mod*3; lum2 = lum + cols; mod += cols + mod; mod *= 3; y = rows / 2; while( y-- ) { x = cols_2; while( x-- ) { register int L; cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; crb_g = 1*768+256 + colortab[ *cr + 1*256 ] + colortab[ *cb + 2*256 ]; cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; ++cr; ++cb; L = *lum++; value = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); *row1++ = (value ) & 0xFF; *row1++ = (value >> 8) & 0xFF; *row1++ = (value >> 16) & 0xFF; L = *lum++; value = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); *row1++ = (value ) & 0xFF; *row1++ = (value >> 8) & 0xFF; *row1++ = (value >> 16) & 0xFF; /* Now, do second row. */ L = *lum2++; value = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); *row2++ = (value ) & 0xFF; *row2++ = (value >> 8) & 0xFF; *row2++ = (value >> 16) & 0xFF; L = *lum2++; value = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); *row2++ = (value ) & 0xFF; *row2++ = (value >> 8) & 0xFF; *row2++ = (value >> 16) & 0xFF; } /* * These values are at the start of the next line, (due * to the ++'s above),but they need to be at the start * of the line after that. */ lum += cols; lum2 += cols; row1 += mod; row2 += mod; }}static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ){ unsigned int* row1; unsigned int* row2; unsigned char* lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; row1 = (unsigned int*) out; row2 = row1 + cols + mod; lum2 = lum + cols; mod += cols + mod; y = rows / 2; while( y-- ) { x = cols_2; while( x-- ) { register int L; cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; crb_g = 1*768+256 + colortab[ *cr + 1*256 ] + colortab[ *cb + 2*256 ]; cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; ++cr; ++cb; L = *lum++; *row1++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); L = *lum++; *row1++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); /* Now, do second row. */ L = *lum2++; *row2++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); L = *lum2++; *row2++ = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); } /* * These values are at the start of the next line, (due * to the ++'s above),but they need to be at the start * of the line after that. */ lum += cols; lum2 += cols; row1 += mod; row2 += mod; }}/* * In this function I make use of a nasty trick. The tables have the lower * 16 bits replicated in the upper 16. This means I can write ints and get * the horisontal doubling for free (almost). */static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ){ unsigned int* row1 = (unsigned int*) out; const int next_row = cols+(mod/2); unsigned int* row2 = row1 + 2*next_row; unsigned char* lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; lum2 = lum + cols; mod = (next_row * 3) + (mod/2); y = rows / 2; while( y-- ) { x = cols_2; while( x-- ) { register int L; cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; crb_g = 1*768+256 + colortab[ *cr + 1*256 ] + colortab[ *cb + 2*256 ]; cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; ++cr; ++cb; L = *lum++; row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); row1++; L = *lum++; row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); row1++; /* Now, do second row. */ L = *lum2++; row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | rgb_2_pix[ L + crb_g ] | rgb_2_pix[ L + cb_b ]); row2++; L = *lum2++; row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -