48#define BITMAPINFOHEADER_SIZE 0x28
49#define TDSF_HEADER_SIZE 0x56
50#define TDSB_HEADER_SIZE 0x08
119 if (!
ctx->refframe || !
ctx->jpgframe || !
ctx->jpkt)
125 if (!
ctx->jpeg_avctx)
127 ctx->jpeg_avctx->flags = avctx->
flags;
141#define APPLY_ALPHA(src, new, alpha) \
142 src = (src * (256 - alpha) + new * alpha) >> 8
148 const uint8_t *cursor =
ctx->cursor;
150 int w =
ctx->cursor_w;
151 int h =
ctx->cursor_h;
160 if ((
unsigned)
ctx->cursor_x >=
ctx->width ||
161 (
unsigned)
ctx->cursor_y >=
ctx->height)
164 x =
ctx->cursor_x -
ctx->cursor_hot_x;
165 y =
ctx->cursor_y -
ctx->cursor_hot_y;
167 if (x +
w >
ctx->width)
169 if (y +
h >
ctx->height)
179 cursor += -y *
ctx->cursor_stride;
186 for (j = 0; j <
h; j++) {
187 for (
i = 0;
i <
w;
i++) {
188 uint8_t
alpha = cursor[
i * 4];
194 cursor +=
ctx->cursor_stride;
202 int i, j, k, ret, cursor_fmt;
205 ctx->cursor_hot_x = bytestream2_get_le16(&
ctx->gbc);
206 ctx->cursor_hot_y = bytestream2_get_le16(&
ctx->gbc);
207 ctx->cursor_w = bytestream2_get_le16(&
ctx->gbc);
208 ctx->cursor_h = bytestream2_get_le16(&
ctx->gbc);
211 cursor_fmt = bytestream2_get_le32(&
ctx->gbc);
213 if (
ctx->cursor_w < 1 ||
ctx->cursor_w > 256 ||
214 ctx->cursor_h < 1 ||
ctx->cursor_h > 256) {
216 "Invalid cursor dimensions %dx%d.\n",
217 ctx->cursor_w,
ctx->cursor_h);
220 if (
ctx->cursor_hot_x >
ctx->cursor_w ||
221 ctx->cursor_hot_y >
ctx->cursor_h) {
223 ctx->cursor_hot_x,
ctx->cursor_hot_y);
236 switch (cursor_fmt) {
238 for (j = 0; j <
ctx->cursor_h; j++) {
239 for (
i = 0;
i <
ctx->cursor_w;
i += 32) {
240 uint32_t
bits = bytestream2_get_be32(&
ctx->gbc);
241 for (k = 0; k < 32; k++) {
242 dst[0] = !!(
bits & 0x80000000);
250 for (j = 0; j <
ctx->cursor_h; j++) {
251 for (
i = 0;
i <
ctx->cursor_w;
i += 32) {
252 uint32_t
bits = bytestream2_get_be32(&
ctx->gbc);
253 for (k = 0; k < 32; k++) {
254 int mask_bit = !!(
bits & 0x80000000);
255 switch (
dst[0] * 2 + mask_bit) {
285 if (cursor_fmt & 8) {
286 for (j = 0; j <
ctx->cursor_h; j++) {
287 for (
i = 0;
i <
ctx->cursor_w;
i++) {
288 int val = bytestream2_get_be32(&
ctx->gbc);
294 dst +=
ctx->cursor_stride -
ctx->cursor_w * 4;
297 for (j = 0; j <
ctx->cursor_h; j++) {
298 for (
i = 0;
i <
ctx->cursor_w;
i++) {
299 int val = bytestream2_get_be32(&
ctx->gbc);
305 dst +=
ctx->cursor_stride -
ctx->cursor_w * 4;
327 const uint8_t *srcy,
int srcy_stride,
328 const uint8_t *srcu,
const uint8_t *srcv,
333 for (col = 0; col <
width; col++)
335 srcu[col >> 1] - 128, srcv[col >> 1] - 128);
339 srcu += srcuv_stride * (
line & 1);
340 srcv += srcuv_stride * (
line & 1);
346 int x,
int y,
int w,
int h)
353 ctx->jpkt->data =
ctx->tilebuffer;
354 ctx->jpkt->size = tile_size;
364 w >
ctx->jpgframe->width ||
h >
ctx->jpgframe->height) {
366 "JPEG decoding error (%d).\n", ret);
376 tdsc_blit(
ctx->refframe->data[0] + x * 3 +
ctx->refframe->linesize[0] * y,
377 ctx->refframe->linesize[0],
378 ctx->jpgframe->data[0],
ctx->jpgframe->linesize[0],
379 ctx->jpgframe->data[1],
ctx->jpgframe->data[2],
380 ctx->jpgframe->linesize[1],
w,
h);
394 for (
i = 0;
i < number_tiles;
i++) {
397 int x, y, x2, y2,
w,
h;
401 bytestream2_get_le32(&
ctx->gbc) !=
MKTAG(
'T',
'D',
'S',
'B') ||
407 tile_size = bytestream2_get_le32(&
ctx->gbc);
411 tile_mode = bytestream2_get_le32(&
ctx->gbc);
413 x = bytestream2_get_le32(&
ctx->gbc);
414 y = bytestream2_get_le32(&
ctx->gbc);
415 x2 = bytestream2_get_le32(&
ctx->gbc);
416 y2 = bytestream2_get_le32(&
ctx->gbc);
418 if (x < 0 || y < 0 || x2 <= x || y2 <= y ||
419 x2 >
ctx->width || y2 >
ctx->height
422 "Invalid tile position (%d.%d %d.%d outside %dx%d).\n",
423 x, y, x2, y2,
ctx->width,
ctx->height);
430 if (!
ctx->tilebuffer)
435 if (tile_mode ==
MKTAG(
'G',
'E',
'P',
'J')) {
440 }
else if (tile_mode ==
MKTAG(
' ',
'W',
'A',
'R')) {
441 if (3LL *
w *
h > tile_size)
446 ctx->refframe->linesize[0] * y,
447 ctx->refframe->linesize[0],
ctx->tilebuffer,
462 int ret,
w,
h, init_refframe = !
ctx->refframe->data[0];
470 w = bytestream2_get_le32(&
ctx->gbc);
471 h = -bytestream2_get_le32(&
ctx->gbc);
473 if (bytestream2_get_le16(&
ctx->gbc) != 1 ||
474 bytestream2_get_le16(&
ctx->gbc) != 24)
495 ctx->refframe->width =
w;
496 ctx->refframe->height =
h;
510 int action = bytestream2_get_le32(&
ctx->gbc);
514 if (action == 2 || action == 3) {
516 ctx->cursor_x = bytestream2_get_le32(&
ctx->gbc);
517 ctx->cursor_y = bytestream2_get_le32(&
ctx->gbc);
537 int ret, tag_header, keyframe = 0;
542 int deflatelen = avctx->
width * avctx->
height * (3 + 1);
543 if (deflatelen !=
ctx->deflatelen) {
544 ctx->deflatelen =deflatelen;
552 dlen =
ctx->deflatelen;
555 ret = uncompress(
ctx->deflatebuffer, &dlen, avpkt->
data, avpkt->
size);
570 tag_header = bytestream2_get_le32(&
ctx->gbc);
572 if (tag_header ==
MKTAG(
'T',
'D',
'S',
'F')) {
579 number_tiles = bytestream2_get_le32(&
ctx->gbc);
582 keyframe = bytestream2_get_le32(&
ctx->gbc) == 0x30;
590 tag_header = bytestream2_get_le32(&
ctx->gbc);
594 if (tag_header ==
MKTAG(
'D',
'T',
'S',
'M')) {
596 int tag_size = bytestream2_get_le32(&
ctx->gbc);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_mjpeg_decoder
const FFCodec ff_tdsc_decoder
static AVFormatContext * ctx
Libavcodec external API header.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
#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...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#define AV_EF_EXPLODE
abort decoding on minor error detection
static const uint8_t bits[8]
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
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.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static const int16_t alpha[]
#define MKTAG(a, b, c, d)
Memory handling functions.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int flags2
AV_CODEC_FLAG2_*.
int64_t max_pixels
The number of pixels per image to maximally accept.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int flags
AV_CODEC_FLAG_*.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVCodecContext * jpeg_avctx
#define avpriv_request_sample(...)
static av_cold int tdsc_close(AVCodecContext *avctx)
static int tdsc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
#define BITMAPINFOHEADER_SIZE
static av_cold int tdsc_init(AVCodecContext *avctx)
static void tdsc_paint_cursor(AVCodecContext *avctx, uint8_t *dst, int stride)
static int tdsc_decode_tiles(AVCodecContext *avctx, int number_tiles)
static int tdsc_parse_tdsf(AVCodecContext *avctx, int number_tiles)
#define APPLY_ALPHA(src, new, alpha)
static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int tile_size, int x, int y, int w, int h)
static void tdsc_yuv2rgb(uint8_t *out, int Y, int U, int V)
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)
static int tdsc_parse_dtsm(AVCodecContext *avctx)
static int tdsc_load_cursor(AVCodecContext *avctx)