FFmpeg
Loading...
Searching...
No Matches
sp5xdec.c
Go to the documentation of this file.
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
37 AVFrame *frame, int *got_frame,
38 AVPacket *avpkt)
39{
40 const uint8_t *buf = avpkt->data;
41 int buf_size = avpkt->size;
42 uint8_t *recoded;
43 int i = 0, j = 0;
44 int ret;
45
46 if (!avctx->width || !avctx->height)
47 return -1;
48
49 recoded = av_mallocz(buf_size + 1024);
50 if (!recoded)
51 return -1;
52
53 /* SOI */
54 recoded[j++] = 0xFF;
55 recoded[j++] = 0xD8;
56
57 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
58 memcpy(recoded + j + 5, &sp5x_qscale_five_quant_table[0], 64);
59 memcpy(recoded + j + 70, &sp5x_qscale_five_quant_table[1], 64);
60 j += sizeof(sp5x_data_dqt);
61
62 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
63 j += sizeof(sp5x_data_dht);
64
65 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
66 AV_WB16(recoded+j+5, avctx->coded_height);
67 AV_WB16(recoded+j+7, avctx->coded_width);
68 j += sizeof(sp5x_data_sof);
69
70 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
71 j += sizeof(sp5x_data_sos);
72
73 if(avctx->codec_id==AV_CODEC_ID_AMV)
74 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
75 recoded[j++] = buf[i];
76 else
77 for (i = 14; i < buf_size && j < buf_size+1024-3; i++)
78 {
79 recoded[j++] = buf[i];
80 if (buf[i] == 0xff)
81 recoded[j++] = 0;
82 }
83
84 /* EOI */
85 recoded[j++] = 0xFF;
86 recoded[j++] = 0xD9;
87
88 ret = ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame,
89 avpkt, recoded, j);
90
91 av_free(recoded);
92
93 return ret < 0 ? ret : avpkt->size;
94}
95
96#if CONFIG_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),
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
112const 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),
121 .p.max_lowres = 3,
122 .p.capabilities = AV_CODEC_CAP_DR1,
123 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
124};
125#endif
const FFCodec ff_sp5x_decoder
const FFCodec ff_amv_decoder
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_SP5X
Definition codec_id.h:60
@ AV_CODEC_ID_AMV
Definition codec_id.h:157
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_WB16(p, v)
Memory handling functions.
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
Definition mjpegdec.c:124
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
Definition mjpegdec.c:2900
int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *avpkt, const uint8_t *buf, const int buf_size)
Definition mjpegdec.c:2394
MJPEG decoder.
static const uint8_t sp5x_data_dqt[]
Definition sp5x.h:53
static const uint8_t sp5x_data_dht[]
Definition sp5x.h:77
static const uint8_t sp5x_data_sos[]
Definition sp5x.h:40
static const uint8_t sp5x_qscale_five_quant_table[][64]
Definition sp5x.h:135
static const uint8_t sp5x_data_sof[]
Definition sp5x.h:27
static int sp5x_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition sp5xdec.c:36
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
enum AVCodecID codec_id
Definition avcodec.h:453
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:619
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
#define av_free(p)
#define av_mallocz(s)