diff mbox

[FFmpeg-devel] avcodec/pnm_parser: Remember the length already scanned for ascii images

Message ID 20190427125838.26876-1-michael@niedermayer.cc
State Accepted
Commit 801939588999a5cfe8d2aeabe7114a09f892a1f4
Headers show

Commit Message

Michael Niedermayer April 27, 2019, 12:58 p.m. UTC
Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm
Found-by: Michael Koch
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/pnm_parser.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Paul B Mahol April 27, 2019, 1:16 p.m. UTC | #1
On 4/27/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm
> Found-by: Michael Koch
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/pnm_parser.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>

This code does not apply with current master code.
Michael Niedermayer April 27, 2019, 1:16 p.m. UTC | #2
On Sat, Apr 27, 2019 at 02:58:38PM +0200, Michael Niedermayer wrote:
> Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm
> Found-by: Michael Koch
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/pnm_parser.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)

this depends on " avcodec/pnm_parser: Remember the size of the image and do not reparse the header"

[...]
Paul B Mahol April 27, 2019, 1:26 p.m. UTC | #3
On 4/27/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Sat, Apr 27, 2019 at 02:58:38PM +0200, Michael Niedermayer wrote:
>> Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm
>> Found-by: Michael Koch
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>  libavcodec/pnm_parser.c | 15 ++++++++++++++-
>>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> this depends on " avcodec/pnm_parser: Remember the size of the image and do
> not reparse the header"

LGTM then
Michael Niedermayer April 27, 2019, 8:39 p.m. UTC | #4
On Sat, Apr 27, 2019 at 03:26:35PM +0200, Paul B Mahol wrote:
> On 4/27/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > On Sat, Apr 27, 2019 at 02:58:38PM +0200, Michael Niedermayer wrote:
> >> Fixes: speed regression with xmap_samsung_gear_2560x1280.pgm
> >> Found-by: Michael Koch
> >> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >> ---
> >>  libavcodec/pnm_parser.c | 15 ++++++++++++++-
> >>  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > this depends on " avcodec/pnm_parser: Remember the size of the image and do
> > not reparse the header"
> 
> LGTM then

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index 210a8a048e..de0e32ba9c 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -19,6 +19,7 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 
 #include "parser.h" //for ParseContext
@@ -27,6 +28,7 @@ 
 typedef struct PNMParseContext {
     ParseContext pc;
     int remaining_bytes;
+    int ascii_scan;
 }PNMParseContext;
 
 static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx,
@@ -77,17 +79,28 @@  retry:
     } else if (pnmctx.type < 4) {
               uint8_t *bs  = pnmctx.bytestream;
         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) {
-            int c = *bs++;
+            int c;
+            sync = bs;
+            c = *bs++;
             if (c == '#')  {
                 while (c != '\n' && bs < end)
                     c = *bs++;
             } else if (c == 'P') {
                 next = bs - pnmctx.bytestream_start + skip - 1;
+                pnmpc->ascii_scan = 0;
                 break;
             }
         }
+        if (next == END_NOT_FOUND)
+            pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;
     } else {
         next = pnmctx.bytestream - pnmctx.bytestream_start + skip
                + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);