DUNZIP - decompress DZIP output to recover original data USAGE: M = dzip(Z) VARIABLES: Z = compressed variable to decompress M = decompressed output NOTES: (1) The input variable Z is created by the DZIP function and is a vector of type uint8 (2) The decompressed output will have the same data type and dimensions as the original data provided to DZIP. (3) See DZIP for other notes. (4) Carefully tested, but no warranty; use at your own risk. (5) Michael Kleder, Nov 2005
0001 function M = dunzip(Z) 0002 % DUNZIP - decompress DZIP output to recover original data 0003 % 0004 % USAGE: 0005 % M = dzip(Z) 0006 % 0007 % VARIABLES: 0008 % Z = compressed variable to decompress 0009 % M = decompressed output 0010 % 0011 % NOTES: (1) The input variable Z is created by the DZIP function and 0012 % is a vector of type uint8 0013 % (2) The decompressed output will have the same data type and 0014 % dimensions as the original data provided to DZIP. 0015 % (3) See DZIP for other notes. 0016 % (4) Carefully tested, but no warranty; use at your own risk. 0017 % (5) Michael Kleder, Nov 2005 0018 0019 import com.mathworks.mlwidgets.io.InterruptibleStreamCopier 0020 a=java.io.ByteArrayInputStream(Z); 0021 b=java.util.zip.InflaterInputStream(a); 0022 isc = InterruptibleStreamCopier.getInterruptibleStreamCopier; 0023 c = java.io.ByteArrayOutputStream; 0024 isc.copyStream(b,c); 0025 Q=typecast(c.toByteArray,'uint8'); 0026 cn = double(Q(1)); % class 0027 nd = double(Q(2)); % # dims 0028 s = typecast(Q(3:8*nd+2),'double')'; % size 0029 Q=Q(8*nd+3:end); 0030 if cn == 3 0031 M = logical(Q); 0032 elseif cn == 4 0033 M = char(Q); 0034 else 0035 ct = {'double','single','logical','char','int8','uint8',... 0036 'int16','uint16','int32','uint32','int64','uint64'}; 0037 M = typecast(Q,ct{cn}); 0038 end 0039 M=reshape(M,s); 0040 return