FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
frmdec.c
Go to the documentation of this file.
1 /*
2  * Megalux Frame demuxer
3  * Copyright (c) 2010 Peter Ross <pross@xvid.org>
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  * Megalux Frame demuxer
25  */
26 
27 #include "libavcodec/raw.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/intreadwrite.h"
30 #include "avformat.h"
31 
32 static const PixelFormatTag frm_pix_fmt_tags[] = {
33  { AV_PIX_FMT_RGB555, 1 },
34  { AV_PIX_FMT_RGB0, 2 },
35  { AV_PIX_FMT_RGB24, 3 },
36  { AV_PIX_FMT_BGR0, 4 },
37  { AV_PIX_FMT_BGRA, 5 },
38  { AV_PIX_FMT_NONE, 0 },
39 };
40 
41 typedef struct {
42  int count;
43 } FrmContext;
44 
46 {
47  if (p->buf_size > 8 &&
48  p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
49  AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
50  return AVPROBE_SCORE_MAX / 4;
51  return 0;
52 }
53 
54 static int frm_read_header(AVFormatContext *avctx)
55 {
56  AVIOContext *pb = avctx->pb;
57  AVStream *st = avformat_new_stream(avctx, 0);
58  if (!st)
59  return AVERROR(ENOMEM);
60 
63  avio_skip(pb, 3);
64 
65  st->codecpar->format = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb));
66  if (!st->codecpar->format)
67  return AVERROR_INVALIDDATA;
68 
69  st->codecpar->codec_tag = 0;
70  st->codecpar->width = avio_rl16(pb);
71  st->codecpar->height = avio_rl16(pb);
72  return 0;
73 }
74 
76 {
77  FrmContext *s = avctx->priv_data;
78  AVCodecParameters *par = avctx->streams[0]->codecpar;
79  int packet_size, ret;
80 
81  if (s->count)
82  return AVERROR_EOF;
83 
84  packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
85  if (packet_size < 0)
86  return AVERROR_INVALIDDATA;
87 
88  ret = av_get_packet(avctx->pb, pkt, packet_size);
89  if (ret < 0)
90  return ret;
91 
92  if (par->format == AV_PIX_FMT_BGRA) {
93  int i;
94  for (i = 3; i + 1 <= pkt->size; i += 4)
95  pkt->data[i] = 0xFF - pkt->data[i];
96  }
97 
98  pkt->stream_index = 0;
99  s->count++;
100 
101  return 0;
102 }
103 
105  .name = "frm",
106  .priv_data_size = sizeof(FrmContext),
107  .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
108  .read_probe = frm_read_probe,
109  .read_header = frm_read_header,
110  .read_packet = frm_read_packet,
111 };
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:155
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int frm_read_header(AVFormatContext *avctx)
Definition: frmdec.c:54
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4066
int size
Definition: avcodec.h:1658
static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: frmdec.c:75
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:316
static AVPacket pkt
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4058
static const PixelFormatTag frm_pix_fmt_tags[]
Definition: frmdec.c:32
Format I/O context.
Definition: avformat.h:1349
int width
Video only.
Definition: avcodec.h:4132
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:252
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4231
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1417
uint8_t * data
Definition: avcodec.h:1657
#define AVERROR_EOF
End of file.
Definition: error.h:55
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:289
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:429
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4062
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:607
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:464
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:463
Raw Video Codec.
Stream structure.
Definition: avformat.h:889
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:1036
AVIOContext * pb
I/O context.
Definition: avformat.h:1391
AVInputFormat ff_frm_demuxer
Definition: frmdec.c:104
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:254
This structure contains the data a format has to probe a file.
Definition: avformat.h:461
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:473
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:722
Main libavformat public API header.
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:339
void * priv_data
Format private data.
Definition: avformat.h:1377
int count
Definition: frmdec.c:42
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:664
AVCodecParameters * codecpar
Definition: avformat.h:1252
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:4070
int stream_index
Definition: avcodec.h:1659
This structure stores compressed data.
Definition: avcodec.h:1634
static int frm_read_probe(AVProbeData *p)
Definition: frmdec.c:45