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
26
30
32 {
34
38
39 return 0;
40 }
41
43 {
45
47
48 return 0;
49 }
50
52 {
54 }
55
56 static 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
64 rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
65 } else {
66 v = frexpf(v, &e) * 256.f / v;
67
72 }
73 }
74
76 {
77 #define MIN_RLE 4
78 int cur = 0;
79
81 int run_count = 0, old_run_count = 0;
82 int beg_run = cur;
83 uint8_t buf[2];
84
86 beg_run += run_count;
87 old_run_count = run_count;
88 run_count = 1;
89 while ((beg_run + run_count <
width) && (run_count < 127) &&
90 (
data[beg_run * 4] ==
data[(beg_run + run_count) * 4]))
91 run_count++;
92 }
93
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];
98 cur = beg_run;
99 }
100
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]);
107 cur += nonrun_count;
108 }
109
111 buf[0] = 128 + run_count;
112 buf[1] =
data[beg_run * 4];
114 cur += run_count;
115 }
116 }
117 }
118
121 {
124 uint8_t *buf;
126
130
141
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]);
146
147 if (avctx->
width < 8 || avctx->
width > 0x7fff) {
148 for (
int x = 0; x < avctx->
width; x++) {
150 buf += 4;
151 }
152 } else {
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);
157
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++)
162 }
163 }
164
166
168
169 *got_packet = 1;
170
171 return 0;
172 }
173
187 };