119 switch (
s->compression) {
123 s->scanline_height = 1;
124 s->nb_scanlines = avctx->
height;
127 s->scanline_height = 16;
128 s->nb_scanlines = (avctx->
height +
s->scanline_height - 1) /
s->scanline_height;
134 s->scanline =
av_calloc(
s->nb_scanlines,
sizeof(*
s->scanline));
145 for (
int y = 0; y <
s->nb_scanlines &&
s->scanline; y++) {
160 const ptrdiff_t half_size = (
size + 1) / 2;
162 uint8_t *t2 =
dst + half_size;
164 for (ptrdiff_t
i = 0;
i < half_size;
i++) {
174 for (ptrdiff_t
i = 1;
i <
size;
i++) {
175 int d =
src[
i] - p + 384;
183 const uint8_t *in,
int64_t in_size)
187 while (
i < in_size) {
188 while (
i +
run < in_size && in[
i] == in[
i +
run] &&
run < 128)
198 if (
i +
run < in_size)
207 for (
int x = 0; x <
copy; x++)
208 out[o + x] = in[
i + x];
225 for (
int y = 0; y <
frame->height; y++) {
228 int64_t max_compressed_size = tmp_size * 3 / 2;
242 switch (
s->pixel_type) {
244 for (
int p = 0; p <
s->planes; p++) {
245 int ch =
s->ch_order[p];
252 for (
int p = 0; p <
s->planes; p++) {
253 int ch =
s->ch_order[p];
255 const uint32_t *
src = (
const uint32_t *)(
frame->data[ch] + y *
frame->linesize[ch]);
257 for (
int x = 0; x <
frame->width; x++)
267 scanline->
tmp, tmp_size);
283 for (
int y = 0; y <
s->nb_scanlines; y++) {
285 const int scanline_height =
FFMIN(
s->scanline_height,
frame->height - y *
s->scanline_height);
286 int64_t tmp_size = element_size *
s->planes *
frame->width * scanline_height;
287 int64_t max_compressed_size = tmp_size * 3 / 2;
288 unsigned long actual_size, source_size;
302 switch (
s->pixel_type) {
304 for (
int l = 0; l < scanline_height; l++) {
305 const int scanline_size =
frame->width * 4 *
s->planes;
307 for (
int p = 0; p <
s->planes; p++) {
308 int ch =
s->ch_order[p];
311 frame->data[ch] + (y *
s->scanline_height + l) *
frame->linesize[ch],
317 for (
int l = 0; l < scanline_height; l++) {
318 const int scanline_size =
frame->width * 2 *
s->planes;
320 for (
int p = 0; p <
s->planes; p++) {
321 int ch =
s->ch_order[p];
323 const uint32_t *
src = (
const uint32_t *)(
frame->data[ch] + (y *
s->scanline_height + l) *
frame->linesize[ch]);
325 for (
int x = 0; x <
frame->width; x++)
334 source_size = tmp_size;
335 actual_size = max_compressed_size;
337 scanline->
tmp, source_size);
360 avctx->
height, 64) * 3LL / 2;
367 bytestream2_put_le32(pb, 20000630);
368 bytestream2_put_byte(pb, 2);
369 bytestream2_put_le24(pb, 0);
371 bytestream2_put_le32(pb,
s->planes * 18 + 1);
373 for (
int p = 0; p <
s->planes; p++) {
374 bytestream2_put_byte(pb,
s->ch_names[p]);
375 bytestream2_put_byte(pb, 0);
376 bytestream2_put_le32(pb,
s->pixel_type);
377 bytestream2_put_le32(pb, 0);
378 bytestream2_put_le32(pb, 1);
379 bytestream2_put_le32(pb, 1);
381 bytestream2_put_byte(pb, 0);
384 bytestream2_put_le32(pb, 1);
385 bytestream2_put_byte(pb,
s->compression);
388 bytestream2_put_le32(pb, 16);
389 bytestream2_put_le32(pb, 0);
390 bytestream2_put_le32(pb, 0);
391 bytestream2_put_le32(pb, avctx->
width - 1);
392 bytestream2_put_le32(pb, avctx->
height - 1);
395 bytestream2_put_le32(pb, 16);
396 bytestream2_put_le32(pb, 0);
397 bytestream2_put_le32(pb, 0);
398 bytestream2_put_le32(pb, avctx->
width - 1);
399 bytestream2_put_le32(pb, avctx->
height - 1);
402 bytestream2_put_le32(pb, 1);
403 bytestream2_put_byte(pb, 0);
406 bytestream2_put_le32(pb, 8);
407 bytestream2_put_le64(pb, 0);
410 bytestream2_put_le32(pb, 4);
415 bytestream2_put_le32(pb, 4);
421 bytestream2_put_le32(pb, 8);
427 bytestream2_put_le32(pb, 4);
431 bytestream2_put_le32(pb, 4);
433 bytestream2_put_byte(pb, 0);
435 switch (
s->compression) {
450 switch (
s->compression) {
456 for (
int y = 0; y < avctx->
height; y++) {
457 bytestream2_put_le64(pb,
offset);
461 for (
int y = 0; y < avctx->
height; y++) {
462 bytestream2_put_le32(pb, y);
463 bytestream2_put_le32(pb,
s->planes * avctx->
width * 4);
464 for (
int p = 0; p <
s->planes; p++) {
465 int ch =
s->ch_order[p];
471 for (
int y = 0; y < avctx->
height; y++) {
472 bytestream2_put_le64(pb,
offset);
476 for (
int y = 0; y < avctx->
height; y++) {
477 bytestream2_put_le32(pb, y);
478 bytestream2_put_le32(pb,
s->planes * avctx->
width * 2);
479 for (
int p = 0; p <
s->planes; p++) {
480 int ch =
s->ch_order[p];
481 const uint32_t *
src = (
const uint32_t *)(
frame->data[ch] + y *
frame->linesize[ch]);
483 for (
int x = 0; x <
frame->width; x++)
494 for (
int y = 0; y <
s->nb_scanlines; y++) {
497 bytestream2_put_le64(pb,
offset);
501 for (
int y = 0; y <
s->nb_scanlines; y++) {
504 bytestream2_put_le32(pb, y *
s->scanline_height);
521#define OFFSET(x) offsetof(EXRContext, x)
522#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_exr_encoder
static av_cold int encode_init(AVCodecContext *avctx)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
static av_cold int encode_close(AVCodecContext *avctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static const AVClass exr_class
static const uint8_t gbra_order[4]
static int encode_scanline_zip(EXRContext *s, const AVFrame *frame)
static const char bgr_chlist[4]
static void reorder_pixels(uint8_t *dst, const uint8_t *src, ptrdiff_t size)
static void predictor(uint8_t *src, ptrdiff_t size)
static const char abgr_chlist[4]
static const uint8_t y_order[4]
static av_cold int encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static int encode_scanline_rle(EXRContext *s, const AVFrame *frame)
static const uint8_t gbr_order[4]
static int64_t rle_compress(uint8_t *out, int64_t out_size, const uint8_t *in, int64_t in_size)
static const char y_chlist[4]
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
static uint16_t float2half(uint32_t f, const Float2HalfTables *t)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
#define LIBAVUTIL_VERSION_INT
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
void ff_init_float2half_tables(Float2HalfTables *t)
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define AV_PIX_FMT_GBRPF32
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
#define AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GBRAPF32
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Float2HalfTables f2h_tables
enum ExrCompr compression
enum ExrPixelType pixel_type
EXRScanlineData * scanline
unsigned int uncompressed_size
uint8_t * compressed_data
uint8_t * uncompressed_data
unsigned int compressed_size
static void copy(const float *p1, float *p2, const int length)