Skip to content

Commit 60bae63

Browse files
committed
updale libnsgif from upstream
seems slightly slower overall
1 parent 1192d87 commit 60bae63

File tree

4 files changed

+243
-171
lines changed

4 files changed

+243
-171
lines changed

libvips/foreign/libnsgif/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ but within the libvips build system.
88
Run `./update.sh` to update this copy of libnsgif from the upstream repo. It
99
will also patch libnsgif.c to prevent it modifying the input.
1010

11-
Last updated 28 Feb 2021.
11+
Last updated 7 Oct 2021.
1212

1313
# To do
1414

15-
No attempt made to run tests or build docs. Though the gif loader is tested as
16-
part of the libvips test suite.
15+
No attempt made to run tests or build docs. Though the gif loader is tested
16+
as part of the libvips test suite.

libvips/foreign/libnsgif/libnsgif.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ static gif_result gif_error_from_lzw(lzw_result l_res)
549549
[LZW_BAD_ICODE] = GIF_FRAME_DATA_ERROR,
550550
[LZW_BAD_CODE] = GIF_FRAME_DATA_ERROR,
551551
};
552+
assert(l_res != LZW_BAD_PARAM);
553+
assert(l_res != LZW_NO_COLOUR);
552554
return g_res[l_res];
553555
}
554556

@@ -638,9 +640,8 @@ gif__decode_complex(gif_animation *gif,
638640
lzw_result res;
639641

640642
/* Initialise the LZW decoding */
641-
res = lzw_decode_init(gif->lzw_ctx, gif->gif_data,
642-
gif->buffer_size, gif->buffer_position,
643-
minimum_code_size);
643+
res = lzw_decode_init(gif->lzw_ctx, minimum_code_size,
644+
gif->gif_data, gif->buffer_size, gif->buffer_position);
644645
if (res != LZW_OK) {
645646
return gif_error_from_lzw(res);
646647
}
@@ -675,20 +676,28 @@ gif__decode_complex(gif_animation *gif,
675676
}
676677
break;
677678
}
678-
res = lzw_decode_continuous(gif->lzw_ctx,
679+
res = lzw_decode(gif->lzw_ctx,
679680
&uncompressed, &available);
680681
}
681682

682683
row_available = x < available ? x : available;
683684
x -= row_available;
684685
available -= row_available;
685-
while (row_available-- > 0) {
686-
register unsigned int colour;
687-
colour = *uncompressed++;
688-
if (colour != transparency_index) {
689-
*frame_scanline = colour_table[colour];
686+
if (transparency_index > 0xFF) {
687+
while (row_available-- > 0) {
688+
*frame_scanline++ =
689+
colour_table[*uncompressed++];
690+
}
691+
} else {
692+
while (row_available-- > 0) {
693+
register unsigned int colour;
694+
colour = *uncompressed++;
695+
if (colour != transparency_index) {
696+
*frame_scanline =
697+
colour_table[colour];
698+
}
699+
frame_scanline++;
690700
}
691-
frame_scanline++;
692701
}
693702
}
694703
}
@@ -710,23 +719,22 @@ gif__decode_simple(gif_animation *gif,
710719
gif_result ret = GIF_OK;
711720
lzw_result res;
712721

722+
transparency_index = gif->frames[frame].transparency ?
723+
gif->frames[frame].transparency_index :
724+
GIF_NO_TRANSPARENCY;
725+
713726
/* Initialise the LZW decoding */
714-
res = lzw_decode_init(gif->lzw_ctx, gif->gif_data,
715-
gif->buffer_size, gif->buffer_position,
716-
minimum_code_size);
727+
res = lzw_decode_init_map(gif->lzw_ctx,
728+
minimum_code_size, transparency_index, colour_table,
729+
gif->gif_data, gif->buffer_size, gif->buffer_position);
717730
if (res != LZW_OK) {
718731
return gif_error_from_lzw(res);
719732
}
720733

721-
transparency_index = gif->frames[frame].transparency ?
722-
gif->frames[frame].transparency_index :
723-
GIF_NO_TRANSPARENCY;
724-
725734
frame_data += (offset_y * gif->width);
726735

727736
while (pixels > 0) {
728-
res = lzw_decode_map_continuous(gif->lzw_ctx,
729-
transparency_index, colour_table,
737+
res = lzw_decode_map(gif->lzw_ctx,
730738
frame_data, pixels, &written);
731739
pixels -= written;
732740
frame_data += written;

0 commit comments

Comments
 (0)