-
-
Notifications
You must be signed in to change notification settings - Fork 425
Add image(buffer, size) API #2961
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
Open
RealEdwardS
wants to merge
53
commits into
f3d-app:master
Choose a base branch
from
RealEdwardS:add-image-function-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 46 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
8723e62
Implementation, testing, c, java, and python bindings
RealEdwardS 02c9216
Removed config.cxx file
RealEdwardS 6cd7274
Removed unnecessary iostream
RealEdwardS e955178
Removed double comment
RealEdwardS 2e8017d
Formatting
RealEdwardS b4e7a44
Fixed java and python bindings
RealEdwardS 44e510d
Added doc, removed file filesystem_error try/catch
RealEdwardS 3ada711
Update python/F3DPythonBindings.cxx
RealEdwardS 6d33273
Updated docs/removed webassembly for now
RealEdwardS c9dbfa9
Updated docs
RealEdwardS d9148ee
Updated api
RealEdwardS 8407e37
Removed comments in testing
RealEdwardS 2e80b88
Added more testing
RealEdwardS 9434128
Fixed best reader iteration
RealEdwardS c851819
Fixed doc on available supported formats
RealEdwardS 44bbd60
Added WebP to doc
RealEdwardS a7c5fe0
Updated docs
RealEdwardS 01cd40b
Formatting and fixed best reader
RealEdwardS a9736ec
Formatting
RealEdwardS 6a5d325
Formatting
RealEdwardS d9d537a
Formatting again
RealEdwardS 563dbec
Formatting again again
RealEdwardS 2a09647
Added vtk version check
RealEdwardS 9d1f812
Removed duplicate header include
RealEdwardS bbab7b2
Fixed variable redeclaration in testing, and added version check in t…
RealEdwardS 4f7d762
Fixed unreferenced parameter warning/error
RealEdwardS 4ad5f97
Formatting in testing
RealEdwardS b897187
Revert "Fixed variable redeclaration in testing, and added version ch…
RealEdwardS 2d87f8b
Fix redeclaration error
RealEdwardS 7863b0f
Removed assigning variables to itself
RealEdwardS 12b17c8
Modified SDKImage Test to see if everything else works - Binding test…
RealEdwardS 33cfb62
Changed version build
RealEdwardS 2a3f4c7
Added std::byte library in testing
RealEdwardS 91d1801
Renamed bestReader to reader
RealEdwardS cde32df
Removed unnecessary cstddef library
RealEdwardS 21d2a44
Created new python test
RealEdwardS 066bb7f
Created dedicated test for java
RealEdwardS 3d84a9c
Created dedicated c test
RealEdwardS fc48c8d
Changed version
RealEdwardS 6aeb46d
Formatting
RealEdwardS edea228
Created dedicated cpp test
RealEdwardS 85c6e11
Fixed memory leak in c binding test
RealEdwardS 38fcd2b
Removed duplicate test case py
RealEdwardS 68c4bf4
Formatting
RealEdwardS cb04623
Rerun
RealEdwardS f26cff5
Rerun pt2
RealEdwardS 0f16cb2
Renamed file and removed unncessary comment for TestSDKImageStream
RealEdwardS 2839274
Renamed TestImageStream to TestSDKImageStream
RealEdwardS 2047c90
Added version requirement to docs
RealEdwardS 599337f
Added eol to c binding test case
RealEdwardS 2aec1ff
Renamed compare variable in c binding test
RealEdwardS 4a0fc8f
Freed memory in c binding
RealEdwardS 3686aa1
Formatting
RealEdwardS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #include <image_c_api.h> | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| int test_image_stream() | ||
| { | ||
| f3d_image_t* img = f3d_image_new_params(800, 600, 3, BYTE); | ||
| if (!img) | ||
| { | ||
| puts("[ERROR] Failed to create image"); | ||
| return 1; | ||
| } | ||
|
|
||
| unsigned int count; | ||
| unsigned char* tempBuffer = f3d_image_save_buffer(NULL, PNG, &count); // this shouldn't crash | ||
| if (tempBuffer != NULL) | ||
| { | ||
| f3d_image_delete(img); | ||
| return 1; | ||
| } | ||
|
|
||
| f3d_image_t* temp_image_stream = f3d_image_new_stream(tempBuffer, 0); | ||
| if (temp_image_stream != NULL) | ||
| { | ||
| f3d_image_delete(img); | ||
| return 1; | ||
| } | ||
|
|
||
| unsigned int buffer_size; | ||
| unsigned char* buffer = f3d_image_save_buffer(img, PNG, &buffer_size); | ||
| if (buffer) | ||
| { | ||
| f3d_image_t* image_stream = f3d_image_new_stream(buffer, buffer_size); | ||
|
|
||
| if (image_stream) | ||
| { | ||
| double stream_error = f3d_image_compare(img, image_stream); | ||
| f3d_image_free_buffer(buffer); | ||
| f3d_image_delete(image_stream); | ||
|
|
||
| if (stream_error != 0) | ||
| { | ||
| f3d_image_delete(img); | ||
| return 1; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| f3d_image_delete(img); | ||
|
RealEdwardS marked this conversation as resolved.
|
||
| return 1; | ||
| } | ||
| } | ||
|
|
||
| f3d_image_delete(img); | ||
| return 0; | ||
| } | ||
|
RealEdwardS marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import app.f3d.F3D.*; | ||
|
|
||
| public class TestImageStream { | ||
| public static void main(String[] args) { | ||
| Image img1 = new Image(300, 200, 3); | ||
|
|
||
| byte[] img1Buffer = img1.saveBuffer(Image.SaveFormat.PNG); | ||
|
|
||
| Image img2 = new Image(img1Buffer); | ||
|
|
||
| img1.equals(img2); | ||
|
|
||
| img1.delete(); | ||
| img2.delete(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "PseudoUnitTest.h" | ||
|
|
||
| #include <image.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <random> | ||
|
|
||
| int TestImageStream([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) | ||
| { | ||
| PseudoUnitTest test; | ||
|
|
||
| constexpr unsigned int width = 64; | ||
| constexpr unsigned int height = 64; | ||
| constexpr unsigned int channels = 3; | ||
|
|
||
| // fill with deterministic random values | ||
| // do not use std::uniform_int_distribution, it's not giving the same result on different | ||
| // platforms | ||
|
RealEdwardS marked this conversation as resolved.
Outdated
|
||
| std::mt19937 randGenerator; | ||
|
|
||
| f3d::image generated(width, height, channels); | ||
| std::vector<uint8_t> pixels(width * height * channels); | ||
| std::ranges::generate(pixels, [&]() { return static_cast<uint8_t>(randGenerator() % 256); }); | ||
| generated.setContent(pixels.data()); | ||
|
|
||
| // check reading stream | ||
| std::vector<unsigned char> generatedBuffer = generated.saveBuffer(); | ||
| std::byte* bufferData = reinterpret_cast<std::byte*>(generatedBuffer.data()); | ||
| f3d::image bufferImage(bufferData, generatedBuffer.size()); | ||
| test("check loading stream from image reader", generated.compare(bufferImage), 0.0); | ||
|
|
||
| // check reading inexistent/null stream | ||
| test.expect<f3d::image::read_exception>( | ||
| "read image from invalid/null stream", [&]() { f3d::image nullImgStream(nullptr, 10); }); | ||
|
|
||
| // check reading invalid stream | ||
| std::vector<unsigned char> invalidBuffer = { 0, 1, 2, 3, 4, 5 }; | ||
| std::byte* invalidBufferData = reinterpret_cast<std::byte*>(invalidBuffer.data()); | ||
| test.expect<f3d::image::read_exception>("read image from invalid stream", | ||
| [&]() { f3d::image invalidImgStream(invalidBufferData, 10); }); | ||
|
|
||
| return test.result(); | ||
| } | ||
|
mwestphal marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.