[x265] [PATCH] Multilib recon fix
Mahesh Pittala
mahesh at multicorewareinc.com
Wed Jan 24 03:49:38 UTC 2024
>From 069e70e0448b2de42dcbd85386b4abbd40d5221f Mon Sep 17 00:00:00 2001
From: Mahesh <mahesh at multicorewareinc.com>
Date: Fri, 19 Jan 2024 10:13:07 +0530
Subject: [PATCH] Multilib recon fix
---
source/output/output.cpp | 6 ++--
source/output/output.h | 2 +-
source/output/y4m.cpp | 58 +++++++++++++++++-----------------
source/output/y4m.h | 4 ++-
source/output/yuv.cpp | 81
+++++++++++++++++++++++++-----------------------
source/output/yuv.h | 4 ++-
source/x265cli.cpp | 2 +-
7 files changed, 82 insertions(+), 75 deletions(-)
diff --git a/source/output/output.cpp b/source/output/output.cpp
index 35ed845..c2327b6 100644
--- a/source/output/output.cpp
+++ b/source/output/output.cpp
@@ -30,14 +30,14 @@
using namespace X265_NS;
-ReconFile* ReconFile::open(const char *fname, int width, int height,
uint32_t bitdepth, uint32_t fpsNum, uint32_t fpsDenom, int csp)
+ReconFile* ReconFile::open(const char *fname, int width, int height,
uint32_t bitdepth, uint32_t fpsNum, uint32_t fpsDenom, int csp, int
sourceBitDepth)
{
const char * s = strrchr(fname, '.');
if (s && !strcmp(s, ".y4m"))
- return new Y4MOutput(fname, width, height, fpsNum, fpsDenom, csp);
+ return new Y4MOutput(fname, width, height, fpsNum, fpsDenom, csp,
sourceBitDepth);
else
- return new YUVOutput(fname, width, height, bitdepth, csp);
+ return new YUVOutput(fname, width, height, bitdepth, csp,
sourceBitDepth);
}
OutputFile* OutputFile::open(const char *fname, InputFileInfo& inputInfo)
diff --git a/source/output/output.h b/source/output/output.h
index ac61d8a..6fee4f2 100644
--- a/source/output/output.h
+++ b/source/output/output.h
@@ -42,7 +42,7 @@ public:
ReconFile() {}
static ReconFile* open(const char *fname, int width, int height,
uint32_t bitdepth,
- uint32_t fpsNum, uint32_t fpsDenom, int csp);
+ uint32_t fpsNum, uint32_t fpsDenom, int csp,
int sourceBitDepth);
virtual bool isFail() const = 0;
diff --git a/source/output/y4m.cpp b/source/output/y4m.cpp
index c1fd3a6..0ebd91c 100644
--- a/source/output/y4m.cpp
+++ b/source/output/y4m.cpp
@@ -28,11 +28,12 @@
using namespace X265_NS;
using namespace std;
-Y4MOutput::Y4MOutput(const char *filename, int w, int h, uint32_t fpsNum,
uint32_t fpsDenom, int csp)
+Y4MOutput::Y4MOutput(const char *filename, int w, int h, uint32_t fpsNum,
uint32_t fpsDenom, int csp, int inputdepth)
: width(w)
, height(h)
, colorSpace(csp)
, frameSize(0)
+ , inputDepth(inputdepth)
{
ofs.open(filename, ios::binary | ios::out);
buf = new char[width];
@@ -72,38 +73,37 @@ bool Y4MOutput::writePicture(const x265_picture& pic)
X265_CHECK(pic.colorSpace == colorSpace, "invalid chroma
subsampling\n");
-#if HIGH_BIT_DEPTH
-
- // encoder gave us short pixels, downshift, then write
- X265_CHECK(pic.bitDepth > 8, "invalid bit depth\n");
- int shift = pic.bitDepth - 8;
- for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ if (inputDepth > 8)
{
- uint16_t *src = (uint16_t*)pic.planes[i];
- for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i];
h++)
- {
- for (int w = 0; w < width >>
x265_cli_csps[colorSpace].width[i]; w++)
- buf[w] = (char)(src[w] >> shift);
-
- ofs.write(buf, width >> x265_cli_csps[colorSpace].width[i]);
- src += pic.stride[i] / sizeof(*src);
- }
+ // encoder gave us short pixels, downshift, then write
+ X265_CHECK(pic.bitDepth > 8, "invalid bit depth\n");
+ int shift = pic.bitDepth - 8;
+ for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ {
+ uint16_t *src = (uint16_t*)pic.planes[i];
+ for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+ {
+ for (int w = 0; w < width >> x265_cli_csps[colorSpace].width[i]; w++)
+ buf[w] = (char)(src[w] >> shift);
+
+ ofs.write(buf, width >> x265_cli_csps[colorSpace].width[i]);
+ src += pic.stride[i] / sizeof(*src);
+ }
+ }
}
-
-#else // if HIGH_BIT_DEPTH
-
- X265_CHECK(pic.bitDepth == 8, "invalid bit depth\n");
- for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ else
{
- char *src = (char*)pic.planes[i];
- for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i];
h++)
- {
- ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
- src += pic.stride[i] / sizeof(*src);
- }
+ X265_CHECK(pic.bitDepth == 8, "invalid bit depth\n");
+ for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ {
+ char *src = (char*)pic.planes[i];
+ for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+ {
+ ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
+ src += pic.stride[i] / sizeof(*src);
+ }
+ }
}
-#endif // if HIGH_BIT_DEPTH
-
return true;
}
diff --git a/source/output/y4m.h b/source/output/y4m.h
index f939a9b..f00175b 100644
--- a/source/output/y4m.h
+++ b/source/output/y4m.h
@@ -42,6 +42,8 @@ protected:
uint32_t frameSize;
+ int inputDepth;
+
std::ofstream ofs;
std::ofstream::pos_type header;
@@ -52,7 +54,7 @@ protected:
public:
- Y4MOutput(const char *filename, int width, int height, uint32_t
fpsNum, uint32_t fpsDenom, int csp);
+ Y4MOutput(const char *filename, int width, int height, uint32_t
fpsNum, uint32_t fpsDenom, int csp, int inputDepth);
virtual ~Y4MOutput();
diff --git a/source/output/yuv.cpp b/source/output/yuv.cpp
index 366d5ce..b078ddf 100644
--- a/source/output/yuv.cpp
+++ b/source/output/yuv.cpp
@@ -28,12 +28,13 @@
using namespace X265_NS;
using namespace std;
-YUVOutput::YUVOutput(const char *filename, int w, int h, uint32_t d, int
csp)
+YUVOutput::YUVOutput(const char *filename, int w, int h, uint32_t d, int
csp, int inputdepth)
: width(w)
, height(h)
, depth(d)
, colorSpace(csp)
, frameSize(0)
+ , inputDepth(inputdepth)
{
ofs.open(filename, ios::binary | ios::out);
buf = new char[width];
@@ -56,50 +57,52 @@ bool YUVOutput::writePicture(const x265_picture& pic)
X265_CHECK(pic.colorSpace == colorSpace, "invalid chroma
subsampling\n");
X265_CHECK(pic.bitDepth == (int)depth, "invalid bit depth\n");
-#if HIGH_BIT_DEPTH
- if (depth == 8)
+ if (inputDepth > 8)
{
- int shift = pic.bitDepth - 8;
- ofs.seekp((std::streamoff)fileOffset);
- for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
- {
- uint16_t *src = (uint16_t*)pic.planes[i];
- for (int h = 0; h < height >>
x265_cli_csps[colorSpace].height[i]; h++)
- {
- for (int w = 0; w < width >>
x265_cli_csps[colorSpace].width[i]; w++)
- buf[w] = (char)(src[w] >> shift);
+ if (depth == 8)
+ {
+ int shift = pic.bitDepth - 8;
+ ofs.seekp((std::streamoff)fileOffset);
+ for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ {
+ uint16_t *src = (uint16_t*)pic.planes[i];
+ for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+ {
+ for (int w = 0; w < width >> x265_cli_csps[colorSpace].width[i]; w++)
+ buf[w] = (char)(src[w] >> shift);
- ofs.write(buf, width >>
x265_cli_csps[colorSpace].width[i]);
- src += pic.stride[i] / sizeof(*src);
- }
- }
+ ofs.write(buf, width >> x265_cli_csps[colorSpace].width[i]);
+ src += pic.stride[i] / sizeof(*src);
+ }
+ }
+ }
+ else
+ {
+ ofs.seekp((std::streamoff)(fileOffset * 2));
+ for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ {
+ uint16_t *src = (uint16_t*)pic.planes[i];
+ for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+ {
+ ofs.write((const char*)src, (width * 2) >>
x265_cli_csps[colorSpace].width[i]);
+ src += pic.stride[i] / sizeof(*src);
+ }
+ }
+ }
}
else
{
- ofs.seekp((std::streamoff)(fileOffset * 2));
- for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
- {
- uint16_t *src = (uint16_t*)pic.planes[i];
- for (int h = 0; h < height >>
x265_cli_csps[colorSpace].height[i]; h++)
- {
- ofs.write((const char*)src, (width * 2) >>
x265_cli_csps[colorSpace].width[i]);
- src += pic.stride[i] / sizeof(*src);
- }
- }
+ ofs.seekp((std::streamoff)fileOffset);
+ for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+ {
+ char *src = (char*)pic.planes[i];
+ for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+ {
+ ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
+ src += pic.stride[i] / sizeof(*src);
+ }
+ }
}
-#else // if HIGH_BIT_DEPTH
- ofs.seekp((std::streamoff)fileOffset);
- for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
- {
- char *src = (char*)pic.planes[i];
- for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i];
h++)
- {
- ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
- src += pic.stride[i] / sizeof(*src);
- }
- }
-
-#endif // if HIGH_BIT_DEPTH
return true;
}
diff --git a/source/output/yuv.h b/source/output/yuv.h
index 6b01b4e..c70c480 100644
--- a/source/output/yuv.h
+++ b/source/output/yuv.h
@@ -46,13 +46,15 @@ protected:
uint32_t frameSize;
+ int inputDepth;
+
char *buf;
std::ofstream ofs;
public:
- YUVOutput(const char *filename, int width, int height, uint32_t
bitdepth, int csp);
+ YUVOutput(const char *filename, int width, int height, uint32_t
bitdepth, int csp, int inputDepth);
virtual ~YUVOutput();
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index cbb3be5..e6ac9bb 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -917,7 +917,7 @@ namespace X265_NS {
if (reconFileBitDepth == 0)
reconFileBitDepth = param->internalBitDepth;
this->recon = ReconFile::open(reconfn, param->sourceWidth,
param->sourceHeight, reconFileBitDepth,
- param->fpsNum, param->fpsDenom, param->internalCsp);
+ param->fpsNum, param->fpsDenom, param->internalCsp,
param->sourceBitDepth);
if (this->recon->isFail())
{
x265_log(param, X265_LOG_WARNING, "unable to write
reconstructed outputs file\n");
--
1.8.3.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240124/dd1ba993/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-for-generating-recon-outputs-with-multilib.patch
Type: application/octet-stream
Size: 10497 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240124/dd1ba993/attachment-0001.obj>
More information about the x265-devel
mailing list