23 #define BITSTREAM_READER_LE
33 const uint8_t *src,
int src_size,
40 if (src_size < avctx->
width * avctx->
height * bpp) {
50 for (h = 0; h < avctx->
height; h++) {
51 memcpy(dst, src, avctx->
width * bpp);
52 src += avctx->
width * bpp;
60 const uint8_t *src,
int src_size)
66 if (src_size < avctx->
width * avctx->
height * 18 / 16) {
81 for (h = 0; h < avctx->
height; h += 4) {
82 for (w = 0; w < avctx->
width; w += 4) {
87 U[w >> 2] = src[16] + 0x80;
88 V[w >> 2] = src[17] + 0x80;
103 const uint8_t *src,
int src_size)
109 if (src_size < avctx->
width * avctx->
height * 3 / 2) {
122 for (h = 0; h < avctx->
height; h += 2) {
123 for (w = 0; w < avctx->
width; w += 2) {
126 U[w >> 1] = src[4] + 0x80;
127 V[w >> 1] = src[5] + 0x80;
140 const uint8_t *src,
int src_size)
158 for (h = 0; h < avctx->
height; h++) {
159 for (w = 0; w < avctx->
width; w++) {
161 U[w] = *src++ ^ 0x80;
162 V[w] = *src++ ^ 0x80;
183 memmove(lru + 1, lru,
sizeof(*lru) * (8 - 1));
186 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
201 memmove(lru + 1, lru,
sizeof(*lru) * (6 - 1));
204 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
220 memcpy(lru[2], def_lru_555, 8 *
sizeof(*
def_lru));
222 for (y = 0; y <
height; y++) {
223 for (x = 0; x <
width; x++) {
227 dst[x * 3 + 0] = (r << 3) | (r >> 2);
228 dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
229 dst[x * 3 + 2] = (b << 3) | (b >> 2);
239 const uint8_t *src,
int src_size,
int is_565)
243 int nslices, slice, slice_height;
244 uint32_t
off, slice_size;
249 nslices = bytestream2_get_le16(&gb);
250 off =
FFALIGN(nslices * 4 + 2, 16);
251 if (src_size < off) {
256 if (!nslices || avctx->
height % nslices) {
262 slice_height = avctx->
height / nslices;
268 for (slice = 0; slice < nslices; slice++) {
269 slice_size = bytestream2_get_le32(&gb);
270 if (slice_size > src_size - off) {
272 "invalid slice size %d (only %d bytes left)\n",
273 slice_size, src_size - off);
276 if (slice_size <= 16) {
281 if (
AV_RL32(src + off) != slice_size - 16) {
283 "Slice sizes mismatch: got %d instead of %d\n",
284 AV_RL32(src + off), slice_size - 16);
290 dst += pic->
linesize[0] * slice_height;
303 for (i = 0; i < 3; i++)
306 for (y = 0; y <
height; y++) {
307 for (x = 0; x <
width; x++) {
320 const uint8_t *src,
int src_size)
324 int nslices, slice, slice_height;
325 uint32_t
off, slice_size;
330 nslices = bytestream2_get_le16(&gb);
331 off =
FFALIGN(nslices * 4 + 2, 16);
332 if (src_size < off) {
337 if (!nslices || avctx->
height % nslices) {
343 slice_height = avctx->
height / nslices;
349 for (slice = 0; slice < nslices; slice++) {
350 slice_size = bytestream2_get_le32(&gb);
351 if (slice_size > src_size - off) {
353 "invalid slice size %d (only %d bytes left)\n",
354 slice_size, src_size - off);
357 if (slice_size <= 16) {
362 if (
AV_RL32(src + off) != slice_size - 16) {
364 "Slice sizes mismatch: got %d instead of %d\n",
365 AV_RL32(src + off), slice_size - 16);
371 dst += pic->
linesize[0] * slice_height;
380 int ystride,
int ustride,
int vstride)
385 for (i = 0; i < 3; i++)
388 for (y = 0; y <
height; y += 4) {
389 for (x = 0; x <
width; x += 4) {
390 for (j = 0; j < 4; j++)
391 for (i = 0; i < 4; i++)
392 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
406 const uint8_t *src,
int src_size)
410 int nslices, slice, slice_height, ref_slice_height;
412 uint32_t
off, slice_size;
417 nslices = bytestream2_get_le16(&gb);
418 off =
FFALIGN(nslices * 4 + 2, 16);
419 if (src_size < off) {
424 if (!nslices || avctx->
height % nslices) {
430 ref_slice_height = avctx->
height / nslices;
445 next_y = ref_slice_height;
446 for (slice = 0; slice < nslices; slice++) {
447 slice_size = bytestream2_get_le32(&gb);
448 slice_height = (next_y & ~3) - (cur_y & ~3);
449 if (slice_size > src_size - off) {
451 "invalid slice size %d (only %d bytes left)\n",
452 slice_size, src_size - off);
455 if (slice_size <= 16) {
460 if (
AV_RL32(src + off) != slice_size - 16) {
462 "Slice sizes mismatch: got %d instead of %d\n",
463 AV_RL32(src + off), slice_size - 16);
470 Y += pic->
linesize[0] * slice_height;
471 U += pic->
linesize[1] * (slice_height >> 2);
472 V += pic->
linesize[2] * (slice_height >> 2);
475 next_y += ref_slice_height;
483 int ystride,
int ustride,
int vstride)
488 for (i = 0; i < 3; i++)
491 for (y = 0; y <
height; y+=2) {
492 for (x = 0; x <
width; x += 2) {
493 Y[x + 0 + 0 * ystride] =
decode_sym(gb, lru[0]);
494 Y[x + 1 + 0 * ystride] =
decode_sym(gb, lru[0]);
495 Y[x + 0 + 1 * ystride] =
decode_sym(gb, lru[0]);
496 Y[x + 1 + 1 * ystride] =
decode_sym(gb, lru[0]);
510 const uint8_t *src,
int src_size)
514 int nslices, slice, slice_height, ref_slice_height;
516 uint32_t
off, slice_size;
521 nslices = bytestream2_get_le16(&gb);
522 off =
FFALIGN(nslices * 4 + 2, 16);
523 if (src_size < off) {
528 if (!nslices || avctx->
height % nslices) {
534 ref_slice_height = avctx->
height / nslices;
549 next_y = ref_slice_height;
550 for (slice = 0; slice < nslices; slice++) {
551 slice_size = bytestream2_get_le32(&gb);
552 slice_height = (next_y & ~1) - (cur_y & ~1);
553 if (slice_size > src_size - off) {
555 "invalid slice size %d (only %d bytes left)\n",
556 slice_size, src_size - off);
559 if (slice_size <= 16) {
564 if (
AV_RL32(src + off) != slice_size - 16) {
566 "Slice sizes mismatch: got %d instead of %d\n",
567 AV_RL32(src + off), slice_size - 16);
574 Y += pic->
linesize[0] * slice_height;
575 U += pic->
linesize[1] * (slice_height >> 1);
576 V += pic->
linesize[2] * (slice_height >> 1);
579 next_y += ref_slice_height;
587 int ystride,
int ustride,
int vstride)
592 for (i = 0; i < 3; i++)
595 for (y = 0; y <
height; y++) {
596 for (x = 0; x <
width; x++) {
611 const uint8_t *src,
int src_size)
615 int nslices, slice, slice_height;
616 uint32_t
off, slice_size;
621 nslices = bytestream2_get_le16(&gb);
622 off =
FFALIGN(nslices * 4 + 2, 16);
623 if (src_size < off) {
628 if (!nslices || avctx->
height % nslices) {
634 slice_height = avctx->
height / nslices;
644 for (slice = 0; slice < nslices; slice++) {
645 slice_size = bytestream2_get_le32(&gb);
646 if (slice_size > src_size - off) {
648 "invalid slice size %d (only %d bytes left)\n",
649 slice_size, src_size - off);
652 if (slice_size <= 16) {
657 if (
AV_RL32(src + off) != slice_size - 16) {
659 "Slice sizes mismatch: got %d instead of %d\n",
660 AV_RL32(src + off), slice_size - 16);
667 Y += pic->
linesize[0] * slice_height;
668 U += pic->
linesize[1] * slice_height;
669 V += pic->
linesize[2] * slice_height;
683 if (avpkt->
size < 16) {
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)
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.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
packed RGB 8:8:8, 24bpp, RGBRGB...
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
const uint8_t def_lru_555[8]
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)
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
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)
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. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
packed RGB 8:8:8, 24bpp, BGRBGR...
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)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
AVCodec ff_dxtory_decoder
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int is_565)
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int dx2_decode_slice_565(GetBitContext *gb, int width, int height, uint8_t *dst, int stride, int is_565)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const uint8_t def_lru_565[8]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
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.
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)