Skip to content

Commit 05438a0

Browse files
committed
Refactor image size API to return struct
Changed native_image_get_size to return a native_size_t struct instead of using output parameters for width and height. This simplifies the API and improves error handling by returning zero size on failure.
1 parent 55cc873 commit 05438a0

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/capi/image_c.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,23 @@ void native_image_destroy(native_image_t image) {
7777
}
7878

7979
// Get the size of an image in pixels
80-
void native_image_get_size(native_image_t image,
81-
double* width,
82-
double* height) {
83-
if (!image || !width || !height) {
84-
if (width)
85-
*width = 0.0;
86-
if (height)
87-
*height = 0.0;
88-
return;
80+
native_size_t native_image_get_size(native_image_t image) {
81+
native_size_t result = {0.0, 0.0};
82+
83+
if (!image) {
84+
return result;
8985
}
9086

9187
try {
9288
auto img = static_cast<std::shared_ptr<Image>*>(image);
9389
auto size = (*img)->GetSize();
94-
*width = size.width;
95-
*height = size.height;
90+
result.width = size.width;
91+
result.height = size.height;
9692
} catch (...) {
97-
*width = 0.0;
98-
*height = 0.0;
93+
// Return zero size on error
9994
}
95+
96+
return result;
10097
}
10198

10299
// Get the image format string for debugging purposes

src/capi/image_c.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7+
#include "geometry_c.h"
8+
79
#if _WIN32
810
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
911
#else
@@ -57,11 +59,10 @@ void native_image_destroy(native_image_t image);
5759
/**
5860
* Get the size of an image in pixels
5961
* @param image The image
60-
* @param width Pointer to store the width (will be set to 0 if invalid)
61-
* @param height Pointer to store the height (will be set to 0 if invalid)
62+
* @return Size of the image (width and height will be 0 if invalid)
6263
*/
6364
FFI_PLUGIN_EXPORT
64-
void native_image_get_size(native_image_t image, double* width, double* height);
65+
native_size_t native_image_get_size(native_image_t image);
6566

6667
/**
6768
* Get the image format string for debugging purposes

0 commit comments

Comments
 (0)