78 lines
2.9 KiB
C++
78 lines
2.9 KiB
C++
#include "image.h"
|
|
|
|
#include <godot_cpp/core/class_db.hpp>
|
|
|
|
#include <godot_cpp/classes/global_constants.hpp>
|
|
|
|
#include <godot_cpp/variant/utility_functions.hpp>
|
|
|
|
using namespace godot;
|
|
|
|
void UltraleapImage::_bind_methods() {
|
|
ClassDB::bind_method(D_METHOD("get_data"), &UltraleapImage::get_data);
|
|
ClassDB::bind_method(D_METHOD("get_distortion_matrix"), &UltraleapImage::get_distortion_matrix);
|
|
ClassDB::bind_method(D_METHOD("get_matrix_version"), &UltraleapImage::get_matrix_version);
|
|
ClassDB::bind_method(D_METHOD("get_size"), &UltraleapImage::get_size);
|
|
}
|
|
|
|
void UltraleapImage::fill_images_data(Ref<UltraleapImage> left, Ref<UltraleapImage> right, const LEAP_IMAGE* images) {
|
|
left->size.x = images->properties.width;
|
|
left->size.y = images->properties.height;
|
|
|
|
right->size.x = (images + 1)->properties.width;
|
|
right->size.y = (images + 1)->properties.height;
|
|
|
|
if (images->data == nullptr) {
|
|
UtilityFunctions::print("Oops null pointer for the image");
|
|
return;
|
|
}
|
|
|
|
// We'll shove data 8 bytes by 8 bytes to go fast
|
|
PackedInt64Array temp_left = PackedInt64Array();
|
|
PackedInt64Array temp_right = PackedInt64Array();
|
|
|
|
// From there we'll assume that both images have the same number of pixels
|
|
uint32_t tot_pixels = left->size.x * left->size.y;
|
|
|
|
uint64_t* data_left = (uint64_t*)((uint8_t*)images->data + images->offset);
|
|
uint64_t* data_right = (uint64_t*)((uint8_t*)(images + 1)->data + (images + 1)->offset);
|
|
|
|
// Fill the data 8 bytes at a time
|
|
for (uint32_t i = 0; i < tot_pixels / 8; i++) {
|
|
uint64_t pixel_left = data_left[i];
|
|
uint64_t pixel_right = data_right[i];
|
|
temp_left.push_back(pixel_left);
|
|
temp_right.push_back(pixel_right);
|
|
}
|
|
|
|
left->data = temp_left.to_byte_array();
|
|
right->data = temp_right.to_byte_array();
|
|
|
|
// Check and store left image distortion matrix
|
|
if (left->matrix_version != images->matrix_version) {
|
|
left->matrix_version = images->matrix_version;
|
|
left->distortion_matrix.clear();
|
|
|
|
for (uint32_t i = 0; i < 64; i++) {
|
|
for (uint32_t j = 0; j < 64; j++) {
|
|
float x = images->distortion_matrix->matrix[i][j].x;
|
|
float y = 1.0 - images->distortion_matrix->matrix[i][j].y;
|
|
left->distortion_matrix.push_back(Vector2(x, y));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check and store left image distortion matrix
|
|
if (right->matrix_version != (images + 1)->matrix_version) {
|
|
right->matrix_version = (images + 1)->matrix_version;
|
|
right->distortion_matrix.clear();
|
|
|
|
for (uint32_t i = 0; i < 64; i++) {
|
|
for (uint32_t j = 0; j < 64; j++) {
|
|
float x = (images + 1)->distortion_matrix->matrix[i][j].x;
|
|
float y = 1.0 - (images + 1)->distortion_matrix->matrix[i][j].y;
|
|
right->distortion_matrix.push_back(Vector2(x, y));
|
|
}
|
|
}
|
|
}
|
|
} |