FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/sp5xdec.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 33 35 94.3%
Functions: 1 1 100.0%
Branches: 14 20 70.0%

Line Branch Exec Source
1 /*
2 * Sunplus JPEG decoder (SP5X)
3 * Copyright (c) 2003 Alex Beregszaszi
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 * Sunplus JPEG decoder (SP5X).
25 */
26
27 #include "config_components.h"
28
29 #include "libavutil/mem.h"
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "mjpegdec.h"
33 #include "sp5x.h"
34
35
36 379 static int sp5x_decode_frame(AVCodecContext *avctx,
37 AVFrame *frame, int *got_frame,
38 AVPacket *avpkt)
39 {
40 379 const uint8_t *buf = avpkt->data;
41 379 int buf_size = avpkt->size;
42 uint8_t *recoded;
43 379 int i = 0, j = 0;
44 int ret;
45
46
2/4
✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 379 times.
379 if (!avctx->width || !avctx->height)
47 return -1;
48
49 379 recoded = av_mallocz(buf_size + 1024);
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
379 if (!recoded)
51 return -1;
52
53 /* SOI */
54 379 recoded[j++] = 0xFF;
55 379 recoded[j++] = 0xD8;
56
57 379 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
58 379 memcpy(recoded + j + 5, &sp5x_qscale_five_quant_table[0], 64);
59 379 memcpy(recoded + j + 70, &sp5x_qscale_five_quant_table[1], 64);
60 379 j += sizeof(sp5x_data_dqt);
61
62 379 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
63 379 j += sizeof(sp5x_data_dht);
64
65 379 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
66 379 AV_WB16(recoded+j+5, avctx->coded_height);
67 379 AV_WB16(recoded+j+7, avctx->coded_width);
68 379 j += sizeof(sp5x_data_sof);
69
70 379 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
71 379 j += sizeof(sp5x_data_sos);
72
73
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 11 times.
379 if(avctx->codec_id==AV_CODEC_ID_AMV)
74
3/4
✓ Branch 0 taken 3662104 times.
✓ Branch 1 taken 368 times.
✓ Branch 2 taken 3662104 times.
✗ Branch 3 not taken.
3662472 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
75 3662104 recoded[j++] = buf[i];
76 else
77
3/4
✓ Branch 0 taken 39424 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 39424 times.
✗ Branch 3 not taken.
39435 for (i = 14; i < buf_size && j < buf_size+1024-3; i++)
78 {
79 39424 recoded[j++] = buf[i];
80
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 39331 times.
39424 if (buf[i] == 0xff)
81 93 recoded[j++] = 0;
82 }
83
84 /* EOI */
85 379 recoded[j++] = 0xFF;
86 379 recoded[j++] = 0xD9;
87
88 379 ret = ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame,
89 avpkt, recoded, j);
90
91 379 av_free(recoded);
92
93
1/2
✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
379 return ret < 0 ? ret : avpkt->size;
94 }
95
96 #if CONFIG_SP5X_DECODER
97 const FFCodec ff_sp5x_decoder = {
98 .p.name = "sp5x",
99 CODEC_LONG_NAME("Sunplus JPEG (SP5X)"),
100 .p.type = AVMEDIA_TYPE_VIDEO,
101 .p.id = AV_CODEC_ID_SP5X,
102 .priv_data_size = sizeof(MJpegDecodeContext),
103 .init = ff_mjpeg_decode_init,
104 .close = ff_mjpeg_decode_end,
105 FF_CODEC_DECODE_CB(sp5x_decode_frame),
106 .p.capabilities = AV_CODEC_CAP_DR1,
107 .p.max_lowres = 3,
108 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
109 };
110 #endif
111 #if CONFIG_AMV_DECODER
112 const FFCodec ff_amv_decoder = {
113 .p.name = "amv",
114 CODEC_LONG_NAME("AMV Video"),
115 .p.type = AVMEDIA_TYPE_VIDEO,
116 .p.id = AV_CODEC_ID_AMV,
117 .priv_data_size = sizeof(MJpegDecodeContext),
118 .init = ff_mjpeg_decode_init,
119 .close = ff_mjpeg_decode_end,
120 FF_CODEC_DECODE_CB(sp5x_decode_frame),
121 .p.max_lowres = 3,
122 .p.capabilities = AV_CODEC_CAP_DR1,
123 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
124 };
125 #endif
126