OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.application/] [h.263_encoder_main/] [1.0/] [src/] [yuv.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*---------------------------------------------------------------------------
2
*
3
*  Course:   System Design II
4
*
5
*  Module:   yuv.c
6
*
7
*  Purpose:  YUV raw-file handling functions  for H.263 encoder
8
*
9
*  Notes:
10
*
11
*  Author:   Tero Kangas and Olli Lehtoranta
12
*
13
*  History:  31/10/2002: + Original version ready
14
*
15
**---------------------------------------------------------------------------
16
*/
17
#include "headers.h"
18
 
19
 
20
 
21
/*---------------------------------------------------------------------------
22
*
23
*  Function: yuvOpenInputFile
24
*
25
*  Input:    file_name = name of file to be opened
26
*            frame_count = frame counter (to be initialized)
27
*
28
*  Return:   Pointer to file opened
29
*
30
*  Purpose:  To open a raw YUV file and compute its frame count
31
*
32
**---------------------------------------------------------------------------
33
*/
34
FILE* yuvOpenInputFile( const vchar *file_name, sint32 *frame_count) {
35
 
36
  FILE *file;
37
  vlong  file_size;
38
 
39
  file = fopen(file_name,"rb");
40
  if( file == NULL ){
41
    printf("yuvOpenInputFile: Could not open the file %s\n", file_name);
42
    return NULL;
43
  }
44
 
45
  /* Check the file size */
46
  fseek(file,0,SEEK_END);
47
  file_size = ftell(file);
48
  *frame_count = ( file_size / 38016 );
49
 
50
  /* Set the file position back to the beginning of the file */
51
  fseek(file,0,SEEK_SET);
52
  return file;
53
}
54
 
55
 
56
/*---------------------------------------------------------------------------
57
*
58
*  Function: yuvReadFrame
59
*
60
*  Input:    file = data structure modeling YUV-file
61
*            target_buffer = target memory buffer where to the image is read
62
*
63
*  Return:   V_TRUE, if a frame read operation does not fail
64
*
65
*  Purpose:  Can be used to read frames from raw YUV-file
66
*
67
**---------------------------------------------------------------------------
68
*/
69
vbool yuvReadFrame( FILE * const file,
70
                    uint8 * const target_buffer ){
71
 
72
  if( fread(target_buffer,38016,1,file) != 1 ){
73
    printf("yuvReadFrame: The read was failed!\n");
74
    return V_FALSE;
75
  }
76
 
77
  return V_TRUE;
78
}
79
 
80
/*---------------------------------------------------------------------------
81
*
82
*  Function: yuvWriteFrame
83
*
84
*  Input:    file = data structure modeling YUV-file
85
*            source_buffer = source memory buffer from where image data
86
*                            is stored to file
87
*
88
*  Return:   V_FALSE, if the write operation fails
89
*
90
*  Purpose:  To write singe YUV-frame to the disk. Concatenated after
91
*            existing file.
92
*
93
**---------------------------------------------------------------------------
94
*/
95
vbool yuvWriteFrame( FILE * const file, const uint8 * const source_buffer ) {
96
 
97
  if( file != NULL ){
98
    if( fwrite(source_buffer,38016,1,file) != 1 ){
99
      return V_FALSE;
100
    }
101
  }
102
  return V_TRUE;
103
}
104
 
105
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.