Libav
Data Structures | Macros | Enumerations | Functions | Variables
exr.c File Reference

OpenEXR decoder. More...

#include <zlib.h>
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
#include "get_bits.h"
#include "internal.h"
#include "mathops.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  EXRChannel
 
struct  EXRThreadData
 
struct  EXRContext
 
struct  HufDec
 

Macros

#define USHORT_RANGE   (1 << 16)
 
#define BITMAP_SIZE   (1 << 13)
 
#define HUF_ENCBITS   16
 
#define HUF_DECBITS   14
 
#define HUF_ENCSIZE   ((1 << HUF_ENCBITS) + 1)
 
#define HUF_DECSIZE   (1 << HUF_DECBITS)
 
#define HUF_DECMASK   (HUF_DECSIZE - 1)
 
#define SHORT_ZEROCODE_RUN   59
 
#define LONG_ZEROCODE_RUN   63
 
#define SHORTEST_LONG_RUN   (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)
 
#define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)
 
#define get_char(c, lc, gb)
 
#define get_code(po, rlc, c, lc, gb, out, oe)
 
#define NBITS   16
 
#define A_OFFSET   (1 << (NBITS - 1))
 
#define MOD_MASK   ((1 << NBITS) - 1)
 
#define OFFSET(x)   offsetof(EXRContext, x)
 
#define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Enumerations

enum  ExrCompr {
  EXR_RAW, EXR_RLE, EXR_ZIP1, EXR_ZIP16,
  EXR_PIZ, EXR_PXR24, EXR_B44, EXR_B44A,
  EXR_UNKN
}
 
enum  ExrPixelType { EXR_UINT, EXR_HALF, EXR_FLOAT, EXR_UNKNOWN }
 

Functions

static uint16_t exr_flt2uint (uint32_t v)
 Convert from 32-bit float as uint32_t to uint16_t. More...
 
static uint16_t exr_halflt2uint (uint16_t v)
 Convert from 16-bit float as uint16_t to uint16_t. More...
 
static void predictor (uint8_t *src, int size)
 
static void reorder_pixels (uint8_t *src, uint8_t *dst, int size)
 
static int zip_uncompress (const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static int rle_uncompress (const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static uint16_t reverse_lut (const uint8_t *bitmap, uint16_t *lut)
 
static void apply_lut (const uint16_t *lut, uint16_t *dst, int dsize)
 
static void huf_canonical_code_table (uint64_t *hcode)
 
static int huf_unpack_enc_table (GetByteContext *gb, int32_t im, int32_t iM, uint64_t *hcode)
 
static int huf_build_dec_table (const uint64_t *hcode, int im, int iM, HufDec *hdecod)
 
static int huf_decode (const uint64_t *hcode, const HufDec *hdecod, GetByteContext *gb, int nbits, int rlc, int no, uint16_t *out)
 
static int huf_uncompress (GetByteContext *gb, uint16_t *dst, int dst_size)
 
static void wdec14 (uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
 
static void wdec16 (uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
 
static void wav_decode (uint16_t *in, int nx, int ox, int ny, int oy, uint16_t mx)
 
static int piz_uncompress (EXRContext *s, const uint8_t *src, int ssize, int dsize, EXRThreadData *td)
 
static int pxr24_uncompress (EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static int decode_block (AVCodecContext *avctx, void *tdata, int jobnr, int threadnr)
 
static int check_header_variable (EXRContext *s, const char *value_name, const char *value_type, unsigned int minimum_length)
 Check if the variable name corresponds to its data type. More...
 
static int decode_header (EXRContext *s)
 
static int decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
static av_cold int decode_init (AVCodecContext *avctx)
 
static int decode_init_thread_copy (AVCodecContext *avctx)
 
static av_cold int decode_end (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass exr_class
 
AVCodec ff_exr_decoder
 

Detailed Description

OpenEXR decoder.

Author
Jimmy Christensen

For more information on the OpenEXR format, visit: http://openexr.com/

exr_flt2uint() and exr_halflt2uint() is credited to Reimar Döffinger

Definition in file exr.c.

Macro Definition Documentation

§ USHORT_RANGE

#define USHORT_RANGE   (1 << 16)

Definition at line 243 of file exr.c.

Referenced by reverse_lut().

§ BITMAP_SIZE

#define BITMAP_SIZE   (1 << 13)

Definition at line 244 of file exr.c.

Referenced by piz_uncompress().

§ HUF_ENCBITS

#define HUF_ENCBITS   16

Definition at line 269 of file exr.c.

§ HUF_DECBITS

#define HUF_DECBITS   14

Definition at line 270 of file exr.c.

Referenced by huf_build_dec_table(), and huf_decode().

§ HUF_ENCSIZE

#define HUF_ENCSIZE   ((1 << HUF_ENCBITS) + 1)

Definition at line 272 of file exr.c.

Referenced by huf_canonical_code_table(), and huf_uncompress().

§ HUF_DECSIZE

#define HUF_DECSIZE   (1 << HUF_DECBITS)

Definition at line 273 of file exr.c.

Referenced by huf_uncompress().

§ HUF_DECMASK

#define HUF_DECMASK   (HUF_DECSIZE - 1)

Definition at line 274 of file exr.c.

Referenced by huf_decode().

§ SHORT_ZEROCODE_RUN

#define SHORT_ZEROCODE_RUN   59

Definition at line 305 of file exr.c.

Referenced by huf_unpack_enc_table().

§ LONG_ZEROCODE_RUN

#define LONG_ZEROCODE_RUN   63

Definition at line 306 of file exr.c.

Referenced by huf_unpack_enc_table().

§ SHORTEST_LONG_RUN

#define SHORTEST_LONG_RUN   (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)

Definition at line 307 of file exr.c.

Referenced by huf_unpack_enc_table().

§ LONGEST_LONG_RUN

#define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)

Definition at line 308 of file exr.c.

§ get_char

#define get_char (   c,
  lc,
  gb 
)
Value:
{ \
c = (c << 8) | bytestream2_get_byte(gb); \
lc += 8; \
}

Definition at line 386 of file exr.c.

Referenced by huf_decode().

§ get_code

#define get_code (   po,
  rlc,
  c,
  lc,
  gb,
  out,
  oe 
)
Value:
{ \
if (po == rlc) { \
if (lc < 8) \
get_char(c, lc, gb); \
lc -= 8; \
\
cs = c >> lc; \
if (out + cs > oe) \
\
s = out[-1]; \
\
while (cs-- > 0) \
*out++ = s; \
} else if (out < oe) { \
*out++ = po; \
} else { \
} \
}
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
if(ac->has_optimized_func)

Definition at line 392 of file exr.c.

Referenced by huf_decode().

§ NBITS

#define NBITS   16

Definition at line 547 of file exr.c.

§ A_OFFSET

#define A_OFFSET   (1 << (NBITS - 1))

Definition at line 548 of file exr.c.

Referenced by wdec16().

§ MOD_MASK

#define MOD_MASK   ((1 << NBITS) - 1)

Definition at line 549 of file exr.c.

Referenced by wdec16().

§ OFFSET

#define OFFSET (   x)    offsetof(EXRContext, x)

Definition at line 1320 of file exr.c.

§ VD

Definition at line 1321 of file exr.c.

Enumeration Type Documentation

§ ExrCompr

enum ExrCompr
Enumerator
EXR_RAW 
EXR_RLE 
EXR_ZIP1 
EXR_ZIP16 
EXR_PIZ 
EXR_PXR24 
EXR_B44 
EXR_B44A 
EXR_UNKN 

Definition at line 45 of file exr.c.

§ ExrPixelType

Enumerator
EXR_UINT 
EXR_HALF 
EXR_FLOAT 
EXR_UNKNOWN 

Definition at line 57 of file exr.c.

Function Documentation

§ exr_flt2uint()

static uint16_t exr_flt2uint ( uint32_t  v)
inlinestatic

Convert from 32-bit float as uint32_t to uint16_t.

Parameters
v32-bit float
Returns
normalized 16-bit unsigned int

Definition at line 118 of file exr.c.

Referenced by decode_block().

§ exr_halflt2uint()

static uint16_t exr_halflt2uint ( uint16_t  v)
inlinestatic

Convert from 16-bit float as uint16_t to uint16_t.

Parameters
v16-bit float
Returns
normalized 16-bit unsigned int

Definition at line 138 of file exr.c.

Referenced by decode_block().

§ predictor()

static void predictor ( uint8_t src,
int  size 
)
static

§ reorder_pixels()

static void reorder_pixels ( uint8_t src,
uint8_t dst,
int  size 
)
static

Definition at line 163 of file exr.c.

Referenced by rle_uncompress(), and zip_uncompress().

§ zip_uncompress()

static int zip_uncompress ( const uint8_t src,
int  compressed_size,
int  uncompressed_size,
EXRThreadData td 
)
static

Definition at line 183 of file exr.c.

Referenced by decode_block().

§ rle_uncompress()

static int rle_uncompress ( const uint8_t src,
int  compressed_size,
int  uncompressed_size,
EXRThreadData td 
)
static

Definition at line 198 of file exr.c.

Referenced by decode_block().

§ reverse_lut()

static uint16_t reverse_lut ( const uint8_t bitmap,
uint16_t *  lut 
)
static

Definition at line 246 of file exr.c.

Referenced by piz_uncompress().

§ apply_lut()

static void apply_lut ( const uint16_t *  lut,
uint16_t *  dst,
int  dsize 
)
static

Definition at line 261 of file exr.c.

Referenced by piz_uncompress().

§ huf_canonical_code_table()

static void huf_canonical_code_table ( uint64_t *  hcode)
static

Definition at line 282 of file exr.c.

Referenced by huf_unpack_enc_table().

§ huf_unpack_enc_table()

static int huf_unpack_enc_table ( GetByteContext gb,
int32_t  im,
int32_t  iM,
uint64_t *  hcode 
)
static

Definition at line 310 of file exr.c.

Referenced by huf_uncompress().

§ huf_build_dec_table()

static int huf_build_dec_table ( const uint64_t *  hcode,
int  im,
int  iM,
HufDec hdecod 
)
static

Definition at line 349 of file exr.c.

Referenced by huf_uncompress().

§ huf_decode()

static int huf_decode ( const uint64_t *  hcode,
const HufDec hdecod,
GetByteContext gb,
int  nbits,
int  rlc,
int  no,
uint16_t *  out 
)
static

Definition at line 415 of file exr.c.

Referenced by huf_uncompress().

§ huf_uncompress()

static int huf_uncompress ( GetByteContext gb,
uint16_t *  dst,
int  dst_size 
)
static

Definition at line 483 of file exr.c.

Referenced by piz_uncompress().

§ wdec14()

static void wdec14 ( uint16_t  l,
uint16_t  h,
uint16_t *  a,
uint16_t *  b 
)
inlinestatic

Definition at line 534 of file exr.c.

Referenced by wav_decode().

§ wdec16()

static void wdec16 ( uint16_t  l,
uint16_t  h,
uint16_t *  a,
uint16_t *  b 
)
inlinestatic

Definition at line 551 of file exr.c.

Referenced by wav_decode().

§ wav_decode()

static void wav_decode ( uint16_t *  in,
int  nx,
int  ox,
int  ny,
int  oy,
uint16_t  mx 
)
static

Definition at line 561 of file exr.c.

Referenced by piz_uncompress().

§ piz_uncompress()

static int piz_uncompress ( EXRContext s,
const uint8_t src,
int  ssize,
int  dsize,
EXRThreadData td 
)
static

Definition at line 640 of file exr.c.

Referenced by decode_block().

§ pxr24_uncompress()

static int pxr24_uncompress ( EXRContext s,
const uint8_t src,
int  compressed_size,
int  uncompressed_size,
EXRThreadData td 
)
static

Definition at line 703 of file exr.c.

Referenced by decode_block().

§ decode_block()

static int decode_block ( AVCodecContext avctx,
void tdata,
int  jobnr,
int  threadnr 
)
static

Definition at line 757 of file exr.c.

Referenced by decode_frame().

§ check_header_variable()

static int check_header_variable ( EXRContext s,
const char *  value_name,
const char *  value_type,
unsigned int  minimum_length 
)
static

Check if the variable name corresponds to its data type.

Parameters
sthe EXRContext
value_namename of the variable to check
value_typetype of the variable to check
minimum_lengthminimum length of the variable data
Returns
bytes to read containing variable data -1 if variable is not found 0 if buffer ended prematurely

Definition at line 896 of file exr.c.

Referenced by decode_header().

§ decode_header()

static int decode_header ( EXRContext s)
static

Definition at line 925 of file exr.c.

Referenced by decode_frame().

§ decode_frame()

static int decode_frame ( AVCodecContext avctx,
void data,
int *  got_frame,
AVPacket avpkt 
)
static

Definition at line 1158 of file exr.c.

§ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 1262 of file exr.c.

§ decode_init_thread_copy()

static int decode_init_thread_copy ( AVCodecContext avctx)
static

Definition at line 1291 of file exr.c.

§ decode_end()

static av_cold int decode_end ( AVCodecContext avctx)
static

Definition at line 1302 of file exr.c.

Variable Documentation

§ options

const AVOption options[]
static
Initial value:
= {
{ "layer", "Set the decoding layer", OFFSET(layer),
AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
{ NULL },
}
#define VD
Definition: exr.c:1321
#define OFFSET(x)
Definition: exr.c:1320
NULL
Definition: eval.c:55

Definition at line 1322 of file exr.c.

§ exr_class

const AVClass exr_class
static
Initial value:
= {
.class_name = "EXR",
.item_name = av_default_item_name,
.option = options,
}
static const AVOption options[]
Definition: exr.c:1322
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
av_default_item_name
Definition: dnxhdenc.c:52

Definition at line 1328 of file exr.c.

§ ff_exr_decoder

AVCodec ff_exr_decoder
Initial value:
= {
.name = "exr",
.long_name = NULL_IF_CONFIG_SMALL("OpenEXR image"),
.priv_data_size = sizeof(EXRContext),
.close = decode_end,
.decode = decode_frame,
.priv_class = &exr_class,
}
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
static int decode_init_thread_copy(AVCodecContext *avctx)
Definition: exr.c:1291
static av_cold int decode_init(AVCodecContext *avctx)
Definition: exr.c:1262
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:185
static av_cold int decode_end(AVCodecContext *avctx)
Definition: exr.c:1302
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:759
Definition: exr.c:80
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:755
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: exr.c:1158
static const AVClass exr_class
Definition: exr.c:1328

Definition at line 1335 of file exr.c.