📄 roqvideo.c
字号:
/* * Copyright (C) 2003 the ffmpeg project * * 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 * *//** * @file roqvideo.c * Id RoQ Video Decoder by Dr. Tim Ferguson * For more information about the Id RoQ format, visit: * http://www.csse.monash.edu.au/~timf/ */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include "common.h"#include "avcodec.h"#include "dsputil.h"typedef struct { unsigned char y0, y1, y2, y3, u, v;} roq_cell;typedef struct { int idx[4];} roq_qcell;static int uiclip[1024], *uiclp; /* clipping table */#define avg2(a,b) uiclp[(((int)(a)+(int)(b)+1)>>1)]#define avg4(a,b,c,d) uiclp[(((int)(a)+(int)(b)+(int)(c)+(int)(d)+2)>>2)]typedef struct RoqContext { AVCodecContext *avctx; DSPContext dsp; AVFrame last_frame; AVFrame current_frame; int first_frame; int y_stride; int c_stride; roq_cell cells[256]; roq_qcell qcells[256]; unsigned char *buf; int size;} RoqContext;#define RoQ_INFO 0x1001#define RoQ_QUAD_CODEBOOK 0x1002#define RoQ_QUAD_VQ 0x1011#define RoQ_SOUND_MONO 0x1020#define RoQ_SOUND_STEREO 0x1021#define RoQ_ID_MOT 0x00#define RoQ_ID_FCC 0x01#define RoQ_ID_SLD 0x02#define RoQ_ID_CCC 0x03#define get_byte(in_buffer) *(in_buffer++)#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \ (in_buffer[-1] << 8 | in_buffer[-2])))#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \ (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4])))static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell){ unsigned char *yptr; yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x; *yptr++ = cell->y0; *yptr++ = cell->y1; yptr += (ri->y_stride - 2); *yptr++ = cell->y2; *yptr++ = cell->y3; ri->current_frame.data[1][(y/2) * (ri->c_stride) + x/2] = cell->u; ri->current_frame.data[2][(y/2) * (ri->c_stride) + x/2] = cell->v;}static void apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell){ unsigned long row_inc, c_row_inc; register unsigned char y0, y1, u, v; unsigned char *yptr, *uptr, *vptr; yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x; uptr = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2; vptr = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2; row_inc = ri->y_stride - 4; c_row_inc = (ri->c_stride) - 2; *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v; *yptr++ = y0; *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v; *yptr++ = y1; yptr += row_inc; *yptr++ = y0; *yptr++ = y0; *yptr++ = y1; *yptr++ = y1; yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc; *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v; *yptr++ = y0; *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v; *yptr++ = y1; yptr += row_inc; *yptr++ = y0; *yptr++ = y0; *yptr++ = y1; *yptr++ = y1;}static void apply_motion_4x4(RoqContext *ri, int x, int y, unsigned char mv, signed char mean_x, signed char mean_y){ int i, hw, mx, my; unsigned char *pa, *pb; mx = x + 8 - (mv >> 4) - mean_x; my = y + 8 - (mv & 0xf) - mean_y; pa = ri->current_frame.data[0] + (y * ri->y_stride) + x; pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx; for(i = 0; i < 4; i++) { pa[0] = pb[0]; pa[1] = pb[1]; pa[2] = pb[2]; pa[3] = pb[3]; pa += ri->y_stride; pb += ri->y_stride; }#if 0 pa = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2; pb = ri->last_frame.data[1] + (my/2) * (ri->c_stride) + (mx + 1)/2; for(i = 0; i < 2; i++) { pa[0] = pb[0]; pa[1] = pb[1]; pa += ri->c_stride; pb += ri->c_stride; } pa = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2; pb = ri->last_frame.data[2] + (my/2) * (ri->c_stride) + (mx + 1)/2; for(i = 0; i < 2; i++) { pa[0] = pb[0]; pa[1] = pb[1]; pa += ri->c_stride; pb += ri->c_stride; }#else hw = ri->y_stride/2; pa = ri->current_frame.data[1] + (y * ri->y_stride)/4 + x/2; pb = ri->last_frame.data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; for(i = 0; i < 2; i++) { switch(((my & 0x01) << 1) | (mx & 0x01)) { case 0: pa[0] = pb[0]; pa[1] = pb[1]; pa[hw] = pb[hw]; pa[hw+1] = pb[hw+1]; break; case 1: pa[0] = avg2(pb[0], pb[1]); pa[1] = avg2(pb[1], pb[2]); pa[hw] = avg2(pb[hw], pb[hw+1]); pa[hw+1] = avg2(pb[hw+1], pb[hw+2]); break; case 2: pa[0] = avg2(pb[0], pb[hw]); pa[1] = avg2(pb[1], pb[hw+1]); pa[hw] = avg2(pb[hw], pb[hw*2]); pa[hw+1] = avg2(pb[hw+1], pb[(hw*2)+1]); break; case 3: pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]); pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]); pa[hw] = avg4(pb[hw], pb[hw+1], pb[hw*2], pb[(hw*2)+1]); pa[hw+1] = avg4(pb[hw+1], pb[hw+2], pb[(hw*2)+1], pb[(hw*2)+1]); break; } pa = ri->current_frame.data[2] + (y * ri->y_stride)/4 + x/2; pb = ri->last_frame.data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; }#endif}static void apply_motion_8x8(RoqContext *ri, int x, int y, unsigned char mv, signed char mean_x, signed char mean_y){ int mx, my, i, j, hw; unsigned char *pa, *pb; mx = x + 8 - (mv >> 4) - mean_x; my = y + 8 - (mv & 0xf) - mean_y; pa = ri->current_frame.data[0] + (y * ri->y_stride) + x; pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx; for(i = 0; i < 8; i++) { pa[0] = pb[0]; pa[1] = pb[1]; pa[2] = pb[2]; pa[3] = pb[3]; pa[4] = pb[4]; pa[5] = pb[5]; pa[6] = pb[6]; pa[7] = pb[7]; pa += ri->y_stride; pb += ri->y_stride; }#if 0 pa = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2; pb = ri->last_frame.data[1] + (my/2) * (ri->c_stride) + (mx + 1)/2; for(i = 0; i < 4; i++) { pa[0] = pb[0]; pa[1] = pb[1]; pa[2] = pb[2]; pa[3] = pb[3]; pa += ri->c_stride; pb += ri->c_stride;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -