Skip to content

Commit

Permalink
feat(graphics): add getframe, movie functions and double buffering
Browse files Browse the repository at this point in the history
- im2frame, frame2im functions
  • Loading branch information
Nelson-numerical-software committed Feb 27, 2025
1 parent ff80f3d commit 5e65c6a
Show file tree
Hide file tree
Showing 81 changed files with 1,341 additions and 50 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 1.13.0 (UNRELEASED)

### Added

- Double Buffering for Plots:

- Implementation of a double buffering mechanism to improve the smoothness and responsiveness of graphical plots.
- Significant reduction in flickering during graphic refresh.

- `getframe`: Capture axes or figure as movie frame.
- `movie`: Play recorded movie frames.
- `im2frame`: Convert image to movie frame.
- `frame2im`: Return image data associated with movie frame.
- `DevicePixelRatio`: property for figure.

- Example to connect ollama with Nelson
`edit([modulepath('webtools'), '/examples/ollama/readme.md'])`

### Changed

- `plot`: speed optimization: `tic();plot(rand(300,300), rand(300,300));toc()`
- fmtlib 11.1.3

## 1.12.0 (2025-02-16)
Expand Down
3 changes: 3 additions & 0 deletions CMake/C17Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ include(Clang-cxx-dev-tools)
# ==============================================================================
include(CheckCXXCompilerFlag)
# ==============================================================================
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# ==============================================================================
if("${CMAKE_CXX_COMPILE_FEATURES}" MATCHES "cxx_std_17")
set(CMAKE_CXX_STANDARD 17)
else()
Expand Down
5 changes: 2 additions & 3 deletions modules/engine/src/cpp/TimeoutThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ class WaitTimeout
start(uint64 _timeout_seconds)
{
_running = true;
std::chrono::nanoseconds begin_time
= std::chrono::high_resolution_clock::now().time_since_epoch();
std::chrono::nanoseconds begin_time = std::chrono::steady_clock::now().time_since_epoch();
bool bContinue = true;
do {
std::this_thread::sleep_for(std::chrono::milliseconds(uint64(1)));
std::chrono::nanoseconds current_time
= std::chrono::high_resolution_clock::now().time_since_epoch();
= std::chrono::steady_clock::now().time_since_epoch();
std::chrono::nanoseconds difftime = (current_time - begin_time);
bContinue = (difftime <= std::chrono::seconds(_timeout_seconds));
} while (bContinue && !_stop);
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/builtin/c/nlsGraphics_builtin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<ClCompile Include="..\cpp\axesBuiltin.cpp" />
<ClCompile Include="..\cpp\closeBuiltin.cpp" />
<ClCompile Include="..\cpp\drawnowBuiltin.cpp" />
<ClCompile Include="..\cpp\__getframe__Builtin.cpp" />
<ClCompile Include="..\cpp\GOConstructorHelpers.cpp" />
<ClCompile Include="..\cpp\copygraphicsBuiltin.cpp" />
<ClCompile Include="..\cpp\dllMain.cpp" />
Expand Down Expand Up @@ -270,6 +271,7 @@
<ClInclude Include="..\include\figureBuiltin.hpp" />
<ClInclude Include="..\include\gcaBuiltin.hpp" />
<ClInclude Include="..\include\gcfBuiltin.hpp" />
<ClInclude Include="..\include\__getframe__Builtin.hpp" />
<ClInclude Include="..\include\graphics_object_deleteBuiltin.hpp" />
<ClInclude Include="..\include\graphics_object_displayBuiltin.hpp" />
<ClInclude Include="..\include\graphics_object_eqBuiltin.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<ClCompile Include="..\cpp\waitforBuiltin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\cpp\__getframe__Builtin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\__image__Builtin.hpp">
Expand Down Expand Up @@ -246,6 +249,9 @@
<ClInclude Include="..\include\waitforBuiltin.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\__getframe__Builtin.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\etc\finish.m" />
Expand Down
5 changes: 4 additions & 1 deletion modules/graphics/builtin/cpp/GOConstructorHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ GOCommonConstructorHelper(GraphicsObject* fp, const ArrayOfVector& arg)
}

finalizeConstruction(fp);

GOFigure* fig = getCurrentGOFigure();
if (fig && !fig->isRenderingStateInvalid()) {
fig->setRenderingStateInvalid(true);
}
return thisHandle;
}
//=============================================================================
Expand Down
42 changes: 27 additions & 15 deletions modules/graphics/builtin/cpp/Gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "__zoom__Builtin.hpp"
#include "__pan__Builtin.hpp"
#include "__rotate3d__Builtin.hpp"
#include "__getframe__Builtin.hpp"
#include "uicontrolBuiltin.hpp"
#include "figureBuiltin.hpp"
#include "graphics_object_displayBuiltin.hpp"
Expand Down Expand Up @@ -53,19 +54,31 @@ using namespace Nelson;
//=============================================================================
const std::wstring gatewayName = L"graphics";
//=============================================================================
static const nlsGateway gateway[] = {
{ "__line__", (ptrBuiltin)Nelson::GraphicsGateway::__line__Builtin, -1, 1, CPP_BUILTIN },
{ "__text__", (ptrBuiltin)Nelson::GraphicsGateway::__text__Builtin, -1, 1, CPP_BUILTIN },
{ "__surf__", (ptrBuiltin)Nelson::GraphicsGateway::__surf__Builtin, -1, 1, CPP_BUILTIN },
{ "__image__", (ptrBuiltin)Nelson::GraphicsGateway::__image__Builtin, -1, 1, CPP_BUILTIN },
{ "__patch__", (ptrBuiltin)Nelson::GraphicsGateway::__patch__Builtin, -1, 1, CPP_BUILTIN },
{ "__contour__", (ptrBuiltin)Nelson::GraphicsGateway::__contour__Builtin, -1, 1, CPP_BUILTIN },
{ "__hggroup__", (ptrBuiltin)Nelson::GraphicsGateway::__hggroup__Builtin, -1, 1, CPP_BUILTIN },
{ "__view__", (ptrBuiltin)Nelson::GraphicsGateway::__view__Builtin, -1, 4, CPP_BUILTIN },
{ "__zoom__", (ptrBuiltin)Nelson::GraphicsGateway::__zoom__Builtin, -1, 2, CPP_BUILTIN },
{ "__pan__", (ptrBuiltin)Nelson::GraphicsGateway::__pan__Builtin, -1, 2, CPP_BUILTIN },
{ "__rotate3d__", (ptrBuiltin)Nelson::GraphicsGateway::__rotate3d__Builtin, -1, 2,
CPP_BUILTIN },
static const nlsGateway gateway[] = { { "__line__",
(ptrBuiltin)Nelson::GraphicsGateway::__line__Builtin, -1,
1, CPP_BUILTIN, NLS_OVERLOAD_AUTO_OFF },
{ "__text__", (ptrBuiltin)Nelson::GraphicsGateway::__text__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__surf__", (ptrBuiltin)Nelson::GraphicsGateway::__surf__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__image__", (ptrBuiltin)Nelson::GraphicsGateway::__image__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__patch__", (ptrBuiltin)Nelson::GraphicsGateway::__patch__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__contour__", (ptrBuiltin)Nelson::GraphicsGateway::__contour__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__hggroup__", (ptrBuiltin)Nelson::GraphicsGateway::__hggroup__Builtin, -1, 1, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__view__", (ptrBuiltin)Nelson::GraphicsGateway::__view__Builtin, -1, 4, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__zoom__", (ptrBuiltin)Nelson::GraphicsGateway::__zoom__Builtin, -1, 2, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__pan__", (ptrBuiltin)Nelson::GraphicsGateway::__pan__Builtin, -1, 2, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__rotate3d__", (ptrBuiltin)Nelson::GraphicsGateway::__rotate3d__Builtin, -1, 2, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
{ "__getframe__", (ptrBuiltin)Nelson::GraphicsGateway::__getframe__Builtin, -1, 2, CPP_BUILTIN,
NLS_OVERLOAD_AUTO_OFF },
//=============================================================================
{ OVERLOAD_FUNCTION_NAME(NLS_GO_HANDLE_STR, "display"),
(ptrBuiltin)Nelson::GraphicsGateway::graphics_object_displayBuiltin, 0, 2,
Expand Down Expand Up @@ -123,8 +136,7 @@ static const nlsGateway gateway[] = {
{ "waitforbuttonpress", (ptrBuiltin)Nelson::GraphicsGateway::waitforbuttonpressBuiltin, -1, 0,
CPP_BUILTIN },
{ "waitfor", (ptrBuiltin)Nelson::GraphicsGateway::waitforBuiltin, 0, 3,
CPP_BUILTIN_WITH_EVALUATOR }
};
CPP_BUILTIN_WITH_EVALUATOR } };
//=============================================================================
static bool
initializeGraphicsModule(Nelson::Evaluator* eval)
Expand Down
47 changes: 47 additions & 0 deletions modules/graphics/builtin/cpp/__getframe__Builtin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//=============================================================================
// Copyright (c) 2016-present Allan CORNET (Nelson)
//=============================================================================
// This file is part of the Nelson.
//=============================================================================
// LICENCE_BLOCK_BEGIN
// SPDX-License-Identifier: LGPL-3.0-or-later
// LICENCE_BLOCK_END
//=============================================================================
#include "__getframe__Builtin.hpp"
#include "GOWindow.hpp"
#include "GOHelpers.hpp"
#include "GOFiguresManager.hpp"
#include "Error.hpp"
#include "i18n.hpp"
#include "GetFrame.hpp"
#include "InputOutputArgumentsCheckers.hpp"
//=============================================================================
using namespace Nelson;
//=============================================================================
namespace Nelson::GraphicsGateway {
//=============================================================================
ArrayOfVector
__getframe__Builtin(int nLhs, const ArrayOfVector& argIn)
{
nargincheck(argIn, 1, 2);
nargoutcheck(nLhs, 0, 1);

if (!argIn[0].isGraphicsObject()) {
Error(_W("Expected graphics object."));
}
nelson_handle* gobject = (nelson_handle*)(argIn[0].getDataPointer());
if (isDeletedGraphicsObject(gobject[0])) {
Error(_W("Valid graphics object expected."));
}

if (gobject[0] == HANDLE_ROOT_OBJECT || gobject[0] >= HANDLE_OFFSET_OBJECT) {
Error("figure object expected.");
}
GOWindow* goWindow = getFigure(gobject[0]);
ArrayOfVector retval;
retval << GetFrame(goWindow);
return retval;
}
//=============================================================================
}
//=============================================================================
1 change: 1 addition & 0 deletions modules/graphics/builtin/cpp/__view__Builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ __view__Builtin(int nLhs, const ArrayOfVector& argIn)
GOAxis* axis = (GOAxis*)fp;
if (argIn.size() >= 2) {
axis->setView(azimuth, elevation);
axis->getParentFigure()->setRenderingStateInvalid(true);
axis->updateState();
}

Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/builtin/cpp/axesBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ axesBuiltin(int nLhs, const ArrayOfVector& argIn)
GO_Z_LIM_MODE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_AUTO_STR);
}
ArrayOfVector retval;
fig->setRenderingStateInvalid(true);
retval << ArrayOf::graphicsObjectConstructor(handle);
return retval;
}
Expand All @@ -99,6 +100,7 @@ axesBuiltin(int nLhs, const ArrayOfVector& argIn)
}
children.insert(children.begin(), 1, handle);
cp->data(children);
fig->setRenderingStateInvalid(true);
fig->repaint();
return ArrayOfVector();
}
Expand Down
1 change: 1 addition & 0 deletions modules/graphics/builtin/cpp/copygraphicsBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ copygraphicsBuiltin(int nLhs, const ArrayOfVector& argIn)
if (!f) {
Error(_W("Invalid handle."));
}
f->getGOFigure()->setRenderingStateInvalid(true);
QClipboard* cb = QApplication::clipboard();
cb->setPixmap(f->getMainQWigdet()->grab());
return retval;
Expand Down
2 changes: 1 addition & 1 deletion modules/graphics/builtin/cpp/figureBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ figureBuiltin(int nLhs, const ArrayOfVector& argIn)
if (goCallback) {
goCallback->executeNow(fig);
}

fig->setRenderingStateInvalid(true);
return retval;
}
//=============================================================================
Expand Down
1 change: 1 addition & 0 deletions modules/graphics/builtin/cpp/gcaBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gcaBuiltin(int nLhs, const ArrayOfVector& argIn)
ArrayOfVector arg2;
axesBuiltin(0, arg2);
current = fig->findGoProperty(GO_CURRENT_AXES_PROPERTY_NAME_STR);
fig->setRenderingStateInvalid(true);
}
retval << ArrayOf::graphicsObjectConstructor(current);
return retval;
Expand Down
5 changes: 5 additions & 0 deletions modules/graphics/builtin/cpp/gcfBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "gcfBuiltin.hpp"
#include "GOFiguresManager.hpp"
#include "InputOutputArgumentsCheckers.hpp"
#include "GOHelpers.hpp"
//=============================================================================
namespace Nelson::GraphicsGateway {
//=============================================================================
Expand All @@ -28,6 +29,10 @@ gcfBuiltin(int nLhs, const ArrayOfVector& argIn)
currentFigureID = figs.back();
}
}
GOFigure* fig = findGOFigure(currentFigureID);
if (fig) {
fig->setRenderingStateInvalid(true);
}
retval << ArrayOf::graphicsObjectConstructor(currentFigureID);
return retval;
}
Expand Down
3 changes: 3 additions & 0 deletions modules/graphics/builtin/cpp/graphics_object_setBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "GOHelpers.hpp"
#include "GORoot.hpp"
#include "InputOutputArgumentsCheckers.hpp"
#include "GOFiguresManager.hpp"
//=============================================================================
namespace Nelson::GraphicsGateway {
//=============================================================================
Expand Down Expand Up @@ -77,10 +78,12 @@ graphics_object_setBuiltin(int nLhs, const ArrayOfVector& argIn)
&& !fp->isType(GO_PROPERTY_VALUE_UICONTROL_STR)) {
GOFigure* fig = fp->getParentFigure();
if (fig) {
fig->setRenderingStateInvalid(true);
fig->repaint();
}
}
}

return ArrayOfVector();
}
//=============================================================================
Expand Down
20 changes: 20 additions & 0 deletions modules/graphics/builtin/include/__getframe__Builtin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//=============================================================================
// Copyright (c) 2016-present Allan CORNET (Nelson)
//=============================================================================
// This file is part of the Nelson.
//=============================================================================
// LICENCE_BLOCK_BEGIN
// SPDX-License-Identifier: LGPL-3.0-or-later
// LICENCE_BLOCK_END
//=============================================================================
#pragma once
//=============================================================================
#include "ArrayOf.hpp"
//=============================================================================
namespace Nelson::GraphicsGateway {
//=============================================================================
ArrayOfVector
__getframe__Builtin(int nLhs, const ArrayOfVector& argIn);
//=============================================================================
}
//=============================================================================
Binary file added modules/graphics/examples/movie/dance_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/dance_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions modules/graphics/examples/movie/demo_movie.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%=============================================================================
% Copyright (c) 2016-present Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
clear('M');
movie_directory = fileparts(mfilename('fullpathext'));
figure('Position', [0 50 806 530]);

% Define sequences and number of frames
sequences = {'dance', 8; 'leap', 9; 'run', 8};
nb_frames = sum([sequences{:,2}]);

% Initialize the structure M
M(nb_frames) = struct('cdata', [], 'colormap', []);

L = 1;
for s = 1:size(sequences, 1)
action = sequences{s, 1};
nb_frames_action = sequences{s, 2};

for i = 1:nb_frames_action
% Construct the filename for the current frame
filename = fullfile(movie_directory, sprintf('%s_%d.png', action, i));

% Read the image and store it in the movie structure
M(L).cdata = imread(filename);
L = L + 1;
end
end

% Play the movie 5 times
movie(M, 5);
Binary file added modules/graphics/examples/movie/leap_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/leap_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions modules/graphics/examples/movie/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
images from https://furiirakun.com/
https://furiirakun.com/aboutlicense

Free to use, Free to share.
Binary file added modules/graphics/examples/movie/run_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/graphics/examples/movie/run_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions modules/graphics/functions/frame2im.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%=============================================================================
% Copyright (c) 2016-present Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
function varargout = frame2im(varargin)
% RGB = frame2im(F)
% [X, map] = frame2im(F)
narginchk(1, 1);
nargoutchk(0, 2);
F = varargin{1};
mustBeA(varargin{1}, 'struct');
if (~isequal(fieldnames(F), {'cdata';'colormap'}))
error('Nelson:frame2im:invalidInput', _('Invalid structure fields.'));
end
n = numel(F);
X = [];
map = [];
if (n > 0)
x = [F.cdata];
map(1) = F(1).colormap;
end
varargout{1} = x;
if nargout > 1
varargout{2} = map;
end
end
%=============================================================================
Loading

0 comments on commit 5e65c6a

Please sign in to comment.