mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 02:24:07 +00:00
Move writing reconstructed image to yuv_io module.
Adds function yuv_io_write.
This commit is contained in:
parent
7bd23f5dbb
commit
012c0580df
|
@ -942,26 +942,10 @@ void encoder_compute_stats(encoder_state_t *state, FILE * const recout, double f
|
|||
threadqueue_waitfor(encoder->threadqueue, state->tqj_bitstream_written);
|
||||
|
||||
if (recout) {
|
||||
const videoframe_t * const frame = state->tile->frame;
|
||||
// Write reconstructed frame out.
|
||||
// Use conformance-window dimensions instead of internal ones.
|
||||
const int width = frame->width;
|
||||
const int out_width = encoder->in.real_width;
|
||||
const int out_height = encoder->in.real_height;
|
||||
int y;
|
||||
const pixel_t *y_rec = frame->rec->y;
|
||||
const pixel_t *u_rec = frame->rec->u;
|
||||
const pixel_t *v_rec = frame->rec->v;
|
||||
|
||||
for (y = 0; y < out_height; ++y) {
|
||||
fwrite(&y_rec[y * width], sizeof(*y_rec), out_width, recout);
|
||||
}
|
||||
for (y = 0; y < out_height / 2; ++y) {
|
||||
fwrite(&u_rec[y * width / 2], sizeof(*u_rec), out_width / 2, recout);
|
||||
}
|
||||
for (y = 0; y < out_height / 2; ++y) {
|
||||
fwrite(&v_rec[y * width / 2], sizeof(*v_rec), out_width / 2, recout);
|
||||
}
|
||||
yuv_io_write(recout,
|
||||
state->tile->frame->rec,
|
||||
encoder->in.real_width,
|
||||
encoder->in.real_height);
|
||||
}
|
||||
|
||||
videoframe_compute_psnr(state->tile->frame, frame_psnr);
|
||||
|
|
30
src/yuv_io.c
30
src/yuv_io.c
|
@ -148,3 +148,33 @@ int yuv_io_seek(FILE* file, unsigned frames,
|
|||
|
||||
return !error || feof(file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Write a single frame to a file.
|
||||
*
|
||||
* \param file output file
|
||||
* \param img image to output
|
||||
* \param output_width width of the output in pixels
|
||||
* \param output_height height of the output in pixels
|
||||
*
|
||||
* \return 1 on success, 0 on failure
|
||||
*/
|
||||
int yuv_io_write(FILE* file,
|
||||
image_t const* img,
|
||||
unsigned output_width, unsigned output_height)
|
||||
{
|
||||
const int width = img->width;
|
||||
for (int y = 0; y < output_height; ++y) {
|
||||
fwrite(&img->y[y * width], sizeof(*img->y), output_width, file);
|
||||
// TODO: Check that fwrite succeeded.
|
||||
}
|
||||
for (int y = 0; y < output_height / 2; ++y) {
|
||||
fwrite(&img->u[y * width / 2], sizeof(*img->u), output_width / 2, file);
|
||||
}
|
||||
for (int y = 0; y < output_height / 2; ++y) {
|
||||
fwrite(&img->v[y * width / 2], sizeof(*img->v), output_width / 2, file);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -35,4 +35,8 @@ int yuv_io_read(FILE* file,
|
|||
int yuv_io_seek(FILE* file, unsigned frames,
|
||||
unsigned input_width, unsigned input_height);
|
||||
|
||||
int yuv_io_write(FILE* file,
|
||||
image_t const* img,
|
||||
unsigned output_width, unsigned output_height);
|
||||
|
||||
#endif // YUV_IO_H_
|
||||
|
|
Loading…
Reference in a new issue