| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * XWD parser | ||
| 3 | * Copyright (c) 2022 Paul B Mahol | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * XWD parser | ||
| 25 | **/ | ||
| 26 | |||
| 27 | #include "libavutil/intreadwrite.h" | ||
| 28 | #include "parser.h" | ||
| 29 | #include "parser_internal.h" | ||
| 30 | #include "xwd.h" | ||
| 31 | |||
| 32 | typedef struct XWDParseContext { | ||
| 33 | ParseContext pc; | ||
| 34 | int left; | ||
| 35 | int idx; | ||
| 36 | uint8_t hdr[XWD_HEADER_SIZE]; | ||
| 37 | } XWDParseContext; | ||
| 38 | |||
| 39 | 1883 | static int xwd_parse(AVCodecParserContext *s, AVCodecContext *avctx, | |
| 40 | const uint8_t **poutbuf, int *poutbuf_size, | ||
| 41 | const uint8_t *buf, int buf_size) | ||
| 42 | { | ||
| 43 | 1883 | XWDParseContext *t = s->priv_data; | |
| 44 | 1883 | ParseContext *pc = &t->pc; | |
| 45 | 1883 | int next = END_NOT_FOUND; | |
| 46 | |||
| 47 | 1883 | s->pict_type = AV_PICTURE_TYPE_NONE; | |
| 48 | |||
| 49 | 1883 | *poutbuf = NULL; | |
| 50 | 1883 | *poutbuf_size = 0; | |
| 51 | |||
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1883 times.
|
1883 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 53 | ✗ | next = buf_size; | |
| 54 | } else { | ||
| 55 |
2/2✓ Branch 0 taken 7605999 times.
✓ Branch 1 taken 1859 times.
|
7607858 | for (int i = 0; i < buf_size; i++) { |
| 56 |
2/2✓ Branch 0 taken 7603499 times.
✓ Branch 1 taken 2500 times.
|
7605999 | if (t->left > 0) { |
| 57 | 7603499 | t->left--; | |
| 58 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7603475 times.
|
7603499 | if (t->left == 0) { |
| 59 | 24 | next = i; | |
| 60 | 24 | break; | |
| 61 | } | ||
| 62 | 7603475 | continue; | |
| 63 | } | ||
| 64 | |||
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2500 times.
|
2500 | if (t->idx >= 100) { |
| 66 | ✗ | t->idx = 99; | |
| 67 | ✗ | memmove(&t->hdr[0], &t->hdr[1], XWD_HEADER_SIZE-1); | |
| 68 | } | ||
| 69 | |||
| 70 | 2500 | t->hdr[t->idx++] = buf[i]; | |
| 71 | |||
| 72 |
3/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2475 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
|
2500 | if (t->idx >= 100 && AV_RB32(t->hdr + 4) == XWD_VERSION) { |
| 73 | 25 | uint32_t header_size = AV_RB32(t->hdr + 0); | |
| 74 | 25 | uint32_t height = AV_RB32(t->hdr + 20); | |
| 75 | 25 | uint32_t lsize = AV_RB32(t->hdr + 48); | |
| 76 | 25 | uint32_t ncolors = AV_RB32(t->hdr + 76); | |
| 77 | 25 | uint32_t size = header_size + ncolors * XWD_CMAP_SIZE + height * lsize; | |
| 78 | 25 | pc->frame_start_found = 1; | |
| 79 | 25 | t->left = size - XWD_HEADER_SIZE + 1; | |
| 80 | 25 | t->idx = 0; | |
| 81 | 25 | memset(t->hdr, 0, sizeof(t->hdr)); | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 |
2/2✓ Branch 1 taken 1857 times.
✓ Branch 2 taken 26 times.
|
1883 | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) |
| 86 | 1857 | return buf_size; | |
| 87 | } | ||
| 88 | |||
| 89 | 26 | *poutbuf = buf; | |
| 90 | 26 | *poutbuf_size = buf_size; | |
| 91 | |||
| 92 | 26 | s->pict_type = AV_PICTURE_TYPE_I; | |
| 93 | 26 | s->key_frame = 1; | |
| 94 | 26 | s->duration = 1; | |
| 95 | |||
| 96 | 26 | return next; | |
| 97 | } | ||
| 98 | |||
| 99 | const FFCodecParser ff_xwd_parser = { | ||
| 100 | PARSER_CODEC_LIST(AV_CODEC_ID_XWD), | ||
| 101 | .priv_data_size = sizeof(XWDParseContext), | ||
| 102 | .parse = xwd_parse, | ||
| 103 | .close = ff_parse_close, | ||
| 104 | }; | ||
| 105 |