64 return le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
69 return le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
75 case TIFF_BYTE:
return bytestream2_get_byte(gb);
78 default:
return UINT_MAX;
83 static int tiff_uncompress(uint8_t *dst,
unsigned long *
len,
const uint8_t *src,
int size)
88 memset(&zstream, 0,
sizeof(zstream));
89 zstream.next_in = src;
90 zstream.avail_in =
size;
91 zstream.next_out = dst;
92 zstream.avail_out = *
len;
93 zret = inflateInit(&zstream);
98 zret = inflate(&zstream, Z_SYNC_FLUSH);
100 *len = zstream.total_out;
101 return zret == Z_STREAM_END ? Z_OK : zret;
107 int c,
line, pixels, code;
110 uint8_t *zbuf;
unsigned long outlen;
114 outlen = width * lines;
116 ret = tiff_uncompress(zbuf, &outlen, src, size);
118 av_log(s->
avctx,
AV_LOG_ERROR,
"Uncompressing failed (%lu of %lu) with error %d\n", outlen, (
unsigned long)width * lines, ret);
123 for(line = 0; line < lines; line++){
124 memcpy(dst, src, width);
137 for (line = 0; line < lines; line++) {
139 if (pixels < width) {
162 memcpy(src2, src, size);
164 for(i = 0; i <
size; i++)
182 for(line = 0; line < lines; line++){
192 for (i = 0; i <
width; i++)
193 bytestream2_put_byte(&pb,
av_reverse[bytestream2_get_byte(&s->
gb)]);
197 for(pixels = 0; pixels <
width;){
198 code = (int8_t)bytestream2_get_byte(&s->
gb);
203 }
else if(code != -128){
205 c = bytestream2_get_byte(&s->
gb);
224 "Unsupported image parameters: bpp=%d, bppcount=%d\n",
250 "This format is not supported (bpp=%d, bppcount=%d)\n",
271 for (i = 0; i < 256; i++)
272 pal[i] = i * 0x010101;
280 unsigned tag, type, count,
off, value = 0;
317 if (count <= 4 &&
type_sizes[type] * count <= 4)
336 if(count == 1) s->
bpp = value;
340 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) + ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
345 for (i = 0; i < count; i++)
356 "Samples per pixel requires a single value, many provided\n");
394 if (type ==
TIFF_LONG && value == UINT_MAX)
443 if(value < 1 || value > 2){
453 if (count / 3 > 256 ||
456 pal_gb[0] = pal_gb[1] = pal_gb[2] = s->
gb;
460 for(i = 0; i < count / 3; i++){
461 uint32_t p = 0xFF000000;
462 p |= (
tget(&pal_gb[0], type, s->
le) >>
off) << 16;
463 p |= (
tget(&pal_gb[1], type, s->
le) >>
off) << 8;
464 p |=
tget(&pal_gb[2], type, s->
le) >>
off;
492 void *
data,
int *data_size,
502 unsigned soff, ssize;
512 id = bytestream2_get_le16(&s->
gb);
513 if(
id == 0x4949)
le = 1;
514 else if(
id == 0x4D4D)
le = 0;
526 av_log(avctx,
AV_LOG_ERROR,
"The answer to life, universe and everything is not correct!\n");
533 if (
off >= UINT_MAX - 14 || avpkt->
size <
off + 14) {
539 for(i = 0; i < entries; i++){
582 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
594 ssize = s->
width * soff;
595 for(i = 0; i < s->
height; i++) {
596 for(j = soff; j < ssize; j++)
597 dst[j] += dst[j - soff];
607 for(j = 0; j < s->
height; j++){
609 src[i] = 255 - src[i];
int ff_lzw_decode(LZWState *p, uint8_t *buf, int len)
Decode given number of bytes NOTE: the algorithm here is inspired from the LZW GIF decoder written by...
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
const uint8_t av_reverse[256]
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_always_inline void bytestream2_set_buffer(PutByteContext *p, const uint8_t c, unsigned int size)
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
AVFrame * coded_frame
the picture in the bitstream
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
av_cold void ff_lzw_decode_close(LZWState **p)
av_cold void ff_lzw_decode_open(LZWState **p)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define FF_ARRAY_ELEMS(a)
four components are given, that's all.
static unsigned tget_short(GetByteContext *gb, int le)
static unsigned tget_long(GetByteContext *gb, int le)
av_cold void ff_ccitt_unpack_init(void)
initialize upacker code
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
static int init_image(TiffContext *s)
static av_cold int tiff_init(AVCodecContext *avctx)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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. ...
struct TiffContext TiffContext
static av_cold int tiff_end(AVCodecContext *avctx)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
static int tiff_decode_tag(TiffContext *s)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr, int opts)
unpack data compressed with CCITT Group 3 1/2-D or Group 4 method
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...
int width
picture width / height.
static unsigned tget(GetByteContext *gb, int type, int le)
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
TiffCompr
list of TIFF compression types
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, GetByteContext *g, unsigned int size)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
common internal and external API header
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
8 bit with PIX_FMT_RGB32 palette
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
CCITT Fax Group 3 and 4 decompression.