Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_image_resize2.h crashes when up sampling an image with specific resolution #1678

Open
greyishsong opened this issue Aug 30, 2024 · 2 comments

Comments

@greyishsong
Copy link

Describe the bug

When I try to up sample an image (232x232 px) to 300x300 px, stb_image_resize2 crashes.

The content of image does not matter, the key issue is input/output size.

  • If I change the output size to 302x302 px, it still crashes. But with output size as 303x303 px, no crash.
  • If I keep the scaling factor (i.e. 232/300) but change the size, it
    • still crashes when performing 464x464 -> 600x600
    • but does not crash when performing 387x387 -> 500x500

Crash only occurs when using the point sampling filter STBIR_FILTER_POINT_SAMPLE. I am not familiar with image processing, so is it wrong to use point sampling filter for up sampling, or I use it in a wrong form?

The stack trace from Visual Studio debugger:

stbir__horizontal_gather_4_channels_with_2_coeffs(float * output_buffer, unsigned int output_sub_size, const float * decode_buffer, const stbir__contributors * horizontal_contributors, const float * horizontal_coefficients, int coefficient_width) line 10013
stbir__resample_horizontal_gather(const stbir__info * stbir_info, float * output_buffer, const float * input_buffer) line 5992
stbir__decode_and_resample_for_vertical_gather_loop(const stbir__info * stbir_info, stbir__per_split_info * split_info, int n) line 6051
stbir__vertical_gather_loop(const stbir__info * stbir_info, stbir__per_split_info * split_info, int split_count) line 6105
stbir__perform_resize(const stbir__info * info, int split_start, int split_count) line 7089
stbir_resize_extended(STBIR_RESIZE * resize) line 7713
stbir_resize(const void * input_pixels, int input_w, int input_h, int input_stride_in_bytes, void * output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_layout, stbir_datatype data_type, stbir_edge edge, stbir_filter filter) line 7883
main() line 19

To Reproduce
Steps to reproduce the behavior:

  1. Use the stb_image_resize2.h (on commit f75e8d1cad7d90d72ef7a4661f1b994ef78b4e31)
  2. Create a minimal test example like this:
#include <cstring>
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize2.h"

int main()
{
    int input_w = 232;
    int input_h = 232;
    int output_w = 300;
    int output_h = 300;
    unsigned char* input = new unsigned char[input_w * input_h * 4];
    std::memset(input, 0, input_w * input_h * 4);
    unsigned char* output = new unsigned char[output_w * output_h * 4];
    stbir_resize(
        input, input_w, input_h, 0,
        output, output_w, output_h, 0,
        STBIR_RGBA, STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_POINT_SAMPLE
    );

    delete[] input;
    delete[] output;
    return 0;
}
  1. Build and run it
  2. The program crashes

Expected behavior

The program should exit normally and return 0.

@jeffatrad
Copy link
Contributor

Hmmm, the point sample filter isn't used very often (it's just for pixel art, really) - I must have a bug in there, it definitely shouldn't be using 2 coeffs. I'll look at it sometime - use STBIR_FILTER_BOX for now...

@greyishsong
Copy link
Author

OK, I tried to use it for analysis 🤣 Before the point filter becomes available, I will use the box filter instead. Anyway, thanks for your effort in developing all these functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants