29#define BITSTREAM_READER_LE
95 const uint8_t *
src,
int src_size,
96 int id,
int bpp, uint32_t vflipped)
126 const uint8_t *
src,
int src_size,
130 uint8_t *Y1, *Y2, *Y3, *Y4, *
U, *
V;
164 U[
w >> 2] =
src[16] + 0x80;
165 V[
w >> 2] =
src[17] + 0x80;
169 for (
w = 0;
w < hmargin;
w++) {
176 U[huvborder] =
src[0] + 0x80;
177 V[huvborder] =
src[1] + 0x80;
196 U[
w >> 2] =
src[0] + 0x80;
197 V[
w >> 2] =
src[1] + 0x80;
201 for (
w = 0;
w < hmargin;
w++) {
209 U[huvborder] =
src[0] + 0x80;
210 V[huvborder] =
src[1] + 0x80;
221 const uint8_t *
src,
int src_size,
225 uint8_t *Y1, *Y2, *
U, *
V;
255 U[
w >> 1] =
src[4] + 0x80;
256 V[
w >> 1] =
src[5] + 0x80;
262 U[huvborder] =
src[2] + 0x80;
263 V[huvborder] =
src[3] + 0x80;
275 U[
w >> 1] =
src[0] + 0x80;
276 V[
w >> 1] =
src[1] + 0x80;
281 U[huvborder] =
src[1] + 0x80;
282 V[huvborder] =
src[2] + 0x80;
293 const uint8_t *
src,
int src_size,
315 for (
w = 0;
w < avctx->
width;
w++) {
317 U[
w] = *
src++ ^ 0x80;
318 V[
w] = *
src++ ^ 0x80;
330static const uint8_t
def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
331static const uint8_t
def_lru_555[8] = { 0x00, 0x08, 0x10, 0x18, 0x1F };
332static const uint8_t
def_lru_565[8] = { 0x00, 0x08, 0x10, 0x20, 0x30, 0x3F };
341 memmove(lru + 1, lru,
sizeof(*lru) * (8 - 1));
344 memmove(lru + 1, lru,
sizeof(*lru) * (
c - 1));
352 const uint8_t *
src,
int src_size,
353 int slice_size,
int off)
357 if (slice_size > src_size - off) {
359 "invalid slice size %d (only %d bytes left)\n",
360 slice_size, src_size - off);
363 if (slice_size <= 16) {
370 if (cur_slice_size != slice_size - 16) {
372 "Slice sizes mismatch: got %d instead of %d\n",
373 cur_slice_size, slice_size - 16);
380 const uint8_t *
src,
int src_size,
382 int *nslices,
int *off)
385 *nslices = bytestream2_get_le16(gb);
386 *off =
FFALIGN(*nslices * 4 + 2, 16);
387 if (src_size < *off) {
409 memmove(lru + 1, lru,
sizeof(*lru) * (6 - 1));
412 memmove(lru + 1, lru,
sizeof(*lru) * (
c - 1));
425 const uint8_t *
src,
int src_size,
433 int nslices, slice,
line = 0;
434 uint32_t off, slice_size;
445 for (slice = 0; slice < nslices; slice++) {
446 slice_size = bytestream2_get_le32(&gb_check);
448 if (slice_size <= 16 + (avctx->
height * avctx->
width / (8 * nslices)))
450 off_check += slice_size;
462 for (slice = 0; slice < nslices; slice++) {
463 slice_size = bytestream2_get_le32(&gb);
490 int line,
int left, uint8_t lru[3][8],
500 for (x = 0; x <
width; x++) {
504 dst[x * 3 + 0] = (
r << 3) | (
r >> 2);
505 dst[x * 3 + 1] = is_565 ? (
g << 2) | (
g >> 4) : (
g << 3) | (
g >> 2);
506 dst[x * 3 + 2] = (
b << 3) | (
b >> 2);
530 int line,
int left, uint8_t lru[3][8])
536 int line,
int left, uint8_t lru[3][8])
542 const uint8_t *
src,
int src_size,
int is_565,
559 int line,
int left, uint8_t lru[3][8])
567 for (x = 0; x <
width; x++) {
583 for (
i = 0;
i < 3;
i++)
588 const uint8_t *
src,
int src_size,
604 int ystride =
frame->linesize[0];
605 int ustride =
frame->linesize[1];
606 int vstride =
frame->linesize[2];
609 uint8_t *
U =
frame->data[1] + (ustride >> 2) *
line;
610 uint8_t *
V =
frame->data[2] + (vstride >> 2) *
line;
612 int h,
w, hmargin, vmargin;
617 hmargin =
frame->width -
w;
618 vmargin =
frame->height -
h;
621 for (y = 0; y <
left - 3 &&
get_bits_left(gb) >= 18 *
w / 4 + hmargin * 4 + (!!hmargin * 2); y += 4) {
622 for (x = 0; x <
w; x += 4) {
623 for (j = 0; j < 4; j++)
624 for (
i = 0;
i < 4;
i++)
630 for (j = 0; j < 4; j++)
631 for (
i = 0;
i < hmargin;
i++)
642 if (vmargin && y + vmargin ==
left) {
643 for (x = 0; x <
width; x += 4) {
644 for (j = 0; j < vmargin; j++)
645 for (
i = 0;
i < 4;
i++)
651 for (j = 0; j < vmargin; j++) {
652 for (
i = 0;
i < hmargin;
i++)
667 const uint8_t *
src,
int src_size,
684 int ystride =
frame->linesize[0];
685 int ustride =
frame->linesize[1];
686 int vstride =
frame->linesize[2];
689 uint8_t *
U =
frame->data[1] + (ustride >> 1) *
line;
690 uint8_t *
V =
frame->data[2] + (vstride >> 1) *
line;
692 int h,
w, hmargin, vmargin;
697 hmargin =
frame->width -
w;
698 vmargin =
frame->height -
h;
702 for (x = 0; x <
w; x += 2) {
723 for (x = 0; x <
width; x += 2) {
739 const uint8_t *
src,
int src_size,
756 int ystride =
frame->linesize[0];
757 int ustride =
frame->linesize[1];
758 int vstride =
frame->linesize[2];
765 for (x = 0; x <
width; x++) {
780 const uint8_t *
src,
int src_size,
792 const uint8_t *
src = avpkt->
data;
796 if (avpkt->
size < 16) {
802 vflipped = !!(
type & 0x20);
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_dxtory_decoder
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int id, int bpp, uint32_t vflipped)
int(* decode_slice_func)(GetBitContext *gb, AVFrame *frame, int line, int height, uint8_t lru[3][8])
static int load_buffer(AVCodecContext *avctx, const uint8_t *src, int src_size, GetByteContext *gb, int *nslices, int *off)
static const uint8_t def_lru_565[8]
static int64_t get_raw_size(enum AVPixelFormat fmt, int width, int height)
static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int is_565, uint32_t vflipped)
static void setup_lru_555(uint8_t lru[3][8])
static const uint8_t def_lru[8]
static int dx2_decode_slice_555(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, decode_slice_func decode_slice, setup_lru_func setup_lru, enum AVPixelFormat fmt, uint32_t vflipped)
static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static void default_setup_lru(uint8_t lru[3][8])
static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
static uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8], int bits)
static int decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_frame, AVPacket *avpkt)
void(* setup_lru_func)(uint8_t lru[3][8])
static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static const uint8_t def_lru_555[8]
static av_always_inline int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8], int is_565)
static void do_vflip(AVCodecContext *avctx, AVFrame *pic, int vflip)
static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int check_slice_size(AVCodecContext *avctx, const uint8_t *src, int src_size, int slice_size, int off)
static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static void setup_lru_565(uint8_t lru[3][8])
static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static int dx2_decode_slice_565(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static const uint8_t bits[8]
static int decode_slice(AVCodecContext *c, void *arg)
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Multithreading API for decoders.
Macro definitions for various function/variable attributes.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This structure stores compressed data.
#define avpriv_request_sample(...)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.