GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/sp5xdec.c Lines: 37 39 94.9 %
Date: 2021-01-22 05:18:52 Branches: 13 18 72.2 %

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 "avcodec.h"
28
#include "internal.h"
29
#include "mjpeg.h"
30
#include "mjpegdec.h"
31
#include "sp5x.h"
32
33
378
int ff_sp5x_process_packet(AVCodecContext *avctx, AVPacket *avpkt)
34
{
35
378
    const uint8_t *buf = avpkt->data;
36
378
    int buf_size = avpkt->size;
37
    AVBufferRef *buf_recoded;
38
378
    const int qscale = 5;
39
    uint8_t *recoded;
40
378
    int i = 0, j = 0;
41
42

378
    if (!avctx->width || !avctx->height)
43
        return -1;
44
45
378
    buf_recoded = av_buffer_allocz(buf_size + 1024);
46
378
    if (!buf_recoded)
47
        return -1;
48
378
    recoded = buf_recoded->data;
49
50
    /* SOI */
51
378
    recoded[j++] = 0xFF;
52
378
    recoded[j++] = 0xD8;
53
54
378
    memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
55
378
    memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
56
378
    memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
57
378
    j += sizeof(sp5x_data_dqt);
58
59
378
    memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
60
378
    j += sizeof(sp5x_data_dht);
61
62
378
    memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
63
378
    AV_WB16(recoded+j+5, avctx->coded_height);
64
378
    AV_WB16(recoded+j+7, avctx->coded_width);
65
378
    j += sizeof(sp5x_data_sof);
66
67
378
    memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
68
378
    j += sizeof(sp5x_data_sos);
69
70
378
    if(avctx->codec_id==AV_CODEC_ID_AMV)
71

3659228
        for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
72
3658861
            recoded[j++] = buf[i];
73
    else
74

39435
    for (i = 14; i < buf_size && j < buf_size+1024-3; i++)
75
    {
76
39424
        recoded[j++] = buf[i];
77
39424
        if (buf[i] == 0xff)
78
93
            recoded[j++] = 0;
79
    }
80
81
    /* EOI */
82
378
    recoded[j++] = 0xFF;
83
378
    recoded[j++] = 0xD9;
84
85
378
    av_buffer_unref(&avpkt->buf);
86
378
    avpkt->buf  = buf_recoded;
87
378
    avpkt->data = recoded;
88
378
    avpkt->size = j;
89
90
378
    return 0;
91
}
92
93
#if CONFIG_SP5X_DECODER
94
AVCodec ff_sp5x_decoder = {
95
    .name           = "sp5x",
96
    .long_name      = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
97
    .type           = AVMEDIA_TYPE_VIDEO,
98
    .id             = AV_CODEC_ID_SP5X,
99
    .priv_data_size = sizeof(MJpegDecodeContext),
100
    .init           = ff_mjpeg_decode_init,
101
    .close          = ff_mjpeg_decode_end,
102
    .receive_frame  = ff_mjpeg_receive_frame,
103
    .capabilities   = AV_CODEC_CAP_DR1,
104
    .max_lowres     = 3,
105
    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
106
                      FF_CODEC_CAP_SETS_PKT_DTS,
107
};
108
#endif
109
#if CONFIG_AMV_DECODER
110
AVCodec ff_amv_decoder = {
111
    .name           = "amv",
112
    .long_name      = NULL_IF_CONFIG_SMALL("AMV Video"),
113
    .type           = AVMEDIA_TYPE_VIDEO,
114
    .id             = AV_CODEC_ID_AMV,
115
    .priv_data_size = sizeof(MJpegDecodeContext),
116
    .init           = ff_mjpeg_decode_init,
117
    .close          = ff_mjpeg_decode_end,
118
    .receive_frame  = ff_mjpeg_receive_frame,
119
    .max_lowres     = 3,
120
    .capabilities   = AV_CODEC_CAP_DR1,
121
    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
122
                      FF_CODEC_CAP_SETS_PKT_DTS,
123
};
124
#endif