106 unsigned int exp = v >> 23;
109 if (exp<= 127 + 7 - 24)
114 return (v + (1 << 23)) >> (127 + 7 - exp);
125 unsigned exp = 14 - (v >> 10);
127 if (exp == 14)
return (v >> 9) & 1;
128 else return (v & 0x8000) ? 0 : 0xffff;
131 return (v + (1 << 16)) >> (exp + 1);
145 unsigned int variable_buffer_data_size = bytestream_get_le32(buf);
146 if (variable_buffer_data_size >= buf_end - *buf)
148 return variable_buffer_data_size;
168 const char *value_name,
169 const char *value_type,
170 unsigned int minimum_length,
171 unsigned int *variable_buffer_data_size)
173 if (buf_end - *buf >= minimum_length && !strcmp(*buf, value_name)) {
174 *buf += strlen(value_name)+1;
175 if (!strcmp(*buf, value_type)) {
176 *buf += strlen(value_type)+1;
178 if (!*variable_buffer_data_size)
182 *buf -= strlen(value_name)+1;
194 int d = (int)t[-1] + (
int)t[0] - 128;
202 const int8_t *
t1 =
src;
203 const int8_t *
t2 = src + (size + 1) / 2;
205 int8_t *stop = s +
size;
223 unsigned long dest_len = uncompressed_size;
225 if (uncompress(td->
tmp, &dest_len, src, compressed_size) != Z_OK ||
226 dest_len != uncompressed_size)
238 int8_t *d = (int8_t *)td->
tmp;
239 const int8_t *
s = (
const int8_t *)
src;
240 int ssize = compressed_size;
241 int dsize = uncompressed_size;
242 int8_t *dend = d + dsize;
251 if ((dsize -= count ) < 0 ||
252 (ssize -= count + 1) < 0)
260 if ((dsize -= count) < 0 ||
281 int compressed_size,
int uncompressed_size,
284 unsigned long dest_len = uncompressed_size;
289 if (uncompress(td->
tmp, &dest_len, src, compressed_size) != Z_OK ||
290 dest_len != uncompressed_size)
294 for (i = 0; i < s->
ysize; i++) {
303 ptr[1] = ptr[0] + s->
xdelta;
304 ptr[2] = ptr[1] + s->
xdelta;
307 for (j = 0; j < s->
xdelta; ++j) {
308 uint32_t
diff = (*(ptr[0]++) << 24) |
309 (*(ptr[1]++) << 16) |
312 bytestream_put_le32(&out, pixel);
317 ptr[1] = ptr[0] + s->
xdelta;
319 for (j = 0; j < s->
xdelta; j++) {
320 uint32_t
diff = (*(ptr[0]++) << 8) | *(ptr[1]++);
323 bytestream_put_le16(&out, pixel);
336 int jobnr,
int threadnr)
341 const uint8_t *channel_buffer[4] = { 0 };
343 uint64_t line_offset, uncompressed_size;
344 uint32_t xdelta = s->
xdelta;
356 if (line_offset > buf_size - 8)
359 src = buf + line_offset + 8;
365 if (data_size <= 0 || data_size > buf_size)
370 if ((s->
compr ==
EXR_RAW && (data_size != uncompressed_size ||
371 line_offset > buf_size - uncompressed_size)) ||
372 (s->
compr !=
EXR_RAW && (data_size > uncompressed_size ||
373 line_offset > buf_size - data_size))) {
377 if (data_size < uncompressed_size) {
408 r = channel_buffer[0];
409 g = channel_buffer[1];
410 b = channel_buffer[2];
411 if (channel_buffer[3])
412 a = channel_buffer[3];
414 ptr_x = (uint16_t *)ptr;
417 memset(ptr_x, 0, bxmin);
421 for (x = 0; x < xdelta; x++) {
425 if (channel_buffer[3])
430 for (x = 0; x < xdelta; x++) {
434 if (channel_buffer[3])
440 memset(ptr_x, 0, axmax);
445 if (channel_buffer[3])
458 unsigned int buf_size = avpkt->
size;
459 const uint8_t *buf_end = buf + buf_size;
471 int scan_line_blocks;
473 unsigned int current_channel_offset = 0;
496 magic_number = bytestream_get_le32(&buf);
497 if (magic_number != 20000630) {
502 version = bytestream_get_byte(&buf);
508 flags = bytestream_get_le24(&buf);
515 while (buf < buf_end && buf[0]) {
516 unsigned int variable_buffer_data_size;
518 if (
check_header_variable(avctx, &buf, buf_end,
"channels",
"chlist", 38, &variable_buffer_data_size) >= 0) {
519 const uint8_t *channel_list_end;
520 if (!variable_buffer_data_size)
523 channel_list_end = buf + variable_buffer_data_size;
524 while (channel_list_end - buf >= 19) {
526 int current_pixel_type = -1;
527 int channel_index = -1;
530 if (!strcmp(buf,
"R"))
532 else if (!strcmp(buf,
"G"))
534 else if (!strcmp(buf,
"B"))
536 else if (!strcmp(buf,
"A"))
541 while (bytestream_get_byte(&buf) && buf < channel_list_end)
544 if (channel_list_end - * &buf < 4) {
549 current_pixel_type = bytestream_get_le32(&buf);
550 if (current_pixel_type > 2) {
556 xsub = bytestream_get_le32(&buf);
557 ysub = bytestream_get_le32(&buf);
558 if (xsub != 1 || ysub != 1) {
563 if (channel_index >= 0) {
577 channel->
xsub = xsub;
578 channel->
ysub = ysub;
580 current_channel_offset += 1 << current_pixel_type;
598 buf = channel_list_end;
600 }
else if (
check_header_variable(avctx, &buf, buf_end,
"dataWindow",
"box2i", 31, &variable_buffer_data_size) >= 0) {
601 if (!variable_buffer_data_size)
611 buf += variable_buffer_data_size;
613 }
else if (
check_header_variable(avctx, &buf, buf_end,
"displayWindow",
"box2i", 34, &variable_buffer_data_size) >= 0) {
614 if (!variable_buffer_data_size)
620 buf += variable_buffer_data_size;
622 }
else if (
check_header_variable(avctx, &buf, buf_end,
"lineOrder",
"lineOrder", 25, &variable_buffer_data_size) >= 0) {
623 if (!variable_buffer_data_size)
632 buf += variable_buffer_data_size;
634 }
else if (
check_header_variable(avctx, &buf, buf_end,
"pixelAspectRatio",
"float", 31, &variable_buffer_data_size) >= 0) {
635 if (!variable_buffer_data_size)
640 buf += variable_buffer_data_size;
642 }
else if (
check_header_variable(avctx, &buf, buf_end,
"compression",
"compression", 29, &variable_buffer_data_size) >= 0) {
643 if (!variable_buffer_data_size)
651 buf += variable_buffer_data_size;
656 if (buf_end - buf <= 9) {
662 for (i = 0; i < 2; i++) {
664 while (++buf < buf_end)
670 if (buf_end - buf >= 5) {
672 if (!variable_buffer_data_size) {
676 buf += variable_buffer_data_size;
680 if (s->
compr == -1) {
685 if (buf >= buf_end) {
744 size_t thread_data_size, prev_size;
761 if (buf_end - buf < scan_line_blocks * 8)
764 ptr = picture->
data[0];
767 for (y = 0; y < s->
ymin; y++) {
768 memset(ptr, 0, out_line_size);
776 for (y = s->
ymax + 1; y < avctx->
height; y++) {
777 memset(ptr, 0, out_line_size);