How can i create a pointer for more than one array?

3 views (last 30 days)
Hello,
i want to call a function from my DLL which includes a pointer to an array. In my case the array size is 1920x1080, an image.
When i execute the DLL function, it transfers the array (image data) to the hardware memory.
pic = imread('Test.png');
pic = rgb2gray(pic);
pic = fliplr(pic)';
imwrite(pic,'pic.png');
UserArray = uint8(pic);
UserArrayPtr = libpointer('voidPtr',UserArray); % Pointer
[STATUS_ALP_SEQ_PUT, ~] = calllib('alp4395','AlpSeqPut', ALP_ID, SequenceID, PicOffset, PicLoad, UserArrayPtr);
This is working fine!
But how can i create a pointer which contains more than one image?
I tried:
  • Execute "calllib" in loop (didnt work)
  • Create a n x m cell fur UserArray (didnt work)
I'm really helpness right now and i dont know how to solve this problem. I hope someone can help me!

Answers (1)

Deepak
Deepak on 3 Dec 2024
To pass multiple images to the DLL function using a pointer, we need to ensure that the images are stored sequentially in memory. This means creating a single large array that contains all the images one after the other.
First, read and prepare each image by converting them to grayscale and transpose as needed. Then, combine all images into a single array and create a pointer to this large array. Finally, call the DLL function with the pointer.
Below is the sample MATLAB code to achieve the same:
% Assume you have a list of image filenames
imageFiles = {'Test1.png', 'Test2.png', 'Test3.png'};
numImages = length(imageFiles);
% Initialize an array to hold all images
% Assuming each image is 1920x1080
imageHeight = 1080;
imageWidth = 1920;
allImages = zeros(imageHeight, imageWidth, numImages, 'uint8');
% Read and process each image
for i = 1:numImages
pic = imread(imageFiles{i});
pic = rgb2gray(pic);
pic = fliplr(pic)';
allImages(:,:,i) = pic;
end
% Reshape the 3D array into a 2D array (concatenating images)
allImages = reshape(allImages, imageHeight * imageWidth * numImages, 1);
% Create a pointer to the concatenated image data
UserArrayPtr = libpointer('voidPtr', allImages);
% Call the DLL function
% Loop over each image if necessary, or modify the DLL function to handle multiple images
for i = 1:numImages
offset = (i - 1) * imageHeight * imageWidth;
[STATUS_ALP_SEQ_PUT, ~] = calllib('alp4395', 'AlpSeqPut', ALP_ID, SequenceID, PicOffset + offset, PicLoad, UserArrayPtr);
end
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!