aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/aliaspixenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-06 13:57:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-07 11:57:23 +0200
commit5e1b5b52fe7fdfa6d9e1a78ac0576cf5931a82bb (patch)
tree1843de9626075ab009349e07505e1b40e5c1c265 /libavcodec/aliaspixenc.c
parent66f468591056b92057a9ae4adc4806546cd19eeb (diff)
downloadffmpeg-5e1b5b52fe7fdfa6d9e1a78ac0576cf5931a82bb.tar.gz
avcodec/aliaspixenc: Remove redundant counter
Improves performance by 33.8% for BGR24 and by 26.4% for GRAY8. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/aliaspixenc.c')
-rw-r--r--libavcodec/aliaspixenc.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/libavcodec/aliaspixenc.c b/libavcodec/aliaspixenc.c
index 01461c984b..fa273df9c2 100644
--- a/libavcodec/aliaspixenc.c
+++ b/libavcodec/aliaspixenc.c
@@ -31,8 +31,8 @@
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
- int width, height, bits_pixel, i, j, length, ret;
- uint8_t *in_buf, *buf;
+ int width, height, bits_pixel, length, ret;
+ uint8_t *buf;
width = avctx->width;
height = avctx->height;
@@ -66,15 +66,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytestream_put_be32(&buf, 0); /* X, Y offset */
bytestream_put_be16(&buf, bits_pixel);
- for (j = 0; j < height; j++) {
- in_buf = frame->data[0] + frame->linesize[0] * j;
- for (i = 0; i < width; ) {
+ for (int j = 0, bytes_pixel = bits_pixel >> 3; j < height; j++) {
+ const uint8_t *in_buf = frame->data[0] + frame->linesize[0] * j;
+ const uint8_t *const line_end = in_buf + bytes_pixel * width;
+ while (in_buf < line_end) {
int count = 0;
int pixel;
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
pixel = *in_buf;
- while (count < 255 && count + i < width && pixel == *in_buf) {
+ while (count < 255 && in_buf < line_end && pixel == *in_buf) {
count++;
in_buf++;
}
@@ -82,7 +83,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytestream_put_byte(&buf, pixel);
} else { /* AV_PIX_FMT_BGR24 */
pixel = AV_RB24(in_buf);
- while (count < 255 && count + i < width &&
+ while (count < 255 && in_buf < line_end &&
pixel == AV_RB24(in_buf)) {
count++;
in_buf += 3;
@@ -90,7 +91,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytestream_put_byte(&buf, count);
bytestream_put_be24(&buf, pixel);
}
- i += count;
}
}