00001
00015 #include "contributors.h"
00016
00017 #include "global.h"
00018 #include "report.h"
00019 #include "img_io.h"
00020
00021 #define FAST_READ 1
00022
00023 #if FAST_READ
00024 static inline void ReadData (int vfile, FrameFormat *source, unsigned char *buf)
00025 {
00026 unsigned char *cur_buf = buf;
00027 int read_size = source->pic_unit_size_shift3 * source->width;
00028 int i, j;
00029 for (i = 0; i < source->height; i++)
00030 {
00031 if (read(vfile, cur_buf, read_size) != read_size)
00032 {
00033 printf ("ReadOneFrame: cannot read %d bytes from input file, unexpected EOF, exiting...\n", source->width);
00034 report_stats_on_error();
00035 }
00036 cur_buf += read_size;
00037 }
00038
00039 if (source->yuv_format != YUV400)
00040 {
00041 read_size = source->pic_unit_size_shift3 * source->width_cr;
00042 for (j = 0; j < 2; j++)
00043 {
00044 for (i = 0; i < source->height_cr; i++)
00045 {
00046 if (read(vfile, cur_buf, read_size) != read_size)
00047 {
00048 printf ("ReadOneFrame: cannot read %d bytes from input file, unexpected EOF, exiting...\n", source->width_cr);
00049 report_stats_on_error();
00050 }
00051 cur_buf += read_size;
00052 }
00053 }
00054 }
00055 }
00056 #else
00057 static inline void ReadData (int vfile, int framesize_in_bytes, unsigned char *buf)
00058 {
00059 if (read(vfile, buf, (int) framesize_in_bytes) != (int) framesize_in_bytes)
00060 {
00061 printf ("ReadOneFrame: cannot read %d bytes from input file, unexpected EOF, exiting...\n", (int) framesize_in_bytes);
00062 report_stats_on_error();
00063 }
00064 }
00065 #endif
00066
00067
00088 void ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf)
00089 {
00090 int vfile = input_file->f_num;
00091 unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3;
00092
00093 const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes;
00094 const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes;
00095
00096 const int64 framesize_in_bytes = bytes_y + 2*bytes_uv;
00097
00098 #if 0
00099
00100 if (lseek (vfile, HeaderSize, SEEK_SET) != HeaderSize)
00101 {
00102 error ("ReadOneFrame: cannot fseek to (Header size) in input file", -1);
00103 }
00104
00105
00106 if (lseek (vfile, framesize_in_bytes * p_Inp->start_frame, SEEK_CUR) == -1)
00107 {
00108 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", p_Inp->start_frame);
00109 error (errortext,-1);
00110 }
00111
00112
00113 if (lseek (vfile, framesize_in_bytes * (FrameNoInFile), SEEK_CUR) == -1)
00114 {
00115 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", p_Inp->start_frame + FrameNoInFile);
00116 error (errortext,-1);
00117 }
00118 #else
00119
00120 if (lseek (vfile, HeaderSize + framesize_in_bytes * (FrameNoInFile + p_Inp->start_frame), SEEK_SET) == -1)
00121 {
00122 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", p_Inp->start_frame + FrameNoInFile);
00123 error (errortext,-1);
00124 }
00125 #endif
00126
00127
00128 if ((source->pic_unit_size_on_disk & 0x07) == 0)
00129 {
00130 #if FAST_READ
00131 ReadData (vfile, source, buf);
00132 #else
00133 ReadData (vfile, (int) framesize_in_bytes, buf);
00134 #endif
00135 }
00136 else
00137 {
00138 printf ("ReadOneFrame (NOT IMPLEMENTED): pic unit size on disk must be divided by 8");
00139 exit (-1);
00140 }
00141 }
00142
00163 void ReadFrameSeparate (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf)
00164 {
00165 int vfile = input_file->f_num;
00166
00167 OpenFrameFile( input_file, FrameNoInFile + p_Inp->start_frame);
00168
00169
00170 if (lseek (vfile, HeaderSize, SEEK_SET) != HeaderSize)
00171 {
00172 error ("ReadOneFrame: cannot fseek to (Header size) in input file", -1);
00173 }
00174
00175
00176 if ((source->pic_unit_size_on_disk & 0x07) == 0)
00177 {
00178 #if FAST_READ
00179 ReadData (vfile, source, buf);
00180 #else
00181 unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3;
00182
00183 const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes;
00184 const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes;
00185 const int64 framesize_in_bytes = bytes_y + 2*bytes_uv;
00186
00187 ReadData (vfile, (int) framesize_in_bytes, buf);
00188 #endif
00189 }
00190 else
00191 {
00192 printf ("ReadOneFrame (NOT IMPLEMENTED): pic unit size on disk must be divided by 8");
00193 exit (-1);
00194 }
00195
00196 if (vfile != -1)
00197 close(vfile);
00198 }