1 /*
2 * Brute Force & Ignorance (BFI) video decoder
3 * Copyright (c) 2008 Sisir Koppaka
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 * @brief Brute Force & Ignorance (.bfi) video decoder
25 * @author Sisir Koppaka ( sisir.koppaka at gmail dot com )
26 * @see http://wiki.multimedia.cx/index.php?title=BFI
27 */
28
33
39
41 {
47 return 0;
48 }
49
52 {
55 int buf_size = avpkt->
size;
60 uint32_t *pal;
62
64 return ret;
65
67
68 /* Set frame parameters and palette, if necessary */
72 /* Setting the palette */
76 }
77 pal = (uint32_t *)frame->
data[1];
81 for (j = 0; j < 3; j++, shift -= 8)
82 *pal += ((avctx->
extradata[i * 3 + j] << 2) |
84 pal++;
85 }
86 memcpy(bfi->
pal, frame->
data[1],
sizeof(bfi->
pal));
88 } else {
92 memcpy(frame->
data[1], bfi->
pal,
sizeof(bfi->
pal));
93 }
94
96
97 while (dst != frame_end) {
98 static const uint8_t lentab[4] = { 0, 2, 0, 1 };
100 unsigned int code = byte >> 6;
101 unsigned int length = byte & ~0xC0;
102
105 "Input resolution larger than actual frame.\n");
107 }
108
109 /* Get length and offset (if required) */
110 if (length == 0) {
111 if (code == 1) {
112 length = bytestream2_get_byte(&g);
113 offset = bytestream2_get_le16(&g);
114 } else {
115 length = bytestream2_get_le16(&g);
116 if (code == 2 && length == 0)
117 break;
118 }
119 } else {
120 if (code == 1)
121 offset = bytestream2_get_byte(&g);
122 }
123
124 /* Do boundary check */
125 if (dst + (length << lentab[code]) > frame_end)
126 break;
127
128 switch (code) {
129 case 0: // normal chain
133 }
136 break;
137 case 1: // back chain
138 dst_offset = dst -
offset;
139 length *= 4; // Convert dwords to bytes.
140 if (dst_offset < bfi->dst)
141 break;
142 while (length--)
143 *dst++ = *dst_offset++;
144 break;
145 case 2: // skip chain
147 break;
148 case 3: // fill chain
149 colour1 = bytestream2_get_byte(&g);
150 colour2 = bytestream2_get_byte(&g);
151 while (length--) {
152 *dst++ = colour1;
153 *dst++ = colour2;
154 }
155 break;
156 }
157 }
158
160 dst = frame->
data[0];
161 while (height--) {
162 memcpy(dst, src, avctx->
width);
165 }
166 *got_frame = 1;
167
168 return buf_size;
169 }
170
172 {
175 return 0;
176 }
177
189 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
8 bits with AV_PIX_FMT_RGB32 palette
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
static void frame_end(MpegEncContext *s)
enum AVPictureType pict_type
Picture type of the frame.
static av_cold int bfi_decode_close(AVCodecContext *avctx)
int width
picture width / height.
Libavcodec external API header.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int bfi_decode_init(AVCodecContext *avctx)
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int palette_has_changed
Tell user application that palette has changed from previous frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
common internal and external API header
static int bfi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int key_frame
1 -> keyframe, 0-> not
int frame_number
Frame counter, set by libavcodec.
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.