Browse code

avcodec: add bmp parser

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2012/08/06 08:46:41
Showing 5 changed files
... ...
@@ -41,6 +41,7 @@ version next:
41 41
 - Canopus Lossless Codec decoder
42 42
 - bitmap subtitles in filters (experimental and temporary)
43 43
 - MP2 encoding via TwoLAME
44
+- bmp parser
44 45
 
45 46
 
46 47
 version 0.11:
... ...
@@ -718,6 +718,7 @@ OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o \
718 718
 OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o \
719 719
                                           aac_ac3_parser.o
720 720
 OBJS-$(CONFIG_ADX_PARSER)              += adx_parser.o adx.o
721
+OBJS-$(CONFIG_BMP_PARSER)              += bmp_parser.o
721 722
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
722 723
 OBJS-$(CONFIG_COOK_PARSER)             += cook_parser.o
723 724
 OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o dca.o
... ...
@@ -456,6 +456,7 @@ void avcodec_register_all(void)
456 456
     REGISTER_PARSER  (AAC_LATM, aac_latm);
457 457
     REGISTER_PARSER  (AC3, ac3);
458 458
     REGISTER_PARSER  (ADX, adx);
459
+    REGISTER_PARSER  (BMP, bmp);
459 460
     REGISTER_PARSER  (CAVSVIDEO, cavsvideo);
460 461
     REGISTER_PARSER  (COOK, cook);
461 462
     REGISTER_PARSER  (DCA, dca);
462 463
new file mode 100644
... ...
@@ -0,0 +1,91 @@
0
+/*
1
+ * BMP parser
2
+ * Copyright (c) 2012 Paul B Mahol
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file
23
+ * BMP parser
24
+ */
25
+
26
+#include "libavutil/bswap.h"
27
+#include "parser.h"
28
+
29
+typedef struct BMPParseContext {
30
+    ParseContext pc;
31
+    uint32_t fsize;
32
+    uint32_t remaining_size;
33
+} BMPParseContext;
34
+
35
+static int bmp_parse(AVCodecParserContext *s, AVCodecContext *avctx,
36
+                     const uint8_t **poutbuf, int *poutbuf_size,
37
+                     const uint8_t *buf, int buf_size)
38
+{
39
+    BMPParseContext *bpc = s->priv_data;
40
+    uint64_t state = bpc->pc.state64;
41
+    int next = END_NOT_FOUND;
42
+    int i = 0;
43
+
44
+    s->pict_type = AV_PICTURE_TYPE_NONE;
45
+
46
+    *poutbuf_size = 0;
47
+    if (buf_size == 0)
48
+        return 0;
49
+
50
+    if (!bpc->pc.frame_start_found) {
51
+        for (; i < buf_size; i++) {
52
+            state = (state << 8) | buf[i];
53
+            if ((state >> 48) == (('B' << 8) | 'M')) {
54
+                bpc->fsize = av_bswap32(state >> 16);
55
+                bpc->pc.frame_start_found = 1;
56
+                if (bpc->fsize > buf_size - i + 7)
57
+                    bpc->remaining_size = bpc->fsize - buf_size + i - 7;
58
+                else
59
+                    next = bpc->fsize + i - 7;
60
+                break;
61
+            }
62
+        }
63
+        bpc->pc.state64 = state;
64
+    } else {
65
+        if (bpc->remaining_size) {
66
+            i = FFMIN(bpc->remaining_size, buf_size);
67
+            bpc->remaining_size -= i;
68
+            if (bpc->remaining_size)
69
+                goto flush;
70
+            next = i;
71
+        }
72
+    }
73
+
74
+flush:
75
+    if (ff_combine_frame(&bpc->pc, next, &buf, &buf_size) < 0)
76
+        return buf_size;
77
+
78
+    bpc->pc.frame_start_found = 0;
79
+
80
+    *poutbuf      = buf;
81
+    *poutbuf_size = buf_size;
82
+    return next;
83
+}
84
+
85
+AVCodecParser ff_bmp_parser = {
86
+    .codec_ids      = { CODEC_ID_BMP },
87
+    .priv_data_size = sizeof(BMPParseContext),
88
+    .parser_parse   = bmp_parse,
89
+    .parser_close   = ff_parse_close,
90
+};
... ...
@@ -27,7 +27,7 @@
27 27
  */
28 28
 
29 29
 #define LIBAVCODEC_VERSION_MAJOR 54
30
-#define LIBAVCODEC_VERSION_MINOR 49
30
+#define LIBAVCODEC_VERSION_MINOR 50
31 31
 #define LIBAVCODEC_VERSION_MICRO 100
32 32
 
33 33
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \