FFmpeg
Loading...
Searching...
No Matches
hdrenc.c
Go to the documentation of this file.
1/*
2 * Radiance HDR image format
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/mem.h"
22#include "avcodec.h"
23#include "bytestream.h"
24#include "codec_internal.h"
25#include "encode.h"
26
27typedef struct HDREncContext {
28 uint8_t *scanline;
30
32{
33 HDREncContext *s = avctx->priv_data;
34
35 s->scanline = av_calloc(avctx->width * 4, sizeof(*s->scanline));
36 if (!s->scanline)
37 return AVERROR(ENOMEM);
38
39 return 0;
40}
41
43{
44 HDREncContext *s = avctx->priv_data;
45
46 av_freep(&s->scanline);
47
48 return 0;
49}
50
51static void bytestream_put_str(uint8_t **buf, const char *const line)
52{
53 bytestream_put_buffer(buf, line, strlen(line));
54}
55
56static void float2rgbe(uint8_t *rgbe, float red, float green, float blue)
57{
58 float v;
59 int e;
60
61 v = FFMAX3(red, green, blue);
62
63 if (v < 1e-32f) {
64 rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;