00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "contributors.h"
00016
00017 #include "global.h"
00018 #include "report.h"
00019 #include "img_io.h"
00020
00021
00022 #define FAST_READ 1
00023
00024 #if FAST_READ
00025 static inline void ReadData (int vfile, FrameFormat *source, unsigned char *buf)
00026 {
00027 unsigned char *cur_buf = buf;
00028 int i, j;
00029 for (i = 0; i < source->height; i++)
00030 {
00031 if (read(vfile, cur_buf, source->width) != source->width)
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 += source->width;
00037 }
00038 for (j = 0; j < 2; j++)
00039 {
00040 for (i = 0; i < source->height_cr; i++)
00041 {
00042 if (read(vfile, cur_buf, source->width_cr) != source->width_cr)
00043 {
00044 printf ("ReadOneFrame: cannot read %d bytes from input file, unexpected EOF, exiting...\n", source->width_cr);
00045 report_stats_on_error();
00046 }
00047 cur_buf += source->width_cr;
00048 }
00049 }
00050 }
00051 #else
00052 static inline void ReadData (int vfile, int framesize_in_bytes, unsigned char *buf)
00053 {
00054 if (read(vfile, buf, (int) framesize_in_bytes) != (int) framesize_in_bytes)
00055 {
00056 printf ("ReadOneFrame: cannot read %d bytes from input file, unexpected EOF, exiting...\n", (int) framesize_in_bytes);
00057 report_stats_on_error();
00058 }
00059 }
00060 #endif
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void ReadFrameConcatenated (VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf)
00082 {
00083 int vfile = input_file->f_num;
00084 unsigned int symbol_size_in_bytes = img->pic_unit_size_on_disk >> 3;
00085
00086 const int imgsize_y = source->width * source->height;
00087 const int imgsize_uv = source->width_cr * source->height_cr;
00088
00089 const int bytes_y = imgsize_y * symbol_size_in_bytes;
00090 const int bytes_uv = imgsize_uv * symbol_size_in_bytes;
00091
00092 const int64 framesize_in_bytes = bytes_y + 2*bytes_uv;
00093
00094 #if 0
00095
00096 if (lseek (vfile, HeaderSize, SEEK_SET) != HeaderSize)
00097 {
00098 error ("ReadOneFrame: cannot fseek to (Header size) in input file", -1);
00099 }
00100
00101
00102 if (lseek (vfile, framesize_in_bytes * params->start_frame, SEEK_CUR) == -1)
00103 {
00104 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", params->start_frame);
00105 error (errortext,-1);
00106 }
00107
00108
00109 if (lseek (vfile, framesize_in_bytes * (FrameNoInFile), SEEK_CUR) == -1)
00110 {
00111 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", params->start_frame + FrameNoInFile);
00112 error (errortext,-1);
00113 }
00114 #else
00115
00116 if (lseek (vfile, HeaderSize + framesize_in_bytes * (FrameNoInFile + params->start_frame), SEEK_SET) == -1)
00117 {
00118 snprintf(errortext, ET_SIZE, "ReadOneFrame: cannot advance file pointer in input file beyond frame %d\n", params->start_frame + FrameNoInFile);
00119 error (errortext,-1);
00120 }
00121 #endif
00122
00123
00124 if ((img->pic_unit_size_on_disk & 0x07) == 0)
00125 {
00126 #if FAST_READ
00127 ReadData (vfile, source, buf);
00128 #else
00129 ReadData (vfile, (int) framesize_in_bytes, buf);
00130 #endif
00131 }
00132 else
00133 {
00134 printf ("ReadOneFrame (NOT IMPLEMENTED): pic unit size on disk must be divided by 8");
00135 exit (-1);
00136 }
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 void ReadFrameSeparate (VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf)
00158 {
00159 int vfile = input_file->f_num;
00160
00161 OpenFrameFile( input_file, params, FrameNoInFile + params->start_frame);
00162
00163
00164 if (lseek (vfile, HeaderSize, SEEK_SET) != HeaderSize)
00165 {
00166 error ("ReadOneFrame: cannot fseek to (Header size) in input file", -1);
00167 }
00168
00169
00170 if ((img->pic_unit_size_on_disk & 0x07) == 0)
00171 {
00172 #if FAST_READ
00173 ReadData (vfile, source, buf);
00174 #else
00175 unsigned int symbol_size_in_bytes = img->pic_unit_size_on_disk >> 3;
00176
00177 const int imgsize_y = source->width * source->height;
00178 const int imgsize_uv = source->width_cr * source->height_cr;
00179
00180 const int bytes_y = imgsize_y * symbol_size_in_bytes;
00181 const int bytes_uv = imgsize_uv * symbol_size_in_bytes;
00182 const int64 framesize_in_bytes = bytes_y + 2*bytes_uv;
00183
00184 ReadData (vfile, (int) framesize_in_bytes, buf);
00185 #endif
00186 }
00187 else
00188 {
00189 printf ("ReadOneFrame (NOT IMPLEMENTED): pic unit size on disk must be divided by 8");
00190 exit (-1);
00191 }
00192
00193 if (vfile != -1)
00194 close(vfile);
00195 }