56static void float2rgbe(uint8_t *rgbe,
float red,
float green,
float blue)
61 v =
FFMAX3(red, green, blue);
64 rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
66 v = frexpf(v, &e) * 256.f / v;
81 int run_count = 0, old_run_count = 0;
87 old_run_count = run_count;
89 while ((beg_run + run_count <
width) && (run_count < 127) &&
90 (
data[beg_run * 4] ==
data[(beg_run + run_count) * 4]))
94 if ((old_run_count > 1) && (old_run_count == beg_run - cur)) {
95 buf[0] = 128 + old_run_count;
96 buf[1] =
data[cur * 4];
101 while (cur < beg_run) {
102 int nonrun_count =
FFMIN(128, beg_run - cur);
103 buf[0] = nonrun_count;
104 bytestream_put_byte(
buffer, buf[0]);
105 for (
int n = 0; n < nonrun_count; n++)
106 bytestream_put_byte(
buffer,
data[(cur + n) * 4]);
111 buf[0] = 128 + run_count;
112 buf[1] =
data[beg_run * 4];
142 for (
int y = 0; y < avctx->
height; y++) {
143 const float *red = (
const float *)(
frame->data[2] + y *
frame->linesize[2]);
144 const float *green = (
const float *)(
frame->data[0] + y *
frame->linesize[0]);
145 const float *blue = (
const float *)(
frame->data[1] + y *
frame->linesize[1]);
147 if (avctx->
width < 8 || avctx->
width > 0x7fff) {
148 for (
int x = 0; x < avctx->
width; x++) {
153 bytestream_put_byte(&buf, 2);
154 bytestream_put_byte(&buf, 2);
155 bytestream_put_byte(&buf, avctx->
width >> 8);
156 bytestream_put_byte(&buf, avctx->
width & 0xFF);
158 for (
int x = 0; x < avctx->
width; x++)
159 float2rgbe(
s->scanline + 4 * x, red[x], green[x], blue[x]);
160 for (
int p = 0; p < 4; p++)
161 rle(&buf,
s->scanline + p, avctx->
width);
const FFCodec ff_hdr_encoder
Libavcodec external API header.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
#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.
@ AV_CODEC_ID_RADIANCE_HDR
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static int hdr_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static av_cold int hdr_encode_init(AVCodecContext *avctx)
static void rle(uint8_t **buffer, const uint8_t *data, int width)
static void float2rgbe(uint8_t *rgbe, float red, float green, float blue)
static void bytestream_put_str(uint8_t **buf, const char *const line)
static av_cold int hdr_encode_close(AVCodecContext *avctx)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define AV_PIX_FMT_GBRPF32
main external API structure.
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.