105 lines
2.4 KiB
C++
105 lines
2.4 KiB
C++
#include "./image.h"
|
|
|
|
#ifdef __cplusplus
|
|
#include <openMVG/image/image_io.hpp>
|
|
#include <openMVG/image/image_concat.hpp>
|
|
#endif // __ cplusplus
|
|
|
|
_FFI_PLUGIN
|
|
ImageResult *image_result_new(const u_char *data, const size_t data_len) {
|
|
ImageResult *r = (ImageResult *) malloc(sizeof(ImageResult));
|
|
r->data = (u_char *) calloc(sizeof(u_char), data_len);
|
|
memcpy(r->data, data, data_len * sizeof(u_char));
|
|
r->data_len = data_len;
|
|
r->error = 0;
|
|
return r;
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
ImageResult *image_result_new_error(const error_t err) {
|
|
ImageResult *r = (ImageResult *) malloc(sizeof(ImageResult));
|
|
r->data = NULL;
|
|
r->data_len = 0;
|
|
r->error = err;
|
|
return r;
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
void free_image_result(ImageResult *image_result) {
|
|
free(image_result->data);
|
|
free(image_result);
|
|
}
|
|
|
|
const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
|
|
{
|
|
Frame *f = (Frame *)malloc(sizeof(Frame));
|
|
f->stream = stream;
|
|
f->w = w;
|
|
f->h = h;
|
|
f->depth = depth;
|
|
return f;
|
|
}
|
|
|
|
FILE *make_buffer(const uint8_t *data, const size_t data_len)
|
|
{
|
|
FILE *file = fmemopen((void *)data, data_len, "r+");
|
|
|
|
if (file == NULL)
|
|
{
|
|
perror("Error opening file");
|
|
return NULL;
|
|
}
|
|
|
|
// Seek to the beginning of the file
|
|
rewind(file);
|
|
|
|
// Write the data to the file
|
|
fwrite(data, sizeof(uint8_t), data_len, file);
|
|
|
|
return file;
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
const Frame *
|
|
new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, int depth)
|
|
{
|
|
FILE *buf = make_buffer(data, data_len);
|
|
return new_frame_from_handle(buf, w, h, depth);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
ImageResult *Archimedes::get_image_data(const Frame *frame)
|
|
{
|
|
std::vector<unsigned char> imageData;
|
|
rewind(frame->stream);
|
|
if (!openMVG::image::ReadPngStream(frame->stream, &imageData, (int *)&(frame->w), (int *)&(frame->h), (int *)&(frame->depth))) {
|
|
printf("ERROR: Could not read stream!\n");
|
|
return image_result_new_error(1);
|
|
}
|
|
printf("Read %lu bytes.\n", imageData.size());
|
|
const unsigned char *data = imageData.data();
|
|
return image_result_new(data, imageData.size());
|
|
}
|
|
|
|
#endif
|
|
|
|
_FFI_PLUGIN
|
|
ImageResult *archimedes_get_image_data(const Frame *frame)
|
|
{
|
|
return Archimedes::get_image_data(frame);
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
int archimedes_images_to_sfm(const Frame **frames, size_t n_frames)
|
|
{
|
|
return Archimedes::images_to_sfm(frames, n_frames);
|
|
} |