FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cdgraphics.c
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 
22 #include "avcodec.h"
23 #include "bytestream.h"
24 #include "internal.h"
25 
26 /**
27  * @file
28  * @brief CD Graphics Video Decoder
29  * @author Michael Tison
30  * @see http://wiki.multimedia.cx/index.php?title=CD_Graphics
31  * @see http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg
32  */
33 
34 /// default screen sizes
35 #define CDG_FULL_WIDTH 300
36 #define CDG_FULL_HEIGHT 216
37 #define CDG_DISPLAY_WIDTH 294
38 #define CDG_DISPLAY_HEIGHT 204
39 #define CDG_BORDER_WIDTH 6
40 #define CDG_BORDER_HEIGHT 12
41 
42 /// masks
43 #define CDG_COMMAND 0x09
44 #define CDG_MASK 0x3F
45 
46 /// instruction codes
47 #define CDG_INST_MEMORY_PRESET 1
48 #define CDG_INST_BORDER_PRESET 2
49 #define CDG_INST_TILE_BLOCK 6
50 #define CDG_INST_SCROLL_PRESET 20
51 #define CDG_INST_SCROLL_COPY 24
52 #define CDG_INST_LOAD_PAL_LO 30
53 #define CDG_INST_LOAD_PAL_HIGH 31
54 #define CDG_INST_TILE_BLOCK_XOR 38
55 
56 /// data sizes
57 #define CDG_PACKET_SIZE 24
58 #define CDG_DATA_SIZE 16
59 #define CDG_TILE_HEIGHT 12
60 #define CDG_TILE_WIDTH 6
61 #define CDG_MINIMUM_PKT_SIZE 6
62 #define CDG_MINIMUM_SCROLL_SIZE 3
63 #define CDG_HEADER_SIZE 8
64 #define CDG_PALETTE_SIZE 16
65 
66 typedef struct CDGraphicsContext {
68  int hscroll;
69  int vscroll;
71 
73 {
74  CDGraphicsContext *cc = avctx->priv_data;
75 
76  cc->frame = av_frame_alloc();
77  if (!cc->frame)
78  return AVERROR(ENOMEM);
79 
80  avctx->pix_fmt = AV_PIX_FMT_PAL8;
82 }
83 
85 {
86  int y;
87  int lsize = cc->frame->linesize[0];
88  uint8_t *buf = cc->frame->data[0];
89  int color = data[0] & 0x0F;
90 
91  if (!(data[1] & 0x0F)) {
92  /// fill the top and bottom borders
93  memset(buf, color, CDG_BORDER_HEIGHT * lsize);
94  memset(buf + (CDG_FULL_HEIGHT - CDG_BORDER_HEIGHT) * lsize,
95  color, CDG_BORDER_HEIGHT * lsize);
96 
97  /// fill the side borders
99  memset(buf + y * lsize, color, CDG_BORDER_WIDTH);
100  memset(buf + CDG_FULL_WIDTH - CDG_BORDER_WIDTH + y * lsize,
101  color, CDG_BORDER_WIDTH);
102  }
103  }
104 }
105 
106 static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low)
107 {
108  uint8_t r, g, b;
109  uint16_t color;
110  int i;
111  int array_offset = low ? 0 : 8;
112  uint32_t *palette = (uint32_t *) cc->frame->data[1];
113 
114  for (i = 0; i < 8; i++) {
115  color = (data[2 * i] << 6) + (data[2 * i + 1] & 0x3F);
116  r = ((color >> 8) & 0x000F) * 17;
117  g = ((color >> 4) & 0x000F) * 17;
118  b = ((color ) & 0x000F) * 17;
119  palette[i + array_offset] = 0xFFU << 24 | r << 16 | g << 8 | b;
120  }
121  cc->frame->palette_has_changed = 1;
122 }
123 
125 {
126  unsigned ci, ri;
127  int color;
128  int x, y;
129  int ai;
130  int stride = cc->frame->linesize[0];
131  uint8_t *buf = cc->frame->data[0];
132 
133  ri = (data[2] & 0x1F) * CDG_TILE_HEIGHT + cc->vscroll;
134  ci = (data[3] & 0x3F) * CDG_TILE_WIDTH + cc->hscroll;
135 
136  if (ri > (CDG_FULL_HEIGHT - CDG_TILE_HEIGHT))
137  return AVERROR(EINVAL);
138  if (ci > (CDG_FULL_WIDTH - CDG_TILE_WIDTH))
139  return AVERROR(EINVAL);
140 
141  for (y = 0; y < CDG_TILE_HEIGHT; y++) {
142  for (x = 0; x < CDG_TILE_WIDTH; x++) {
143  if (!((data[4 + y] >> (5 - x)) & 0x01))
144  color = data[0] & 0x0F;
145  else
146  color = data[1] & 0x0F;
147 
148  ai = ci + x + (stride * (ri + y));
149  if (b)
150  color ^= buf[ai];
151  buf[ai] = color;
152  }
153  }
154 
155  return 0;
156 }
157 
158 #define UP 2
159 #define DOWN 1
160 #define LEFT 2
161 #define RIGHT 1
162 
163 static void cdg_copy_rect_buf(int out_tl_x, int out_tl_y, uint8_t *out,
164  int in_tl_x, int in_tl_y, uint8_t *in,
165  int w, int h, int stride)
166 {
167  int y;
168 
169  in += in_tl_x + in_tl_y * stride;
170  out += out_tl_x + out_tl_y * stride;
171  for (y = 0; y < h; y++)
172  memcpy(out + y * stride, in + y * stride, w);
173 }
174 
175 static void cdg_fill_rect_preset(int tl_x, int tl_y, uint8_t *out,
176  int color, int w, int h, int stride)
177 {
178  int y;
179 
180  for (y = tl_y; y < tl_y + h; y++)
181  memset(out + tl_x + y * stride, color, w);
182 }
183 
184 static void cdg_fill_wrapper(int out_tl_x, int out_tl_y, uint8_t *out,
185  int in_tl_x, int in_tl_y, uint8_t *in,
186  int color, int w, int h, int stride, int roll)
187 {
188  if (roll) {
189  cdg_copy_rect_buf(out_tl_x, out_tl_y, out, in_tl_x, in_tl_y,
190  in, w, h, stride);
191  } else {
192  cdg_fill_rect_preset(out_tl_x, out_tl_y, out, color, w, h, stride);
193  }
194 }
195 
197  AVFrame *new_frame, int roll_over)
198 {
199  int color;
200  int hscmd, h_off, hinc, vscmd, v_off, vinc;
201  int y;
202  int stride = cc->frame->linesize[0];
203  uint8_t *in = cc->frame->data[0];
204  uint8_t *out = new_frame->data[0];
205 
206  color = data[0] & 0x0F;
207  hscmd = (data[1] & 0x30) >> 4;
208  vscmd = (data[2] & 0x30) >> 4;
209 
210  h_off = FFMIN(data[1] & 0x07, CDG_BORDER_WIDTH - 1);
211  v_off = FFMIN(data[2] & 0x0F, CDG_BORDER_HEIGHT - 1);
212 
213  /// find the difference and save the offset for cdg_tile_block usage
214  hinc = h_off - cc->hscroll;
215  vinc = v_off - cc->vscroll;
216  cc->hscroll = h_off;
217  cc->vscroll = v_off;
218 
219  if (vscmd == UP)
220  vinc -= 12;
221  if (vscmd == DOWN)
222  vinc += 12;
223  if (hscmd == LEFT)
224  hinc -= 6;
225  if (hscmd == RIGHT)
226  hinc += 6;
227 
228  if (!hinc && !vinc)
229  return;
230 
231  memcpy(new_frame->data[1], cc->frame->data[1], CDG_PALETTE_SIZE * 4);
232 
233  for (y = FFMAX(0, vinc); y < FFMIN(CDG_FULL_HEIGHT + vinc, CDG_FULL_HEIGHT); y++)
234  memcpy(out + FFMAX(0, hinc) + stride * y,
235  in + FFMAX(0, hinc) - hinc + (y - vinc) * stride,
236  FFMIN(stride + hinc, stride));
237 
238  if (vinc > 0)
239  cdg_fill_wrapper(0, 0, out,
240  0, CDG_FULL_HEIGHT - vinc, in, color,
241  stride, vinc, stride, roll_over);
242  else if (vinc < 0)
243  cdg_fill_wrapper(0, CDG_FULL_HEIGHT + vinc, out,
244  0, 0, in, color,
245  stride, -1 * vinc, stride, roll_over);
246 
247  if (hinc > 0)
248  cdg_fill_wrapper(0, 0, out,
249  CDG_FULL_WIDTH - hinc, 0, in, color,
250  hinc, CDG_FULL_HEIGHT, stride, roll_over);
251  else if (hinc < 0)
252  cdg_fill_wrapper(CDG_FULL_WIDTH + hinc, 0, out,
253  0, 0, in, color,
254  -1 * hinc, CDG_FULL_HEIGHT, stride, roll_over);
255 
256 }
257 
259  void *data, int *got_frame, AVPacket *avpkt)
260 {
261  GetByteContext gb;
262  int buf_size = avpkt->size;
263  int ret;
264  uint8_t command, inst;
265  uint8_t cdg_data[CDG_DATA_SIZE] = {0};
266  AVFrame *frame = data;
267  CDGraphicsContext *cc = avctx->priv_data;
268 
269  if (buf_size < CDG_MINIMUM_PKT_SIZE) {
270  av_log(avctx, AV_LOG_ERROR, "buffer too small for decoder\n");
271  return AVERROR(EINVAL);
272  }
273  if (buf_size > CDG_HEADER_SIZE + CDG_DATA_SIZE) {
274  av_log(avctx, AV_LOG_ERROR, "buffer too big for decoder\n");
275  return AVERROR(EINVAL);
276  }
277 
278  bytestream2_init(&gb, avpkt->data, avpkt->size);
279 
280  if ((ret = ff_reget_buffer(avctx, cc->frame)) < 0)
281  return ret;
282  if (!avctx->frame_number) {
283  memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
284  memset(cc->frame->data[1], 0, AVPALETTE_SIZE);
285  }
286 
287  command = bytestream2_get_byte(&gb);
288  inst = bytestream2_get_byte(&gb);
289  inst &= CDG_MASK;
290  bytestream2_skip(&gb, 2);
291  bytestream2_get_buffer(&gb, cdg_data, sizeof(cdg_data));
292 
293  if ((command & CDG_MASK) == CDG_COMMAND) {
294  switch (inst) {
296  if (!(cdg_data[1] & 0x0F))
297  memset(cc->frame->data[0], cdg_data[0] & 0x0F,
298  cc->frame->linesize[0] * CDG_FULL_HEIGHT);
299  break;
302  if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
303  av_log(avctx, AV_LOG_ERROR, "buffer too small for loading palette\n");
304  return AVERROR(EINVAL);
305  }
306 
307  cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);
308  break;
310  cdg_border_preset(cc, cdg_data);
311  break;
313  case CDG_INST_TILE_BLOCK:
314  if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
315  av_log(avctx, AV_LOG_ERROR, "buffer too small for drawing tile\n");
316  return AVERROR(EINVAL);
317  }
318 
319  ret = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);
320  if (ret) {
321  av_log(avctx, AV_LOG_ERROR, "tile is out of range\n");
322  return ret;
323  }
324  break;
327  if (buf_size - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {
328  av_log(avctx, AV_LOG_ERROR, "buffer too small for scrolling\n");
329  return AVERROR(EINVAL);
330  }
331 
332  if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
333  return ret;
334 
335  cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
336  av_frame_unref(cc->frame);
337  ret = av_frame_ref(cc->frame, frame);
338  if (ret < 0)
339  return ret;
340  break;
341  default:
342  break;
343  }
344 
345  if (!frame->data[0]) {
346  ret = av_frame_ref(frame, cc->frame);
347  if (ret < 0)
348  return ret;
349  }
350  *got_frame = 1;
351  } else {
352  *got_frame = 0;
353  }
354 
355  return avpkt->size;
356 }
357 
359 {
360  CDGraphicsContext *cc = avctx->priv_data;
361 
362  av_frame_free(&cc->frame);
363 
364  return 0;
365 }
366 
368  .name = "cdgraphics",
369  .long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"),
370  .type = AVMEDIA_TYPE_VIDEO,
372  .priv_data_size = sizeof(CDGraphicsContext),
374  .close = cdg_decode_end,
376  .capabilities = AV_CODEC_CAP_DR1,
377 };
#define CDG_BORDER_HEIGHT
Definition: cdgraphics.c:40
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define CDG_TILE_WIDTH
Definition: cdgraphics.c:60
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
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.
Definition: utils.c:216
const char * g
Definition: vf_curves.c:108
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int size
Definition: avcodec.h:1434
const char * b
Definition: vf_curves.c:109
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1732
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
static void cdg_border_preset(CDGraphicsContext *cc, uint8_t *data)
Definition: cdgraphics.c:84
#define CDG_INST_LOAD_PAL_HIGH
Definition: cdgraphics.c:53
AVCodec.
Definition: avcodec.h:3482
#define UP
Definition: cdgraphics.c:158
#define CDG_INST_SCROLL_PRESET
Definition: cdgraphics.c:50
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)
Definition: cdgraphics.c:184
static int cdg_tile_block(CDGraphicsContext *cc, uint8_t *data, int b)
Definition: cdgraphics.c:124
uint8_t
#define av_cold
Definition: attributes.h:74
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
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)
Definition: cdgraphics.c:163
8 bit with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:78
#define CDG_COMMAND
masks
Definition: cdgraphics.c:43
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
#define AVPALETTE_SIZE
Definition: pixfmt.h:33
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:366
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1433
#define av_log(a,...)
#define U(x)
Definition: vp56_arith.h:37
#define CDG_HEADER_SIZE
Definition: cdgraphics.c:63
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static av_cold int cdg_decode_init(AVCodecContext *avctx)
Definition: cdgraphics.c:72
#define CDG_MINIMUM_PKT_SIZE
Definition: cdgraphics.c:61
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
static void cdg_fill_rect_preset(int tl_x, int tl_y, uint8_t *out, int color, int w, int h, int stride)
Definition: cdgraphics.c:175
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:178
#define CDG_PALETTE_SIZE
Definition: cdgraphics.c:64
const char * r
Definition: vf_curves.c:107
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:263
#define CDG_INST_BORDER_PRESET
Definition: cdgraphics.c:48
static av_cold int cdg_decode_end(AVCodecContext *avctx)
Definition: cdgraphics.c:358
#define CDG_INST_TILE_BLOCK
Definition: cdgraphics.c:49
const char * name
Name of the codec implementation.
Definition: avcodec.h:3489
#define FFMAX(a, b)
Definition: common.h:90
Libavcodec external API header.
#define CDG_FULL_WIDTH
default screen sizes
Definition: cdgraphics.c:35
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: utils.c:1097
#define FFMIN(a, b)
Definition: common.h:92
float y
static int cdg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: cdgraphics.c:258
#define CDG_INST_MEMORY_PRESET
instruction codes
Definition: cdgraphics.c:47
#define CDG_TILE_HEIGHT
Definition: cdgraphics.c:59
static void cdg_scroll(CDGraphicsContext *cc, uint8_t *data, AVFrame *new_frame, int roll_over)
Definition: cdgraphics.c:196
#define CDG_DATA_SIZE
Definition: cdgraphics.c:58
static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low)
Definition: cdgraphics.c:106
AVFrame * frame
Definition: cdgraphics.c:67
AVCodec ff_cdgraphics_decoder
Definition: cdgraphics.c:367
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
main external API structure.
Definition: avcodec.h:1512
#define CDG_INST_LOAD_PAL_LO
Definition: cdgraphics.c:52
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:765
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1048
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define DOWN
Definition: cdgraphics.c:159
void * buf
Definition: avisynth_c.h:553
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:377
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:465
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
#define CDG_INST_TILE_BLOCK_XOR
Definition: cdgraphics.c:54
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:521
int palette
Definition: v4l.c:61
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
#define CDG_BORDER_WIDTH
Definition: cdgraphics.c:39
common internal api header.
void * priv_data
Definition: avcodec.h:1554
#define CDG_FULL_HEIGHT
Definition: cdgraphics.c:36
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define RIGHT
Definition: cdgraphics.c:161
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2303
#define CDG_INST_SCROLL_COPY
Definition: cdgraphics.c:51
#define stride
#define LEFT
Definition: cdgraphics.c:160
#define CDG_MASK
Definition: cdgraphics.c:44
This structure stores compressed data.
Definition: avcodec.h:1410
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1216
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
for(j=16;j >0;--j)
#define CDG_MINIMUM_SCROLL_SIZE
Definition: cdgraphics.c:62