avcodec/vbn(dec|enc): Avoid always-false checks

Do this by switching to bytestream2_(get|put)_le32u() from
bytestream2_(get|put)_le32(); it has after all already been checked
that the packet contains at least a full header, making all
the implicit checks in bytestream2_(get|put)_le32() dead code.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-04-12 19:58:16 +02:00
parent 300dd79c3d
commit cc0a4fa630
2 changed files with 21 additions and 21 deletions

View File

@ -71,20 +71,20 @@ static int vbn_decode_frame(AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
if (bytestream2_get_le32(gb) != VBN_MAGIC ||
bytestream2_get_le32(gb) != VBN_MAJOR ||
bytestream2_get_le32(gb) != VBN_MINOR) {
if (bytestream2_get_le32u(gb) != VBN_MAGIC ||
bytestream2_get_le32u(gb) != VBN_MAJOR ||
bytestream2_get_le32u(gb) != VBN_MINOR) {
av_log(avctx, AV_LOG_ERROR, "Invalid VBN header\n");
return AVERROR_INVALIDDATA;
}
width = bytestream2_get_le32(gb);
height = bytestream2_get_le32(gb);
components = bytestream2_get_le32(gb);
format = bytestream2_get_le32(gb);
pix_fmt = bytestream2_get_le32(gb);
bytestream2_get_le32(gb); // mipmaps
data_size = bytestream2_get_le32(gb);
width = bytestream2_get_le32u(gb);
height = bytestream2_get_le32u(gb);
components = bytestream2_get_le32u(gb);
format = bytestream2_get_le32u(gb);
pix_fmt = bytestream2_get_le32u(gb);
bytestream2_get_le32u(gb); // mipmaps
data_size = bytestream2_get_le32u(gb);
bytestream2_seek(gb, VBN_HEADER_SIZE, SEEK_SET);
compression = format & 0xffffff00;

View File

@ -97,18 +97,18 @@ static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt,
memset(pkt->data, 0, VBN_HEADER_SIZE);
bytestream2_init_writer(pb, pkt->data, pkt_size);
bytestream2_put_le32(pb, VBN_MAGIC);
bytestream2_put_le32(pb, VBN_MAJOR);
bytestream2_put_le32(pb, VBN_MINOR);
bytestream2_put_le32(pb, frame->width);
bytestream2_put_le32(pb, frame->height);
bytestream2_put_le32(pb, frame->format == AV_PIX_FMT_RGBA ? 4 : 3);
bytestream2_put_le32(pb, ctx->format);
bytestream2_put_le32(pb, frame->format == AV_PIX_FMT_RGBA ? VBN_PIX_RGBA : VBN_PIX_RGB);
bytestream2_put_le32(pb, 0); // mipmaps
bytestream2_put_le32(pb, pkt_size - VBN_HEADER_SIZE);
bytestream2_put_le32u(pb, VBN_MAGIC);
bytestream2_put_le32u(pb, VBN_MAJOR);
bytestream2_put_le32u(pb, VBN_MINOR);
bytestream2_put_le32u(pb, frame->width);
bytestream2_put_le32u(pb, frame->height);
bytestream2_put_le32u(pb, frame->format == AV_PIX_FMT_RGBA ? 4 : 3);
bytestream2_put_le32u(pb, ctx->format);
bytestream2_put_le32u(pb, frame->format == AV_PIX_FMT_RGBA ? VBN_PIX_RGBA : VBN_PIX_RGB);
bytestream2_put_le32u(pb, 0); // mipmaps
bytestream2_put_le32u(pb, pkt_size - VBN_HEADER_SIZE);
bytestream2_seek_p(pb, 64, SEEK_SET);
bytestream2_put_le32(pb, pkt_size - VBN_HEADER_SIZE);
bytestream2_put_le32u(pb, pkt_size - VBN_HEADER_SIZE);
if (ctx->format == VBN_FORMAT_DXT1 || ctx->format == VBN_FORMAT_DXT5) {
ctx->enc.frame_data.in = (frame->height - 1) * frame->linesize[0] + frame->data[0];