FFmpeg
exr.c File Reference

OpenEXR decoder. More...

`#include <float.h>`
`#include <zlib.h>`
`#include "libavutil/imgutils.h"`
`#include "libavutil/intfloat.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  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 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 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 (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_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.

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

 #define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP   0x38000000

Definition at line 118 of file exr.c.

Referenced by exr_half2float().

 #define HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP   0x47800000

Definition at line 122 of file exr.c.

 #define FLOAT_MAX_BIASED_EXP   (0xFF << 23)

Definition at line 125 of file exr.c.

Referenced by exr_half2float().

 #define HALF_FLOAT_MAX_BIASED_EXP   (0x1F << 10)

Definition at line 127 of file exr.c.

Referenced by exr_half2float().

 #define USHORT_RANGE   (1 << 16)

Definition at line 312 of file exr.c.

Referenced by reverse_lut().

 #define BITMAP_SIZE   (1 << 13)

Definition at line 313 of file exr.c.

Referenced by piz_uncompress().

 #define HUF_ENCBITS   16

Definition at line 338 of file exr.c.

 #define HUF_DECBITS   14

Definition at line 339 of file exr.c.

Referenced by huf_build_dec_table(), and huf_decode().

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

Definition at line 341 of file exr.c.

Referenced by huf_canonical_code_table(), and huf_uncompress().

 #define HUF_DECSIZE   (1 << HUF_DECBITS)

Definition at line 342 of file exr.c.

Referenced by huf_uncompress().

Definition at line 343 of file exr.c.

Referenced by huf_decode().

 #define SHORT_ZEROCODE_RUN   59

Definition at line 374 of file exr.c.

Referenced by huf_unpack_enc_table().

 #define LONG_ZEROCODE_RUN   63

Definition at line 375 of file exr.c.

Referenced by huf_unpack_enc_table().

 #define SHORTEST_LONG_RUN   (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)

Definition at line 376 of file exr.c.

Referenced by huf_unpack_enc_table().

 #define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)

Definition at line 377 of file exr.c.

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

Definition at line 456 of file exr.c.

Referenced by huf_decode().

 #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 { \
} \
}
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define get_char(c, lc, gb)
Definition: exr.c:456
return
if(ret< 0)
Definition: vf_mcdeint.c:280
static double c
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out

Definition at line 462 of file exr.c.

Referenced by huf_decode().

 #define NBITS   16

Definition at line 617 of file exr.c.

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

Definition at line 618 of file exr.c.

Referenced by wdec16().

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

Definition at line 619 of file exr.c.

Referenced by wdec16().

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

Definition at line 1423 of file exr.c.

 #define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM

Definition at line 1424 of file exr.c.

## Enumeration Type Documentation

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

Definition at line 48 of file exr.c.

 enum ExrPixelType
Enumerator
EXR_UINT
EXR_HALF
EXR_FLOAT
EXR_UNKNOWN

Definition at line 60 of file exr.c.

## Function Documentation

 static union av_intfloat32 exr_half2float ( uint16_t hf )
static

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

Parameters
 hf half float as uint16_t
Returns
float value

Definition at line 136 of file exr.c.

Referenced by decode_init().

 static uint16_t exr_flt2uint ( uint32_t v )
inlinestatic

Convert from 32-bit float as uint32_t to uint16_t.

Parameters
 v 32-bit float
Returns
normalized 16-bit unsigned int

Definition at line 187 of file exr.c.

Referenced by decode_block(), and decode_init().

 static uint16_t exr_halflt2uint ( uint16_t v )
inlinestatic

Convert from 16-bit float as uint16_t to uint16_t.

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

Definition at line 207 of file exr.c.

Referenced by decode_block(), and decode_init().

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

Definition at line 232 of file exr.c.

Referenced by rle_uncompress(), and zip_uncompress().

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

Definition at line 252 of file exr.c.

Referenced by decode_block().

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

Definition at line 267 of file exr.c.

Referenced by decode_block().

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

Definition at line 315 of file exr.c.

Referenced by piz_uncompress().

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

Definition at line 330 of file exr.c.

Referenced by piz_uncompress().

 static void huf_canonical_code_table ( uint64_t * hcode )
static

Definition at line 351 of file exr.c.

Referenced by 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 379 of file exr.c.

Referenced by huf_uncompress().

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

Definition at line 419 of file exr.c.

Referenced by huf_uncompress().

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

Referenced by huf_uncompress().

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

Definition at line 553 of file exr.c.

Referenced by piz_uncompress().

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

Definition at line 604 of file exr.c.

Referenced by wav_decode().

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

Definition at line 621 of file exr.c.

Referenced by wav_decode().

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

Definition at line 631 of file exr.c.

Referenced by piz_uncompress().

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

Definition at line 710 of file exr.c.

Referenced by decode_block().

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

Definition at line 773 of file exr.c.

Referenced by decode_block().

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

Definition at line 827 of file exr.c.

Referenced by decode_frame().

 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
 s the EXRContext value_name name of the variable to check value_type type of the variable to check minimum_length minimum 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 979 of file exr.c.

 static int decode_header ( EXRContext * s )
static

Definition at line 1008 of file exr.c.

Referenced by decode_frame().

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

Definition at line 1257 of file exr.c.

 static av_cold int decode_init ( AVCodecContext * avctx )
static

Definition at line 1361 of file exr.c.

 static int decode_init_thread_copy ( AVCodecContext * avctx )
static

Definition at line 1394 of file exr.c.

 static av_cold int decode_end ( AVCodecContext * avctx )
static

Definition at line 1405 of file exr.c.

## Variable Documentation

 const AVOption options[]
static
Initial value:
= {
{ "layer", "Set the decoding layer", OFFSET(layer),
AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
{ "gamma", "Set the float gamma value when decoding", OFFSET(gamma),
AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define VD
Definition: exr.c:1424
#define OFFSET(x)
Definition: exr.c:1423

Definition at line 1425 of file exr.c.

 const AVClass exr_class
static
Initial value:
= {
.class_name = "EXR",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
static const AVOption options[]
Definition: exr.c:1425
av_default_item_name

Definition at line 1433 of file exr.c.

 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,
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
Definition: exr.c:1394
static av_cold int decode_init(AVCodecContext *avctx)
Definition: exr.c:1361
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
Definition: avcodec.h:920
Define a function with only the non-default version specified.
Definition: internal.h:214
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:924
static av_cold int decode_end(AVCodecContext *avctx)
Definition: exr.c:1405
Definition: exr.c:83
{"ft_lang_label":"__label__en","ft_lang_prob":0.5245773,"math_prob":0.8959165,"size":8759,"snap":"2021-43-2021-49","text_gpt3_token_len":2674,"char_repetition_ratio":0.22444318,"word_repetition_ratio":0.21389891,"special_character_ratio":0.3006051,"punctuation_ratio":0.18608059,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9623315,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-06T00:31:44Z\",\"WARC-Record-ID\":\"<urn:uuid:ab2dfb01-75df-42fb-8fae-906ed6d719bb>\",\"Content-Length\":\"124238\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:221681c5-3c90-4004-98af-5c564636dc6a>\",\"WARC-Concurrent-To\":\"<urn:uuid:93fc1a61-bc2e-40ac-ba67-3e3cc83139a3>\",\"WARC-IP-Address\":\"79.124.17.100\",\"WARC-Target-URI\":\"http://ffmpeg.org/doxygen/2.8/exr_8c.html\",\"WARC-Payload-Digest\":\"sha1:QU3KYOG2WRAGF5LXJPUDPCTRLU6X4D6M\",\"WARC-Block-Digest\":\"sha1:MLN6GASPJJRH534AV53FUHELIJ6IYBK5\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363226.68_warc_CC-MAIN-20211205221915-20211206011915-00173.warc.gz\"}"}