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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

stbi: add resize image function #18484

Merged
merged 3 commits into from
Jun 19, 2023
Merged

stbi: add resize image function #18484

merged 3 commits into from
Jun 19, 2023

Conversation

Casper64
Copy link
Member

@Casper64 Casper64 commented Jun 18, 2023

Add the stbi_image_resize.h thirdparty file so it's possible to resize images that are loaded with stbi.load(path).

This pr adds the ability to resize images with stbi.stbi_resize_image.

Usage

module main

import os
import stbi

fn main() {
vroot := @VEXEROOT
	path := os.join_path(vroot, 'examples', 'assets', 'logo.png')
d_s := stbi.load(path) or { panic(err) }

new_width, new_height := 100, 100
d_r := stbi.stbi_resize_image(d_s, new_width, new_height) or { panic(err) }

out_path := 'test.png'
stbi.stbi_write_png(out_path, d_r.width, d_r.height, 4, d_r.data, d_r.width * 4) or {
		panic(err)
	}
}

馃 Generated by Copilot at 8ce0922

This pull request adds image resizing functionality to the stbi module, using the third-party library stb_image_resize. It also adds a test function to verify the resizing works as expected.

馃 Generated by Copilot at 8ce0922

  • Define macro and include header for stb_image_resize library (link,link)
  • Add wrapper function for resizing images using stb_image_resize (link)
  • Add test function for resizing images and checking dimensions and channels (link)

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include "stb_image_resize.h" should be added in stbi.c.v around line 34 as well

@Casper64
Copy link
Member Author

#include "stb_image_resize.h" should be added in stbi.c.v around line 34 as well

Just found it myself. Added it.

fn C.stbir_resize_uint8(input_pixels &u8, input_w int, input_h int, input_stride_in_bytes int, output_pixels &u8, output_w int, output_h int, output_stride_in_bytes int, num_channels int) int

// stbi_resize_image resize `img` to dimensions of `output_w` and `output_h`
pub fn stbi_resize_image(img &Image, output_w int, output_h int) !Image {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stbi_ prefix for the name of the V wrapper here, is superfluous.

In the caller, that role is served by the module name, i.e. C.stbi_load is wrapped by load, and in the call sites, it is stbi.load, similarly, C.stbi_resize_uint8 can be wrapped by resize_uint8, and be available as stbi.resize_uint8 in the call sites.

@spytheman spytheman merged commit 2bedb6f into vlang:master Jun 19, 2023
35 checks passed
@Casper64 Casper64 deleted the stbi_resize branch November 20, 2023 23:12
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

Successfully merging this pull request may close these issues.

None yet

2 participants