Skip to content

Commit

Permalink
smolscale: Fix bad output when rowstride is not a multiple of 4
Browse files Browse the repository at this point in the history
Reported by @jstkdng. It's irritating that we had this error in for so
long; it went unnoticed because it didn't affect the command-line tool
due to a combination of lucky factors.

Fixes #141 (GitHub).
  • Loading branch information
hpjansson committed May 19, 2023
1 parent 766cff9 commit 3843ac7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions chafa/internal/smolscale/smolscale-avx2.c
Expand Up @@ -1239,14 +1239,14 @@ static SMOL_INLINE const uint32_t *
inrow_ofs_to_pointer (const SmolScaleCtx *scale_ctx,
uint32_t inrow_ofs)
{
return scale_ctx->pixels_in + scale_ctx->rowstride_in * inrow_ofs;
return (const uint32_t *) (((const uint8_t *) scale_ctx->pixels_in) + scale_ctx->rowstride_in * inrow_ofs);
}

static SMOL_INLINE uint32_t *
outrow_ofs_to_pointer (const SmolScaleCtx *scale_ctx,
uint32_t outrow_ofs)
{
return scale_ctx->pixels_out + scale_ctx->rowstride_out * outrow_ofs;
return (uint32_t *) (((uint8_t *) scale_ctx->pixels_out) + scale_ctx->rowstride_out * outrow_ofs);
}

static SMOL_INLINE uint64_t
Expand Down
10 changes: 5 additions & 5 deletions chafa/internal/smolscale/smolscale.c
Expand Up @@ -1004,14 +1004,14 @@ static SMOL_INLINE const uint32_t *
inrow_ofs_to_pointer (const SmolScaleCtx *scale_ctx,
uint32_t inrow_ofs)
{
return scale_ctx->pixels_in + scale_ctx->rowstride_in * inrow_ofs;
return (const uint32_t *) (((const uint8_t *) scale_ctx->pixels_in) + scale_ctx->rowstride_in * inrow_ofs);
}

static SMOL_INLINE uint32_t *
outrow_ofs_to_pointer (const SmolScaleCtx *scale_ctx,
uint32_t outrow_ofs)
{
return scale_ctx->pixels_out + scale_ctx->rowstride_out * outrow_ofs;
return (uint32_t *) (((uint8_t *) scale_ctx->pixels_out) + scale_ctx->rowstride_out * outrow_ofs);
}

static SMOL_INLINE uint64_t
Expand Down Expand Up @@ -2369,7 +2369,7 @@ do_rows (const SmolScaleCtx *scale_ctx,
for (i = row_out_index; i < row_out_index + n_rows; i++)
{
scale_outrow (scale_ctx, &vertical_ctx, i, outrows_dest);
outrows_dest = (uint32_t *) outrows_dest + scale_ctx->rowstride_out;
outrows_dest = (uint8_t *) outrows_dest + scale_ctx->rowstride_out;
}

for (i = 0; i < n_stored_rows; i++)
Expand Down Expand Up @@ -2917,12 +2917,12 @@ smol_scale_init (SmolScaleCtx *scale_ctx,
scale_ctx->pixels_in = pixels_in;
scale_ctx->width_in = width_in;
scale_ctx->height_in = height_in;
scale_ctx->rowstride_in = rowstride_in / sizeof (uint32_t);
scale_ctx->rowstride_in = rowstride_in;
scale_ctx->pixel_type_out = pixel_type_out;
scale_ctx->pixels_out = pixels_out;
scale_ctx->width_out = width_out;
scale_ctx->height_out = height_out;
scale_ctx->rowstride_out = rowstride_out / sizeof (uint32_t);
scale_ctx->rowstride_out = rowstride_out;

scale_ctx->post_row_func = post_row_func;
scale_ctx->user_data = user_data;
Expand Down

0 comments on commit 3843ac7

Please sign in to comment.