25 #define BITSTREAM_READER_LE
31 #include "libavutil/common.h"
32 #include "libavutil/intreadwrite.h"
35 const uint8_t *src,
int src_size,
42 if (src_size < avctx->
width * avctx->
height * bpp) {
52 for (h = 0; h < avctx->
height; h++) {
53 memcpy(dst, src, avctx->
width * bpp);
54 src += avctx->
width * bpp;
62 const uint8_t *src,
int src_size)
68 if (src_size < avctx->
width * avctx->
height * 18 / 16) {
83 for (h = 0; h < avctx->
height; h += 4) {
84 for (w = 0; w < avctx->
width; w += 4) {
89 U[w >> 2] = src[16] + 0x80;
90 V[w >> 2] = src[17] + 0x80;
105 const uint8_t *src,
int src_size)
111 if (src_size < avctx->
width * avctx->
height * 3 / 2) {
124 for (h = 0; h < avctx->
height; h += 2) {
125 for (w = 0; w < avctx->
width; w += 2) {
128 U[w >> 1] = src[4] + 0x80;
129 V[w >> 1] = src[5] + 0x80;
142 const uint8_t *src,
int src_size)
160 for (h = 0; h < avctx->
height; h++) {
161 for (w = 0; w < avctx->
width; w++) {
163 U[w] = *src++ ^ 0x80;
164 V[w] = *src++ ^ 0x80;
185 memmove(lru + 1, lru,
sizeof(*lru) * (8 - 1));
188 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
203 memmove(lru + 1, lru,
sizeof(*lru) * (6 - 1));
206 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
222 memcpy(lru[2], def_lru_555, 8 *
sizeof(*
def_lru));
224 for (y = 0; y <
height; y++) {
225 for (x = 0; x <
width; x++) {
229 dst[x * 3 + 0] = (r << 3) | (r >> 2);
230 dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
231 dst[x * 3 + 2] = (b << 3) | (b >> 2);
241 const uint8_t *src,
int src_size,
int is_565)
245 int nslices, slice, slice_height;
246 uint32_t off, slice_size;
251 nslices = bytestream2_get_le16(&gb);
252 off =
FFALIGN(nslices * 4 + 2, 16);
253 if (src_size < off) {
258 if (!nslices || avctx->
height % nslices) {
264 slice_height = avctx->
height / nslices;
270 for (slice = 0; slice < nslices; slice++) {
271 slice_size = bytestream2_get_le32(&gb);
272 if (slice_size > src_size - off) {
274 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
275 slice_size, src_size - off);
278 if (slice_size <= 16) {
283 if (
AV_RL32(src + off) != slice_size - 16) {
285 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
286 AV_RL32(src + off), slice_size - 16);
292 dst += pic->
linesize[0] * slice_height;
305 for (i = 0; i < 3; i++)
308 for (y = 0; y <
height; y++) {
309 for (x = 0; x <
width; x++) {
322 const uint8_t *src,
int src_size)
326 int nslices, slice, slice_height;
327 uint32_t off, slice_size;
332 nslices = bytestream2_get_le16(&gb);
333 off =
FFALIGN(nslices * 4 + 2, 16);
334 if (src_size < off) {
339 if (!nslices || avctx->
height % nslices) {
345 slice_height = avctx->
height / nslices;
351 for (slice = 0; slice < nslices; slice++) {
352 slice_size = bytestream2_get_le32(&gb);
353 if (slice_size > src_size - off) {
355 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
356 slice_size, src_size - off);
359 if (slice_size <= 16) {
365 if (
AV_RL32(src + off) != slice_size - 16) {
367 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
368 AV_RL32(src + off), slice_size - 16);
374 dst += pic->
linesize[0] * slice_height;
383 int ystride,
int ustride,
int vstride)
388 for (i = 0; i < 3; i++)
391 for (y = 0; y <
height; y += 4) {
392 for (x = 0; x <
width; x += 4) {
393 for (j = 0; j < 4; j++)
394 for (i = 0; i < 4; i++)
395 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
409 const uint8_t *src,
int src_size)
413 int nslices, slice, slice_height, ref_slice_height;
415 uint32_t off, slice_size;
420 nslices = bytestream2_get_le16(&gb);
421 off =
FFALIGN(nslices * 4 + 2, 16);
422 if (src_size < off) {
427 if (!nslices || avctx->
height % nslices) {
433 ref_slice_height = avctx->
height / nslices;
448 next_y = ref_slice_height;
449 for (slice = 0; slice < nslices; slice++) {
450 slice_size = bytestream2_get_le32(&gb);
451 slice_height = (next_y & ~3) - (cur_y & ~3);
452 if (slice_size > src_size - off) {
454 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
455 slice_size, src_size - off);
458 if (slice_size <= 16) {
463 if (
AV_RL32(src + off) != slice_size - 16) {
465 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
466 AV_RL32(src + off), slice_size - 16);
473 Y += pic->
linesize[0] * slice_height;
474 U += pic->
linesize[1] * (slice_height >> 2);
475 V += pic->
linesize[2] * (slice_height >> 2);
478 next_y += ref_slice_height;
486 int ystride,
int ustride,
int vstride)
491 for (i = 0; i < 3; i++)
494 for (y = 0; y <
height; y+=2) {
495 for (x = 0; x <
width; x += 2) {
496 Y[x + 0 + 0 * ystride] =
decode_sym(gb, lru[0]);
497 Y[x + 1 + 0 * ystride] =
decode_sym(gb, lru[0]);
498 Y[x + 0 + 1 * ystride] =
decode_sym(gb, lru[0]);
499 Y[x + 1 + 1 * ystride] =
decode_sym(gb, lru[0]);
513 const uint8_t *src,
int src_size)
517 int nslices, slice, slice_height, ref_slice_height;
519 uint32_t off, slice_size;
524 nslices = bytestream2_get_le16(&gb);
525 off =
FFALIGN(nslices * 4 + 2, 16);
526 if (src_size < off) {
531 if (!nslices || avctx->
height % nslices) {
537 ref_slice_height = avctx->
height / nslices;
552 next_y = ref_slice_height;
553 for (slice = 0; slice < nslices; slice++) {
554 slice_size = bytestream2_get_le32(&gb);
555 slice_height = (next_y & ~1) - (cur_y & ~1);
556 if (slice_size > src_size - off) {
558 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
559 slice_size, src_size - off);
562 if (slice_size <= 16) {
567 if (
AV_RL32(src + off) != slice_size - 16) {
569 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
570 AV_RL32(src + off), slice_size - 16);
577 Y += pic->
linesize[0] * slice_height;
578 U += pic->
linesize[1] * (slice_height >> 1);
579 V += pic->
linesize[2] * (slice_height >> 1);
582 next_y += ref_slice_height;
590 int ystride,
int ustride,
int vstride)
595 for (i = 0; i < 3; i++)
598 for (y = 0; y <
height; y++) {
599 for (x = 0; x <
width; x++) {
614 const uint8_t *src,
int src_size)
618 int nslices, slice, slice_height;
619 uint32_t off, slice_size;
624 nslices = bytestream2_get_le16(&gb);
625 off =
FFALIGN(nslices * 4 + 2, 16);
626 if (src_size < off) {
631 if (!nslices || avctx->
height % nslices) {
637 slice_height = avctx->
height / nslices;
647 for (slice = 0; slice < nslices; slice++) {
648 slice_size = bytestream2_get_le32(&gb);
649 if (slice_size > src_size - off) {
651 "invalid slice size %"PRIu32
" (only %"PRIu32
" bytes left)\n",
652 slice_size, src_size - off);
655 if (slice_size <= 16) {
660 if (
AV_RL32(src + off) != slice_size - 16) {
662 "Slice sizes mismatch: got %"PRIu32
" instead of %"PRIu32
"\n",
663 AV_RL32(src + off), slice_size - 16);
670 Y += pic->
linesize[0] * slice_height;
671 U += pic->
linesize[1] * slice_height;
672 V += pic->
linesize[2] * slice_height;
686 if (avpkt->
size < 16) {
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int dx2_decode_slice_444(GetBitContext *gb, int width, int height, uint8_t *Y, uint8_t *U, uint8_t *V, int ystride, int ustride, int vstride)
static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
static int dx2_decode_slice_rgb(GetBitContext *gb, int width, int height, uint8_t *dst, int stride)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
packed RGB 8:8:8, 24bpp, RGBRGB...
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
const uint8_t def_lru_555[8]
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
const char * name
Name of the codec implementation.
static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
bitstream reader API header.
static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int dx2_decode_slice_420(GetBitContext *gb, int width, int height, uint8_t *Y, uint8_t *U, uint8_t *V, int ystride, int ustride, int vstride)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Libavcodec external API header.
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
static uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
AVCodec ff_dxtory_decoder
static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int is_565)
main external API structure.
packed RGB 8:8:8, 24bpp, BGRBGR...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int dx2_decode_slice_565(GetBitContext *gb, int width, int height, uint8_t *dst, int stride, int is_565)
const uint8_t def_lru_565[8]
common internal api header.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int key_frame
1 -> keyframe, 0-> not
static int dx2_decode_slice_410(GetBitContext *gb, int width, int height, uint8_t *Y, uint8_t *U, uint8_t *V, int ystride, int ustride, int vstride)
static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int id, int bpp)
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8], int bits)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)