From fa7f179ea1ee4a0d9580a3eacf4ea56fdc1e6aa3 Mon Sep 17 00:00:00 2001 From: Maksim Belov <45949002+artdeell@users.noreply.github.com> Date: Sat, 21 Mar 2026 23:57:18 +0300 Subject: [PATCH 1/2] STB: wrap resize v1 functions into their v2 alternatives --- .../java/org/lwjgl/stb/STBImageResize.java | 169 +++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-) diff --git a/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java b/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java index a7f96367cc..0c20477b87 100644 --- a/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java +++ b/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java @@ -440,4 +440,171 @@ private static int calculateBufferSize(int width, int height, int stride_in_byte 1, 1, 1, 2, 4, 2 }; -} \ No newline at end of file + + // LEGACY FUNCTIONS + + // --- [ stbir_resize_uint8_generic ] --- + + + private static int selectV2PixelLayout(int num_channels, int alpha_channel) { + if(alpha_channel == -1) return num_channels; // use backwards compatibility + switch(num_channels) { + case 2: + switch(alpha_channel) { + case 0: return STBIR_AR; + case 1: return STBIR_RA; + default: + throw new RuntimeException("cannot select dual channel alpha=" +alpha_channel); + } + break; + case 4: + switch(alpha_channel) { + case 0: return STBIR_ARGB; + case 3: return STBIR_RGBA; + default: + throw new RuntimeException("cannot select quad channel alpha=" +alpha_channel); + } + break; + default: + throw new RuntimeException("cannot select pixel layout for " + num_channels + " color channels"); + } + } + + private static int makePremultiplied(int pixel_layout) { + switch(pixel_layout) { + case STBIR_RGBA: return STBIR_RGBA_PM; + case STBIR_BGRA: return STBIR_BGRA_PM; + case STBIR_ARGB: return STBIR_ARGB_PM; + case STBIR_ABGR: return STBIR_ABGR_PM; + case STBIR_RA: return STBIR_RA_PM; + case STBIR_AR: return STBIR_AR_PM; + default: return pixel_layout; + } + } + + public static int nstbir_resize_uint8_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context) { + num_channels = selectV2PixelLayout(num_channels, alpha_channel); + if((flags & (1 << 0)) != 0) num_channels = makePremultiplied(num_channels); + int data_type; + switch(space) { + case 0: data_type = STBIR_TYPE_UINT8; break; + case 1: { + if((flags & (1 << 1)) != 0) data_type = STBIR_TYPE_UINT8_SRGB_ALPHA; + else data_type = STBIR_TYPE_UINT8_SRGB; + } + default: throw new RuntimeException("unknown colorspace " + space); + } + nstbir_resize(input_pixels, input_w, input_h, input_stride_in_bytes, output_pixels, output_w, output_h, output_stride_in_bytes, num_channels, data_type, edge_wrap_mode, filter); + return 1; + } + + /** + * Medium-complexity version of {@link #stbir_resize_uint8 resize_uint8}. + * + * @param input_pixels the source image data + * @param input_w the source image width + * @param input_h the source image height + * @param input_stride_in_bytes the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param output_pixels returns the scaled image data + * @param output_w the resized image width + * @param output_h the resized image height + * @param output_stride_in_bytes the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param num_channels the number of channels in the image (e.g. RGB=3, RGBA=4) + * @param alpha_channel the alpha channel index, or {@link #STBIR_ALPHA_CHANNEL_NONE ALPHA_CHANNEL_NONE} if there is no alpha channel + * @param flags the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
{@link #STBIR_FLAG_ALPHA_PREMULTIPLIED FLAG_ALPHA_PREMULTIPLIED}{@link #STBIR_FLAG_ALPHA_USES_COLORSPACE FLAG_ALPHA_USES_COLORSPACE}
+ * @param edge_wrap_mode the edge wrap mode. One of:
{@link #STBIR_EDGE_CLAMP EDGE_CLAMP}{@link #STBIR_EDGE_REFLECT EDGE_REFLECT}{@link #STBIR_EDGE_WRAP EDGE_WRAP}{@link #STBIR_EDGE_ZERO EDGE_ZERO}
+ * @param filter the scale filter. One of:
{@link #STBIR_FILTER_DEFAULT FILTER_DEFAULT}{@link #STBIR_FILTER_BOX FILTER_BOX}{@link #STBIR_FILTER_TRIANGLE FILTER_TRIANGLE}{@link #STBIR_FILTER_CUBICBSPLINE FILTER_CUBICBSPLINE}{@link #STBIR_FILTER_CATMULLROM FILTER_CATMULLROM}
{@link #STBIR_FILTER_MITCHELL FILTER_MITCHELL}
+ * @param space the image colorspace. One of:
{@link #STBIR_COLORSPACE_LINEAR COLORSPACE_LINEAR}{@link #STBIR_COLORSPACE_SRGB COLORSPACE_SRGB}
+ * + * @return 1 on success, 0 on failure + */ + @NativeType("int") + public static boolean stbir_resize_uint8_generic(@NativeType("unsigned char const *") ByteBuffer input_pixels, int input_w, int input_h, int input_stride_in_bytes, @NativeType("unsigned char *") ByteBuffer output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, @NativeType("stbir_edge") int edge_wrap_mode, @NativeType("stbir_filter") int filter, @NativeType("stbir_colorspace") int space) { + if (CHECKS) { + check(input_pixels, input_h * (input_stride_in_bytes == 0 ? input_w * num_channels : input_stride_in_bytes)); + check(output_pixels, output_h * (output_stride_in_bytes == 0 ? output_w * num_channels : output_stride_in_bytes)); + } + return nstbir_resize_uint8_generic(memAddress(input_pixels), input_w, input_h, input_stride_in_bytes, memAddress(output_pixels), output_w, output_h, output_stride_in_bytes, num_channels, alpha_channel, flags, edge_wrap_mode, filter, space, NULL) != 0; + } + + // --- [ stbir_resize_uint16_generic ] --- + + public static int nstbir_resize_uint16_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context) { + if((flags & (1 << 1)) != 0 || space == 1) throw new RuntimeException("(u16) Open a GitHub issue in https://github.com/MojoLauncher/lwjgl3/"); + num_channels = selectV2PixelLayout(num_channels, alpha_channel); + if((flags & (1 << 0)) != 0) num_channels = makePremultiplied(num_channels); + int data_type = STBIR_TYPE_UINT16; + nstbir_resize(input_pixels, input_w, input_h, input_stride_in_bytes, output_pixels, output_w, output_h, output_stride_in_bytes, num_channels, data_type, edge_wrap_mode, filter); + return 1; + } + + /** + * Short version of {@link #stbir_resize_uint8_generic resize_uint8_generic}. + * + * @param input_pixels the source image data + * @param input_w the source image width + * @param input_h the source image height + * @param input_stride_in_bytes the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param output_pixels returns the scaled image data + * @param output_w the resized image width + * @param output_h the resized image height + * @param output_stride_in_bytes the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param num_channels the number of channels in the image (e.g. RGB=3, RGBA=4) + * @param alpha_channel the alpha channel index, or {@link #STBIR_ALPHA_CHANNEL_NONE ALPHA_CHANNEL_NONE} if there is no alpha channel + * @param flags the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
{@link #STBIR_FLAG_ALPHA_PREMULTIPLIED FLAG_ALPHA_PREMULTIPLIED}{@link #STBIR_FLAG_ALPHA_USES_COLORSPACE FLAG_ALPHA_USES_COLORSPACE}
+ * @param edge_wrap_mode the edge wrap mode. One of:
{@link #STBIR_EDGE_CLAMP EDGE_CLAMP}{@link #STBIR_EDGE_REFLECT EDGE_REFLECT}{@link #STBIR_EDGE_WRAP EDGE_WRAP}{@link #STBIR_EDGE_ZERO EDGE_ZERO}
+ * @param filter the scale filter. One of:
{@link #STBIR_FILTER_DEFAULT FILTER_DEFAULT}{@link #STBIR_FILTER_BOX FILTER_BOX}{@link #STBIR_FILTER_TRIANGLE FILTER_TRIANGLE}{@link #STBIR_FILTER_CUBICBSPLINE FILTER_CUBICBSPLINE}{@link #STBIR_FILTER_CATMULLROM FILTER_CATMULLROM}
{@link #STBIR_FILTER_MITCHELL FILTER_MITCHELL}
+ * @param space the image colorspace. One of:
{@link #STBIR_COLORSPACE_LINEAR COLORSPACE_LINEAR}{@link #STBIR_COLORSPACE_SRGB COLORSPACE_SRGB}
+ * + * @return 1 on success, 0 on failure + */ + @NativeType("int") + public static boolean stbir_resize_uint16_generic(@NativeType("stbir_uint16 const *") ShortBuffer input_pixels, int input_w, int input_h, int input_stride_in_bytes, @NativeType("stbir_uint16 *") ShortBuffer output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, @NativeType("stbir_edge") int edge_wrap_mode, @NativeType("stbir_filter") int filter, @NativeType("stbir_colorspace") int space) { + if (CHECKS) { + check(input_pixels, input_h * (input_stride_in_bytes == 0 ? input_w * num_channels : (input_stride_in_bytes >> 1))); + check(output_pixels, output_h * (output_stride_in_bytes == 0 ? output_w * num_channels : (output_stride_in_bytes >> 1))); + } + return nstbir_resize_uint16_generic(memAddress(input_pixels), input_w, input_h, input_stride_in_bytes, memAddress(output_pixels), output_w, output_h, output_stride_in_bytes, num_channels, alpha_channel, flags, edge_wrap_mode, filter, space, NULL) != 0; + } + + // --- [ stbir_resize_float_generic ] --- + + public static int nstbir_resize_float_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context) { + if((flags & (1 << 1)) != 0 || space == 1) throw new RuntimeException("(float) Open a GitHub issue in https://github.com/MojoLauncher/lwjgl3/"); + num_channels = selectV2PixelLayout(num_channels, alpha_channel); + if((flags & (1 << 0)) != 0) num_channels = makePremultiplied(num_channels); + int data_type = STBIR_TYPE_FLOAT; + nstbir_resize(input_pixels, input_w, input_h, input_stride_in_bytes, output_pixels, output_w, output_h, output_stride_in_bytes, num_channels, data_type, edge_wrap_mode, filter); + return 1; + } + + /** + * Float version of {@link #stbir_resize_uint8_generic resize_uint8_generic}. + * + * @param input_pixels the source image data + * @param input_w the source image width + * @param input_h the source image height + * @param input_stride_in_bytes the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param output_pixels returns the scaled image data + * @param output_w the resized image width + * @param output_h the resized image height + * @param output_stride_in_bytes the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory + * @param num_channels the number of channels in the image (e.g. RGB=3, RGBA=4) + * @param alpha_channel the alpha channel index, or {@link #STBIR_ALPHA_CHANNEL_NONE ALPHA_CHANNEL_NONE} if there is no alpha channel + * @param flags the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
{@link #STBIR_FLAG_ALPHA_PREMULTIPLIED FLAG_ALPHA_PREMULTIPLIED}{@link #STBIR_FLAG_ALPHA_USES_COLORSPACE FLAG_ALPHA_USES_COLORSPACE}
+ * @param edge_wrap_mode the edge wrap mode. One of:
{@link #STBIR_EDGE_CLAMP EDGE_CLAMP}{@link #STBIR_EDGE_REFLECT EDGE_REFLECT}{@link #STBIR_EDGE_WRAP EDGE_WRAP}{@link #STBIR_EDGE_ZERO EDGE_ZERO}
+ * @param filter the scale filter. One of:
{@link #STBIR_FILTER_DEFAULT FILTER_DEFAULT}{@link #STBIR_FILTER_BOX FILTER_BOX}{@link #STBIR_FILTER_TRIANGLE FILTER_TRIANGLE}{@link #STBIR_FILTER_CUBICBSPLINE FILTER_CUBICBSPLINE}{@link #STBIR_FILTER_CATMULLROM FILTER_CATMULLROM}
{@link #STBIR_FILTER_MITCHELL FILTER_MITCHELL}
+ * @param space the image colorspace. One of:
{@link #STBIR_COLORSPACE_LINEAR COLORSPACE_LINEAR}{@link #STBIR_COLORSPACE_SRGB COLORSPACE_SRGB}
+ * + * @return 1 on success, 0 on failure + */ + @NativeType("int") + public static boolean stbir_resize_float_generic(@NativeType("float const *") FloatBuffer input_pixels, int input_w, int input_h, int input_stride_in_bytes, @NativeType("float *") FloatBuffer output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, @NativeType("stbir_edge") int edge_wrap_mode, @NativeType("stbir_filter") int filter, @NativeType("stbir_colorspace") int space) { + if (CHECKS) { + check(input_pixels, input_h * (input_stride_in_bytes == 0 ? input_w * num_channels : (input_stride_in_bytes >> 2))); + check(output_pixels, output_h * (output_stride_in_bytes == 0 ? output_w * num_channels : (output_stride_in_bytes >> 2))); + } + return nstbir_resize_float_generic(memAddress(input_pixels), input_w, input_h, input_stride_in_bytes, memAddress(output_pixels), output_w, output_h, output_stride_in_bytes, num_channels, alpha_channel, flags, edge_wrap_mode, filter, space, NULL) != 0; + } + +} From 53cd1acd2a41cd3137751bd59d6eeb1e6c1e77ef Mon Sep 17 00:00:00 2001 From: Maksim Belov <45949002+artdeell@users.noreply.github.com> Date: Sun, 22 Mar 2026 00:02:00 +0300 Subject: [PATCH 2/2] remove unreachable breaks --- .../stb/src/generated/java/org/lwjgl/stb/STBImageResize.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java b/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java index 0c20477b87..805ec2d581 100644 --- a/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java +++ b/modules/lwjgl/stb/src/generated/java/org/lwjgl/stb/STBImageResize.java @@ -456,7 +456,6 @@ private static int selectV2PixelLayout(int num_channels, int alpha_channel) { default: throw new RuntimeException("cannot select dual channel alpha=" +alpha_channel); } - break; case 4: switch(alpha_channel) { case 0: return STBIR_ARGB; @@ -464,7 +463,6 @@ private static int selectV2PixelLayout(int num_channels, int alpha_channel) { default: throw new RuntimeException("cannot select quad channel alpha=" +alpha_channel); } - break; default: throw new RuntimeException("cannot select pixel layout for " + num_channels + " color channels"); }