📄 mem_transfer.c
字号:
/*****************************************************************************
*
* XVID MPEG-4 VIDEO CODEC
* - 8bit<->16bit transfer -
*
* This program is an implementation of a part of one or more MPEG-4
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending
* to use this software module in hardware or software products are
* advised that its use may infringe existing patents or copyrights, and
* any such use would be at such party's own risk. The original
* developer of this software module and his/her company, and subsequent
* editors and their companies, will have no liability for use of this
* software or modifications or derivatives thereof.
*
* 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
*
****************************************************************************/
/*****************************************************************************
*
* History
*
* - 14.06.2002 Changed legal header with the new FSF address
* - 14.04.2002 added transfer_8to16sub2
* - 07.01.2002 merge functions from compensate; rename functions
* - 22.12.2001 transfer_8to8add16 limit fix
* - 07.11.2001 initial version; (c)2001 peter ross <pross@cs.rmit.edu.au>
*
* $Id: mem_transfer.c,v 1.4 2002/06/15 22:15:57 edgomez Exp $
*
****************************************************************************/
#include "../global.h"
#include "mem_transfer.h"
#ifdef _TRIMEDIA
#include <custom_defs.h>
#endif
/* Function pointers - Initialized in the xvid.c module */
/*========8 to 16 copy,for transform====================*/
TRANSFER_8TO16COPY_PTR transfer_8to16copy;
/*========16 to 8 copy,after transform==================*/
TRANSFER_16TO8COPY_PTR transfer_16to8copy;
/*========8 to 16 sub,do in compensate,for transform====*/
TRANSFER_8TO16SUB_PTR transfer_8to16sub;
/*========16 to 8 add,after transform===================*/
TRANSFER_16TO8ADD_PTR transfer_16to8add;
/*========8 to 8 copy,for interpolate8x8_switch=========*/
TRANSFER8X8_COPY_PTR transfer8x8_copy;
/*****************************************************************************
*
* All these functions are used to transfer data from a 8 bit data array
* to a 16 bit data array.
*
* This is typically used during motion compensation, that's why some
* functions also do the addition/substraction of another buffer during the
* so called transfer.
*
****************************************************************************/
/*!
************************************************************************
* \brief
* the function does the 8->16 bit transfer and this serie of operations
*
************************************************************************
*/
/*#ifdef _TRIMEDIA*/
void
transfer_8to16copy_c(int16_t * const dst, /*<--> the destination buffer*/
const uint8_t * const src, /*<-- the source buffer*/
uint32_t stride /*<-- stride*/
)
{
uint32_t i, j;
for (j = 0; j < 8; j++) {
for (i = 0; i < 8; i++) {
dst[j * 8 + i] = (int16_t) src[j * stride + i];
}
}
}
/*#endif*/
/*just loop unroll*/
/*#define optimize_8to16copy3*/
#ifdef optimize_8to16copy1
void
transfer_8to16copy_c(int16_t * const dst,
const uint8_t * const src,
uint32_t stride)
{
uint32_t i, j,k;
for ( j = 0; j < 8; j++) {
dst[j * 8 + 0] = (int16_t) src[j * stride + 0];
dst[j * 8 + 1] = (int16_t) src[j * stride + 1];
dst[j * 8 + 2] = (int16_t) src[j * stride + 2];
dst[j * 8 + 3] = (int16_t) src[j * stride + 3];
dst[j * 8 + 4] = (int16_t) src[j * stride + 4];
dst[j * 8 + 5] = (int16_t) src[j * stride + 5];
dst[j * 8 + 6] = (int16_t) src[j * stride + 6];
dst[j * 8 + 7] = (int16_t) src[j * stride + 7];
}
}
#endif
/*use pointer add,but cannot parallel */
#ifdef optimize_8to16copy2
void
transfer_8to16copy_c(int16_t * const dst,
const uint8_t * const src,
uint32_t stride)
{
uint32_t i, j;
int16_t * ptr_dst = dst;
uint8_t const * ptr_src = src;
/*
for (k = i = j = 0; j < 8; j++) {
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
*(ptr_dst + i++) = *(ptr_src + k++);
ptr_dst += 8;
ptr_src += stride;
}
*/
uint32_t stride1 = stride-8;
for (j = 0; j < 8; j++) {
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
*(ptr_dst++) = *(ptr_src++);
ptr_src += stride1;
}
}
#endif
#ifdef optimize_8to16copy3
void
transfer_8to16copy_c(int16_t * const dst,
const uint8_t * const src,
uint32_t stride)
{
uint32_t i, j;
int16_t * ptr_dst = dst;
uint8_t const * ptr_src = src;
for (j = 0; j < 8; j++) {
*(ptr_dst+0) = *(ptr_src+0);
*(ptr_dst+1) = *(ptr_src+1);
*(ptr_dst+2) = *(ptr_src+2);
*(ptr_dst+3) = *(ptr_src+3);
*(ptr_dst+4) = *(ptr_src+4);
*(ptr_dst+5) = *(ptr_src+5);
*(ptr_dst+6) = *(ptr_src+6);
*(ptr_dst+7) = *(ptr_src+7);
ptr_src += stride;
ptr_dst +=8;
}
}
#endif
/*!
************************************************************************
* \brief
* the function does the 16->8 bit transfer and this serie of operations
* SRC (16bit) = SRC
* DST (8bit) = max(min(SRC, 255), 0)
************************************************************************
*/
#ifdef _TRIMEDIA
#define optimize_16to8copy_3 /*useful*/
#endif
#ifndef _TRIMEDIA
void
transfer_16to8copy_c(uint8_t * const dst, /*<--> the destination buffer*/
const int16_t * const src, /*<-- the source buffer*/
uint32_t stride) /*<-- stride*/
{
uint32_t i, j;
int16_t pixel ;
for (j = 0; j < 8; j++) {
for (i = 0; i < 8; i++) {
pixel = src[j * 8 + i];
if (pixel < 0) {
pixel = 0;
}
else if (pixel > 255) {
pixel = 255;
}
dst[j * stride + i] = (uint8_t) pixel;
}
}
}
#endif
#ifdef optimize_16to8copy_2
void
transfer_16to8copy_c(uint8_t * const dst, /*<--> the destination buffer*/
const int16_t * const src, /*<-- the source buffer*/
uint32_t stride) /*<-- stride*/
{
uint32_t i, j;
int16_t pixel ;
int16_t src0,src1,src2,src3;
int16_t src4,src5,src6,src7;
uint8_t *ptr_dst = dst;
int16_t *ptr_src = src;
uint32_t clip_src0,clip_src1,clip_src2,clip_src3;
uint32_t clip_src4,clip_src5,clip_src6,clip_src7;
uint32_t stride1;
stride1 = stride - 8;
for (j = 0; j < 8; j++) {
src0 = *(ptr_src++);
src1 = *(ptr_src++);
src2 = *(ptr_src++);
src3 = *(ptr_src++);
src4 = *(ptr_src++);
src5 = *(ptr_src++);
src6 = *(ptr_src++);
src7 = *(ptr_src++);
clip_src0 = UCLIPI(src0,255);
clip_src1 = UCLIPI(src1,255);
clip_src2 = UCLIPI(src2,255);
clip_src3 = UCLIPI(src3,255);
clip_src4 = UCLIPI(src4,255);
clip_src5 = UCLIPI(src5,255);
clip_src6 = UCLIPI(src6,255);
clip_src7 = UCLIPI(src7,255);
*(ptr_dst++) = (uint8_t)clip_src0;
*(ptr_dst++) = (uint8_t)clip_src1;
*(ptr_dst++) = (uint8_t)clip_src2;
*(ptr_dst++) = (uint8_t)clip_src3;
*(ptr_dst++) = (uint8_t)clip_src4;
*(ptr_dst++) = (uint8_t)clip_src5;
*(ptr_dst++) = (uint8_t)clip_src6;
*(ptr_dst++) = (uint8_t)clip_src7;
ptr_dst += stride1;
/*for (i = 0; i < 8; i++) {
pixel = src[j * 8 + i];
if (pixel < 0) {
pixel = 0;
}
else if (pixel > 255) {
pixel = 255;
}
dst[j * stride + i] = (uint8_t) pixel;
}*/
}
}
#endif
#ifdef optimize_16to8copy_3
void
transfer_16to8copy_c(uint8_t * const dst, /*<--> the destination buffer*/
const int16_t * const src, /*<-- the source buffer*/
uint32_t stride) /*<-- stride*/
{
uint32_t i, j;
int16_t pixel ;
int16_t src0,src1,src2,src3;
int16_t src4,src5,src6,src7;
/* uint8_t * restrict ptr_dst = dst;
const int16_t * restrict ptr_src = src;*/
uint8_t *ptr_dst = dst;
const int16_t *ptr_src = src;
uint32_t clip_src0,clip_src1,clip_src2,clip_src3;
uint32_t clip_src4,clip_src5,clip_src6,clip_src7;
for (j = 0; j < 8; j++) {
src0 = *(ptr_src+0);
src1 = *(ptr_src+1);
src2 = *(ptr_src+2);
src3 = *(ptr_src+3);
src4 = *(ptr_src+4);
src5 = *(ptr_src+5);
src6 = *(ptr_src+6);
src7 = *(ptr_src+7);
clip_src0 = UCLIPI(src0,255);
clip_src1 = UCLIPI(src1,255);
clip_src2 = UCLIPI(src2,255);
clip_src3 = UCLIPI(src3,255);
clip_src4 = UCLIPI(src4,255);
clip_src5 = UCLIPI(src5,255);
clip_src6 = UCLIPI(src6,255);
clip_src7 = UCLIPI(src7,255);
*(ptr_dst+0) = (uint8_t)clip_src0;
*(ptr_dst+1) = (uint8_t)clip_src1;
*(ptr_dst+2) = (uint8_t)clip_src2;
*(ptr_dst+3) = (uint8_t)clip_src3;
*(ptr_dst+4) = (uint8_t)clip_src4;
*(ptr_dst+5) = (uint8_t)clip_src5;
*(ptr_dst+6) = (uint8_t)clip_src6;
*(ptr_dst+7) = (uint8_t)clip_src7;
ptr_dst += stride;
ptr_src += 8;
/*for (i = 0; i < 8; i++) {
pixel = src[j * 8 + i];
if (pixel < 0) {
pixel = 0;
}
else if (pixel > 255) {
pixel = 255;
}
dst[j * stride + i] = (uint8_t) pixel;
}*/
}
}
#endif
#ifdef optimize_16to8copy_1
void
transfer_16to8copy_c(uint8_t * const dst, /*<--> the destination buffer*/
const int16_t * const src, /*<-- the source buffer*/
uint32_t stride) /*<-- stride*/
{
uint32_t i, j;
int16_t pixel ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -