FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
exr.c File Reference

OpenEXR decoder. More...

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

Go to the source code of this file.

Data Structures

struct  EXRChannel
 
struct  EXRThreadData
 
struct  EXRContext
 
struct  HufDec
 

Macros

#define OFFSET(x)   offsetof(EXRContext, x)
 
#define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
#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)
 

Enumerations

enum  ExrCompr {
  EXR_RAW = 0, EXR_RLE = 1, EXR_ZIP1 = 2, EXR_ZIP16 = 3,
  EXR_PIZ = 4, EXR_PXR24 = 5, EXR_B44 = 6, EXR_B44A = 7
}
 
enum  ExrPixelType { EXR_UINT, EXR_HALF, EXR_FLOAT }
 

Functions

static uint16_t exr_flt2uint (uint32_t v)
 Converts from 32-bit float as uint32_t to uint16_t.
 
static uint16_t exr_halflt2uint (uint16_t v)
 Converts from 16-bit float as uint16_t to uint16_t.
 
static unsigned int get_header_variable_length (const uint8_t **buf, const uint8_t *buf_end)
 Gets the size of the header variable.
 
static int check_header_variable (AVCodecContext *avctx, const uint8_t **buf, const uint8_t *buf_end, const char *value_name, const char *value_type, unsigned int minimum_length, unsigned int *variable_buffer_data_size)
 Checks if the variable name corresponds with it's data type.
 
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 decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
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

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

Definition at line 107 of file exr.c.

Definition at line 108 of file exr.c.

#define USHORT_RANGE   (1 << 16)

Definition at line 303 of file exr.c.

Referenced by reverse_lut().

#define BITMAP_SIZE   (1 << 13)

Definition at line 304 of file exr.c.

Referenced by piz_uncompress().

#define HUF_ENCBITS   16

Definition at line 330 of file exr.c.

#define HUF_DECBITS   14

Definition at line 331 of file exr.c.

Referenced by huf_build_dec_table(), and huf_decode().

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

Definition at line 333 of file exr.c.

Referenced by huf_canonical_code_table(), and huf_uncompress().

#define HUF_DECSIZE   (1 << HUF_DECBITS)

Definition at line 334 of file exr.c.

Referenced by huf_uncompress().

#define HUF_DECMASK   (HUF_DECSIZE - 1)

Definition at line 335 of file exr.c.

Referenced by huf_decode().

#define SHORT_ZEROCODE_RUN   59

Definition at line 366 of file exr.c.

Referenced by huf_unpack_enc_table().

#define LONG_ZEROCODE_RUN   63

Definition at line 367 of file exr.c.

Referenced by huf_unpack_enc_table().

#define SHORTEST_LONG_RUN   (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)

Definition at line 368 of file exr.c.

Referenced by huf_unpack_enc_table().

#define LONGEST_LONG_RUN   (255 + SHORTEST_LONG_RUN)

Definition at line 369 of file exr.c.

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

Definition at line 447 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 { \
} \
}

Definition at line 452 of file exr.c.

Referenced by huf_decode().

#define NBITS   16

Definition at line 607 of file exr.c.

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

Definition at line 608 of file exr.c.

Referenced by wdec16().

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

Definition at line 609 of file exr.c.

Referenced by wdec16().

Enumeration Type Documentation

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

Definition at line 45 of file exr.c.

Enumerator:
EXR_UINT 
EXR_HALF 
EXR_FLOAT 

Definition at line 56 of file exr.c.

Function Documentation

static uint16_t exr_flt2uint ( uint32_t  v)
inlinestatic

Converts from 32-bit float as uint32_t to uint16_t.

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

Definition at line 127 of file exr.c.

Referenced by decode_block().

static uint16_t exr_halflt2uint ( uint16_t  v)
inlinestatic

Converts from 16-bit float as uint16_t to uint16_t.

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

Definition at line 146 of file exr.c.

Referenced by decode_block().

static unsigned int get_header_variable_length ( const uint8_t **  buf,
const uint8_t buf_end 
)
static

Gets the size of the header variable.

Parameters
**bufthe current pointer location in the header where the variable data starts
*buf_endpointer location of the end of the buffer
Returns
size of variable data

Definition at line 165 of file exr.c.

Referenced by check_header_variable(), and decode_frame().

static int check_header_variable ( AVCodecContext avctx,
const uint8_t **  buf,
const uint8_t buf_end,
const char *  value_name,
const char *  value_type,
unsigned int  minimum_length,
unsigned int *  variable_buffer_data_size 
)
static

Checks if the variable name corresponds with it's data type.

Parameters
*avctxthe AVCodecContext
**bufthe current pointer location in the header where the variable name starts
*buf_endpointer location of the end of the buffer
*value_namename of the varible to check
*value_typetype of the varible to check
minimum_lengthminimum length of the variable data
variable_buffer_data_sizevariable length read from the header after it's checked
Returns
negative if variable is invalid

Definition at line 188 of file exr.c.

Referenced by decode_frame().

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 223 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 243 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 258 of file exr.c.

Referenced by decode_block().

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

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

Referenced by piz_uncompress().

static void huf_canonical_code_table ( uint64_t *  hcode)
static

Definition at line 343 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 371 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 410 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 474 of file exr.c.

Referenced by huf_uncompress().

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

Definition at line 542 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 594 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 611 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 621 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 700 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 758 of file exr.c.

Referenced by decode_block().

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

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

static av_cold int decode_end ( AVCodecContext avctx)
static

Definition at line 1279 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},
{ NULL },
}

Definition at line 109 of file exr.c.

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

Definition at line 114 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),
.priv_class = &exr_class,
}

Definition at line 1299 of file exr.c.