FFmpeg
Loading...
Searching...
No Matches
exr.c File Reference

OpenEXR decoder. More...

#include <float.h>
#include <zlib.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/intfloat.h"
#include "libavutil/avstring.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/float2half.h"
#include "libavutil/half2float.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "exrdsp.h"
#include "get_bits.h"
#include "mathops.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  HuffEntry
 
struct  EXRChannel
 
struct  EXRTileAttribute
 
struct  EXRThreadData
 
struct  EXRContext
 

Macros

#define M(chr)
 
#define USHORT_RANGE   (1 << 16)
 
#define BITMAP_SIZE   (1 << 13)
 
#define HUF_ENCBITS   16
 
#define HUF_ENCSIZE   ((1 << HUF_ENCBITS) + 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 NBITS   16
 
#define A_OFFSET   (1 << (NBITS - 1))
 
#define MOD_MASK   ((1 << NBITS) - 1)
 
#define OFFSET(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_DWAA , EXR_DWAB , 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 int zip_uncompress (const EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static int rle (uint8_t *dst, const uint8_t *src, int compressed_size, int uncompressed_size)
 
static int rle_uncompress (const 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 *freq)
 
static int huf_unpack_enc_table (GetByteContext *gb, int32_t im, int32_t iM, uint64_t *freq)
 
static int huf_build_dec_table (const EXRContext *s, EXRThreadData *td, int im, int iM)
 
static int huf_decode (VLC *vlc, GetByteContext *gb, int nbits, int run_sym, int no, uint16_t *out)
 
static int huf_uncompress (const EXRContext *s, EXRThreadData *td, 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 (const EXRContext *s, const uint8_t *src, int ssize, int dsize, EXRThreadData *td)
 
static int pxr24_uncompress (const 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 (const EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
 
static int ac_uncompress (const EXRContext *s, GetByteContext *gb, float *block)
 
static void idct_1d (float *blk, int step)
 
static void dct_inverse (float *block)
 
static void convert (float y, float u, float v, float *b, float *g, float *r)
 
static float to_linear (float x, float scale)
 
static int dwa_uncompress (const 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 void skip_header_chunk (EXRContext *s)
 
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.
 
static int decode_header (EXRContext *s, AVFrame *frame)
 
static int decode_frame (AVCodecContext *avctx, AVFrame *picture, 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
 
const FFCodec ff_exr_decoder
 

Detailed Description

OpenEXR decoder.

Author
Jimmy Christensen

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

Definition in file exr.c.

Macro Definition Documentation

◆ M

◆ USHORT_RANGE

#define USHORT_RANGE   (1 << 16)

Definition at line 274 of file exr.c.

Referenced by reverse_lut().

◆ BITMAP_SIZE

#define BITMAP_SIZE   (1 << 13)

Definition at line 275 of file exr.c.

Referenced by piz_uncompress().

◆ HUF_ENCBITS

#define HUF_ENCBITS   16

Definition at line 300 of file exr.c.

◆ HUF_ENCSIZE

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

Definition at line 301 of file exr.c.

Referenced by huf_canonical_code_table(), and huf_uncompress().

◆ SHORT_ZEROCODE_RUN

#define SHORT_ZEROCODE_RUN   59

Definition at line 326 of file exr.c.

Referenced by huf_unpack_enc_table().

◆ LONG_ZEROCODE_RUN

#define LONG_ZEROCODE_RUN   63

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

Referenced by huf_unpack_enc_table().

◆ LONGEST_LONG_RUN

#define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)

Definition at line 329 of file exr.c.

◆ NBITS

#define NBITS   16

Definition at line 504 of file exr.c.

◆ A_OFFSET

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

Definition at line 505 of file exr.c.

Referenced by wdec16().

◆ MOD_MASK

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

Definition at line 506 of file exr.c.

Referenced by wdec16().

◆ OFFSET

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

Definition at line 2350 of file exr.c.

◆ VD

Definition at line 2351 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_DWAA 
EXR_DWAB 
EXR_UNKN 

Definition at line 61 of file exr.c.

◆ ExrPixelType

Enumerator
EXR_UINT 
EXR_HALF 
EXR_FLOAT 
EXR_UNKNOWN 

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

◆ ExrTileLevelRound

Enumerator
EXR_TILE_ROUND_UP 
EXR_TILE_ROUND_DOWN 
EXR_TILE_ROUND_UNKNOWN 

Definition at line 89 of file exr.c.

Function Documentation

◆ zip_uncompress()

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

Definition at line 200 of file exr.c.

Referenced by decode_block().

◆ rle()

static int rle ( uint8_t * dst,
const uint8_t * src,
int compressed_size,
int uncompressed_size )
static

◆ rle_uncompress()

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

Definition at line 259 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 277 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 292 of file exr.c.

Referenced by check_values(), and piz_uncompress().

◆ huf_canonical_code_table()

static void huf_canonical_code_table ( uint64_t * freq)
static

Definition at line 303 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 * freq )
static

Definition at line 331 of file exr.c.

Referenced by huf_uncompress().

◆ huf_build_dec_table()

static int huf_build_dec_table ( const EXRContext * s,
EXRThreadData * td,
int im,
int iM )
static

Definition at line 374 of file exr.c.

Referenced by huf_uncompress().

◆ huf_decode()

static int huf_decode ( VLC * vlc,
GetByteContext * gb,
int nbits,
int run_sym,
int no,
uint16_t * out )
static

Definition at line 420 of file exr.c.

Referenced by huf_uncompress().

◆ huf_uncompress()

static int huf_uncompress ( const EXRContext * s,
EXRThreadData * td,
GetByteContext * gb,
uint16_t * dst,
int dst_size )
static

Definition at line 449 of file exr.c.

Referenced by dwa_uncompress(), and piz_uncompress().

◆ wdec14()

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

Definition at line 491 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 508 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 518 of file exr.c.

Referenced by piz_uncompress().

◆ piz_uncompress()

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

Definition at line 597 of file exr.c.

Referenced by decode_block().

◆ pxr24_uncompress()

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

Definition at line 686 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 770 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 805 of file exr.c.

Referenced by b44_uncompress().

◆ b44_uncompress()

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

Definition at line 821 of file exr.c.

Referenced by decode_block().

◆ ac_uncompress()

static int ac_uncompress ( const EXRContext * s,
GetByteContext * gb,
float * block )
static

Definition at line 892 of file exr.c.

Referenced by dwa_uncompress().

◆ idct_1d()

static void idct_1d ( float * blk,
int step )
static

Definition at line 913 of file exr.c.

Referenced by dct_inverse().

◆ dct_inverse()

static void dct_inverse ( float * block)
static

Definition at line 957 of file exr.c.

Referenced by dwa_uncompress().

◆ convert()

static void convert ( float y,
float u,
float v,
float * b,
float * g,
float * r )
static

Definition at line 968 of file exr.c.

Referenced by dwa_uncompress(), filter_frame(), and hdr_decode_frame().

◆ to_linear()

static float to_linear ( float x,
float scale )
static

Definition at line 976 of file exr.c.

Referenced by dwa_uncompress().

◆ dwa_uncompress()

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

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

◆ skip_header_chunk()

static void skip_header_chunk ( EXRContext * s)
static

Definition at line 1512 of file exr.c.

Referenced by decode_header().

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

Referenced by decode_header().

◆ decode_header()

static int decode_header ( EXRContext * s,
AVFrame * frame )
static

Definition at line 1571 of file exr.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext * avctx,
AVFrame * picture,
int * got_frame,
AVPacket * avpkt )
static

Definition at line 2083 of file exr.c.

◆ decode_init()

static av_cold int decode_init ( AVCodecContext * avctx)
static

Definition at line 2301 of file exr.c.

◆ decode_end()

static av_cold int decode_end ( AVCodecContext * avctx)
static

Definition at line 2324 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 },
{ "part", "Set the decoding part", OFFSET(selected_part),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VD },
{ NULL },
}
#define VD
Definition amfdec.c:787
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275

Definition at line 2352 of file exr.c.

◆ exr_class

const AVClass exr_class
static
Initial value:
= {
.class_name = "EXR",
.item_name = av_default_item_name,
.option = options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 2360 of file exr.c.

◆ ff_exr_decoder

const FFCodec ff_exr_decoder
Initial value:
= {
.p.name = "exr",
CODEC_LONG_NAME("OpenEXR image"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_EXR,
.priv_data_size = sizeof(EXRContext),
.p.priv_class = &exr_class,
}
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static const AVClass exr_class
Definition exr.c:2360
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_EXR
Definition codec_id.h:229
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static av_cold int decode_end(AVCodecContext *avctx)
Definition 4xm.c:980
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837

Definition at line 2367 of file exr.c.