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

📄 store.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
字号:
/*
 *  +-------------------------------------------------------------------+
 *  | Copyright (c) 1995-2000 by TriMedia Technologies.                 |
 *  |                                                                   |
 *  | This software  is furnished under a license  and may only be used |
 *  | and copied in accordance with the terms  and conditions of such a |
 *  | license  and with  the inclusion of this  copyright notice.  This |
 *  | software or any other copies of this software may not be provided |
 *  | or otherwise  made available  to any other person.  The ownership |
 *  | and title of this software is not transferred.                    |
 *  |                                                                   |
 *  | The information  in this software  is subject  to change  without |
 *  | any  prior notice  and should not be construed as a commitment by |
 *  | TriMedia Technologies.                                            |
 *  |                                                                   |
 *  | This  code  and  information  is  provided  "as is"  without  any |
 *  | warranty of any kind,  either expressed or implied, including but |
 *  | not limited  to the implied warranties  of merchantability and/or |
 *  | fitness for any particular purpose.                               |
 *  +-------------------------------------------------------------------+
 *
 *  Module name              : mpegstore.c    1.0
 *
 *  Last update              : 
 *
 *  Description              :
 *		YUV file storage 
 ********/
#ifdef WRITE_TO_FILE

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "tmalTm2VdecMpeg.h"

#define OBFRSIZE (4096*2)
#define FILENAME_SLENGTH 2048

#ifdef FILEIO
extern char FrameName[];
#else
char FrameName[80] = "d:\\rec";
#endif

static int outfile;

static void store_frame(char *outname,unsigned long *src[],unsigned long *src2[],
		 int incr,int hsize, int height, int prog_seq, int prog_frm);
static void store_yuv (char *name, unsigned char *src,
  int offset, int incr, int width, int height);
static void store_prog_yuv(char *name, unsigned char *src,unsigned char *src2, int offset,
			   int incr,int width,int height);
static void store_yuv_full(char *name, unsigned char *src,int offset,int incr,int width,int height);

 /* separate headerless files for y, u and v */


void putpic(ptm2MpegDecInstVars_t livp) {

  char tmpname[FILENAME_SLENGTH];
  Int width=livp->codedPictureWidth;
  Int height =  livp->ph.vertical_size;

  sprintf(tmpname,"%s%d", FrameName,livp->bitstreamFramenum-1);

  if(livp->ph.picture_coding_type==B_TYPE) {   
    
    store_frame(tmpname, livp->currentFrame[0],livp->currentFrame[1], 
		livp->lineSize, width, height,
	         livp->ph.progressive_sequence, livp->ph.progressive_frame);



  }
  else {
    
    store_frame(tmpname, livp->forwardReferenceFrame[0],livp->forwardReferenceFrame[1], 
		livp->lineSize, width, height,
	         livp->ph.progressive_sequence, livp->ph.progressive_frame);
  }
  
}

void putlast(ptm2MpegDecInstVars_t livp) {

  char tmpname[FILENAME_SLENGTH];
  
  sprintf(tmpname,"%s%d", FrameName,livp->bitstreamFramenum-1);
  store_frame(tmpname, livp->backwardReferenceFrame[0],livp->backwardReferenceFrame[1], 
		livp->lineSize, livp->codedPictureWidth, livp->ph.vertical_size,
	         livp->ph.progressive_sequence, livp->ph.progressive_frame);

}


static void store_frame(char *outname,unsigned long *src[],unsigned long *src2[],
		 int incr,int hsize, int height, int prog_seq, int prog_frm)

{
  char tmpname[FILENAME_SLENGTH];

  /* always output in field mode */



  if (prog_seq || prog_frm ) {

    sprintf(tmpname,"%sf.Y",outname);
    store_prog_yuv(tmpname,(unsigned char *)src[0],(unsigned char *)src2[0],0,incr,hsize,height);

    height>>=1;
    
    sprintf(tmpname,"%sf.UV",outname);
    store_prog_yuv(tmpname,(unsigned char*) src[1],(unsigned char*) src2[1],0,incr,hsize,height);

  }

  else {

    sprintf(tmpname,"%sa.Y",outname);
    _cache_invalidate(src[0], hsize * height>>1);
    store_yuv(tmpname,(unsigned char *)src[0],0,incr,hsize,height>>1);
    
    sprintf(tmpname,"%sb.Y",outname);
    _cache_invalidate(src2[0], hsize * height>>1);
    store_yuv(tmpname,(unsigned char *)src2[0],0,incr,hsize,height>>1);
    
    height>>=1;
    
    sprintf(tmpname,"%sa.UV",outname);
    _cache_invalidate(src[1], hsize * height>>1);    
    store_yuv(tmpname,(unsigned char*) src[1],0,incr,hsize,height>>1);

    sprintf(tmpname,"%sb.UV",outname);
    _cache_invalidate(src2[1], hsize * height>>1);
    store_yuv(tmpname,(unsigned char*) src2[1],0,incr,hsize,height>>1);


  }

}

/* for interlaced video */
static void store_yuv(char *name, unsigned char *src,int offset,int incr,int width,int height)

{
  int i, j, nb;
  unsigned char *p;
  unsigned char databack[800];

#ifndef QUIET
  printf("saving %s\n",name);
#endif
  if ((outfile = open(name,O_CREAT|O_TRUNC|O_RDWR|O_BINARY,0666))==-1)
  {
    fprintf(stderr,"Couldn't create %s\n",name);
    exit(-1);
   
  }

  for (i=0; i<height; i++)
  {
    p = src + offset + incr*i;

    nb = write(outfile,p,width);
    while ( nb != width ) {
      printf(" Write error. Num byte written=%d. Line=%d. Source=0x%x\n",nb,i,p);
      nb = write(outfile,p,width);
    }

  }
  close(outfile);
  
}

/* For progressive frames/sequences */

static void store_prog_yuv(char *name, unsigned char *src,unsigned char *src2, int offset,
			   int incr,int width,int height)

{
  int i, j, nb;
  unsigned char *p;
#ifndef QUIET
  printf("saving %s\n",name);
#endif
  if ((outfile = open(name,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
  {
    fprintf(stderr,"Couldn't create %s\n",name);
    exit(-1);
   
  }

  for (i=0; i<(height>>1); i++)
  {
    p = src + offset + incr*i;
    nb = write(outfile,p,width);

    while ( nb != width ) {
      printf(" Write error. Num byte written only %d\n",nb);
      nb = write(outfile,p,width);
    }
		     

    p = src2 + offset + incr*i;
    nb = write(outfile,p,width);

    while ( nb != width ) {
      printf(" Write error. Num byte written only %d\n",nb);
      nb = write(outfile,p,width);
    }

  }
  close(outfile);


}

#endif

⌨️ 快捷键说明

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