Select Git revision
Press.m
Press.m 1.30 KiB
% Helper function called by NCD
% uses libbz2.dll to bzip Compress V1,V2
% Returns the size in bytes of the compressed data
%
function nBytes = Press(V1,V2)
persistent lib
if ~libisloaded('bzlib')
warning('off','MATLAB:loadlibrary:StructTypeExists');
warning('off','MATLAB:loadlibrary:parsewarnings');
warning('off','MATLAB:loadlibrary:TypeNotFoundForStructure');
thisFile=fileparts(mfilename('fullpath'));
path(path,fullfile(thisFile,'../../lib'));
if isunix
[nf,w]=loadlibrary('bzip2.so','bzlib.h','alias', 'bzlib');
else
loadlibrary bz2dll.dll bzlib.h alias bzlib
end
end
if iscell(V1)
V1=cell2mat(V1);
end
if iscell(V2)
V2=cell2mat(V2);
end
vv=combineString(V1,V2);
sz=length(vv(:));
dsz=sz+1024;
dest= mat2str(zeros(dsz,1));
pstr=libpointer('cstring', vv);
pdest=libpointer('cstring', dest);
pdsz = libpointer('uint32Ptr',dsz);
rval=calllib('bzlib', 'BZ2_bzBuffToBuffCompress', pdest,pdsz,vv,sz,9,0,30);
if rval
disp 'ACK! bad return from bzip'
rval
end
nBytes=double(get(pdsz, 'Value'));
function vv=combineString(V1,V2)
s1=prepareString(V1);
s2=prepareString(V2);
vv=[s1 ';' s2];
function s=prepareString(v)
if isempty(v)
s='';
return
end
if ischar(v)
s=v;
return
end
s=mat2str(v);
if length(v)>1
s=s(2:end-1);
end