commit:     72f38bc8bfc7116f3472a106f22cd01283984b66
Author:     Paul Zander <negril.nx+gentoo <AT> gmail <DOT> com>
AuthorDate: Sun Jun 29 16:15:13 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Oct 19 18:02:20 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=72f38bc8

media-libs/x265: splitup 3.6 code cleanup patch

Signed-off-by: Paul Zander <negril.nx+gentoo <AT> gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/44229
Signed-off-by: Sam James <sam <AT> gentoo.org>

 media-libs/x265/files/x265-3.6-code-cleanup.patch  | 99 ----------------------
 .../x265/files/x265-3.6-code-cleanup_2.patch       | 23 +++++
 .../x265/files/x265-3.6-code-cleanup_3.patch       | 61 +++++++++++++
 .../x265/files/x265-3.6-code-cleanup_4.patch       | 20 +++++
 media-libs/x265/x265-3.6-r1.ebuild                 |  3 +
 5 files changed, 107 insertions(+), 99 deletions(-)

diff --git a/media-libs/x265/files/x265-3.6-code-cleanup.patch 
b/media-libs/x265/files/x265-3.6-code-cleanup.patch
index dbea7ef6c1ff..54f63f0b6614 100644
--- a/media-libs/x265/files/x265-3.6-code-cleanup.patch
+++ b/media-libs/x265/files/x265-3.6-code-cleanup.patch
@@ -39,102 +39,3 @@ index 8397f05..7f132e6 100644
  };
  
  enum PredMode
-
-From 4ec09af244e2cfe3dfb739d74af7640ac114e775 Mon Sep 17 00:00:00 2001
-From: Paul Zander <[email protected]>
-Date: Mon, 26 Aug 2024 14:45:33 +0200
-Subject: [PATCH 3/4] register is a unused and reserved keyword in c++-17
-
-Signed-off-by: Paul Zander <[email protected]>
-
-diff --git a/common/md5.cpp b/common/md5.cpp
-index a9042f4..7e638e7 100644
---- a/common/md5.cpp
-+++ b/common/md5.cpp
-@@ -185,7 +185,10 @@ void MD5Final(MD5Context *ctx, uint8_t *digest)
-  */
- void MD5Transform(uint32_t *buf, uint32_t *in)
- {
--    register uint32_t a, b, c, d;
-+#if __cplusplus < 201703L
-+    register
-+#endif
-+    uint32_t a, b, c, d;
- 
-     a = buf[0];
-     b = buf[1];
-
-From 09379bbfe797e54f91ef5702c802f75aad604067 Mon Sep 17 00:00:00 2001
-From: Paul Zander <[email protected]>
-Date: Mon, 26 Aug 2024 14:26:55 +0200
-Subject: [PATCH 4/4] use std::abs instead of abs to avoid truncating values
-
-Signed-off-by: Paul Zander <[email protected]>
-
-diff --git a/common/pixel.cpp b/common/pixel.cpp
-index 3cd074c..62410f3 100644
---- a/common/pixel.cpp
-+++ b/common/pixel.cpp
-@@ -124,10 +124,10 @@ int ads_x4(int encDC[4], uint32_t *sums, int delta, 
uint16_t *costMvX, int16_t *
-     int nmv = 0;
-     for (int16_t i = 0; i < width; i++, sums++)
-     {
--        int ads = abs(encDC[0] - long(sums[0]))
--            + abs(encDC[1] - long(sums[lx >> 1]))
--            + abs(encDC[2] - long(sums[delta]))
--            + abs(encDC[3] - long(sums[delta + (lx >> 1)]))
-+        int ads = std::abs(encDC[0] - long(sums[0]))
-+            + std::abs(encDC[1] - long(sums[lx >> 1]))
-+            + std::abs(encDC[2] - long(sums[delta]))
-+            + std::abs(encDC[3] - long(sums[delta + (lx >> 1)]))
-             + costMvX[i];
-         if (ads < thresh)
-             mvs[nmv++] = i;
-@@ -141,8 +141,8 @@ int ads_x2(int encDC[2], uint32_t *sums, int delta, 
uint16_t *costMvX, int16_t *
-     int nmv = 0;
-     for (int16_t i = 0; i < width; i++, sums++)
-     {
--        int ads = abs(encDC[0] - long(sums[0]))
--            + abs(encDC[1] - long(sums[delta]))
-+        int ads = std::abs(encDC[0] - long(sums[0]))
-+            + std::abs(encDC[1] - long(sums[delta]))
-             + costMvX[i];
-         if (ads < thresh)
-             mvs[nmv++] = i;
-@@ -156,7 +156,7 @@ int ads_x1(int encDC[1], uint32_t *sums, int, uint16_t 
*costMvX, int16_t *mvs, i
-     int nmv = 0;
-     for (int16_t i = 0; i < width; i++, sums++)
-     {
--        int ads = abs(encDC[0] - long(sums[0]))
-+        int ads = std::abs(encDC[0] - long(sums[0]))
-             + costMvX[i];
-         if (ads < thresh)
-             mvs[nmv++] = i;
-diff --git a/encoder/analysis.cpp b/encoder/analysis.cpp
-index aabf386..127032d 100644
---- a/encoder/analysis.cpp
-+++ b/encoder/analysis.cpp
-@@ -2692,8 +2692,8 @@ void Analysis::classifyCU(const CUData& ctu, const 
CUGeom& cuGeom, const Mode& b
-             {
-                 offset = (depth * X265_REFINE_INTER_LEVELS) + i;
-                 /* Calculate distance values */
--                diffRefine[i] = abs((int64_t)(trainData.cuVariance - 
m_frame->m_classifyVariance[offset]));
--                diffRefineRd[i] = abs((int64_t)(cuCost - 
m_frame->m_classifyRd[offset]));
-+                diffRefine[i] = std::abs((int64_t)(trainData.cuVariance - 
m_frame->m_classifyVariance[offset]));
-+                diffRefineRd[i] = std::abs((int64_t)(cuCost - 
m_frame->m_classifyRd[offset]));
- 
-                 /* Calculate prior probability - ranges between 0 and 1 */
-                 if (trainingCount)
-diff --git a/encoder/ratecontrol.cpp b/encoder/ratecontrol.cpp
-index 9f2b8d9..7732ccd 100644
---- a/encoder/ratecontrol.cpp
-+++ b/encoder/ratecontrol.cpp
-@@ -1891,7 +1891,7 @@ double RateControl::tuneQScaleForGrain(double rcOverflow)
-     int newQp = rcOverflow > 1.1 ? curQp + 2 : rcOverflow > 1 ? curQp + 1 : 
curQp - 1 ;
-     double projectedBitrate =  int(m_fps + 0.5) * m_qpToEncodedBits[newQp];
-     if (curBitrate > 0 && projectedBitrate > 0)
--        q =  abs(projectedBitrate - m_bitrate) < abs (curBitrate - m_bitrate) 
? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
-+        q =  std::abs(projectedBitrate - m_bitrate) < std::abs (curBitrate - 
m_bitrate) ? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
-     else
-         q = rcOverflow > 1 ? qScaleAvg * qpstep : rcOverflow < 1 ?  qScaleAvg 
/ qpstep : m_lastQScaleFor[P_SLICE];
-     return q;

diff --git a/media-libs/x265/files/x265-3.6-code-cleanup_2.patch 
b/media-libs/x265/files/x265-3.6-code-cleanup_2.patch
new file mode 100644
index 000000000000..cfc8cd606a4d
--- /dev/null
+++ b/media-libs/x265/files/x265-3.6-code-cleanup_2.patch
@@ -0,0 +1,23 @@
+From 4ec09af244e2cfe3dfb739d74af7640ac114e775 Mon Sep 17 00:00:00 2001
+From: Paul Zander <[email protected]>
+Date: Mon, 26 Aug 2024 14:45:33 +0200
+Subject: [PATCH 3/4] register is a unused and reserved keyword in c++-17
+
+Signed-off-by: Paul Zander <[email protected]>
+
+diff --git a/common/md5.cpp b/common/md5.cpp
+index a9042f4..7e638e7 100644
+--- a/common/md5.cpp
++++ b/common/md5.cpp
+@@ -185,7 +185,10 @@ void MD5Final(MD5Context *ctx, uint8_t *digest)
+  */
+ void MD5Transform(uint32_t *buf, uint32_t *in)
+ {
+-    register uint32_t a, b, c, d;
++#if __cplusplus < 201703L
++    register
++#endif
++    uint32_t a, b, c, d;
+ 
+     a = buf[0];
+     b = buf[1];

diff --git a/media-libs/x265/files/x265-3.6-code-cleanup_3.patch 
b/media-libs/x265/files/x265-3.6-code-cleanup_3.patch
new file mode 100644
index 000000000000..f19529b5cddd
--- /dev/null
+++ b/media-libs/x265/files/x265-3.6-code-cleanup_3.patch
@@ -0,0 +1,61 @@
+From 09379bbfe797e54f91ef5702c802f75aad604067 Mon Sep 17 00:00:00 2001
+From: Paul Zander <[email protected]>
+Date: Mon, 26 Aug 2024 14:26:55 +0200
+Subject: [PATCH 4/4] use std::abs instead of abs to avoid truncating values
+
+Signed-off-by: Paul Zander <[email protected]>
+
+diff --git a/common/pixel.cpp b/common/pixel.cpp
+index 3cd074c..62410f3 100644
+--- a/common/pixel.cpp
++++ b/common/pixel.cpp
+@@ -124,10 +124,10 @@ int ads_x4(int encDC[4], uint32_t *sums, int delta, 
uint16_t *costMvX, int16_t *
+     int nmv = 0;
+     for (int16_t i = 0; i < width; i++, sums++)
+     {
+-        int ads = abs(encDC[0] - long(sums[0]))
+-            + abs(encDC[1] - long(sums[lx >> 1]))
+-            + abs(encDC[2] - long(sums[delta]))
+-            + abs(encDC[3] - long(sums[delta + (lx >> 1)]))
++        int ads = std::abs(encDC[0] - long(sums[0]))
++            + std::abs(encDC[1] - long(sums[lx >> 1]))
++            + std::abs(encDC[2] - long(sums[delta]))
++            + std::abs(encDC[3] - long(sums[delta + (lx >> 1)]))
+             + costMvX[i];
+         if (ads < thresh)
+             mvs[nmv++] = i;
+@@ -141,8 +141,8 @@ int ads_x2(int encDC[2], uint32_t *sums, int delta, 
uint16_t *costMvX, int16_t *
+     int nmv = 0;
+     for (int16_t i = 0; i < width; i++, sums++)
+     {
+-        int ads = abs(encDC[0] - long(sums[0]))
+-            + abs(encDC[1] - long(sums[delta]))
++        int ads = std::abs(encDC[0] - long(sums[0]))
++            + std::abs(encDC[1] - long(sums[delta]))
+             + costMvX[i];
+         if (ads < thresh)
+             mvs[nmv++] = i;
+@@ -156,7 +156,7 @@ int ads_x1(int encDC[1], uint32_t *sums, int, uint16_t 
*costMvX, int16_t *mvs, i
+     int nmv = 0;
+     for (int16_t i = 0; i < width; i++, sums++)
+     {
+-        int ads = abs(encDC[0] - long(sums[0]))
++        int ads = std::abs(encDC[0] - long(sums[0]))
+             + costMvX[i];
+         if (ads < thresh)
+             mvs[nmv++] = i;
+diff --git a/encoder/analysis.cpp b/encoder/analysis.cpp
+index aabf386..127032d 100644
+--- a/encoder/analysis.cpp
++++ b/encoder/analysis.cpp
+@@ -2692,8 +2692,8 @@ void Analysis::classifyCU(const CUData& ctu, const 
CUGeom& cuGeom, const Mode& b
+             {
+                 offset = (depth * X265_REFINE_INTER_LEVELS) + i;
+                 /* Calculate distance values */
+-                diffRefine[i] = abs((int64_t)(trainData.cuVariance - 
m_frame->m_classifyVariance[offset]));
+-                diffRefineRd[i] = abs((int64_t)(cuCost - 
m_frame->m_classifyRd[offset]));
++                diffRefine[i] = std::abs((int64_t)(trainData.cuVariance - 
m_frame->m_classifyVariance[offset]));
++                diffRefineRd[i] = std::abs((int64_t)(cuCost - 
m_frame->m_classifyRd[offset]));
+ 
+                 /* Calculate prior probability - ranges between 0 and 1 */
+                 if (trainingCount)

diff --git a/media-libs/x265/files/x265-3.6-code-cleanup_4.patch 
b/media-libs/x265/files/x265-3.6-code-cleanup_4.patch
new file mode 100644
index 000000000000..131393bf461c
--- /dev/null
+++ b/media-libs/x265/files/x265-3.6-code-cleanup_4.patch
@@ -0,0 +1,20 @@
+From 09379bbfe797e54f91ef5702c802f75aad604067 Mon Sep 17 00:00:00 2001
+From: Paul Zander <[email protected]>
+Date: Mon, 26 Aug 2024 14:26:55 +0200
+Subject: [PATCH 4/4] use std::abs instead of abs to avoid truncating values
+
+Signed-off-by: Paul Zander <[email protected]>
+
+diff --git a/encoder/ratecontrol.cpp b/encoder/ratecontrol.cpp
+index 9f2b8d9..7732ccd 100644
+--- a/encoder/ratecontrol.cpp
++++ b/encoder/ratecontrol.cpp
+@@ -1891,7 +1891,7 @@ double RateControl::tuneQScaleForGrain(double rcOverflow)
+     int newQp = rcOverflow > 1.1 ? curQp + 2 : rcOverflow > 1 ? curQp + 1 : 
curQp - 1 ;
+     double projectedBitrate =  int(m_fps + 0.5) * m_qpToEncodedBits[newQp];
+     if (curBitrate > 0 && projectedBitrate > 0)
+-        q =  abs(projectedBitrate - m_bitrate) < abs (curBitrate - m_bitrate) 
? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
++        q =  std::abs(projectedBitrate - m_bitrate) < std::abs (curBitrate - 
m_bitrate) ? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
+     else
+         q = rcOverflow > 1 ? qScaleAvg * qpstep : rcOverflow < 1 ?  qScaleAvg 
/ qpstep : m_lastQScaleFor[P_SLICE];
+     return q;

diff --git a/media-libs/x265/x265-3.6-r1.ebuild 
b/media-libs/x265/x265-3.6-r1.ebuild
index aa50f4b7c014..1654986fc417 100644
--- a/media-libs/x265/x265-3.6-r1.ebuild
+++ b/media-libs/x265/x265-3.6-r1.ebuild
@@ -47,6 +47,9 @@ PATCHES=(
        "${FILESDIR}/${PN}-3.6-test-ns_2.patch"
 
        "${FILESDIR}/${PN}-3.6-code-cleanup.patch"
+       "${FILESDIR}/${PN}-3.6-code-cleanup_2.patch"
+       "${FILESDIR}/${PN}-3.6-code-cleanup_3.patch"
+       "${FILESDIR}/${PN}-3.6-code-cleanup_4.patch"
 )
 
 pkg_setup() {

Reply via email to