22#define BITSTREAM_READER_LE
64 s->num_superblocks = ((unsigned)avctx->
width / 8) *
65 ((
unsigned)avctx->
height / 8);
79 for (
i = 0;
i < 3;
i++)
100 unsigned mask_bits =
get_bits(gb, 4);
105 for (j = 0; j < 4; j++)
106 cb.blocks[
i].pixels[j] =
color[(mask_bits>>j) & 1];
123 if (
value != (1 + ((1 << 3) - 1)))
127 if (
value != (1 + ((1 << 3) - 1)) + ((1 << 7) - 1))
134 int* codebook_index,
int superblock_index)
138 unsigned block_index, depth;
141 static const int8_t transitions[3][2] = { {2, 1}, {0, 2}, {1, 0} };
143 *codebook_index = transitions[*codebook_index][
value];
146 depth =
s->codebooks[*codebook_index].depth;
153 if (*codebook_index == 1) {
154 block_index += superblock_index <<
s->codebooks[1].depth;
159 if (block_index >=
s->codebooks[*codebook_index].size || !
s->codebooks[*codebook_index].blocks)
162 return s->codebooks[*codebook_index].blocks[block_index];
170 dst[0] =
mb.pixels32[0];
171 dst[4] =
mb.pixels32[1];
175 uint16_t*
src, ptrdiff_t src_stride)
179 for (y = 0; y < 8; y++)
180 memcpy(dest + y * dest_stride,
src + y * src_stride,
181 sizeof(uint16_t) * 8);
183 for (y = 0; y < 8; y++)
184 memset(dest + y * dest_stride, 0,
sizeof(uint16_t) * 8);
188 0x4, 0x8, 0x40, 0x80,
189 0x100, 0x200, 0x1000, 0x2000,
190 0x400, 0x800, 0x4000, 0x8000};
195 int buf_size = avpkt->
size;
202 unsigned superblock_index, cb_index = 1,
203 superblock_col_index = 0,
204 superblocks_per_row = avctx->
width / 8,
skip = -1;
206 uint16_t* old_frame_data, *new_frame_data;
207 ptrdiff_t old_stride, new_stride;
228 if (!(frame_flags & 0x114) || !(frame_flags & 0x7800000)) {
229 if (!
s->frame->data[0])
241 for (
i = 0;
i < 3;
i++) {
242 if (frame_flags & (1 << (17 +
i))) {
243 unsigned cb_depth, cb_size;
252 cb_depth =
av_log2(cb_size - 1) + 1;
258 cb_size = 1 << cb_depth;
263 cb_size =
s->num_superblocks << cb_depth;
266 if (
s->num_superblocks >= INT_MAX >> cb_depth) {
272 if (cb_size >= INT_MAX / 34 ||
get_bits_left(&gb) < (
int)cb_size * 34)
278 if (!
s->codebooks[
i].blocks)
286 new_frame_data = (uint16_t*)
frame->data[0];
287 new_stride =
frame->linesize[0] / 2;
288 old_frame_data = (uint16_t*)
s->frame->data[0];
289 old_stride =
s->frame->linesize[0] / 2;
291 for (superblock_index = 0; superblock_index <
s->num_superblocks;
292 superblock_index++) {
295 unsigned multi_mask = 0;
305 old_frame_data, old_stride);
308 old_frame_data, old_stride);
315 for (
i = 0;
i < 16;
i++) {
323 unsigned inv_mask =
get_bits(&gb, 4);
324 for (
i = 0;
i < 4;
i++) {
325 if (inv_mask & (1 <<
i)) {
326 multi_mask ^= 0xF <<
i*4;
332 for (
i = 0;
i < 16;
i++) {
339 }
else if (frame_flags & (1 << 16)) {
349 superblock_col_index++;
353 if (superblock_col_index == superblocks_per_row) {
354 new_frame_data += new_stride * 8 - superblocks_per_row * 8;
356 old_frame_data += old_stride * 8 - superblocks_per_row * 8;
357 superblock_col_index = 0;
363 "Escape sizes: %i, %i, %i\n",
376 .p.name =
"escape124",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_escape124_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
static MacroBlock decode_macroblock(Escape124Context *s, GetBitContext *gb, int *codebook_index, int superblock_index)
static CodeBook unpack_codebook(GetBitContext *gb, unsigned depth, unsigned size)
static const uint16_t mask_matrix[]
static av_cold int escape124_decode_init(AVCodecContext *avctx)
Initialize the decoder.
static int escape124_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static unsigned decode_skip_count(GetBitContext *gb)
static void copy_superblock(uint16_t *dest, ptrdiff_t dest_stride, uint16_t *src, ptrdiff_t src_stride)
static av_cold int escape124_decode_close(AVCodecContext *avctx)
static void insert_mb_into_sb(SuperBlock *sb, MacroBlock mb, unsigned index)
static const uint8_t frame_size[4]
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
Memory handling functions.
#define AV_PIX_FMT_RGB555
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
static double cb(void *priv, double x, double y)