FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
exr.c File Reference
#include <float.h>
#include <zlib.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/intfloat.h"
#include "libavutil/opt.h"
#include "libavutil/color_utils.h"
#include "avcodec.h"
#include "bytestream.h"
#include "exrdsp.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  EXRTileAttribute
 
struct  EXRThreadData
 
struct  EXRContext
 
struct  HufDec
 

Macros

#define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP   0x38000000
 
#define HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP   0x47800000
 
#define FLOAT_MAX_BIASED_EXP   (0xFF << 23)
 
#define HALF_FLOAT_MAX_BIASED_EXP   (0x1F << 10)
 
#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, outb)
 
#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_DWA, EXR_DWB, EXR_UNKN
}
 
enum  ExrPixelType { EXR_UINT, EXR_HALF, EXR_FLOAT, EXR_UNKNOWN }
 
enum  ExrTileLevelMode { EXR_TILE_LEVEL_ONE, EXR_TILE_LEVEL_MIPMAP, EXR_TILE_LEVEL_RIPMAP, EXR_TILE_LEVEL_UNKNOWN }
 
enum  ExrTileLevelRound { EXR_TILE_ROUND_UP, EXR_TILE_ROUND_DOWN, EXR_TILE_ROUND_UNKNOWN }
 

Functions

static union av_intfloat32 exr_half2float (uint16_t hf)
 Convert a half float as a uint16_t into a full float. More...
 
static uint16_t exr_flt2uint (int32_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 int zip_uncompress (EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static int rle_uncompress (EXRContext *ctx, 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 void unpack_14 (const uint8_t b[14], uint16_t s[16])
 
static void unpack_3 (const uint8_t b[3], uint16_t s[16])
 
static int b44_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, AVFrame *frame)
 
static int decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
static av_cold int decode_init (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. exr_half2float() is credited to Aaftab Munshi, Dan Ginsburg, Dave Shreiner.

Definition in file exr.c.

Macro Definition Documentation

◆ HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP

#define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP   0x38000000

Definition at line 166 of file exr.c.

◆ HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP

#define HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP   0x47800000

Definition at line 170 of file exr.c.

◆ FLOAT_MAX_BIASED_EXP

#define FLOAT_MAX_BIASED_EXP   (0xFF << 23)

Definition at line 173 of file exr.c.

◆ HALF_FLOAT_MAX_BIASED_EXP

#define HALF_FLOAT_MAX_BIASED_EXP   (0x1F << 10)

Definition at line 175 of file exr.c.

◆ USHORT_RANGE

#define USHORT_RANGE   (1 << 16)

Definition at line 332 of file exr.c.

◆ BITMAP_SIZE

#define BITMAP_SIZE   (1 << 13)

Definition at line 333 of file exr.c.

◆ HUF_ENCBITS

#define HUF_ENCBITS   16

Definition at line 358 of file exr.c.

◆ HUF_DECBITS

#define HUF_DECBITS   14

Definition at line 359 of file exr.c.

◆ HUF_ENCSIZE

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

Definition at line 361 of file exr.c.

◆ HUF_DECSIZE

#define HUF_DECSIZE   (1 << HUF_DECBITS)

Definition at line 362 of file exr.c.

◆ HUF_DECMASK

#define HUF_DECMASK   (HUF_DECSIZE - 1)

Definition at line 363 of file exr.c.

◆ SHORT_ZEROCODE_RUN

#define SHORT_ZEROCODE_RUN   59

Definition at line 394 of file exr.c.

◆ LONG_ZEROCODE_RUN

#define LONG_ZEROCODE_RUN   63

Definition at line 395 of file exr.c.

◆ SHORTEST_LONG_RUN

#define SHORTEST_LONG_RUN   (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)

Definition at line 396 of file exr.c.

◆ LONGEST_LONG_RUN

#define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)

Definition at line 397 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 476 of file exr.c.

◆ get_code

#define get_code (   po,
  rlc,
  c,
  lc,
  gb,
  out,
  oe,
  outb 
)
Value:
{ \
if (po == rlc) { \
if (lc < 8) \
get_char(c, lc, gb); \
lc -= 8; \
\
cs = c >> lc; \
if (out + cs > oe || out == outb) \
\
s = out[-1]; \
\
while (cs-- > 0) \
*out++ = s; \
} else if (out < oe) { \
*out++ = po; \
} else { \
} \
}

Definition at line 482 of file exr.c.

◆ NBITS

#define NBITS   16

Definition at line 638 of file exr.c.

◆ A_OFFSET

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

Definition at line 639 of file exr.c.

◆ MOD_MASK

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

Definition at line 640 of file exr.c.

◆ OFFSET

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

Definition at line 1919 of file exr.c.

◆ VD

Definition at line 1920 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_DWA 
EXR_DWB 
EXR_UNKN 

Definition at line 60 of file exr.c.

◆ ExrPixelType

Enumerator
EXR_UINT 
EXR_HALF 
EXR_FLOAT 
EXR_UNKNOWN 

Definition at line 74 of file exr.c.

◆ ExrTileLevelMode

Enumerator
EXR_TILE_LEVEL_ONE 
EXR_TILE_LEVEL_MIPMAP 
EXR_TILE_LEVEL_RIPMAP 
EXR_TILE_LEVEL_UNKNOWN 

Definition at line 81 of file exr.c.

◆ ExrTileLevelRound

Enumerator
EXR_TILE_ROUND_UP 
EXR_TILE_ROUND_DOWN 
EXR_TILE_ROUND_UNKNOWN 

Definition at line 88 of file exr.c.

Function Documentation

◆ exr_half2float()

static union av_intfloat32 exr_half2float ( uint16_t  hf)
static

Convert a half float as a uint16_t into a full float.

Parameters
hfhalf float as uint16_t
Returns
float value

Definition at line 184 of file exr.c.

Referenced by decode_init().

◆ exr_flt2uint()

static uint16_t exr_flt2uint ( int32_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 235 of file exr.c.

Referenced by decode_block(), and decode_init().

◆ 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 255 of file exr.c.

Referenced by decode_block(), and decode_init().

◆ zip_uncompress()

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

Definition at line 268 of file exr.c.

Referenced by decode_block().

◆ rle_uncompress()

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

Definition at line 285 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 335 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 350 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 371 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 399 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 439 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 505 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 574 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 625 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 642 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 652 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 731 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 816 of file exr.c.

Referenced by decode_block().

◆ unpack_14()

static void unpack_14 ( const uint8_t  b[14],
uint16_t  s[16] 
)
static

Definition at line 900 of file exr.c.

Referenced by b44_uncompress().

◆ unpack_3()

static void unpack_3 ( const uint8_t  b[3],
uint16_t  s[16] 
)
static

Definition at line 935 of file exr.c.

Referenced by b44_uncompress().

◆ b44_uncompress()

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

Definition at line 951 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 1028 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 1281 of file exr.c.

Referenced by decode_header().

◆ decode_header()

static int decode_header ( EXRContext s,
AVFrame frame 
)
static

Definition at line 1310 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 1689 of file exr.c.

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 1839 of file exr.c.

◆ decode_end()

static av_cold int decode_end ( AVCodecContext avctx)
static

Definition at line 1901 of file exr.c.

Variable Documentation

◆ options

const AVOption options[]
static

Definition at line 1921 of file exr.c.

◆ exr_class

const AVClass exr_class
static
Initial value:
= {
.class_name = "EXR",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1966 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),
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
.close = decode_end,
.decode = decode_frame,
.priv_class = &exr_class,
}

Definition at line 1973 of file exr.c.

init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
out
FILE * out
Definition: movenc.c:54
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: exr.c:1839
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: exr.c:1689
options
static const AVOption options[]
Definition: exr.c:1921
decode_end
static av_cold int decode_end(AVCodecContext *avctx)
Definition: exr.c:1901
s
#define s(width, name)
Definition: cbs_vp9.c:257
if
if(ret)
Definition: filter_design.txt:179
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1037
AV_CODEC_ID_EXR
@ AV_CODEC_ID_EXR
Definition: avcodec.h:398
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
ONLY_IF_THREADS_ENABLED
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:227
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
init_thread_copy
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have add an init_thread_copy() which re-allocates them for other threads. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. If there are inter-frame dependencies
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:1041
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
exr_class
static const AVClass exr_class
Definition: exr.c:1966
EXRContext
Definition: exr.c:121