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>
This commit is contained in:
parent
66f4685910
commit
5e1b5b52fe
|
@ -31,8 +31,8 @@
|
||||||
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
const AVFrame *frame, int *got_packet)
|
const AVFrame *frame, int *got_packet)
|
||||||
{
|
{
|
||||||
int width, height, bits_pixel, i, j, length, ret;
|
int width, height, bits_pixel, length, ret;
|
||||||
uint8_t *in_buf, *buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
width = avctx->width;
|
width = avctx->width;
|
||||||
height = avctx->height;
|
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_be32(&buf, 0); /* X, Y offset */
|
||||||
bytestream_put_be16(&buf, bits_pixel);
|
bytestream_put_be16(&buf, bits_pixel);
|
||||||
|
|
||||||
for (j = 0; j < height; j++) {
|
for (int j = 0, bytes_pixel = bits_pixel >> 3; j < height; j++) {
|
||||||
in_buf = frame->data[0] + frame->linesize[0] * j;
|
const uint8_t *in_buf = frame->data[0] + frame->linesize[0] * j;
|
||||||
for (i = 0; i < width; ) {
|
const uint8_t *const line_end = in_buf + bytes_pixel * width;
|
||||||
|
while (in_buf < line_end) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int pixel;
|
int pixel;
|
||||||
|
|
||||||
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
|
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
|
||||||
pixel = *in_buf;
|
pixel = *in_buf;
|
||||||
while (count < 255 && count + i < width && pixel == *in_buf) {
|
while (count < 255 && in_buf < line_end && pixel == *in_buf) {
|
||||||
count++;
|
count++;
|
||||||
in_buf++;
|
in_buf++;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +83,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
bytestream_put_byte(&buf, pixel);
|
bytestream_put_byte(&buf, pixel);
|
||||||
} else { /* AV_PIX_FMT_BGR24 */
|
} else { /* AV_PIX_FMT_BGR24 */
|
||||||
pixel = AV_RB24(in_buf);
|
pixel = AV_RB24(in_buf);
|
||||||
while (count < 255 && count + i < width &&
|
while (count < 255 && in_buf < line_end &&
|
||||||
pixel == AV_RB24(in_buf)) {
|
pixel == AV_RB24(in_buf)) {
|
||||||
count++;
|
count++;
|
||||||
in_buf += 3;
|
in_buf += 3;
|
||||||
|
@ -90,7 +91,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
bytestream_put_byte(&buf, count);
|
bytestream_put_byte(&buf, count);
|
||||||
bytestream_put_be24(&buf, pixel);
|
bytestream_put_be24(&buf, pixel);
|
||||||
}
|
}
|
||||||
i += count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user