FFmpeg: libavcodec/cdgraphics.c Source File
Go to the documentation of this file. 1 /*
2 * CD Graphics Video Decoder
3 * Copyright (c) 2009 Michael Tison
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
26
28
29 /**
30 * @file
31 * @brief CD Graphics Video Decoder
32 * @author Michael Tison
33 * @see http://wiki.multimedia.cx/index.php?title=CD_Graphics
34 * @see http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg
35 */
36
37 /// default screen sizes
38 #define CDG_FULL_WIDTH 300
39 #define CDG_FULL_HEIGHT 216
40 #define CDG_DISPLAY_WIDTH 294
41 #define CDG_DISPLAY_HEIGHT 204
42 #define CDG_BORDER_WIDTH 6
43 #define CDG_BORDER_HEIGHT 12
44
45 /// masks
46 #define CDG_COMMAND 0x09
48
49 /// instruction codes
50 #define CDG_INST_MEMORY_PRESET 1
51 #define CDG_INST_BORDER_PRESET 2
52 #define CDG_INST_TILE_BLOCK 6
53 #define CDG_INST_SCROLL_PRESET 20
54 #define CDG_INST_SCROLL_COPY 24
55 #define CDG_INST_TRANSPARENT_COL 28
56 #define CDG_INST_LOAD_PAL_LO 30
57 #define CDG_INST_LOAD_PAL_HIGH 31
58 #define CDG_INST_TILE_BLOCK_XOR 38
59
60 /// data sizes
61 #define CDG_PACKET_SIZE 24
62 #define CDG_DATA_SIZE 16
63 #define CDG_TILE_HEIGHT 12
64 #define CDG_TILE_WIDTH 6
65 #define CDG_MINIMUM_PKT_SIZE 6
66 #define CDG_MINIMUM_SCROLL_SIZE 3
67 #define CDG_HEADER_SIZE 8
68 #define CDG_PALETTE_SIZE 16
69
77
79 {
81
85
88
91 }
92
94 {
98
99 if (!(
data[1] & 0x0F)) {
100 /// fill the top and bottom borders
105
106 /// fill the side borders
111 }
112 }
113 }
114
116 {
120 int array_offset = low ? 0 : 8;
121 uint32_t *palette = (uint32_t *) cc->
frame->
data[1];
122
125 r = ((
color >> 8) & 0x000F) * 17;
126 g = ((
color >> 4) & 0x000F) * 17;
127 b = ((
color ) & 0x000F) * 17;
128 palette[
i + array_offset] = (uint32_t)cc->
alpha[
i + array_offset] << 24 |
r << 16 |
g << 8 |
b;
129 }
130 }
131
133 {
134 unsigned ci, ri;
136 int x, y;
137 int ai;
140
143
148
151 if (!((
data[4 + y] >> (5 - x)) & 0x01))
153 else
155
156 ai = ci + x + (
stride * (ri + y));
160 }
161 }
162
163 return 0;
164 }
165
170
172 int in_tl_x, int in_tl_y, uint8_t *in,
174 {
175 int y;
176
177 in += in_tl_x + in_tl_y *
stride;
179 for (y = 0; y <
h; y++)
181 }
182
185 {
186 int y;
187
188 for (y = tl_y; y < tl_y +
h; y++)
190 }
191
193 int in_tl_x, int in_tl_y, uint8_t *in,
195 {
196 if (roll) {
199 } else {
201 }
202 }
203
205 AVFrame *new_frame,
int roll_over)
206 {
208 int hscmd, h_off, hinc, vscmd, v_off, vinc;
209 int y;
212 uint8_t *
out = new_frame->
data[0];
213
215 hscmd = (
data[1] & 0x30) >> 4;
216 vscmd = (
data[2] & 0x30) >> 4;
217
220
221 /// find the difference and save the offset for cdg_tile_block usage
226
228 vinc -= 12;
230 vinc += 12;
232 hinc -= 6;
234 hinc += 6;
235
236 if (!hinc && !vinc)
237 return;
238
240
245
246 if (vinc > 0)
250 else if (vinc < 0)
254
255 if (hinc > 0)
259 else if (hinc < 0)
263
264 }
265
268 {
270 int buf_size = avpkt->
size;
275
279 }
283 }
284
286
290 for (
int y = 0; y < avctx->
height; y++)
294 }
295
296 command = bytestream2_get_byte(&gb);
297 inst = bytestream2_get_byte(&gb);
301
303 switch (inst) {
305 if (!(cdg_data[1] & 0x0F)) {
306 for (
int y = 0; y < avctx->
height; y++)
308 cdg_data[0] & 0x0F, avctx->
width);
309 }
310 break;
316 }
317
319 break;
322 break;
328 }
329
334 }
335 break;
341 }
342
345
350 break;
353 cc->
alpha[
i] = 255 - ((cdg_data[
i] & 0x3f) << 2);
354 break;
355 default:
356 break;
357 }
358
359 if (!
frame->data[0]) {
363 }
364 *got_frame = 1;
365 } else {
366 *got_frame = 0;
367 }
368
370 }
371
373 {
375
377 return;
378
379 for (
int y = 0; y < avctx->
height; y++)
383 }
384
386 {
388
390
391 return 0;
392 }
393
395 .
p.
name =
"cdgraphics",
405 };
static void cdg_scroll(CDGraphicsContext *cc, uint8_t *data, AVFrame *new_frame, int roll_over)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int cdg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
#define CDG_INST_SCROLL_PRESET
#define CDG_INST_LOAD_PAL_HIGH
uint8_t alpha[CDG_PALETTE_SIZE]
#define CDG_MINIMUM_PKT_SIZE
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define CDG_INST_TRANSPARENT_COL
This structure describes decoded (raw) audio or video data.
static int cdg_tile_block(CDGraphicsContext *cc, uint8_t *data, int b)
#define CDG_INST_TILE_BLOCK_XOR
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_cold void close(AVCodecParserContext *s)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
AVCodec p
The public AVCodec.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static void cdg_border_preset(CDGraphicsContext *cc, uint8_t *data)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int cdg_decode_init(AVCodecContext *avctx)
#define CDG_BORDER_HEIGHT
#define FF_CODEC_DECODE_CB(func)
static av_cold void cdg_decode_flush(AVCodecContext *avctx)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
#define CODEC_LONG_NAME(str)
#define CDG_MINIMUM_SCROLL_SIZE
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define CDG_FULL_WIDTH
default screen sizes
const FFCodec ff_cdgraphics_decoder
static void cdg_copy_rect_buf(int out_tl_x, int out_tl_y, uint8_t *out, int in_tl_x, int in_tl_y, uint8_t *in, int w, int h, int stride)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low)
static av_cold int cdg_decode_end(AVCodecContext *avctx)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
#define CDG_INST_TILE_BLOCK
#define i(width, name, range_min, range_max)
#define CDG_INST_BORDER_PRESET
#define CDG_INST_SCROLL_COPY
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
int64_t frame_num
Frame counter, set by libavcodec.
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
main external API structure.
#define CDG_INST_MEMORY_PRESET
instruction codes
static void cdg_fill_rect_preset(int tl_x, int tl_y, uint8_t *out, int color, int w, int h, int stride)
This structure stores compressed data.
int width
picture width / height.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define CDG_INST_LOAD_PAL_LO
static void cdg_fill_wrapper(int out_tl_x, int out_tl_y, uint8_t *out, int in_tl_x, int in_tl_y, uint8_t *in, int color, int w, int h, int stride, int roll)
Generated on Fri Oct 17 2025 19:21:47 for FFmpeg by
doxygen
1.8.17