Skip to content

Commit

Permalink
jas_image: _readcmpt() fast path for 8 bits per pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 19, 2020
1 parent e172904 commit 5017d3a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libjasper/base/jas_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,29 @@ int jas_image_readcmpt(jas_image_t *image, unsigned cmptno, jas_image_coord_t x,
* cps, SEEK_SET) < 0) {
return -1;
}

if (cps == 1 && !sgnd && width <= 16384) {
/* fast path for 1 byte per sample and
unsigned with bulk reads */

#ifdef _MSC_VER
/* can't use variable-length arrays here
because MSVC doesn't support this C99
feature */
jas_uchar *buffer = _alloca(width);
#else
jas_uchar buffer[width];
#endif

if (jas_stream_read(stream, buffer, width) != width)
return -1;

for (j = 0; j < width; ++j)
d[j] = buffer[j];

continue;
}

for (j = width; j > 0; --j, ++d) {
v = 0;
for (unsigned k = cps; k > 0; --k) {
Expand Down

0 comments on commit 5017d3a

Please sign in to comment.