diff mbox series

[FFmpeg-devel,5/7] avcodec/pgxdec: Hoist branch out of loop

Message ID AS8PR01MB7944EB78920BA4C5DF3D448B8FF99@AS8PR01MB7944.eurprd01.prod.exchangelabs.com
State Accepted
Commit 84a80ac15de802dfea32d83206deafadbd1947cb
Headers show
Series [FFmpeg-devel,1/7] avcodec/pgxdec: Make better use of size check | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 24, 2022, 4:42 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/pgxdec.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Paul B Mahol April 24, 2022, 11:16 a.m. UTC | #1
lgtm
diff mbox series

Patch

diff --git a/libavcodec/pgxdec.c b/libavcodec/pgxdec.c
index 30895b51ee..29de103167 100644
--- a/libavcodec/pgxdec.c
+++ b/libavcodec/pgxdec.c
@@ -95,16 +95,13 @@  error:
     static inline void write_frame_ ##D(AVFrame *frame, GetByteContext *g, \
                                         int width, int height, int sign, int depth)         \
     {                                                                                       \
+        const unsigned offset = sign ? (1 << (D - 1)) : 0;                                  \
         int i, j;                                                                           \
         for (i = 0; i < height; i++) {                                                      \
             PIXEL *line = (PIXEL*)(frame->data[0] + i * frame->linesize[0]);                \
             for (j = 0; j < width; j++) {                                                   \
-                unsigned val;                                                               \
-                if (sign)                                                                   \
-                    val = (PIXEL)bytestream2_get_ ##suffix##u(g) + (1 << (depth - 1));      \
-                else                                                                        \
-                    val = bytestream2_get_ ##suffix##u(g);                                  \
-                val <<= (D - depth);                                                        \
+                unsigned val = bytestream2_get_ ##suffix##u(g) << (D - depth);              \
+                val ^= offset;                                                              \
                 *(line + j) = val;                                                          \
             }                                                                               \
         }                                                                                   \