34#define HNM4_CHUNK_ID_PL 19536
35#define HNM4_CHUNK_ID_IZ 23113
36#define HNM4_CHUNK_ID_IU 21833
37#define HNM4_CHUNK_ID_SD 17491
56 *bitbuf = bytestream2_get_le32(gb);
72 uint32_t bitbuf = 0, writeoffset = 0, count = 0;
83 "Attempting to write out of bounds\n");
86 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
89 word = bytestream2_get_le16(&gb);
91 offset = (word >> 3) - 0x2000;
93 count = bytestream2_get_byte(&gb);
99 offset = bytestream2_get_byte(&gb) - 0x0100;
106 }
else if (writeoffset + count >= hnm->
width * hnm->
height) {
108 "Attempting to write out of bounds\n");
121 uint32_t x, y, src_y;
124 for (y = 0; y < hnm->
height; y++) {
129 for (x = 0; x <
width; x++) {
143 for (y = 0; y < hnm->
height; y++) {
154 uint32_t writeoffset = 0;
156 uint8_t
tag, previous, backline, backward, swap;
161 count = bytestream2_peek_byte(&gb) & 0x1F;
163 tag = bytestream2_get_byte(&gb) & 0xE0;
171 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
172 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
173 }
else if (
tag == 1) {
174 writeoffset += bytestream2_get_byte(&gb) * 2;
175 }
else if (
tag == 2) {
176 count = bytestream2_get_le16(&gb);
178 writeoffset += count;
179 }
else if (
tag == 3) {
180 count = bytestream2_get_byte(&gb) * 2;
181 if (writeoffset + count > hnm->
width * hnm->
height) {
186 hnm->
current[writeoffset++] = bytestream2_peek_byte(&gb);
198 previous = bytestream2_peek_byte(&gb) & 0x20;
199 backline = bytestream2_peek_byte(&gb) & 0x40;
200 backward = bytestream2_peek_byte(&gb) & 0x80;
202 swap = bytestream2_peek_byte(&gb) & 0x01;
203 offset = bytestream2_get_le16(&gb);
215 }
else if (writeoffset + 2*count > hnm->
width * hnm->
height) {
217 "Attempting to write out of bounds\n");
265 writeoffset -= count * 2;
267 swap = hnm->
current[writeoffset];
269 hnm->
current[writeoffset + 1] = swap;
284 uint32_t writeoffset = 0,
offset;
285 uint8_t
tag, count, previous,
delta;
290 count = bytestream2_peek_byte(&gb) & 0x3F;
292 tag = bytestream2_get_byte(&gb) & 0xC0;
295 writeoffset += bytestream2_get_byte(&gb);
296 }
else if (
tag == 1) {
301 hnm->
current[writeoffset] = bytestream2_get_byte(&gb);
302 hnm->
current[writeoffset + hnm->
width] = bytestream2_get_byte(&gb);
304 }
else if (
tag == 2) {
305 writeoffset += hnm->
width;
306 }
else if (
tag == 3) {
314 delta = bytestream2_peek_byte(&gb) & 0x80;
315 previous = bytestream2_peek_byte(&gb) & 0x40;
319 offset += bytestream2_get_le16(&gb);
363 uint8_t start, writeoffset;
365 int eight_bit_colors;
367 eight_bit_colors =
src[7] & 0x80 && hnm->
version == 0x4a;
373 start = bytestream2_get_byte(&gb);
374 count = bytestream2_get_byte(&gb);
375 if (start == 255 && count == 255)
381 hnm->
palette[writeoffset] = bytestream2_get_be24(&gb);
382 if (!eight_bit_colors)
383 hnm->
palette[writeoffset] <<= 2;
384 hnm->
palette[writeoffset] |= (0xFFU << 24);
398 if (avpkt->
size < 8) {
408 if (avpkt->
size < 12) {
460 "Extradata missing, decoder requires version number\n");
501 .p.name =
"hnm4video",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_hnm4_video_decoder
static av_cold void close(AVCodecParserContext *s)
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)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#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(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static void copy_processed_frame(AVCodecContext *avctx, AVFrame *frame)
static void unpack_intraframe(AVCodecContext *avctx, const uint8_t *src, uint32_t size)
static void postprocess_current_frame(AVCodecContext *avctx)
static av_cold int hnm_decode_init(AVCodecContext *avctx)
static av_cold int hnm_decode_end(AVCodecContext *avctx)
static int getbit(GetByteContext *gb, uint32_t *bitbuf, int *bits)
static int decode_interframe_v4(AVCodecContext *avctx, const uint8_t *src, uint32_t size)
static int hnm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static void hnm_update_palette(AVCodecContext *avctx, const uint8_t *src, uint32_t size)
static void decode_interframe_v4a(AVCodecContext *avctx, const uint8_t *src, uint32_t size)
common internal API header
#define FFSWAP(type, a, b)
Memory handling functions.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.