avcodec/pnm_parser: Remember the length already scanned for ascii images
Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm Found-by: Michael Koch Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
9fc1031ac2
commit
8019395889
@ -19,6 +19,7 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libavutil/avassert.h"
|
||||||
#include "libavutil/imgutils.h"
|
#include "libavutil/imgutils.h"
|
||||||
|
|
||||||
#include "parser.h" //for ParseContext
|
#include "parser.h" //for ParseContext
|
||||||
@ -27,6 +28,7 @@
|
|||||||
typedef struct PNMParseContext {
|
typedef struct PNMParseContext {
|
||||||
ParseContext pc;
|
ParseContext pc;
|
||||||
int remaining_bytes;
|
int remaining_bytes;
|
||||||
|
int ascii_scan;
|
||||||
}PNMParseContext;
|
}PNMParseContext;
|
||||||
|
|
||||||
static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx,
|
static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx,
|
||||||
@ -77,17 +79,28 @@ retry:
|
|||||||
} else if (pnmctx.type < 4) {
|
} else if (pnmctx.type < 4) {
|
||||||
uint8_t *bs = pnmctx.bytestream;
|
uint8_t *bs = pnmctx.bytestream;
|
||||||
const uint8_t *end = pnmctx.bytestream_end;
|
const uint8_t *end = pnmctx.bytestream_end;
|
||||||
|
uint8_t *sync = bs;
|
||||||
|
|
||||||
|
if (pc->index) {
|
||||||
|
av_assert0(pnmpc->ascii_scan <= end - bs);
|
||||||
|
bs += pnmpc->ascii_scan;
|
||||||
|
}
|
||||||
|
|
||||||
while (bs < end) {
|
while (bs < end) {
|
||||||
int c = *bs++;
|
int c;
|
||||||
|
sync = bs;
|
||||||
|
c = *bs++;
|
||||||
if (c == '#') {
|
if (c == '#') {
|
||||||
while (c != '\n' && bs < end)
|
while (c != '\n' && bs < end)
|
||||||
c = *bs++;
|
c = *bs++;
|
||||||
} else if (c == 'P') {
|
} else if (c == 'P') {
|
||||||
next = bs - pnmctx.bytestream_start + skip - 1;
|
next = bs - pnmctx.bytestream_start + skip - 1;
|
||||||
|
pnmpc->ascii_scan = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (next == END_NOT_FOUND)
|
||||||
|
pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;
|
||||||
} else {
|
} else {
|
||||||
next = pnmctx.bytestream - pnmctx.bytestream_start + skip
|
next = pnmctx.bytestream - pnmctx.bytestream_start + skip
|
||||||
+ av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
|
+ av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user