diff --git a/libswscale/format.c b/libswscale/format.c index 6b88fa4c5d..ea7b5b5ebe 100644 --- a/libswscale/format.c +++ b/libswscale/format.c @@ -906,8 +906,11 @@ int ff_sws_decode_pixfmt(SwsOpList *ops, enum AVPixelFormat fmt) /* Set baseline pixel content flags */ const int integer = ff_sws_pixel_type_is_int(raw_type); - for (int i = 0; i < rw_op.elems; i++) - comps.flags[i] = (integer ? SWS_COMP_EXACT : 0); + const int swapped = (desc->flags & AV_PIX_FMT_FLAG_BE) != NATIVE_ENDIAN_FLAG; + for (int i = 0; i < rw_op.elems; i++) { + comps.flags[i] = (integer ? SWS_COMP_EXACT : 0) | + (swapped ? SWS_COMP_SWAPPED : 0); + } /* Generate value range information for simple unpacked formats */ if (integer && !unpack.pattern[0]) { @@ -931,7 +934,7 @@ int ff_sws_decode_pixfmt(SwsOpList *ops, enum AVPixelFormat fmt) .comps = comps, })); - if ((desc->flags & AV_PIX_FMT_FLAG_BE) != NATIVE_ENDIAN_FLAG) { + if (swapped) { RET(ff_sws_op_list_append(ops, &(SwsOp) { .op = SWS_OP_SWAP_BYTES, .type = raw_type, diff --git a/libswscale/ops.c b/libswscale/ops.c index 3fd6f678f5..0b07b21158 100644 --- a/libswscale/ops.c +++ b/libswscale/ops.c @@ -274,11 +274,14 @@ void ff_sws_op_list_update_comps(SwsOpList *ops) op->comps.max[i] = prev.max[i]; } break; + case SWS_OP_SWAP_BYTES: + for (int i = 0; i < 4; i++) + op->comps.flags[i] = prev.flags[i] ^ SWS_COMP_SWAPPED; + break; case SWS_OP_WRITE: for (int i = 0; i < op->rw.elems; i++) av_assert1(!(prev.flags[i] & SWS_COMP_GARBAGE)); /* fall through */ - case SWS_OP_SWAP_BYTES: case SWS_OP_LSHIFT: case SWS_OP_RSHIFT: case SWS_OP_MIN: @@ -620,6 +623,8 @@ static char describe_comp_flags(unsigned flags) return 'X'; else if (flags & SWS_COMP_ZERO) return '0'; + else if (flags & SWS_COMP_SWAPPED) + return 'z'; else if (flags & SWS_COMP_EXACT) return '+'; else @@ -763,7 +768,7 @@ void ff_sws_op_list_print(void *log, int lev, const SwsOpList *ops) } - av_log(log, lev, " (X = unused, + = exact, 0 = zero)\n"); + av_log(log, lev, " (X = unused, z = byteswapped, + = exact, 0 = zero)\n"); } int ff_sws_ops_compile_backend(SwsContext *ctx, const SwsOpBackend *backend, diff --git a/libswscale/ops.h b/libswscale/ops.h index a91b63e63a..d3d06b30e9 100644 --- a/libswscale/ops.h +++ b/libswscale/ops.h @@ -73,6 +73,7 @@ enum SwsCompFlags { SWS_COMP_GARBAGE = 1 << 0, /* contents are undefined / garbage data */ SWS_COMP_EXACT = 1 << 1, /* value is an exact integer */ SWS_COMP_ZERO = 1 << 2, /* known to be a constant zero */ + SWS_COMP_SWAPPED = 1 << 3, /* byte order is swapped */ }; typedef union SwsConst { diff --git a/tests/ref/fate/sws-ops-list b/tests/ref/fate/sws-ops-list index a7d6149d8b..0458a25df4 100644 --- a/tests/ref/fate/sws-ops-list +++ b/tests/ref/fate/sws-ops-list @@ -1 +1 @@ -ef1dd10af970984495f6008e43d0fe1b +6b2360c6fa99f5d0e428a97dfeff7189