Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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 
34 #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 
43 #define CDG_COMMAND 0x09
44 #define CDG_MASK 0x3F
45 
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 
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->width = CDG_FULL_WIDTH;
81  avctx->height = CDG_FULL_HEIGHT;
82  avctx->pix_fmt = AV_PIX_FMT_PAL8;
83 
84  return 0;
85 }
86 
88 {
89  int y;
90  int lsize = cc->frame->linesize[0];
91  uint8_t *buf = cc->frame->data[0];
92  int color = data[0] & 0x0F;
93 
94  if (!(data[1] & 0x0F)) {
96  memset(buf, color, CDG_BORDER_HEIGHT * lsize);
97  memset(buf + (CDG_FULL_HEIGHT - CDG_BORDER_HEIGHT) * lsize,
98  color, CDG_BORDER_HEIGHT * lsize);
99 
101  for (y = CDG_BORDER_HEIGHT; y < CDG_FULL_HEIGHT - CDG_BORDER_HEIGHT; y++) {
102  memset(buf + y * lsize, color, CDG_BORDER_WIDTH);
103  memset(buf + CDG_FULL_WIDTH - CDG_BORDER_WIDTH + y * lsize,
104  color, CDG_BORDER_WIDTH);
105  }
106  }
107 }
108 
109 static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low)
110 {
111  uint8_t r, g, b;
112  uint16_t color;
113  int i;
114  int array_offset = low ? 0 : 8;
115  uint32_t *palette = (uint32_t *) cc->frame->data[1];
116 
117  for (i = 0; i < 8; i++) {
118  color = (data[2 * i] << 6) + (data[2 * i + 1] & 0x3F);
119  r = ((color >> 8) & 0x000F) * 17;
120  g = ((color >> 4) & 0x000F) * 17;
121  b = ((color ) & 0x000F) * 17;
122  palette[i + array_offset] = r << 16 | g << 8 | b;
123  }
124  cc->frame->palette_has_changed = 1;
125 }
126 
128 {
129  unsigned ci, ri;
130  int color;
131  int x, y;
132  int ai;
133  int stride = cc->frame->linesize[0];
134  uint8_t *buf = cc->frame->data[0];
135 
136  ri = (data[2] & 0x1F) * CDG_TILE_HEIGHT + cc->vscroll;
137  ci = (data[3] & 0x3F) * CDG_TILE_WIDTH + cc->hscroll;
138 
139  if (ri > (CDG_FULL_HEIGHT - CDG_TILE_HEIGHT))
140  return AVERROR(EINVAL);
141  if (ci > (CDG_FULL_WIDTH - CDG_TILE_WIDTH))
142  return AVERROR(EINVAL);
143 
144  for (y = 0; y < CDG_TILE_HEIGHT; y++) {
145  for (x = 0; x < CDG_TILE_WIDTH; x++) {
146  if (!((data[4 + y] >> (5 - x)) & 0x01))
147  color = data[0] & 0x0F;
148  else
149  color = data[1] & 0x0F;
150 
151  ai = ci + x + (stride * (ri + y));
152  if (b)
153  color ^= buf[ai];
154  buf[ai] = color;
155  }
156  }
157 
158  return 0;
159 }
160 
161 #define UP 2
162 #define DOWN 1
163 #define LEFT 2
164 #define RIGHT 1
165 
166 static void cdg_copy_rect_buf(int out_tl_x, int out_tl_y, uint8_t *out,
167  int in_tl_x, int in_tl_y, uint8_t *in,
168  int w, int h, int stride)
169 {
170  int y;
171 
172  in += in_tl_x + in_tl_y * stride;
173  out += out_tl_x + out_tl_y * stride;
174  for (y = 0; y < h; y++)
175  memcpy(out + y * stride, in + y * stride, w);
176 }
177 
178 static void cdg_fill_rect_preset(int tl_x, int tl_y, uint8_t *out,
179  int color, int w, int h, int stride)
180 {
181  int y;
182 
183  for (y = tl_y; y < tl_y + h; y++)
184  memset(out + tl_x + y * stride, color, w);
185 }
186 
187 static void cdg_fill_wrapper(int out_tl_x, int out_tl_y, uint8_t *out,
188  int in_tl_x, int in_tl_y, uint8_t *in,
189  int color, int w, int h, int stride, int roll)
190 {
191  if (roll) {
192  cdg_copy_rect_buf(out_tl_x, out_tl_y, out, in_tl_x, in_tl_y,
193  in, w, h, stride);
194  } else {
195  cdg_fill_rect_preset(out_tl_x, out_tl_y, out, color, w, h, stride);
196  }
197 }
198 
200  AVFrame *new_frame, int roll_over)
201 {
202  int color;
203  int hscmd, h_off, hinc, vscmd, v_off, vinc;
204  int y;
205  int stride = cc->frame->linesize[0];
206  uint8_t *in = cc->frame->data[0];
207  uint8_t *out = new_frame->data[0];
208 
209  color = data[0] & 0x0F;
210  hscmd = (data[1] & 0x30) >> 4;
211  vscmd = (data[2] & 0x30) >> 4;
212 
213  h_off = FFMIN(data[1] & 0x07, CDG_BORDER_WIDTH - 1);
214  v_off = FFMIN(data[2] & 0x0F, CDG_BORDER_HEIGHT - 1);
215 
217  hinc = h_off - cc->hscroll;
218  vinc = v_off - cc->vscroll;
219  cc->hscroll = h_off;
220  cc->vscroll = v_off;
221 
222  if (vscmd == UP)
223  vinc -= 12;
224  if (vscmd == DOWN)
225  vinc += 12;
226  if (hscmd == LEFT)
227  hinc -= 6;
228  if (hscmd == RIGHT)
229  hinc += 6;
230 
231  if (!hinc && !vinc)
232  return;
233 
234  memcpy(new_frame->data[1], cc->frame->data[1], CDG_PALETTE_SIZE * 4);
235 
236  for (y = FFMAX(0, vinc); y < FFMIN(CDG_FULL_HEIGHT + vinc, CDG_FULL_HEIGHT); y++)
237  memcpy(out + FFMAX(0, hinc) + stride * y,
238  in + FFMAX(0, hinc) - hinc + (y - vinc) * stride,
239  FFMIN(stride + hinc, stride));
240 
241  if (vinc > 0)
242  cdg_fill_wrapper(0, 0, out,
243  0, CDG_FULL_HEIGHT - vinc, in, color,
244  stride, vinc, stride, roll_over);
245  else if (vinc < 0)
246  cdg_fill_wrapper(0, CDG_FULL_HEIGHT + vinc, out,
247  0, 0, in, color,
248  stride, -1 * vinc, stride, roll_over);
249 
250  if (hinc > 0)
251  cdg_fill_wrapper(0, 0, out,
252  CDG_FULL_WIDTH - hinc, 0, in, color,
253  hinc, CDG_FULL_HEIGHT, stride, roll_over);
254  else if (hinc < 0)
255  cdg_fill_wrapper(CDG_FULL_WIDTH + hinc, 0, out,
256  0, 0, in, color,
257  -1 * hinc, CDG_FULL_HEIGHT, stride, roll_over);
258 
259 }
260 
262  void *data, int *got_frame, AVPacket *avpkt)
263 {
264  GetByteContext gb;
265  int buf_size = avpkt->size;
266  int ret;
267  uint8_t command, inst;
268  uint8_t cdg_data[CDG_DATA_SIZE];
269  AVFrame *frame = data;
270  CDGraphicsContext *cc = avctx->priv_data;
271 
272  bytestream2_init(&gb, avpkt->data, avpkt->size);
273 
274 
275  ret = ff_reget_buffer(avctx, cc->frame);
276  if (ret) {
277  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
278  return ret;
279  }
280  if (!avctx->frame_number)
281  memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
282 
283  command = bytestream2_get_byte(&gb);
284  inst = bytestream2_get_byte(&gb);
285  inst &= CDG_MASK;
286  bytestream2_skip(&gb, 2);
287  bytestream2_get_buffer(&gb, cdg_data, sizeof(cdg_data));
288 
289  if ((command & CDG_MASK) == CDG_COMMAND) {
290  switch (inst) {
292  if (!(cdg_data[1] & 0x0F))
293  memset(cc->frame->data[0], cdg_data[0] & 0x0F,
294  cc->frame->linesize[0] * CDG_FULL_HEIGHT);
295  break;
298  if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
299  av_log(avctx, AV_LOG_ERROR, "buffer too small for loading palette\n");
300  return AVERROR(EINVAL);
301  }
302 
303  cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);
304  break;
306  cdg_border_preset(cc, cdg_data);
307  break;
309  case CDG_INST_TILE_BLOCK:
310  if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
311  av_log(avctx, AV_LOG_ERROR, "buffer too small for drawing tile\n");
312  return AVERROR(EINVAL);
313  }
314 
315  ret = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);
316  if (ret) {
317  av_log(avctx, AV_LOG_ERROR, "tile is out of range\n");
318  return ret;
319  }
320  break;
323  if (buf_size - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {
324  av_log(avctx, AV_LOG_ERROR, "buffer too small for scrolling\n");
325  return AVERROR(EINVAL);
326  }
327 
328  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
329  if (ret) {
330  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
331  return ret;
332  }
333 
334  cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
335  av_frame_unref(cc->frame);
336  ret = av_frame_ref(cc->frame, frame);
337  if (ret < 0)
338  return ret;
339  break;
340  default:
341  break;
342  }
343 
344  if (!frame->data[0]) {
345  ret = av_frame_ref(frame, cc->frame);
346  if (ret < 0)
347  return ret;
348  }
349  *got_frame = 1;
350  } else {
351  *got_frame = 0;
352  }
353 
354  return avpkt->size;
355 }
356 
358 {
359  CDGraphicsContext *cc = avctx->priv_data;
360 
361  av_frame_free(&cc->frame);
362 
363  return 0;
364 }
365 
367  .name = "cdgraphics",
368  .long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"),
369  .type = AVMEDIA_TYPE_VIDEO,
371  .priv_data_size = sizeof(CDGraphicsContext),
375  .capabilities = CODEC_CAP_DR1,
376 };
#define CDG_BORDER_HEIGHT
Definition: cdgraphics.c:40
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
#define CDG_TILE_WIDTH
Definition: cdgraphics.c:60
int size
Definition: avcodec.h:974
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:132
static void cdg_border_preset(CDGraphicsContext *cc, uint8_t *data)
Definition: cdgraphics.c:87
#define CDG_INST_LOAD_PAL_HIGH
Definition: cdgraphics.c:53
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2812
#define UP
Definition: cdgraphics.c:161
#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:187
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
static int cdg_tile_block(CDGraphicsContext *cc, uint8_t *data, int b)
Definition: cdgraphics.c:127
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:57
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:166
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
#define CDG_COMMAND
masks
Definition: cdgraphics.c:43
#define b
Definition: input.c:52
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:188
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
#define r
Definition: input.c:51
#define CDG_HEADER_SIZE
Definition: cdgraphics.c:63
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
static av_cold int cdg_decode_init(AVCodecContext *avctx)
Definition: cdgraphics.c:72
#define AVERROR(e)
Definition: error.h:43
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:161
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:178
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
#define CDG_PALETTE_SIZE
Definition: cdgraphics.c:64
g
Definition: yuv2rgb.c:535
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:260
#define CDG_INST_BORDER_PRESET
Definition: cdgraphics.c:48
static av_cold int cdg_decode_end(AVCodecContext *avctx)
Definition: cdgraphics.c:357
#define CDG_INST_TILE_BLOCK
Definition: cdgraphics.c:49
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
#define FFMAX(a, b)
Definition: common.h:55
#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:808
#define FFMIN(a, b)
Definition: common.h:57
static int cdg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: cdgraphics.c:261
int width
picture width / height.
Definition: avcodec.h:1229
#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:199
#define CDG_DATA_SIZE
Definition: cdgraphics.c:58
static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low)
Definition: cdgraphics.c:109
Libavcodec external API header.
AVFrame * frame
Definition: cdgraphics.c:67
AVCodec ff_cdgraphics_decoder
Definition: cdgraphics.c:366
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
#define CDG_INST_LOAD_PAL_LO
Definition: cdgraphics.c:52
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:612
#define DOWN
Definition: cdgraphics.c:162
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:330
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:283
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
#define CDG_INST_TILE_BLOCK_XOR
Definition: cdgraphics.c:54
#define CDG_BORDER_WIDTH
Definition: cdgraphics.c:39
common internal api header.
static const uint8_t color[]
Definition: log.c:55
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
#define CDG_FULL_HEIGHT
Definition: cdgraphics.c:36
#define RIGHT
Definition: cdgraphics.c:164
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1838
#define CDG_INST_SCROLL_COPY
Definition: cdgraphics.c:51
#define LEFT
Definition: cdgraphics.c:163
#define CDG_MASK
Definition: cdgraphics.c:44
This structure stores compressed data.
Definition: avcodec.h:950
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:850
for(j=16;j >0;--j)
#define CDG_MINIMUM_SCROLL_SIZE
Definition: cdgraphics.c:62