|
33 | 33 | if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
|
34 | 34 | output = zmat(varargin{1}, 0, 'base64');
|
35 | 35 | return
|
36 |
| -elseif (isoctavemesh) |
37 |
| - which('matlab.net.base64decode'); |
38 |
| - if (~isempty(which('matlab.net.base64decode'))) |
39 |
| - output = matlab.net.base64decode(varargin{1}); |
40 |
| - else |
41 |
| - error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave'); |
| 36 | +end |
| 37 | + |
| 38 | +jvmerr = javachk('jvm'); |
| 39 | + |
| 40 | +if (isoctavemesh || isempty(jvmerr)) |
| 41 | + map = uint8(zeros(1, 256) + 65); |
| 42 | + map(uint8(['A':'Z', 'a':'z', '0':'9', '+/='])) = 0:64; |
| 43 | + map(uint8('-_')) = 62:63; |
| 44 | + x = map(varargin{1}(:)); |
| 45 | + |
| 46 | + x(x > 64) = []; % remove non-base64 chars |
| 47 | + x(x == 64) = []; % remove padding characters |
| 48 | + |
| 49 | + nebytes = length(x); |
| 50 | + nchunks = ceil(nebytes / 4); |
| 51 | + if rem(nebytes, 4) > 0 |
| 52 | + x(end + 1:4 * nchunks) = 0; |
42 | 53 | end
|
| 54 | + x = reshape(uint8(x), 4, nchunks); |
| 55 | + output = repmat(uint8(0), 3, nchunks); |
| 56 | + |
| 57 | + output(1, :) = bitshift(x(1, :), 2); |
| 58 | + output(1, :) = bitor(output(1, :), bitshift(x(2, :), -4)); |
| 59 | + output(2, :) = bitshift(x(2, :), 4); |
| 60 | + output(2, :) = bitor(output(2, :), bitshift(x(3, :), -2)); |
| 61 | + output(3, :) = bitshift(x(3, :), 6); |
| 62 | + output(3, :) = bitor(output(3, :), x(4, :)); |
| 63 | + |
| 64 | + switch rem(nebytes, 4) |
| 65 | + case 2 |
| 66 | + output = output(1:end - 2); |
| 67 | + case 3 |
| 68 | + output = output(1:end - 1); |
| 69 | + end |
| 70 | + output = output(:)'; |
| 71 | + return |
43 | 72 | end
|
44 | 73 |
|
45 |
| -error(javachk('jvm')); |
| 74 | +error(jvmerr); |
46 | 75 |
|
47 | 76 | if (ischar(varargin{1}))
|
48 | 77 | varargin{1} = uint8(varargin{1});
|
|
0 commit comments