FFmpeg
tdsc.c
Go to the documentation of this file.
1 /*
2  * TDSC decoder
3  * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
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  * TDSC decoder
25  *
26  * Fourcc: TSDC
27  *
28  * TDSC is very simple. It codes picture by tiles, storing them in raw BGR24
29  * format or compressing them in JPEG. Frames can be full pictures or just
30  * updates to the previous frame. Cursor is found in its own frame or at the
31  * bottom of the picture. Every frame is then packed with zlib.
32  *
33  * Supports: BGR24
34  */
35 
36 #include <stdint.h>
37 #include <zlib.h>
38 
39 #include "libavutil/imgutils.h"
40 
41 #include "avcodec.h"
42 #include "bytestream.h"
43 #include "codec_internal.h"
44 #include "decode.h"
45 
46 #define BITMAPINFOHEADER_SIZE 0x28
47 #define TDSF_HEADER_SIZE 0x56
48 #define TDSB_HEADER_SIZE 0x08
49 
50 typedef struct TDSCContext {
51  AVCodecContext *jpeg_avctx; // wrapper context for MJPEG
52 
53  int width, height;
55 
56  AVFrame *refframe; // full decoded frame (without cursor)
57  AVPacket *jpkt; // encoded JPEG tile
58  AVFrame *jpgframe; // decoded JPEG tile
59  uint8_t *tilebuffer; // buffer containing tile data
60 
61  /* zlib interaction */
62  uint8_t *deflatebuffer;
63  uLongf deflatelen;
64 
65  /* All that is cursor */
66  uint8_t *cursor;
70 } TDSCContext;
71 
72 /* 1 byte bits, 1 byte planes, 2 bytes format (probably) */
74  CUR_FMT_MONO = 0x01010004,
75  CUR_FMT_BGRA = 0x20010004,
76  CUR_FMT_RGBA = 0x20010008,
77 };
78 
79 static av_cold int tdsc_close(AVCodecContext *avctx)
80 {
81  TDSCContext *ctx = avctx->priv_data;
82 
83  av_frame_free(&ctx->refframe);
84  av_frame_free(&ctx->jpgframe);
85  av_packet_free(&ctx->jpkt);
86  av_freep(&ctx->deflatebuffer);
87  av_freep(&ctx->tilebuffer);
88  av_freep(&ctx->cursor);
89  avcodec_free_context(&ctx->jpeg_avctx);
90 
91  return 0;
92 }
93 
94 static av_cold int tdsc_init(AVCodecContext *avctx)
95 {
96  TDSCContext *ctx = avctx->priv_data;
97  const AVCodec *codec;
98  int ret;
99 
100  avctx->pix_fmt = AV_PIX_FMT_BGR24;
101 
102  /* These needs to be set to estimate buffer and frame size */
103  if (!(avctx->width && avctx->height)) {
104  av_log(avctx, AV_LOG_ERROR, "Video size not set.\n");
105  return AVERROR_INVALIDDATA;
106  }
107 
108  /* This value should be large enough for a RAW-only frame plus headers */
109  ctx->deflatelen = avctx->width * avctx->height * (3 + 1);
110  ret = av_reallocp(&ctx->deflatebuffer, ctx->deflatelen);
111  if (ret < 0)
112  return ret;
113 
114  /* Allocate reference and JPEG frame */
115  ctx->refframe = av_frame_alloc();
116  ctx->jpgframe = av_frame_alloc();
117  ctx->jpkt = av_packet_alloc();
118  if (!ctx->refframe || !ctx->jpgframe || !ctx->jpkt)
119  return AVERROR(ENOMEM);
120 
121  /* Prepare everything needed for JPEG decoding */
123  if (!codec)
124  return AVERROR_BUG;
125  ctx->jpeg_avctx = avcodec_alloc_context3(codec);
126  if (!ctx->jpeg_avctx)
127  return AVERROR(ENOMEM);
128  ctx->jpeg_avctx->flags = avctx->flags;
129  ctx->jpeg_avctx->flags2 = avctx->flags2;
130  ctx->jpeg_avctx->idct_algo = avctx->idct_algo;
131  ret = avcodec_open2(ctx->jpeg_avctx, codec, NULL);
132  if (ret < 0)
133  return ret;
134 
135  /* Set the output pixel format on the reference frame */
136  ctx->refframe->format = avctx->pix_fmt;
137 
138  return 0;
139 }
140 
141 #define APPLY_ALPHA(src, new, alpha) \
142  src = (src * (256 - alpha) + new * alpha) >> 8
143 
144 /* Paint a region over a buffer, without drawing out of its bounds. */
145 static void tdsc_paint_cursor(AVCodecContext *avctx, uint8_t *dst, int stride)
146 {
147  TDSCContext *ctx = avctx->priv_data;
148  const uint8_t *cursor = ctx->cursor;
149  int x = ctx->cursor_x - ctx->cursor_hot_x;
150  int y = ctx->cursor_y - ctx->cursor_hot_y;
151  int w = ctx->cursor_w;
152  int h = ctx->cursor_h;
153  int i, j;
154 
155  if (!ctx->cursor)
156  return;
157 
158  if (x + w > ctx->width)
159  w = ctx->width - x;
160  if (y + h > ctx->height)
161  h = ctx->height - y;
162  if (x < 0) {
163  w += x;
164  cursor += -x * 4;
165  } else {
166  dst += x * 3;
167  }
168  if (y < 0) {
169  h += y;
170  cursor += -y * ctx->cursor_stride;
171  } else {
172  dst += y * stride;
173  }
174  if (w < 0 || h < 0)
175  return;
176 
177  for (j = 0; j < h; j++) {
178  for (i = 0; i < w; i++) {
179  uint8_t alpha = cursor[i * 4];
180  APPLY_ALPHA(dst[i * 3 + 0], cursor[i * 4 + 1], alpha);
181  APPLY_ALPHA(dst[i * 3 + 1], cursor[i * 4 + 2], alpha);
182  APPLY_ALPHA(dst[i * 3 + 2], cursor[i * 4 + 3], alpha);
183  }
184  dst += stride;
185  cursor += ctx->cursor_stride;
186  }
187 }
188 
189 /* Load cursor data and store it in ABGR mode. */
191 {
192  TDSCContext *ctx = avctx->priv_data;
193  int i, j, k, ret, cursor_fmt;
194  uint8_t *dst;
195 
196  ctx->cursor_hot_x = bytestream2_get_le16(&ctx->gbc);
197  ctx->cursor_hot_y = bytestream2_get_le16(&ctx->gbc);
198  ctx->cursor_w = bytestream2_get_le16(&ctx->gbc);
199  ctx->cursor_h = bytestream2_get_le16(&ctx->gbc);
200 
201  ctx->cursor_stride = FFALIGN(ctx->cursor_w, 32) * 4;
202  cursor_fmt = bytestream2_get_le32(&ctx->gbc);
203 
204  if (ctx->cursor_x >= avctx->width || ctx->cursor_y >= avctx->height) {
205  av_log(avctx, AV_LOG_ERROR,
206  "Invalid cursor position (%d.%d outside %dx%d).\n",
207  ctx->cursor_x, ctx->cursor_y, avctx->width, avctx->height);
208  return AVERROR_INVALIDDATA;
209  }
210  if (ctx->cursor_w < 1 || ctx->cursor_w > 256 ||
211  ctx->cursor_h < 1 || ctx->cursor_h > 256) {
212  av_log(avctx, AV_LOG_ERROR,
213  "Invalid cursor dimensions %dx%d.\n",
214  ctx->cursor_w, ctx->cursor_h);
215  return AVERROR_INVALIDDATA;
216  }
217  if (ctx->cursor_hot_x > ctx->cursor_w ||
218  ctx->cursor_hot_y > ctx->cursor_h) {
219  av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %d.%d.\n",
220  ctx->cursor_hot_x, ctx->cursor_hot_y);
221  ctx->cursor_hot_x = FFMIN(ctx->cursor_hot_x, ctx->cursor_w - 1);
222  ctx->cursor_hot_y = FFMIN(ctx->cursor_hot_y, ctx->cursor_h - 1);
223  }
224 
225  ret = av_reallocp(&ctx->cursor, ctx->cursor_stride * ctx->cursor_h);
226  if (ret < 0) {
227  av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer.\n");
228  return ret;
229  }
230 
231  dst = ctx->cursor;
232  /* here data is packed in BE */
233  switch (cursor_fmt) {
234  case CUR_FMT_MONO:
235  for (j = 0; j < ctx->cursor_h; j++) {
236  for (i = 0; i < ctx->cursor_w; i += 32) {
237  uint32_t bits = bytestream2_get_be32(&ctx->gbc);
238  for (k = 0; k < 32; k++) {
239  dst[0] = !!(bits & 0x80000000);
240  dst += 4;
241  bits <<= 1;
242  }
243  }
244  dst += ctx->cursor_stride - ctx->cursor_w * 4;
245  }
246 
247  dst = ctx->cursor;
248  for (j = 0; j < ctx->cursor_h; j++) {
249  for (i = 0; i < ctx->cursor_w; i += 32) {
250  uint32_t bits = bytestream2_get_be32(&ctx->gbc);
251  for (k = 0; k < 32; k++) {
252  int mask_bit = !!(bits & 0x80000000);
253  switch (dst[0] * 2 + mask_bit) {
254  case 0:
255  dst[0] = 0xFF;
256  dst[1] = 0x00;
257  dst[2] = 0x00;
258  dst[3] = 0x00;
259  break;
260  case 1:
261  dst[0] = 0xFF;
262  dst[1] = 0xFF;
263  dst[2] = 0xFF;
264  dst[3] = 0xFF;
265  break;
266  default:
267  dst[0] = 0x00;
268  dst[1] = 0x00;
269  dst[2] = 0x00;
270  dst[3] = 0x00;
271  }
272  dst += 4;
273  bits <<= 1;
274  }
275  }
276  dst += ctx->cursor_stride - ctx->cursor_w * 4;
277  }
278  break;
279  case CUR_FMT_BGRA:
280  case CUR_FMT_RGBA:
281  /* Skip monochrome version of the cursor */
282  bytestream2_skip(&ctx->gbc,
283  ctx->cursor_h * (FFALIGN(ctx->cursor_w, 32) >> 3));
284  if (cursor_fmt & 8) { // RGBA -> ABGR
285  for (j = 0; j < ctx->cursor_h; j++) {
286  for (i = 0; i < ctx->cursor_w; i++) {
287  int val = bytestream2_get_be32(&ctx->gbc);
288  *dst++ = val >> 24;
289  *dst++ = val >> 16;
290  *dst++ = val >> 8;
291  *dst++ = val >> 0;
292  }
293  dst += ctx->cursor_stride - ctx->cursor_w * 4;
294  }
295  } else { // BGRA -> ABGR
296  for (j = 0; j < ctx->cursor_h; j++) {
297  for (i = 0; i < ctx->cursor_w; i++) {
298  int val = bytestream2_get_be32(&ctx->gbc);
299  *dst++ = val >> 0;
300  *dst++ = val >> 24;
301  *dst++ = val >> 16;
302  *dst++ = val >> 8;
303  }
304  dst += ctx->cursor_stride - ctx->cursor_w * 4;
305  }
306  }
307  break;
308  default:
309  avpriv_request_sample(avctx, "Cursor format %08x", cursor_fmt);
310  return AVERROR_PATCHWELCOME;
311  }
312 
313  return 0;
314 }
315 
316 /* Convert a single YUV pixel to RGB. */
317 static inline void tdsc_yuv2rgb(uint8_t *out, int Y, int U, int V)
318 {
319  out[0] = av_clip_uint8(Y + ( 91881 * V + 32768 >> 16));
320  out[1] = av_clip_uint8(Y + (-22554 * U - 46802 * V + 32768 >> 16));
321  out[2] = av_clip_uint8(Y + (116130 * U + 32768 >> 16));
322 }
323 
324 /* Convert a YUV420 buffer to a RGB buffer. */
325 static av_always_inline void tdsc_blit(uint8_t *dst, int dst_stride,
326  const uint8_t *srcy, int srcy_stride,
327  const uint8_t *srcu, const uint8_t *srcv,
328  int srcuv_stride, int width, int height)
329 {
330  int col, line;
331  for (line = 0; line < height; line++) {
332  for (col = 0; col < width; col++)
333  tdsc_yuv2rgb(dst + col * 3, srcy[col],
334  srcu[col >> 1] - 128, srcv[col >> 1] - 128);
335 
336  dst += dst_stride;
337  srcy += srcy_stride;
338  srcu += srcuv_stride * (line & 1);
339  srcv += srcuv_stride * (line & 1);
340  }
341 }
342 
343 /* Invoke the MJPEG decoder to decode the tile. */
344 static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int tile_size,
345  int x, int y, int w, int h)
346 {
347  TDSCContext *ctx = avctx->priv_data;
348  int ret;
349 
350  /* Prepare a packet and send to the MJPEG decoder */
351  av_packet_unref(ctx->jpkt);
352  ctx->jpkt->data = ctx->tilebuffer;
353  ctx->jpkt->size = tile_size;
354 
355  ret = avcodec_send_packet(ctx->jpeg_avctx, ctx->jpkt);
356  if (ret < 0) {
357  av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
358  return ret;
359  }
360 
361  ret = avcodec_receive_frame(ctx->jpeg_avctx, ctx->jpgframe);
362  if (ret < 0 || ctx->jpgframe->format != AV_PIX_FMT_YUVJ420P) {
363  av_log(avctx, AV_LOG_ERROR,
364  "JPEG decoding error (%d).\n", ret);
365 
366  /* Normally skip, error if explode */
367  if (avctx->err_recognition & AV_EF_EXPLODE)
368  return AVERROR_INVALIDDATA;
369  else
370  return 0;
371  }
372 
373  /* Let's paint onto the buffer */
374  tdsc_blit(ctx->refframe->data[0] + x * 3 + ctx->refframe->linesize[0] * y,
375  ctx->refframe->linesize[0],
376  ctx->jpgframe->data[0], ctx->jpgframe->linesize[0],
377  ctx->jpgframe->data[1], ctx->jpgframe->data[2],
378  ctx->jpgframe->linesize[1], w, h);
379 
380  av_frame_unref(ctx->jpgframe);
381 
382  return 0;
383 }
384 
385 /* Parse frame and either copy data or decode JPEG. */
386 static int tdsc_decode_tiles(AVCodecContext *avctx, int number_tiles)
387 {
388  TDSCContext *ctx = avctx->priv_data;
389  int i;
390 
391  /* Iterate over the number of tiles */
392  for (i = 0; i < number_tiles; i++) {
393  int tile_size;
394  int tile_mode;
395  int x, y, x2, y2, w, h;
396  int ret;
397 
398  if (bytestream2_get_bytes_left(&ctx->gbc) < 4 ||
399  bytestream2_get_le32(&ctx->gbc) != MKTAG('T','D','S','B') ||
401  av_log(avctx, AV_LOG_ERROR, "TDSB tag is too small.\n");
402  return AVERROR_INVALIDDATA;
403  }
404 
405  tile_size = bytestream2_get_le32(&ctx->gbc);
406  if (bytestream2_get_bytes_left(&ctx->gbc) < tile_size)
407  return AVERROR_INVALIDDATA;
408 
409  tile_mode = bytestream2_get_le32(&ctx->gbc);
410  bytestream2_skip(&ctx->gbc, 4); // unknown
411  x = bytestream2_get_le32(&ctx->gbc);
412  y = bytestream2_get_le32(&ctx->gbc);
413  x2 = bytestream2_get_le32(&ctx->gbc);
414  y2 = bytestream2_get_le32(&ctx->gbc);
415 
416  if (x < 0 || y < 0 || x2 <= x || y2 <= y ||
417  x2 > ctx->width || y2 > ctx->height
418  ) {
419  av_log(avctx, AV_LOG_ERROR,
420  "Invalid tile position (%d.%d %d.%d outside %dx%d).\n",
421  x, y, x2, y2, ctx->width, ctx->height);
422  return AVERROR_INVALIDDATA;
423  }
424  w = x2 - x;
425  h = y2 - y;
426 
427  ret = av_reallocp(&ctx->tilebuffer, tile_size);
428  if (!ctx->tilebuffer)
429  return ret;
430 
431  bytestream2_get_buffer(&ctx->gbc, ctx->tilebuffer, tile_size);
432 
433  if (tile_mode == MKTAG('G','E','P','J')) {
434  /* Decode JPEG tile and copy it in the reference frame */
435  ret = tdsc_decode_jpeg_tile(avctx, tile_size, x, y, w, h);
436  if (ret < 0)
437  return ret;
438  } else if (tile_mode == MKTAG(' ','W','A','R')) {
439  /* Just copy the buffer to output */
440  av_image_copy_plane(ctx->refframe->data[0] + x * 3 +
441  ctx->refframe->linesize[0] * y,
442  ctx->refframe->linesize[0], ctx->tilebuffer,
443  w * 3, w * 3, h);
444  } else {
445  av_log(avctx, AV_LOG_ERROR, "Unknown tile type %08x.\n", tile_mode);
446  return AVERROR_INVALIDDATA;
447  }
448  av_log(avctx, AV_LOG_DEBUG, "Tile %d, %dx%d (%d.%d)\n", i, w, h, x, y);
449  }
450 
451  return 0;
452 }
453 
454 static int tdsc_parse_tdsf(AVCodecContext *avctx, int number_tiles)
455 {
456  TDSCContext *ctx = avctx->priv_data;
457  int ret, w, h, init_refframe = !ctx->refframe->data[0];
458 
459  /* BITMAPINFOHEADER
460  * http://msdn.microsoft.com/en-us/library/windows/desktop/dd183376.aspx */
461  if (bytestream2_get_le32(&ctx->gbc) != BITMAPINFOHEADER_SIZE)
462  return AVERROR_INVALIDDATA;
463 
464  /* Store size, but wait for context reinit before updating avctx */
465  w = bytestream2_get_le32(&ctx->gbc);
466  h = -bytestream2_get_le32(&ctx->gbc);
467 
468  if (bytestream2_get_le16(&ctx->gbc) != 1 || // 1 plane
469  bytestream2_get_le16(&ctx->gbc) != 24) // BGR24
470  return AVERROR_INVALIDDATA;
471 
472  bytestream2_skip(&ctx->gbc, 24); // unused fields
473 
474  /* Update sizes */
475  if (avctx->width != w || avctx->height != h) {
476  av_log(avctx, AV_LOG_DEBUG, "Size update %dx%d -> %d%d.\n",
477  avctx->width, avctx->height, ctx->width, ctx->height);
478  ret = ff_set_dimensions(avctx, w, h);
479  if (ret < 0)
480  return ret;
481  init_refframe = 1;
482  }
483  ctx->refframe->width = ctx->width = w;
484  ctx->refframe->height = ctx->height = h;
485 
486  /* Allocate the reference frame if not already done or on size change */
487  if (init_refframe) {
488  ret = av_frame_get_buffer(ctx->refframe, 0);
489  if (ret < 0)
490  return ret;
491  }
492 
493  /* Decode all tiles in a frame */
494  return tdsc_decode_tiles(avctx, number_tiles);
495 }
496 
497 static int tdsc_parse_dtsm(AVCodecContext *avctx)
498 {
499  TDSCContext *ctx = avctx->priv_data;
500  int ret;
501  int action = bytestream2_get_le32(&ctx->gbc);
502 
503  bytestream2_skip(&ctx->gbc, 4); // some kind of ID or version maybe?
504 
505  if (action == 2 || action == 3) {
506  /* Load cursor coordinates */
507  ctx->cursor_x = bytestream2_get_le32(&ctx->gbc);
508  ctx->cursor_y = bytestream2_get_le32(&ctx->gbc);
509 
510  /* Load a full cursor sprite */
511  if (action == 3) {
512  ret = tdsc_load_cursor(avctx);
513  /* Do not consider cursor errors fatal unless in explode mode */
514  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
515  return ret;
516  }
517  } else {
518  avpriv_request_sample(avctx, "Cursor action %d", action);
519  }
520 
521  return 0;
522 }
523 
525  int *got_frame, AVPacket *avpkt)
526 {
527  TDSCContext *ctx = avctx->priv_data;
528  int ret, tag_header, keyframe = 0;
529  uLongf dlen;
530 
531  /* Resize deflate buffer on resolution change */
532  if (ctx->width != avctx->width || ctx->height != avctx->height) {
533  int deflatelen = avctx->width * avctx->height * (3 + 1);
534  if (deflatelen != ctx->deflatelen) {
535  ctx->deflatelen =deflatelen;
536  ret = av_reallocp(&ctx->deflatebuffer, ctx->deflatelen);
537  if (ret < 0) {
538  ctx->deflatelen = 0;
539  return ret;
540  }
541  }
542  }
543  dlen = ctx->deflatelen;
544 
545  /* Frames are deflated, need to inflate them first */
546  ret = uncompress(ctx->deflatebuffer, &dlen, avpkt->data, avpkt->size);
547  if (ret) {
548  av_log(avctx, AV_LOG_ERROR, "Deflate error %d.\n", ret);
549  return AVERROR_UNKNOWN;
550  }
551 
552  bytestream2_init(&ctx->gbc, ctx->deflatebuffer, dlen);
553 
554  /* Check for tag and for size info */
555  if (bytestream2_get_bytes_left(&ctx->gbc) < 4 + 4) {
556  av_log(avctx, AV_LOG_ERROR, "Frame is too small.\n");
557  return AVERROR_INVALIDDATA;
558  }
559 
560  /* Read tag */
561  tag_header = bytestream2_get_le32(&ctx->gbc);
562 
563  if (tag_header == MKTAG('T','D','S','F')) {
564  int number_tiles;
566  av_log(avctx, AV_LOG_ERROR, "TDSF tag is too small.\n");
567  return AVERROR_INVALIDDATA;
568  }
569  /* First 4 bytes here are the number of GEPJ/WAR tiles in this frame */
570  number_tiles = bytestream2_get_le32(&ctx->gbc);
571 
572  bytestream2_skip(&ctx->gbc, 4); // internal timestamp maybe?
573  keyframe = bytestream2_get_le32(&ctx->gbc) == 0x30;
574 
575  ret = tdsc_parse_tdsf(avctx, number_tiles);
576  if (ret < 0)
577  return ret;
578 
579  /* Check if there is anything else we are able to parse */
580  if (bytestream2_get_bytes_left(&ctx->gbc) >= 4 + 4)
581  tag_header = bytestream2_get_le32(&ctx->gbc);
582  }
583 
584  /* This tag can be after a TDSF block or on its own frame */
585  if (tag_header == MKTAG('D','T','S','M')) {
586  /* First 4 bytes here are the total size in bytes for this frame */
587  int tag_size = bytestream2_get_le32(&ctx->gbc);
588 
589  if (bytestream2_get_bytes_left(&ctx->gbc) < tag_size) {
590  av_log(avctx, AV_LOG_ERROR, "DTSM tag is too small.\n");
591  return AVERROR_INVALIDDATA;
592  }
593 
594  ret = tdsc_parse_dtsm(avctx);
595  if (ret < 0)
596  return ret;
597  }
598 
599  /* Get the output frame and copy the reference frame */
600  ret = ff_get_buffer(avctx, frame, 0);
601  if (ret < 0)
602  return ret;
603 
604  ret = av_frame_copy(frame, ctx->refframe);
605  if (ret < 0)
606  return ret;
607 
608  /* Paint the cursor on the output frame */
609  tdsc_paint_cursor(avctx, frame->data[0], frame->linesize[0]);
610 
611  /* Frame is ready to be output */
612  if (keyframe) {
615  } else {
617  }
618  *got_frame = 1;
619 
620  return avpkt->size;
621 }
622 
624  .p.name = "tdsc",
625  CODEC_LONG_NAME("TDSC"),
626  .p.type = AVMEDIA_TYPE_VIDEO,
627  .p.id = AV_CODEC_ID_TDSC,
628  .init = tdsc_init,
630  .close = tdsc_close,
631  .priv_data_size = sizeof(TDSCContext),
632  .p.capabilities = AV_CODEC_CAP_DR1,
633  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
634 };
TDSCContext::deflatelen
uLongf deflatelen
Definition: tdsc.c:63
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
AVCodec
AVCodec.
Definition: codec.h:187
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AVERROR
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
APPLY_ALPHA
#define APPLY_ALPHA(src, new, alpha)
Definition: tdsc.c:141
tdsc_yuv2rgb
static void tdsc_yuv2rgb(uint8_t *out, int Y, int U, int V)
Definition: tdsc.c:317
out
FILE * out
Definition: movenc.c:54
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:258
GetByteContext
Definition: bytestream.h:33
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1420
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
w
uint8_t w
Definition: llviddspenc.c:38
TDSCContext::cursor_stride
int cursor_stride
Definition: tdsc.c:67
AVPacket::data
uint8_t * data
Definition: packet.h:522
TDSCContext::width
int width
Definition: tdsc.c:53
tdsc_decode_frame
static int tdsc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: tdsc.c:524
FFCodec
Definition: codec_internal.h:127
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
TDSCContext::tilebuffer
uint8_t * tilebuffer
Definition: tdsc.c:59
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
ff_set_dimensions
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:94
TDSCContext::gbc
GetByteContext gbc
Definition: tdsc.c:54
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
TDSCContext::cursor_h
int cursor_h
Definition: tdsc.c:68
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
val
static double val(void *priv, double ch)
Definition: aeval.c:78
tdsc_parse_tdsf
static int tdsc_parse_tdsf(AVCodecContext *avctx, int number_tiles)
Definition: tdsc.c:454
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:118
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:595
tdsc_init
static av_cold int tdsc_init(AVCodecContext *avctx)
Definition: tdsc.c:94
tdsc_paint_cursor
static void tdsc_paint_cursor(AVCodecContext *avctx, uint8_t *dst, int stride)
Definition: tdsc.c:145
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
width
#define width
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1406
TDSCContext::jpkt
AVPacket * jpkt
Definition: tdsc.c:57
bits
uint8_t bits
Definition: vp3data.h:128
avcodec_receive_frame
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
Definition: avcodec.c:681
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
TDSCContext::cursor_hot_x
int cursor_hot_x
Definition: tdsc.c:69
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
tdsc_parse_dtsm
static int tdsc_parse_dtsm(AVCodecContext *avctx)
Definition: tdsc.c:497
AV_CODEC_ID_TDSC
@ AV_CODEC_ID_TDSC
Definition: codec_id.h:239
TDSCContext::cursor_x
int cursor_x
Definition: tdsc.c:68
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
TDSB_HEADER_SIZE
#define TDSB_HEADER_SIZE
Definition: tdsc.c:48
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
V
#define V
Definition: avdct.c:30
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
bytestream2_get_buffer
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:267
TDSCContext::jpeg_avctx
AVCodecContext * jpeg_avctx
Definition: tdsc.c:51
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:128
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:971
TDSCCursorFormat
TDSCCursorFormat
Definition: tdsc.c:73
TDSCContext
Definition: tdsc.c:50
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:509
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
codec_internal.h
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:890
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:186
TDSCContext::cursor_w
int cursor_w
Definition: tdsc.c:68
height
#define height
line
Definition: graph2dot.c:48
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
tdsc_decode_tiles
static int tdsc_decode_tiles(AVCodecContext *avctx, int number_tiles)
Definition: tdsc.c:386
Y
#define Y
Definition: boxblur.h:37
TDSCContext::deflatebuffer
uint8_t * deflatebuffer
Definition: tdsc.c:62
ff_tdsc_decoder
const FFCodec ff_tdsc_decoder
Definition: tdsc.c:623
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:675
TDSCContext::cursor_y
int cursor_y
Definition: tdsc.c:68
TDSCContext::cursor
uint8_t * cursor
Definition: tdsc.c:66
TDSCContext::cursor_hot_y
int cursor_hot_y
Definition: tdsc.c:69
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
av_always_inline
#define av_always_inline
Definition: attributes.h:49
CUR_FMT_RGBA
@ CUR_FMT_RGBA
Definition: tdsc.c:76
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:576
AVCodecContext::idct_algo
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:1547
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
TDSF_HEADER_SIZE
#define TDSF_HEADER_SIZE
Definition: tdsc.c:47
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
ret
ret
Definition: filter_design.txt:187
tdsc_load_cursor
static int tdsc_load_cursor(AVCodecContext *avctx)
Definition: tdsc.c:190
U
#define U(x)
Definition: vpx_arith.h:37
AVCodecContext
main external API structure.
Definition: avcodec.h:445
CUR_FMT_MONO
@ CUR_FMT_MONO
Definition: tdsc.c:74
tdsc_decode_jpeg_tile
static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int tile_size, int x, int y, int w, int h)
Definition: tdsc.c:344
av_clip_uint8
#define av_clip_uint8
Definition: common.h:104
TDSCContext::jpgframe
AVFrame * jpgframe
Definition: tdsc.c:58
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
TDSCContext::height
int height
Definition: tdsc.c:53
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
TDSCContext::refframe
AVFrame * refframe
Definition: tdsc.c:56
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AVPacket
This structure stores compressed data.
Definition: packet.h:499
tdsc_blit
static av_always_inline void tdsc_blit(uint8_t *dst, int dst_stride, const uint8_t *srcy, int srcy_stride, const uint8_t *srcu, const uint8_t *srcv, int srcuv_stride, int width, int height)
Definition: tdsc.c:325
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
bytestream.h
imgutils.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:389
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
tdsc_close
static av_cold int tdsc_close(AVCodecContext *avctx)
Definition: tdsc.c:79
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
h
h
Definition: vp9dsp_template.c:2038
CUR_FMT_BGRA
@ CUR_FMT_BGRA
Definition: tdsc.c:75
BITMAPINFOHEADER_SIZE
#define BITMAPINFOHEADER_SIZE
Definition: tdsc.c:46
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40