Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions c/image_c_api.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ f3d_image_t* f3d_image_new_params(unsigned int width, unsigned int height,
//----------------------------------------------------------------------------
f3d_image_t* f3d_image_new_path(const char* path)
Comment thread
SahilSonar-04 marked this conversation as resolved.
{
if (!path)
{
return nullptr;
Comment thread
SahilSonar-04 marked this conversation as resolved.
}

f3d::image* img = nullptr;

Expand All @@ -75,13 +79,23 @@ f3d_image_t* f3d_image_new_path(const char* path)
//----------------------------------------------------------------------------
void f3d_image_delete(f3d_image_t* img)
{
if (!img)
{
return;
}

f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
delete cpp_img;
}

//----------------------------------------------------------------------------
int f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, double* pixel)
{
if (!img || !pixel)
{
return 0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);

try
Expand All @@ -101,27 +115,47 @@ int f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, double* pixel
//----------------------------------------------------------------------------
unsigned int f3d_image_get_width(f3d_image_t* img)
{
if (!img)
{
return 0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
return cpp_img->getWidth();
}

//----------------------------------------------------------------------------
unsigned int f3d_image_get_height(f3d_image_t* img)
{
if (!img)
{
return 0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
return cpp_img->getHeight();
}

//----------------------------------------------------------------------------
unsigned int f3d_image_get_channel_count(f3d_image_t* img)
{
if (!img)
{
return 0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
return cpp_img->getChannelCount();
}

//----------------------------------------------------------------------------
int f3d_image_get_channel_type(f3d_image_t* img)
{
if (!img)
{
return -1;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);

try
Expand All @@ -139,27 +173,48 @@ int f3d_image_get_channel_type(f3d_image_t* img)
//----------------------------------------------------------------------------
unsigned int f3d_image_get_channel_type_size(f3d_image_t* img)
{
if (!img)
{
return 0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
return cpp_img->getChannelTypeSize();
}

//----------------------------------------------------------------------------
void f3d_image_set_content(f3d_image_t* img, void* buffer)
{
if (!img || !buffer)
{
return;
}

f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
cpp_img->setContent(buffer);
}

//----------------------------------------------------------------------------
void* f3d_image_get_content(f3d_image_t* img)
{
if (!img)
{
return nullptr;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
return cpp_img->getContent();
}

//----------------------------------------------------------------------------
double f3d_image_compare(f3d_image_t* img, f3d_image_t* reference)
{
if (!img || !reference)
{
std::cerr << "Error comparing images: null image" << "\n";
Comment thread
SahilSonar-04 marked this conversation as resolved.
Outdated
return -1.0;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
const f3d::image* cpp_ref = reinterpret_cast<f3d::image*>(reference);

Expand Down Expand Up @@ -237,6 +292,11 @@ int f3d_image_save(f3d_image_t* img, const char* path, f3d_image_save_format_t f
unsigned char* f3d_image_save_buffer(
f3d_image_t* img, f3d_image_save_format_t format, unsigned int* size)
{
if (!size)
{
return nullptr;
}

if (!img)
{
*size = 0;
Expand Down Expand Up @@ -302,6 +362,11 @@ void f3d_image_to_terminal_text(f3d_image_t* img, void* stream)
//----------------------------------------------------------------------------
const char* f3d_image_to_terminal_text_string(f3d_image_t* img)
{
if (!img)
{
return nullptr;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
static std::string result;
result = cpp_img->toTerminalText();
Expand All @@ -311,13 +376,23 @@ const char* f3d_image_to_terminal_text_string(f3d_image_t* img)
//----------------------------------------------------------------------------
void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value)
{
if (!img || !key || !value)
{
return;
}

f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
cpp_img->setMetadata(key, value);
}

//----------------------------------------------------------------------------
const char* f3d_image_get_metadata(f3d_image_t* img, const char* key)
{
if (!img || !key)
{
return nullptr;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
static std::string result;

Expand All @@ -337,6 +412,17 @@ const char* f3d_image_get_metadata(f3d_image_t* img, const char* key)
//----------------------------------------------------------------------------
char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count)
{
if (!count)
{
return nullptr;
}

if (!img)
{
*count = 0;
return nullptr;
}

const f3d::image* cpp_img = reinterpret_cast<f3d::image*>(img);
std::vector<std::string> metadata_keys = cpp_img->allMetadata();
*count = metadata_keys.size();
Expand All @@ -352,6 +438,11 @@ char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count)
//----------------------------------------------------------------------------
void f3d_image_free_metadata_keys(char** keys, unsigned int count)
{
if (!keys)
{
return;
}

for (unsigned int i = 0; i < count; ++i)
{
delete[] keys[i];
Expand Down
Loading