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