../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
166 / 271
61.3%
Branches:
161 / 294
54.8%
Functions:
3 / 6
50.0%

libavcodec/rawdec.c
Line Branch Exec Source
1 /*
2 * Raw Video Decoder
3 * Copyright (c) 2001 Fabrice Bellard
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 * Raw Video Decoder
25 */
26
27 #include "avcodec.h"
28 #include "bswapdsp.h"
29 #include "codec_internal.h"
30 #include "decode.h"
31 #include "get_bits.h"
32 #include "raw.h"
33 #include "libavutil/avassert.h"
34 #include "libavutil/buffer.h"
35 #include "libavutil/intreadwrite.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/mem.h"
38 #include "libavutil/opt.h"
39
40 typedef struct RawVideoContext {
41 AVClass *av_class;
42 AVBufferRef *palette;
43 int frame_size; /* size of the frame in bytes */
44 int flip;
45 int is_1_2_4_8_bpp; // 1, 2, 4 and 8 bpp in avi/mov, 1 and 8 bpp in nut
46 int is_mono;
47 int is_pal8;
48 int is_nut_mono;
49 int is_nut_pal8;
50 int is_yuv2;
51 int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16
52 int tff;
53
54 BswapDSPContext bbdsp;
55 void *bitstream_buf;
56 unsigned int bitstream_buf_size;
57 } RawVideoContext;
58
59 static const AVOption options[]={
60 {"top", "top field first", offsetof(RawVideoContext, tff), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_VIDEO_PARAM},
61 {NULL}
62 };
63
64 static const AVClass rawdec_class = {
65 .class_name = "rawdec",
66 .option = options,
67 .version = LIBAVUTIL_VERSION_INT,
68 };
69
70 1314 static av_cold int raw_init_decoder(AVCodecContext *avctx)
71 {
72 1314 RawVideoContext *context = avctx->priv_data;
73 const AVPixFmtDescriptor *desc;
74
75 1314 ff_bswapdsp_init(&context->bbdsp);
76
77
1/2
✓ Branch 3 → 4 taken 1314 times.
✗ Branch 3 → 5 not taken.
1314 if ( avctx->codec_tag == MKTAG('r','a','w',' ')
78
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1314 times.
1314 || avctx->codec_tag == MKTAG('N','O','1','6'))
79 ✗ avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_MOV,
80 ✗ avctx->bits_per_coded_sample);
81
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 1314 times.
1314 else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W'))
82 ✗ avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_AVI,
83 ✗ avctx->bits_per_coded_sample);
84
4/4
✓ Branch 10 → 11 taken 678 times.
✓ Branch 10 → 14 taken 636 times.
✓ Branch 11 → 12 taken 677 times.
✓ Branch 11 → 14 taken 1 time.
1314 else if (avctx->codec_tag && (avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0))
85 677 avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, avctx->codec_tag);
86
3/4
✓ Branch 14 → 15 taken 15 times.
✓ Branch 14 → 18 taken 622 times.
✓ Branch 15 → 16 taken 15 times.
✗ Branch 15 → 18 not taken.
637 else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample)
87 15 avctx->pix_fmt = avpriv_pix_fmt_find(PIX_FMT_LIST_AVI,
88 15 avctx->bits_per_coded_sample);
89
90 1314 desc = av_pix_fmt_desc_get(avctx->pix_fmt);
91
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 1314 times.
1314 if (!desc) {
92 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid pixel format.\n");
93 ✗ return AVERROR(EINVAL);
94 }
95
96
2/2
✓ Branch 22 → 23 taken 8 times.
✓ Branch 22 → 28 taken 1306 times.
1314 if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
97 8 context->palette = av_buffer_alloc(AVPALETTE_SIZE);
98
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 8 times.
8 if (!context->palette)
99 ✗ return AVERROR(ENOMEM);
100 8 memset(context->palette->data, 0, AVPALETTE_SIZE);
101
1/2
✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 28 not taken.
8 if (avctx->bits_per_coded_sample == 1)
102 8 memset(context->palette->data, 0xff, 4);
103 }
104
105
2/2
✓ Branch 28 → 29 taken 2 times.
✓ Branch 28 → 30 taken 1312 times.
1314 if ((avctx->extradata_size >= 9 &&
106
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 33 taken 2 times.
2 !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) ||
107
1/2
✓ Branch 30 → 31 taken 1312 times.
✗ Branch 30 → 33 not taken.
1312 avctx->codec_tag == MKTAG('c','y','u','v') ||
108
1/2
✓ Branch 31 → 32 taken 1312 times.
✗ Branch 31 → 33 not taken.
1312 avctx->codec_tag == MKTAG(3, 0, 0, 0) ||
109
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 1312 times.
1312 avctx->codec_tag == MKTAG('W','R','A','W'))
110 2 context->flip = 1;
111
112
2/2
✓ Branch 34 → 35 taken 1312 times.
✓ Branch 34 → 36 taken 2 times.
1314 if (avctx->pix_fmt == AV_PIX_FMT_MONOWHITE ||
113
2/2
✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 37 taken 1310 times.
1312 avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
114 4 context->is_mono = 1;
115
2/2
✓ Branch 37 → 38 taken 8 times.
✓ Branch 37 → 39 taken 1302 times.
1310 else if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
116 8 context->is_pal8 = 1;
117
118
2/2
✓ Branch 39 → 40 taken 1313 times.
✓ Branch 39 → 41 taken 1 time.
1314 if (avctx->codec_tag == MKTAG('B','1','W','0') ||
119
2/2
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 42 taken 1312 times.
1313 avctx->codec_tag == MKTAG('B','0','W','1'))
120 2 context->is_nut_mono = 1;
121
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 1312 times.
1312 else if (avctx->codec_tag == MKTAG('P','A','L',8))
122 ✗ context->is_nut_pal8 = 1;
123
124
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 47 taken 1314 times.
1314 if (avctx->codec_tag == AV_RL32("yuv2") &&
125
0/2
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
✗ avctx->pix_fmt == AV_PIX_FMT_YUYV422)
126 ✗ context->is_yuv2 = 1;
127
128 1314 return 0;
129 }
130
131 ✗ static void flip(AVCodecContext *avctx, AVFrame *frame)
132 {
133 ✗ frame->data[0] += frame->linesize[0] * (avctx->height - 1);
134 ✗ frame->linesize[0] *= -1;
135 ✗ }
136
137 /*
138 * Scale sample to 16-bit resolution
139 */
140 #define SCALE16(x, bits) (((x) << (16 - (bits))) | ((x) >> (2 * (bits) - 16)))
141
142 /**
143 * Scale buffer to 16 bits per coded sample resolution
144 */
145 #define MKSCALE16(name, r16, w16) \
146 static void name(AVCodecContext *avctx, uint8_t * dst, const uint8_t *buf, int buf_size, int packed) \
147 { \
148 int i; \
149 if (!packed) { \
150 for (i = 0; i + 1 < buf_size; i += 2) \
151 w16(dst + i, SCALE16(r16(buf + i), avctx->bits_per_coded_sample)); \
152 } else { \
153 GetBitContext gb; \
154 init_get_bits(&gb, buf, buf_size * 8); \
155 for (i = 0; i < avctx->width * avctx->height; i++) { \
156 int sample = get_bits(&gb, avctx->bits_per_coded_sample); \
157 w16(dst + i*2, SCALE16(sample, avctx->bits_per_coded_sample)); \
158 } \
159 } \
160 }
161
162
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 12 not taken.
✗ Branch 10 → 8 not taken.
✗ Branch 10 → 11 not taken.
✗ MKSCALE16(scale16be, AV_RB16, AV_WB16)
163
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 12 not taken.
✗ Branch 10 → 8 not taken.
✗ Branch 10 → 11 not taken.
✗ MKSCALE16(scale16le, AV_RL16, AV_WL16)
164
165 25559 static int raw_decode(AVCodecContext *avctx, AVFrame *frame,
166 int *got_frame, AVPacket *avpkt)
167 {
168 const AVPixFmtDescriptor *desc;
169 25559 RawVideoContext *context = avctx->priv_data;
170 25559 const uint8_t *buf = avpkt->data;
171 25559 int buf_size = avpkt->size;
172 25559 int linesize_align = 4;
173 int stride;
174 int res, len;
175 int need_copy;
176
177
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 25559 times.
25559 if (avctx->width <= 0) {
178 ✗ av_log(avctx, AV_LOG_ERROR, "width is not set\n");
179 ✗ return AVERROR_INVALIDDATA;
180 }
181
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 25559 times.
25559 if (avctx->height <= 0) {
182 ✗ av_log(avctx, AV_LOG_ERROR, "height is not set\n");
183 ✗ return AVERROR_INVALIDDATA;
184 }
185
186
2/2
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 25557 times.
25559 if (context->is_nut_mono)
187 2 stride = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
188
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 25557 times.
25557 else if (context->is_nut_pal8)
189 ✗ stride = avctx->width;
190 else
191 25557 stride = avpkt->size / avctx->height;
192
193 25559 av_log(avctx, AV_LOG_DEBUG, "PACKET SIZE: %d, STRIDE: %d\n", avpkt->size, stride);
194
195
3/4
✓ Branch 14 → 15 taken 25558 times.
✓ Branch 14 → 16 taken 1 time.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 18 taken 25558 times.
25559 if (stride == 0 || avpkt->size < stride * avctx->height) {
196 1 av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
197 1 return AVERROR_INVALIDDATA;
198 }
199
200 25558 desc = av_pix_fmt_desc_get(avctx->pix_fmt);
201
202
2/4
✓ Branch 19 → 20 taken 25558 times.
✗ Branch 19 → 26 not taken.
✓ Branch 20 → 21 taken 25558 times.
✗ Branch 20 → 26 not taken.
25558 if ((avctx->bits_per_coded_sample == 8 || avctx->bits_per_coded_sample == 4 ||
203
3/4
✓ Branch 21 → 22 taken 25558 times.
✗ Branch 21 → 26 not taken.
✓ Branch 22 → 23 taken 25358 times.
✓ Branch 22 → 26 taken 200 times.
25558 avctx->bits_per_coded_sample == 2 || avctx->bits_per_coded_sample == 1 ||
204
5/6
✓ Branch 23 → 24 taken 23556 times.
✓ Branch 23 → 46 taken 1802 times.
✓ Branch 24 → 25 taken 23556 times.
✗ Branch 24 → 26 not taken.
✓ Branch 25 → 26 taken 2 times.
✓ Branch 25 → 46 taken 23554 times.
25358 (avctx->bits_per_coded_sample == 0 && (context->is_nut_pal8 || context->is_mono)) ) &&
205
3/4
✓ Branch 26 → 27 taken 200 times.
✓ Branch 26 → 28 taken 2 times.
✓ Branch 27 → 28 taken 200 times.
✗ Branch 27 → 46 not taken.
202 (context->is_mono || context->is_pal8) &&
206
3/4
✓ Branch 28 → 29 taken 2 times.
✓ Branch 28 → 32 taken 200 times.
✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 32 not taken.
202 (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' ') ||
207
1/4
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 2 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 46 not taken.
204 context->is_nut_mono || context->is_nut_pal8)) {
208
2/2
✓ Branch 32 → 33 taken 200 times.
✓ Branch 32 → 36 taken 2 times.
402 int bits = context->is_mono ? 1 :
209
1/2
✓ Branch 33 → 34 taken 200 times.
✗ Branch 33 → 35 not taken.
200 avctx->bits_per_coded_sample ? avctx->bits_per_coded_sample : 8;
210
1/2
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 40 taken 202 times.
202 if (stride < ((int64_t)avctx->width * bits + 7) / 8) {
211 ✗ av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
212 ✗ return AVERROR_INVALIDDATA;
213 }
214 202 context->is_1_2_4_8_bpp = 1;
215
2/2
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 43 taken 200 times.
202 if (context->is_mono) {
216 2 int row_bytes = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
217 2 context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
218 2 FFALIGN(row_bytes, 16) * 8,
219 avctx->height, 1);
220 } else
221 200 context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
222 200 FFALIGN(avctx->width, 16),
223 avctx->height, 1);
224 } else {
225
5/6
✓ Branch 47 → 48 taken 234 times.
✓ Branch 47 → 51 taken 25122 times.
✓ Branch 48 → 49 taken 200 times.
✓ Branch 48 → 51 taken 34 times.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 200 times.
25356 context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample > 8 && avctx->bits_per_coded_sample < 16;
226 25356 context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width,
227 avctx->height, 1);
228 }
229
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 25558 times.
25558 if (context->frame_size < 0)
230 ✗ return context->frame_size;
231
232
5/8
✓ Branch 56 → 57 taken 25558 times.
✗ Branch 56 → 60 not taken.
✓ Branch 57 → 58 taken 25356 times.
✓ Branch 57 → 60 taken 202 times.
✓ Branch 58 → 59 taken 25356 times.
✗ Branch 58 → 60 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 25356 times.
25558 need_copy = !avpkt->buf || context->is_1_2_4_8_bpp || context->is_yuv2 || context->is_lt_16bpp;
233
234 25558 res = ff_decode_frame_props(avctx, frame);
235
1/2
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 25558 times.
25558 if (res < 0)
236 ✗ return res;
237
238
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 25558 times.
25558 if (context->tff >= 0) {
239 ✗ frame->flags |= AV_FRAME_FLAG_INTERLACED;
240
0/2
✗ Branch 66 → 67 not taken.
✗ Branch 66 → 68 not taken.
✗ if (context->tff == 1)
241 ✗ frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
242 }
243
244
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 25558 times.
25558 if ((res = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
245 ✗ return res;
246
247
2/2
✓ Branch 71 → 72 taken 202 times.
✓ Branch 71 → 74 taken 25356 times.
25558 if (need_copy)
248 202 frame->buf[0] = av_buffer_alloc(FFMAX(context->frame_size, buf_size));
249 else
250 25356 frame->buf[0] = av_buffer_ref(avpkt->buf);
251
1/2
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 25558 times.
25558 if (!frame->buf[0])
252 ✗ return AVERROR(ENOMEM);
253
254 // 1, 2, 4 and 8 bpp in avi/mov, 1 and 8 bpp in nut
255
2/2
✓ Branch 78 → 79 taken 202 times.
✓ Branch 78 → 119 taken 25356 times.
25558 if (context->is_1_2_4_8_bpp) {
256 202 int i, j, row_pix = 0;
257 202 uint8_t *dst = frame->buf[0]->data;
258
2/2
✓ Branch 79 → 80 taken 200 times.
✓ Branch 79 → 81 taken 2 times.
202 buf_size = context->frame_size - (context->is_pal8 ? AVPALETTE_SIZE : 0);
259
4/6
✓ Branch 82 → 83 taken 202 times.
✗ Branch 82 → 85 not taken.
✓ Branch 83 → 84 taken 202 times.
✗ Branch 83 → 85 not taken.
✓ Branch 84 → 85 taken 2 times.
✓ Branch 84 → 95 taken 200 times.
204 if (avctx->bits_per_coded_sample == 8 || context->is_nut_pal8 || context->is_mono) {
260
1/2
✓ Branch 85 → 86 taken 2 times.
✗ Branch 85 → 87 not taken.
2 int pix_per_byte = context->is_mono ? 8 : 1;
261
3/4
✓ Branch 92 → 93 taken 25344 times.
✓ Branch 92 → 94 taken 2 times.
✓ Branch 93 → 89 taken 25344 times.
✗ Branch 93 → 94 not taken.
25346 for (i = 0, j = 0; j < buf_size && i<avpkt->size; i++, j++) {
262 25344 dst[j] = buf[i];
263 25344 row_pix += pix_per_byte;
264
2/2
✓ Branch 89 → 90 taken 576 times.
✓ Branch 89 → 91 taken 24768 times.
25344 if (row_pix >= avctx->width) {
265 576 i += stride - (i % stride) - 1;
266 576 j += 16 - (j % 16) - 1;
267 576 row_pix = 0;
268 }
269 }
270
1/2
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 102 taken 200 times.
200 } else if (avctx->bits_per_coded_sample == 4) {
271
0/4
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 118 not taken.
✗ Branch 101 → 97 not taken.
✗ Branch 101 → 118 not taken.
✗ for (i = 0, j = 0; 2 * j + 1 < buf_size && i<avpkt->size; i++, j++) {
272 ✗ dst[2 * j + 0] = buf[i] >> 4;
273 ✗ dst[2 * j + 1] = buf[i] & 15;
274 ✗ row_pix += 2;
275
0/2
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ if (row_pix >= avctx->width) {
276 ✗ i += stride - (i % stride) - 1;
277 ✗ j += 8 - (j % 8) - 1;
278 ✗ row_pix = 0;
279 }
280 }
281
1/2
✗ Branch 102 → 103 not taken.
✓ Branch 102 → 109 taken 200 times.
200 } else if (avctx->bits_per_coded_sample == 2) {
282
0/4
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 118 not taken.
✗ Branch 108 → 104 not taken.
✗ Branch 108 → 118 not taken.
✗ for (i = 0, j = 0; 4 * j + 3 < buf_size && i<avpkt->size; i++, j++) {
283 ✗ dst[4 * j + 0] = buf[i] >> 6;
284 ✗ dst[4 * j + 1] = buf[i] >> 4 & 3;
285 ✗ dst[4 * j + 2] = buf[i] >> 2 & 3;
286 ✗ dst[4 * j + 3] = buf[i] & 3;
287 ✗ row_pix += 4;
288
0/2
✗ Branch 104 → 105 not taken.
✗ Branch 104 → 106 not taken.
✗ if (row_pix >= avctx->width) {
289 ✗ i += stride - (i % stride) - 1;
290 ✗ j += 4 - (j % 4) - 1;
291 ✗ row_pix = 0;
292 }
293 }
294 } else {
295
1/2
✗ Branch 109 → 110 not taken.
✓ Branch 109 → 112 taken 200 times.
200 av_assert0(avctx->bits_per_coded_sample == 1);
296
3/4
✓ Branch 116 → 117 taken 1909300 times.
✓ Branch 116 → 118 taken 200 times.
✓ Branch 117 → 113 taken 1909300 times.
✗ Branch 117 → 118 not taken.
1909500 for (i = 0, j = 0; 8 * j + 7 < buf_size && i<avpkt->size; i++, j++) {
297 1909300 dst[8 * j + 0] = buf[i] >> 7;
298 1909300 dst[8 * j + 1] = buf[i] >> 6 & 1;
299 1909300 dst[8 * j + 2] = buf[i] >> 5 & 1;
300 1909300 dst[8 * j + 3] = buf[i] >> 4 & 1;
301 1909300 dst[8 * j + 4] = buf[i] >> 3 & 1;
302 1909300 dst[8 * j + 5] = buf[i] >> 2 & 1;
303 1909300 dst[8 * j + 6] = buf[i] >> 1 & 1;
304 1909300 dst[8 * j + 7] = buf[i] & 1;
305 1909300 row_pix += 8;
306
2/2
✓ Branch 113 → 114 taken 44900 times.
✓ Branch 113 → 115 taken 1864400 times.
1909300 if (row_pix >= avctx->width) {
307 44900 i += stride - (i % stride) - 1;
308 44900 j += 2 - (j % 2) - 1;
309 44900 row_pix = 0;
310 }
311 }
312 }
313 202 linesize_align = 16;
314 202 buf = dst;
315
1/2
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 135 taken 25356 times.
25356 } else if (context->is_lt_16bpp) {
316 ✗ uint8_t *dst = frame->buf[0]->data;
317 ✗ int packed = (avctx->codec_tag & 0xFFFFFF) == MKTAG('B','I','T', 0);
318 ✗ int swap = avctx->codec_tag >> 24;
319
320
0/4
✗ Branch 120 → 121 not taken.
✗ Branch 120 → 131 not taken.
✗ Branch 121 → 122 not taken.
✗ Branch 121 → 131 not taken.
✗ if (packed && swap) {
321 ✗ av_fast_padded_malloc(&context->bitstream_buf, &context->bitstream_buf_size, buf_size);
322
0/2
✗ Branch 123 → 124 not taken.
✗ Branch 123 → 125 not taken.
✗ if (!context->bitstream_buf)
323 ✗ return AVERROR(ENOMEM);
324
0/2
✗ Branch 125 → 126 not taken.
✗ Branch 125 → 127 not taken.
✗ if (swap == 16)
325 ✗ context->bbdsp.bswap16_buf(context->bitstream_buf, (const uint16_t*)buf, buf_size / 2);
326
0/2
✗ Branch 127 → 128 not taken.
✗ Branch 127 → 129 not taken.
✗ else if (swap == 32)
327 ✗ context->bbdsp.bswap_buf(context->bitstream_buf, (const uint32_t*)buf, buf_size / 4);
328 else
329 ✗ return AVERROR_INVALIDDATA;
330 ✗ buf = context->bitstream_buf;
331 }
332
333
0/2
✗ Branch 131 → 132 not taken.
✗ Branch 131 → 133 not taken.
✗ if (desc->flags & AV_PIX_FMT_FLAG_BE)
334 ✗ scale16be(avctx, dst, buf, buf_size, packed);
335 else
336 ✗ scale16le(avctx, dst, buf, buf_size, packed);
337
338 ✗ buf = dst;
339
1/2
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 137 taken 25356 times.
25356 } else if (need_copy) {
340 ✗ memcpy(frame->buf[0]->data, buf, buf_size);
341 ✗ buf = frame->buf[0]->data;
342 }
343
344
1/2
✓ Branch 137 → 138 taken 25558 times.
✗ Branch 137 → 139 not taken.
25558 if (avctx->codec_tag == MKTAG('A', 'V', '1', 'x') ||
345
1/2
✗ Branch 138 → 139 not taken.
✓ Branch 138 → 140 taken 25558 times.
25558 avctx->codec_tag == MKTAG('A', 'V', 'u', 'p'))
346 ✗ buf += buf_size - context->frame_size;
347
348
2/2
✓ Branch 140 → 141 taken 200 times.
✓ Branch 140 → 142 taken 25358 times.
25558 len = context->frame_size - (avctx->pix_fmt==AV_PIX_FMT_PAL8 ? AVPALETTE_SIZE : 0);
349
1/6
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 149 taken 25558 times.
✗ Branch 144 → 145 not taken.
✗ Branch 144 → 146 not taken.
✗ Branch 145 → 146 not taken.
✗ Branch 145 → 149 not taken.
25558 if (buf_size < len && ((avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0) || !need_copy)) {
350 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid buffer size, packet size %d < expected frame_size %d\n", buf_size, len);
351 ✗ av_buffer_unref(&frame->buf[0]);
352 ✗ return AVERROR(EINVAL);
353 }
354
355
1/2
✗ Branch 150 → 151 not taken.
✓ Branch 150 → 153 taken 25558 times.
25558 if ((res = av_image_fill_arrays(frame->data, frame->linesize,
356 buf, avctx->pix_fmt,
357 avctx->width, avctx->height, 1)) < 0) {
358 ✗ av_buffer_unref(&frame->buf[0]);
359 ✗ return res;
360 }
361
362
2/2
✓ Branch 153 → 154 taken 200 times.
✓ Branch 153 → 170 taken 25358 times.
25558 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
363 int ret;
364
365
1/2
✗ Branch 154 → 155 not taken.
✓ Branch 154 → 157 taken 200 times.
200 if (!context->palette)
366 ✗ context->palette = av_buffer_alloc(AVPALETTE_SIZE);
367
1/2
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 160 taken 200 times.
200 if (!context->palette) {
368 ✗ av_buffer_unref(&frame->buf[0]);
369 ✗ return AVERROR(ENOMEM);
370 }
371 200 ret = av_buffer_make_writable(&context->palette);
372
1/2
✗ Branch 161 → 162 not taken.
✓ Branch 161 → 164 taken 200 times.
200 if (ret < 0) {
373 ✗ av_buffer_unref(&frame->buf[0]);
374 ✗ return ret;
375 }
376
377
3/4
✓ Branch 165 → 166 taken 196 times.
✓ Branch 165 → 170 taken 4 times.
✗ Branch 166 → 167 not taken.
✓ Branch 166 → 170 taken 196 times.
200 if (!ff_copy_palette(context->palette->data, avpkt, avctx) && context->is_nut_pal8) {
378 ✗ int vid_size = avctx->width * avctx->height;
379 ✗ int pal_size = avpkt->size - vid_size;
380
381
0/4
✗ Branch 167 → 168 not taken.
✗ Branch 167 → 170 not taken.
✗ Branch 168 → 169 not taken.
✗ Branch 168 → 170 not taken.
✗ if (avpkt->size > vid_size && pal_size <= AVPALETTE_SIZE) {
382 ✗ const uint8_t *pal = avpkt->data + vid_size;
383 ✗ memcpy(context->palette->data, pal, pal_size);
384 }
385 }
386 }
387
388
2/2
✓ Branch 170 → 171 taken 25491 times.
✓ Branch 170 → 179 taken 67 times.
25558 if ((avctx->pix_fmt==AV_PIX_FMT_RGB24 ||
389
2/2
✓ Branch 171 → 172 taken 25089 times.
✓ Branch 171 → 179 taken 402 times.
25491 avctx->pix_fmt==AV_PIX_FMT_BGR24 ||
390
2/2
✓ Branch 172 → 173 taken 25063 times.
✓ Branch 172 → 179 taken 26 times.
25089 avctx->pix_fmt==AV_PIX_FMT_GRAY8 ||
391
2/2
✓ Branch 173 → 174 taken 24662 times.
✓ Branch 173 → 179 taken 401 times.
25063 avctx->pix_fmt==AV_PIX_FMT_RGB555LE ||
392
1/2
✓ Branch 174 → 175 taken 24662 times.
✗ Branch 174 → 179 not taken.
24662 avctx->pix_fmt==AV_PIX_FMT_RGB555BE ||
393
2/2
✓ Branch 175 → 176 taken 24461 times.
✓ Branch 175 → 179 taken 201 times.
24662 avctx->pix_fmt==AV_PIX_FMT_RGB565LE ||
394
2/2
✓ Branch 176 → 177 taken 24460 times.
✓ Branch 176 → 179 taken 1 time.
24461 avctx->pix_fmt==AV_PIX_FMT_MONOWHITE ||
395
2/2
✓ Branch 177 → 178 taken 24459 times.
✓ Branch 177 → 179 taken 1 time.
24460 avctx->pix_fmt==AV_PIX_FMT_MONOBLACK ||
396
2/2
✓ Branch 178 → 179 taken 200 times.
✓ Branch 178 → 181 taken 24259 times.
24459 avctx->pix_fmt==AV_PIX_FMT_PAL8) &&
397
2/2
✓ Branch 179 → 180 taken 1249 times.
✓ Branch 179 → 181 taken 50 times.
1299 FFALIGN(frame->linesize[0], linesize_align) * avctx->height <= buf_size)
398 1249 frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align);
399
400
3/4
✓ Branch 181 → 182 taken 1 time.
✓ Branch 181 → 185 taken 25557 times.
✓ Branch 182 → 183 taken 1 time.
✗ Branch 182 → 185 not taken.
25558 if (avctx->pix_fmt == AV_PIX_FMT_NV12 && avctx->codec_tag == MKTAG('N', 'V', '1', '2') &&
401 1 FFALIGN(frame->linesize[0], linesize_align) * avctx->height +
402
1/2
✓ Branch 183 → 184 taken 1 time.
✗ Branch 183 → 185 not taken.
1 FFALIGN(frame->linesize[1], linesize_align) * ((avctx->height + 1) / 2) <= buf_size) {
403 1 int la0 = FFALIGN(frame->linesize[0], linesize_align);
404 1 frame->data[1] += (la0 - frame->linesize[0]) * avctx->height;
405 1 frame->linesize[0] = la0;
406 1 frame->linesize[1] = FFALIGN(frame->linesize[1], linesize_align);
407 }
408
409
3/4
✓ Branch 185 → 186 taken 200 times.
✓ Branch 185 → 192 taken 25358 times.
✓ Branch 186 → 187 taken 200 times.
✗ Branch 186 → 192 not taken.
25558 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->frame_size) {
410 200 frame->buf[1] = av_buffer_ref(context->palette);
411
1/2
✗ Branch 188 → 189 not taken.
✓ Branch 188 → 191 taken 200 times.
200 if (!frame->buf[1]) {
412 ✗ av_buffer_unref(&frame->buf[0]);
413 ✗ return AVERROR(ENOMEM);
414 }
415 200 frame->data[1] = frame->buf[1]->data;
416 }
417
418
2/2
✓ Branch 192 → 193 taken 402 times.
✓ Branch 192 → 195 taken 25156 times.
25558 if (avctx->pix_fmt == AV_PIX_FMT_BGR24 &&
419
2/2
✓ Branch 193 → 194 taken 352 times.
✓ Branch 193 → 195 taken 50 times.
402 ((frame->linesize[0] + 3) & ~3) * avctx->height <= buf_size)
420 352 frame->linesize[0] = (frame->linesize[0] + 3) & ~3;
421
422
1/2
✗ Branch 195 → 196 not taken.
✓ Branch 195 → 197 taken 25558 times.
25558 if (context->flip)
423 ✗ flip(avctx, frame);
424
425
1/2
✓ Branch 197 → 198 taken 25558 times.
✗ Branch 197 → 201 not taken.
25558 if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2') ||
426
1/2
✓ Branch 198 → 199 taken 25558 times.
✗ Branch 198 → 201 not taken.
25558 avctx->codec_tag == MKTAG('Y', 'V', '1', '6') ||
427
1/2
✓ Branch 199 → 200 taken 25558 times.
✗ Branch 199 → 201 not taken.
25558 avctx->codec_tag == MKTAG('Y', 'V', '2', '4') ||
428
1/2
✗ Branch 200 → 201 not taken.
✓ Branch 200 → 202 taken 25558 times.
25558 avctx->codec_tag == MKTAG('Y', 'V', 'U', '9'))
429 ✗ FFSWAP(uint8_t *, frame->data[1], frame->data[2]);
430
431
3/4
✓ Branch 202 → 203 taken 23514 times.
✓ Branch 202 → 205 taken 2044 times.
✗ Branch 203 → 204 not taken.
✓ Branch 203 → 205 taken 23514 times.
25558 if (avctx->codec_tag == AV_RL32("I420") && (avctx->width+1)*(avctx->height+1) * 3/2 == buf_size) {
432 ✗ frame->data[1] = frame->data[1] + (avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height;
433 ✗ frame->data[2] = frame->data[2] + ((avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height)*5/4;
434 }
435
436
1/2
✗ Branch 205 → 206 not taken.
✓ Branch 205 → 213 taken 25558 times.
25558 if (avctx->codec_tag == AV_RL32("yuv2") &&
437
0/2
✗ Branch 206 → 207 not taken.
✗ Branch 206 → 213 not taken.
✗ avctx->pix_fmt == AV_PIX_FMT_YUYV422) {
438 int x, y;
439 ✗ uint8_t *line = frame->data[0];
440
0/2
✗ Branch 212 → 208 not taken.
✗ Branch 212 → 213 not taken.
✗ for (y = 0; y < avctx->height; y++) {
441
0/2
✗ Branch 210 → 209 not taken.
✗ Branch 210 → 211 not taken.
✗ for (x = 0; x < avctx->width; x++)
442 ✗ line[2 * x + 1] ^= 0x80;
443 ✗ line += frame->linesize[0];
444 }
445 }
446
447
1/2
✗ Branch 213 → 214 not taken.
✓ Branch 213 → 221 taken 25558 times.
25558 if (avctx->codec_tag == AV_RL32("b64a") &&
448
0/2
✗ Branch 214 → 215 not taken.
✗ Branch 214 → 221 not taken.
✗ avctx->pix_fmt == AV_PIX_FMT_RGBA64BE) {
449 ✗ uint8_t *dst = frame->data[0];
450 uint64_t v;
451 int x, y;
452
0/2
✗ Branch 220 → 216 not taken.
✗ Branch 220 → 221 not taken.
✗ for (y = 0; y < avctx->height; y++) {
453
0/2
✗ Branch 218 → 217 not taken.
✗ Branch 218 → 219 not taken.
✗ for (x = 0; x >> 3 < avctx->width; x += 8) {
454 ✗ v = AV_RB64(&dst[x]);
455 ✗ AV_WB64(&dst[x], v << 16 | v >> 48);
456 }
457 ✗ dst += frame->linesize[0];
458 }
459 }
460
461
1/2
✗ Branch 221 → 222 not taken.
✓ Branch 221 → 225 taken 25558 times.
25558 if (avctx->field_order > AV_FIELD_PROGRESSIVE) { /* we have interlaced material flagged in container */
462 ✗ frame->flags |= AV_FRAME_FLAG_INTERLACED;
463
0/4
✗ Branch 222 → 223 not taken.
✗ Branch 222 → 224 not taken.
✗ Branch 223 → 224 not taken.
✗ Branch 223 → 225 not taken.
✗ if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
464 ✗ frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
465 }
466
467 25558 *got_frame = 1;
468 25558 return buf_size;
469 }
470
471 1314 static av_cold int raw_close_decoder(AVCodecContext *avctx)
472 {
473 1314 RawVideoContext *context = avctx->priv_data;
474
475 1314 av_buffer_unref(&context->palette);
476 1314 av_freep(&context->bitstream_buf);
477 1314 return 0;
478 }
479
480 const FFCodec ff_rawvideo_decoder = {
481 .p.name = "rawvideo",
482 CODEC_LONG_NAME("raw video"),
483 .p.type = AVMEDIA_TYPE_VIDEO,
484 .p.id = AV_CODEC_ID_RAWVIDEO,
485 .priv_data_size = sizeof(RawVideoContext),
486 .init = raw_init_decoder,
487 .close = raw_close_decoder,
488 FF_CODEC_DECODE_CB(raw_decode),
489 .p.priv_class = &rawdec_class,
490 .p.capabilities = AV_CODEC_CAP_PARAM_CHANGE,
491 };
492