Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Raw video utils | ||
3 | * Copyright (c) 2016 Michael Niedermayer | ||
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 | #include "libavutil/intreadwrite.h" | ||
23 | #include "libavcodec/packet.h" | ||
24 | #include "avformat.h" | ||
25 | #include "rawutils.h" | ||
26 | |||
27 | 625 | int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride) | |
28 | { | ||
29 | int ret; | ||
30 | 625 | AVPacket *pkt = *ppkt; | |
31 |
2/2✓ Branch 0 taken 425 times.
✓ Branch 1 taken 200 times.
|
625 | int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16; |
32 | 625 | int min_stride = (par->width * bpc + 7) >> 3; | |
33 | 625 | int with_pal_size = min_stride * par->height + 1024; | |
34 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 625 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
625 | int contains_pal = bpc == 8 && pkt->size == with_pal_size; |
35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 625 times.
|
625 | int size = contains_pal ? min_stride * par->height : pkt->size; |
36 | 625 | int stride = size / par->height; | |
37 | 625 | int padding = expected_stride - FFMIN(expected_stride, stride); | |
38 | int y; | ||
39 | AVPacket *new_pkt; | ||
40 | |||
41 |
2/2✓ Branch 0 taken 525 times.
✓ Branch 1 taken 100 times.
|
625 | if (pkt->size == expected_stride * par->height) |
42 | 525 | return 0; | |
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (size != stride * par->height) |
44 | ✗ | return 0; | |
45 | |||
46 | 100 | new_pkt = av_packet_alloc(); | |
47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (!new_pkt) |
48 | ✗ | return AVERROR(ENOMEM); | |
49 | |||
50 | 100 | ret = av_new_packet(new_pkt, expected_stride * par->height); | |
51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (ret < 0) |
52 | ✗ | goto fail; | |
53 | |||
54 | 100 | ret = av_packet_copy_props(new_pkt, pkt); | |
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (ret < 0) |
56 | ✗ | goto fail; | |
57 | |||
58 |
2/2✓ Branch 0 taken 3400 times.
✓ Branch 1 taken 100 times.
|
3500 | for (y = 0; y<par->height; y++) { |
59 | 3400 | memcpy(new_pkt->data + y*expected_stride, pkt->data + y*stride, FFMIN(expected_stride, stride)); | |
60 | 3400 | memset(new_pkt->data + y*expected_stride + expected_stride - padding, 0, padding); | |
61 | } | ||
62 | |||
63 | 100 | *ppkt = new_pkt; | |
64 | 100 | return 1 + contains_pal; | |
65 | ✗ | fail: | |
66 | ✗ | av_packet_free(&new_pkt); | |
67 | |||
68 | ✗ | return ret; | |
69 | } | ||
70 | |||
71 | 321 | int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette) | |
72 | { | ||
73 | uint8_t *side_data; | ||
74 | size_t size; | ||
75 | |||
76 | 321 | side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PALETTE, &size); | |
77 |
2/2✓ Branch 0 taken 208 times.
✓ Branch 1 taken 113 times.
|
321 | if (side_data) { |
78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
|
208 | if (size != AVPALETTE_SIZE) { |
79 | ✗ | av_log(s, AV_LOG_ERROR, "Invalid palette side data\n"); | |
80 | ✗ | return AVERROR_INVALIDDATA; | |
81 | } | ||
82 | 208 | memcpy(palette, side_data, AVPALETTE_SIZE); | |
83 | 208 | return 1; | |
84 | } | ||
85 | |||
86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | if (ret == CONTAINS_PAL) { |
87 | ✗ | for (int i = 0; i < AVPALETTE_COUNT; i++) | |
88 | ✗ | palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4); | |
89 | ✗ | return 1; | |
90 | } | ||
91 | |||
92 | 113 | return 0; | |
93 | } | ||
94 |