23 #include "libavutil/avassert.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
67 int mask = 0x10000, bitbuf = 0;
71 segments = bytestream2_get_le32(gb);
72 offset = bytestream2_get_le32(gb);
73 if (segments == 0 && offset == frame_end - frame)
75 if (frame_end - frame <= offset)
81 if (mask == 0x10000) {
82 bitbuf = bytestream2_get_le16u(gb);
85 if (frame_end - frame < 2)
88 v = bytestream2_get_le16(gb);
89 offset = (v & 0x1FFF) << 1;
90 count = ((v >> 13) + 2) << 1;
91 if (frame - frame_start < offset || frame_end - frame < count)
96 *frame++ = bytestream2_get_byte(gb);
97 *frame++ = bytestream2_get_byte(gb);
109 int mask = 0x10000, bitbuf = 0;
112 segments = bytestream2_get_le16(gb);
116 if (mask == 0x10000) {
117 bitbuf = bytestream2_get_le16u(gb);
120 if (frame_end - frame < 2)
123 v = bytestream2_get_le16(gb);
124 offset = (v & 0x1FFF) << 1;
125 count = ((v >> 13) + 2) << 1;
126 if (frame - frame_start < offset || frame_end - frame < count)
130 }
else if (bitbuf & (mask << 1)) {
131 frame += bytestream2_get_le16(gb);
133 *frame++ = bytestream2_get_byte(gb);
134 *frame++ = bytestream2_get_byte(gb);
146 int mask = 0x10000, bitbuf = 0;
149 segments = bytestream2_get_le16(gb);
153 if (mask == 0x10000) {
154 bitbuf = bytestream2_get_le16u(gb);
159 v = bytestream2_get_le16(gb);
160 offset = (v & 0x1FFF) << 2;
161 count = ((v >> 13) + 2) << 1;
162 if (frame - frame_start < offset || frame_end - frame < count*2 + width)
164 for (i = 0; i <
count; i++) {
165 frame[0] = frame[1] =
170 }
else if (bitbuf & (mask << 1)) {
171 v = bytestream2_get_le16(gb)*2;
172 if (frame - frame_end < v)
176 if (frame_end - frame < width + 3)
178 frame[0] = frame[1] =
179 frame[
width] = frame[width + 1] = bytestream2_get_byte(gb);
181 frame[0] = frame[1] =
182 frame[
width] = frame[width + 1] = bytestream2_get_byte(gb);
194 int count, lines, segments;
196 count = bytestream2_get_le16(gb);
199 frame += width *
count;
200 lines = bytestream2_get_le16(gb);
201 if (count + lines > height)
209 segments = bytestream2_get_byteu(gb);
211 if (frame - line_ptr <= bytestream2_peek_byte(gb))
213 line_ptr += bytestream2_get_byte(gb);
214 count = (int8_t)bytestream2_get_byte(gb);
216 if (frame - line_ptr < count)
222 if (frame - line_ptr < count)
224 memset(line_ptr, bytestream2_get_byte(gb), count);
237 int count, i,
v, lines, segments;
240 lines = bytestream2_get_le16(gb);
247 segments = bytestream2_get_le16u(gb);
248 while ((segments & 0xC000) == 0xC000) {
249 unsigned skip_lines = -(int16_t)segments;
250 unsigned delta = -((int16_t)segments * width);
251 if (frame_end - frame <= delta || y + lines + skip_lines > height)
255 segments = bytestream2_get_le16(gb);
258 if (frame_end <= frame)
260 if (segments & 0x8000) {
261 frame[width - 1] = segments & 0xFF;
262 segments = bytestream2_get_le16(gb);
265 if (frame_end - frame < width)
270 if (frame - line_ptr <= bytestream2_peek_byte(gb))
272 line_ptr += bytestream2_get_byte(gb);
273 count = (int8_t)bytestream2_get_byte(gb);
275 if (frame - line_ptr < count * 2)
279 line_ptr += count * 2;
282 if (frame - line_ptr < count * 2)
284 v = bytestream2_get_le16(gb);
285 for (i = 0; i <
count; i++)
286 bytestream_put_le16(&line_ptr, v);
297 uint32_t segments = bytestream2_get_le32(gb);
303 copy = bytestream2_get_byteu(gb) * 2;
304 skip = bytestream2_get_byteu(gb) * 2;
305 if (frame_end - frame < copy + skip ||
318 memset(frame, 0, width * height);
331 "COPY",
"TSW1",
"BDLT",
"WDLT",
"TDLT",
"DSW1",
"BLCK",
"DDS1"
335 void *
data,
int *got_frame,
342 uint32_t chunk_type, chunk_size;
354 chunk_size = bytestream2_get_le32(&gb);
355 chunk_type = bytestream2_get_le32(&gb);
358 if (chunk_type == 1) {
359 pal_elems =
FFMIN(chunk_size / 3, 256);
360 for (i = 0; i < pal_elems; i++) {
361 s->
pal[i] = bytestream2_get_be24(&gb) << 2;
362 s->
pal[i] |= 0xFF
U << 24 | (s->
pal[i] >> 6) & 0x30303;
365 }
else if (chunk_type <= 9) {
379 dst = frame->
data[0];
380 for (i = 0; i < avctx->
height; i++) {
381 if(version == 0x100) {
383 for(j = 0; j < avctx->
width; j++) {
384 dst[j] = buf[ (i&3)*(avctx->
width /4) + (j/4) +
388 memcpy(dst, buf, avctx->
width);
393 memcpy(frame->
data[1], s->
pal,
sizeof(s->
pal));
This structure describes decoded (raw) audio or video data.
static const char * chunk_name[8]
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
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 av_cold int dfa_decode_end(AVCodecContext *avctx)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static const uint8_t offset[511][2]
const char * name
Name of the codec implementation.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
static int decode_blck(GetByteContext *gb, uint8_t *frame, int width, int height)
static int dfa_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int decode_tdlt(GetByteContext *gb, uint8_t *frame, int width, int height)
static int decode_dsw1(GetByteContext *gb, uint8_t *frame, int width, int height)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Libavcodec external API header.
static int decode_copy(GetByteContext *gb, uint8_t *frame, int width, int height)
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...
static const chunk_decoder decoder[8]
int width
picture width / height.
static av_cold int dfa_decode_init(AVCodecContext *avctx)
static int decode_bdlt(GetByteContext *gb, uint8_t *frame, int width, int height)
static int decode_dds1(GetByteContext *gb, uint8_t *frame, int width, int height)
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
BYTE int const BYTE int int int height
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int decode_wdlt(GetByteContext *gb, uint8_t *frame, int width, int height)
common internal api header.
static int decode_tsw1(GetByteContext *gb, uint8_t *frame, int width, int height)
#define AVERROR_INVALIDDATA
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int(* chunk_decoder)(GetByteContext *gb, uint8_t *frame, int width, int height)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
8 bit with PIX_FMT_RGB32 palette
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...